mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
python 2.4 stuff
This commit is contained in:
parent
8277b718b9
commit
b3fa4b906c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,484 +1,497 @@
|
|||||||
// Filename: interfaceMakerPythonSimple.cxx
|
// Filename: interfaceMakerPythonSimple.cxx
|
||||||
// Created by: drose (01Oct01)
|
// Created by: drose (01Oct01)
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// PANDA 3D SOFTWARE
|
// PANDA 3D SOFTWARE
|
||||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||||
//
|
//
|
||||||
// All use of this software is subject to the terms of the Panda 3d
|
// All use of this software is subject to the terms of the Panda 3d
|
||||||
// Software license. You should have received a copy of this license
|
// Software license. You should have received a copy of this license
|
||||||
// along with this source code; you will also find a current copy of
|
// along with this source code; you will also find a current copy of
|
||||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||||
//
|
//
|
||||||
// To contact the maintainers of this program write to
|
// To contact the maintainers of this program write to
|
||||||
// panda3d-general@lists.sourceforge.net .
|
// panda3d-general@lists.sourceforge.net .
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "interfaceMakerPythonSimple.h"
|
#include "interfaceMakerPythonSimple.h"
|
||||||
#include "interrogateBuilder.h"
|
#include "interrogateBuilder.h"
|
||||||
#include "interrogate.h"
|
#include "interrogate.h"
|
||||||
#include "functionRemap.h"
|
#include "functionRemap.h"
|
||||||
#include "parameterRemapUnchanged.h"
|
#include "parameterRemapUnchanged.h"
|
||||||
#include "typeManager.h"
|
#include "typeManager.h"
|
||||||
|
|
||||||
#include "interrogateDatabase.h"
|
#include "interrogateDatabase.h"
|
||||||
#include "interrogateType.h"
|
#include "interrogateType.h"
|
||||||
#include "interrogateFunction.h"
|
#include "interrogateFunction.h"
|
||||||
#include "cppFunctionType.h"
|
#include "cppFunctionType.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::Constructor
|
// Function: InterfaceMakerPythonSimple::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
InterfaceMakerPythonSimple::
|
InterfaceMakerPythonSimple::
|
||||||
InterfaceMakerPythonSimple(InterrogateModuleDef *def) :
|
InterfaceMakerPythonSimple(InterrogateModuleDef *def) :
|
||||||
InterfaceMakerPython(def)
|
InterfaceMakerPython(def)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::Destructor
|
// Function: InterfaceMakerPythonSimple::Destructor
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
InterfaceMakerPythonSimple::
|
InterfaceMakerPythonSimple::
|
||||||
~InterfaceMakerPythonSimple() {
|
~InterfaceMakerPythonSimple() {
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::write_prototypes
|
// Function: InterfaceMakerPythonSimple::write_prototypes
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
// Description: Generates the list of function prototypes
|
// Description: Generates the list of function prototypes
|
||||||
// corresponding to the functions that will be output in
|
// corresponding to the functions that will be output in
|
||||||
// write_functions().
|
// write_functions().
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::
|
void InterfaceMakerPythonSimple::
|
||||||
write_prototypes(ostream &out,ostream *out_h) {
|
write_prototypes(ostream &out,ostream *out_h) {
|
||||||
Functions::iterator fi;
|
Functions::iterator fi;
|
||||||
for (fi = _functions.begin(); fi != _functions.end(); ++fi) {
|
for (fi = _functions.begin(); fi != _functions.end(); ++fi) {
|
||||||
Function *func = (*fi);
|
Function *func = (*fi);
|
||||||
write_prototype_for(out, func);
|
write_prototype_for(out, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "\n";
|
out << "\n";
|
||||||
InterfaceMakerPython::write_prototypes(out,out_h);
|
InterfaceMakerPython::write_prototypes(out,out_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::write_functions
|
// Function: InterfaceMakerPythonSimple::write_functions
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
// Description: Generates the list of functions that are appropriate
|
// Description: Generates the list of functions that are appropriate
|
||||||
// for this interface. This function is called *before*
|
// for this interface. This function is called *before*
|
||||||
// write_prototypes(), above.
|
// write_prototypes(), above.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::
|
void InterfaceMakerPythonSimple::
|
||||||
write_functions(ostream &out) {
|
write_functions(ostream &out) {
|
||||||
Functions::iterator fi;
|
Functions::iterator fi;
|
||||||
for (fi = _functions.begin(); fi != _functions.end(); ++fi) {
|
for (fi = _functions.begin(); fi != _functions.end(); ++fi) {
|
||||||
Function *func = (*fi);
|
Function *func = (*fi);
|
||||||
write_function_for(out, func);
|
write_function_for(out, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
InterfaceMakerPython::write_functions(out);
|
InterfaceMakerPython::write_functions(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::write_module
|
// Function: InterfaceMakerPythonSimple::write_module
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
// Description: Generates whatever additional code is required to
|
// Description: Generates whatever additional code is required to
|
||||||
// support a module file.
|
// support a module file.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::
|
void InterfaceMakerPythonSimple::
|
||||||
write_module(ostream &out,ostream *out_h, InterrogateModuleDef *def) {
|
write_module(ostream &out,ostream *out_h, InterrogateModuleDef *def) {
|
||||||
InterfaceMakerPython::write_module(out,out_h, def);
|
InterfaceMakerPython::write_module(out,out_h, def);
|
||||||
|
|
||||||
out << "static PyMethodDef python_simple_funcs[] = {\n";
|
out << "static PyMethodDef python_simple_funcs[] = {\n";
|
||||||
|
|
||||||
Functions::iterator fi;
|
Functions::iterator fi;
|
||||||
for (fi = _functions.begin(); fi != _functions.end(); ++fi) {
|
for (fi = _functions.begin(); fi != _functions.end(); ++fi) {
|
||||||
Function *func = (*fi);
|
Function *func = (*fi);
|
||||||
Function::Remaps::const_iterator ri;
|
Function::Remaps::const_iterator ri;
|
||||||
for (ri = func->_remaps.begin(); ri != func->_remaps.end(); ++ri) {
|
for (ri = func->_remaps.begin(); ri != func->_remaps.end(); ++ri) {
|
||||||
FunctionRemap *remap = (*ri);
|
FunctionRemap *remap = (*ri);
|
||||||
out << " { \"" << remap->_reported_name << "\", &"
|
out << " { \"" << remap->_reported_name << "\", &"
|
||||||
<< remap->_wrapper_name << ", METH_VARARGS },\n";
|
<< remap->_wrapper_name << ", METH_VARARGS },\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out << " { NULL, NULL }\n"
|
out << " { NULL, NULL }\n"
|
||||||
<< "};\n\n"
|
<< "};\n\n"
|
||||||
|
|
||||||
<< "#ifdef _WIN32\n"
|
<< "#ifdef _WIN32\n"
|
||||||
<< "extern \"C\" __declspec(dllexport) void init" << def->library_name << "();\n"
|
<< "extern \"C\" __declspec(dllexport) void init" << def->library_name << "();\n"
|
||||||
<< "#else\n"
|
<< "#else\n"
|
||||||
<< "extern \"C\" void init" << def->library_name << "();\n"
|
<< "extern \"C\" void init" << def->library_name << "();\n"
|
||||||
<< "#endif\n\n"
|
<< "#endif\n\n"
|
||||||
|
|
||||||
<< "void init" << def->library_name << "() {\n"
|
<< "void init" << def->library_name << "() {\n"
|
||||||
<< " Py_InitModule(\"" << def->library_name
|
<< " Py_InitModule(\"" << def->library_name
|
||||||
<< "\", python_simple_funcs);\n"
|
<< "\", python_simple_funcs);\n"
|
||||||
<< "}\n\n";
|
<< "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::synthesize_this_parameter
|
// Function: InterfaceMakerPythonSimple::synthesize_this_parameter
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
// Description: This method should be overridden and redefined to
|
// Description: This method should be overridden and redefined to
|
||||||
// return true for interfaces that require the implicit
|
// return true for interfaces that require the implicit
|
||||||
// "this" parameter, if present, to be passed as the
|
// "this" parameter, if present, to be passed as the
|
||||||
// first parameter to any wrapper functions.
|
// first parameter to any wrapper functions.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool InterfaceMakerPythonSimple::
|
bool InterfaceMakerPythonSimple::
|
||||||
synthesize_this_parameter() {
|
synthesize_this_parameter() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::get_wrapper_prefix
|
// Function: InterfaceMakerPythonSimple::get_wrapper_prefix
|
||||||
// Access: Protected, Virtual
|
// Access: Protected, Virtual
|
||||||
// Description: Returns the prefix string used to generate wrapper
|
// Description: Returns the prefix string used to generate wrapper
|
||||||
// function names.
|
// function names.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
string InterfaceMakerPythonSimple::
|
string InterfaceMakerPythonSimple::
|
||||||
get_wrapper_prefix() {
|
get_wrapper_prefix() {
|
||||||
return "_inP";
|
return "_inP";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::get_unique_prefix
|
// Function: InterfaceMakerPythonSimple::get_unique_prefix
|
||||||
// Access: Protected, Virtual
|
// Access: Protected, Virtual
|
||||||
// Description: Returns the prefix string used to generate unique
|
// Description: Returns the prefix string used to generate unique
|
||||||
// symbolic names, which are not necessarily C-callable
|
// symbolic names, which are not necessarily C-callable
|
||||||
// function names.
|
// function names.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
string InterfaceMakerPythonSimple::
|
string InterfaceMakerPythonSimple::
|
||||||
get_unique_prefix() {
|
get_unique_prefix() {
|
||||||
return "p";
|
return "p";
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::record_function_wrapper
|
// Function: InterfaceMakerPythonSimple::record_function_wrapper
|
||||||
// Access: Protected, Virtual
|
// Access: Protected, Virtual
|
||||||
// Description: Associates the function wrapper with its function in
|
// Description: Associates the function wrapper with its function in
|
||||||
// the appropriate structures in the database.
|
// the appropriate structures in the database.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::
|
void InterfaceMakerPythonSimple::
|
||||||
record_function_wrapper(InterrogateFunction &ifunc,
|
record_function_wrapper(InterrogateFunction &ifunc,
|
||||||
FunctionWrapperIndex wrapper_index) {
|
FunctionWrapperIndex wrapper_index) {
|
||||||
ifunc._python_wrappers.push_back(wrapper_index);
|
ifunc._python_wrappers.push_back(wrapper_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::write_prototype_for
|
// Function: InterfaceMakerPythonSimple::write_prototype_for
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Writes the prototype for the indicated function.
|
// Description: Writes the prototype for the indicated function.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::
|
void InterfaceMakerPythonSimple::
|
||||||
write_prototype_for(ostream &out, InterfaceMaker::Function *func) {
|
write_prototype_for(ostream &out, InterfaceMaker::Function *func) {
|
||||||
Function::Remaps::const_iterator ri;
|
Function::Remaps::const_iterator ri;
|
||||||
|
|
||||||
for (ri = func->_remaps.begin(); ri != func->_remaps.end(); ++ri) {
|
for (ri = func->_remaps.begin(); ri != func->_remaps.end(); ++ri) {
|
||||||
FunctionRemap *remap = (*ri);
|
FunctionRemap *remap = (*ri);
|
||||||
if (!output_function_names) {
|
if (!output_function_names) {
|
||||||
// If we're not saving the function names, don't export it from
|
// If we're not saving the function names, don't export it from
|
||||||
// the library.
|
// the library.
|
||||||
out << "static ";
|
out << "static ";
|
||||||
} else {
|
} else {
|
||||||
out << "extern \"C\" ";
|
out << "extern \"C\" ";
|
||||||
}
|
}
|
||||||
out << "PyObject *"
|
out << "PyObject *"
|
||||||
<< remap->_wrapper_name << "(PyObject *self, PyObject *args);\n";
|
<< remap->_wrapper_name << "(PyObject *self, PyObject *args);\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::write_function_for
|
// Function: InterfaceMakerPythonSimple::write_function_for
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Writes the definition for a function that will call
|
// Description: Writes the definition for a function that will call
|
||||||
// the indicated C++ function or method.
|
// the indicated C++ function or method.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::
|
void InterfaceMakerPythonSimple::
|
||||||
write_function_for(ostream &out, InterfaceMaker::Function *func) {
|
write_function_for(ostream &out, InterfaceMaker::Function *func) {
|
||||||
Function::Remaps::const_iterator ri;
|
Function::Remaps::const_iterator ri;
|
||||||
|
|
||||||
for (ri = func->_remaps.begin(); ri != func->_remaps.end(); ++ri) {
|
for (ri = func->_remaps.begin(); ri != func->_remaps.end(); ++ri) {
|
||||||
FunctionRemap *remap = (*ri);
|
FunctionRemap *remap = (*ri);
|
||||||
write_function_instance(out, func, remap);
|
write_function_instance(out, func, remap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: InterfaceMakerPythonSimple::write_function_instance
|
// Function: InterfaceMakerPythonSimple::write_function_instance
|
||||||
// Access: Private
|
// Access: Private
|
||||||
// Description: Writes out the particular function that handles a
|
// Description: Writes out the particular function that handles a
|
||||||
// single instance of an overloaded function.
|
// single instance of an overloaded function.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void InterfaceMakerPythonSimple::write_function_instance(ostream &out, InterfaceMaker::Function *func,
|
void InterfaceMakerPythonSimple::write_function_instance(ostream &out, InterfaceMaker::Function *func,
|
||||||
FunctionRemap *remap) {
|
FunctionRemap *remap) {
|
||||||
out << "/*\n"
|
out << "/*\n"
|
||||||
<< " * Python simple wrapper for\n"
|
<< " * Python simple wrapper for\n"
|
||||||
<< " * ";
|
<< " * ";
|
||||||
remap->write_orig_prototype(out, 0);
|
remap->write_orig_prototype(out, 0);
|
||||||
out << "\n"
|
out << "\n"
|
||||||
<< " */\n";
|
<< " */\n";
|
||||||
|
|
||||||
if (!output_function_names) {
|
if (!output_function_names) {
|
||||||
// If we're not saving the function names, don't export it from
|
// If we're not saving the function names, don't export it from
|
||||||
// the library.
|
// the library.
|
||||||
out << "static ";
|
out << "static ";
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "PyObject *\n"
|
out << "PyObject *\n"
|
||||||
<< remap->_wrapper_name << "(PyObject *, PyObject *args) {\n";
|
<< remap->_wrapper_name << "(PyObject *, PyObject *args) {\n";
|
||||||
|
|
||||||
if (generate_spam) {
|
if (generate_spam) {
|
||||||
write_spam_message(out, remap);
|
write_spam_message(out, remap);
|
||||||
}
|
}
|
||||||
|
|
||||||
string format_specifiers;
|
string format_specifiers;
|
||||||
string parameter_list;
|
string parameter_list;
|
||||||
string container;
|
string container;
|
||||||
vector_string pexprs;
|
vector_string pexprs;
|
||||||
string extra_convert;
|
string extra_convert;
|
||||||
string extra_param_check;
|
string extra_param_check;
|
||||||
string extra_cleanup;
|
string extra_cleanup;
|
||||||
|
|
||||||
// Make one pass through the parameter list. We will output a
|
// Make one pass through the parameter list. We will output a
|
||||||
// one-line temporary variable definition for each parameter, while
|
// one-line temporary variable definition for each parameter, while
|
||||||
// simultaneously building the ParseTuple() function call and also
|
// simultaneously building the ParseTuple() function call and also
|
||||||
// the parameter expression list for call_function().
|
// the parameter expression list for call_function().
|
||||||
|
|
||||||
int pn;
|
int pn;
|
||||||
for (pn = 0; pn < (int)remap->_parameters.size(); pn++) {
|
for (pn = 0; pn < (int)remap->_parameters.size(); ++pn) {
|
||||||
indent(out, 2);
|
indent(out, 2);
|
||||||
CPPType *orig_type = remap->_parameters[pn]._remap->get_orig_type();
|
CPPType *orig_type = remap->_parameters[pn]._remap->get_orig_type();
|
||||||
CPPType *type = remap->_parameters[pn]._remap->get_new_type();
|
CPPType *type = remap->_parameters[pn]._remap->get_new_type();
|
||||||
string param_name = remap->get_parameter_name(pn);
|
string param_name = remap->get_parameter_name(pn);
|
||||||
|
|
||||||
// This is the string to convert our local variable to the
|
// This is the string to convert our local variable to the
|
||||||
// appropriate C++ type. Normally this is just a cast.
|
// appropriate C++ type. Normally this is just a cast.
|
||||||
string pexpr_string =
|
string pexpr_string =
|
||||||
"(" + type->get_local_name(&parser) + ")" + param_name;
|
"(" + type->get_local_name(&parser) + ")" + param_name;
|
||||||
|
|
||||||
if (remap->_parameters[pn]._remap->new_type_is_atomic_string()) {
|
if (remap->_parameters[pn]._remap->new_type_is_atomic_string()) {
|
||||||
if (TypeManager::is_char_pointer(orig_type)) {
|
if (TypeManager::is_char_pointer(orig_type)) {
|
||||||
out << "char *" << param_name;
|
out << "char *" << param_name;
|
||||||
format_specifiers += "s";
|
format_specifiers += "s";
|
||||||
parameter_list += ", &" + param_name;
|
parameter_list += ", &" + param_name;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
out << "char *" << param_name
|
out << "char *" << param_name
|
||||||
<< "_str; int " << param_name << "_len";
|
<< "_str; int " << param_name << "_len";
|
||||||
format_specifiers += "s#";
|
format_specifiers += "s#";
|
||||||
parameter_list += ", &" + param_name
|
parameter_list += ", &" + param_name
|
||||||
+ "_str, &" + param_name + "_len";
|
+ "_str, &" + param_name + "_len";
|
||||||
pexpr_string = "basic_string<char>(" +
|
pexpr_string = "basic_string<char>(" +
|
||||||
param_name + "_str, " +
|
param_name + "_str, " +
|
||||||
param_name + "_len)";
|
param_name + "_len)";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (TypeManager::is_bool(type)) {
|
} else if (TypeManager::is_bool(type)) {
|
||||||
out << "PyObject *" << param_name;
|
out << "PyObject *" << param_name;
|
||||||
format_specifiers += "O";
|
format_specifiers += "O";
|
||||||
parameter_list += ", &" + param_name;
|
parameter_list += ", &" + param_name;
|
||||||
pexpr_string = "(PyObject_IsTrue(" + param_name + ")!=0)";
|
pexpr_string = "(PyObject_IsTrue(" + param_name + ")!=0)";
|
||||||
|
|
||||||
} else if (TypeManager::is_unsigned_longlong(type)) {
|
} else if (TypeManager::is_unsigned_longlong(type)) {
|
||||||
out << "PyObject *" << param_name;
|
out << "PyObject *" << param_name;
|
||||||
format_specifiers += "O";
|
format_specifiers += "O";
|
||||||
parameter_list += ", &" + param_name;
|
parameter_list += ", &" + param_name;
|
||||||
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
||||||
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
||||||
pexpr_string = "PyLong_AsUnsignedLongLong(" + param_name + "_long)";
|
pexpr_string = "PyLong_AsUnsignedLongLong(" + param_name + "_long)";
|
||||||
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
||||||
|
|
||||||
} else if (TypeManager::is_longlong(type)) {
|
} else if (TypeManager::is_longlong(type)) {
|
||||||
out << "PyObject *" << param_name;
|
out << "PyObject *" << param_name;
|
||||||
format_specifiers += "O";
|
format_specifiers += "O";
|
||||||
parameter_list += ", &" + param_name;
|
parameter_list += ", &" + param_name;
|
||||||
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
extra_convert += " PyObject *" + param_name + "_long = PyNumber_Long(" + param_name + ");";
|
||||||
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
extra_param_check += "|| (" + param_name + "_long == NULL)";
|
||||||
pexpr_string = "PyLong_AsLongLong(" + param_name + "_long)";
|
pexpr_string = "PyLong_AsLongLong(" + param_name + "_long)";
|
||||||
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
extra_cleanup += " Py_XDECREF(" + param_name + "_long);";
|
||||||
|
|
||||||
} else if (TypeManager::is_integer(type)) {
|
#ifndef USE_PYTHON_2_2_OR_EARLIER
|
||||||
out << "int " << param_name;
|
} else if (TypeManager::is_unsigned_integer(type)) {
|
||||||
format_specifiers += "i";
|
out << "unsigned int " << param_name;
|
||||||
parameter_list += ", &" + param_name;
|
format_specifiers += "I"; // This requires Python 2.3 or better
|
||||||
|
parameter_list += ", &" + param_name;
|
||||||
} else if (TypeManager::is_float(type)) {
|
#endif
|
||||||
out << "double " << param_name;
|
|
||||||
format_specifiers += "d";
|
} else if (TypeManager::is_integer(type)) {
|
||||||
parameter_list += ", &" + param_name;
|
out << "int " << param_name;
|
||||||
|
format_specifiers += "i";
|
||||||
} else if (TypeManager::is_char_pointer(type)) {
|
parameter_list += ", &" + param_name;
|
||||||
out << "char *" << param_name;
|
|
||||||
format_specifiers += "s";
|
} else if (TypeManager::is_float(type)) {
|
||||||
parameter_list += ", &" + param_name;
|
out << "double " << param_name;
|
||||||
|
format_specifiers += "d";
|
||||||
} else if (TypeManager::is_pointer_to_PyObject(type)) {
|
parameter_list += ", &" + param_name;
|
||||||
out << "PyObject *" << param_name;
|
|
||||||
format_specifiers += "O";
|
} else if (TypeManager::is_char_pointer(type)) {
|
||||||
parameter_list += ", &" + param_name;
|
out << "char *" << param_name;
|
||||||
pexpr_string = param_name;
|
format_specifiers += "s";
|
||||||
|
parameter_list += ", &" + param_name;
|
||||||
} else if (TypeManager::is_pointer(type)) {
|
|
||||||
out << "int " << param_name;
|
} else if (TypeManager::is_pointer_to_PyObject(type)) {
|
||||||
format_specifiers += "i";
|
out << "PyObject *" << param_name;
|
||||||
parameter_list += ", &" + param_name;
|
format_specifiers += "O";
|
||||||
|
parameter_list += ", &" + param_name;
|
||||||
} else {
|
pexpr_string = param_name;
|
||||||
// Ignore a parameter.
|
|
||||||
out << "PyObject *" << param_name;
|
} else if (TypeManager::is_pointer(type)) {
|
||||||
format_specifiers += "O";
|
out << "int " << param_name;
|
||||||
parameter_list += ", &" + param_name;
|
format_specifiers += "i";
|
||||||
}
|
parameter_list += ", &" + param_name;
|
||||||
|
|
||||||
out << ";\n";
|
} else {
|
||||||
if (remap->_has_this && pn == 0) {
|
// Ignore a parameter.
|
||||||
// The "this" parameter gets passed in separately.
|
out << "PyObject *" << param_name;
|
||||||
container = pexpr_string;
|
format_specifiers += "O";
|
||||||
}
|
parameter_list += ", &" + param_name;
|
||||||
pexprs.push_back(pexpr_string);
|
}
|
||||||
}
|
|
||||||
|
out << ";\n";
|
||||||
out << " if (PyArg_ParseTuple(args, \"" << format_specifiers
|
if (remap->_has_this && pn == 0) {
|
||||||
<< "\"" << parameter_list << ")) {\n";
|
// The "this" parameter gets passed in separately.
|
||||||
|
container = pexpr_string;
|
||||||
if (!extra_convert.empty()) {
|
}
|
||||||
out << " " << extra_convert << "\n";
|
pexprs.push_back(pexpr_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extra_param_check.empty()) {
|
out << " if (PyArg_ParseTuple(args, \"" << format_specifiers
|
||||||
out << " if (" << extra_param_check.substr(3) << ") {\n";
|
<< "\"" << parameter_list << ")) {\n";
|
||||||
if (!extra_cleanup.empty()) {
|
|
||||||
out << " " << extra_cleanup << "\n";
|
if (!extra_convert.empty()) {
|
||||||
}
|
out << " " << extra_convert << "\n";
|
||||||
out << " PyErr_SetString(PyExc_TypeError, \"Invalid parameters.\");\n"
|
}
|
||||||
<< " return (PyObject *)NULL;\n"
|
|
||||||
<< " }\n";
|
if (!extra_param_check.empty()) {
|
||||||
}
|
out << " if (" << extra_param_check.substr(3) << ") {\n";
|
||||||
|
if (!extra_cleanup.empty()) {
|
||||||
if (track_interpreter) {
|
out << " " << extra_cleanup << "\n";
|
||||||
out << " in_interpreter = 0;\n";
|
}
|
||||||
}
|
out << " PyErr_SetString(PyExc_TypeError, \"Invalid parameters.\");\n"
|
||||||
|
<< " return (PyObject *)NULL;\n"
|
||||||
if (!remap->_void_return &&
|
<< " }\n";
|
||||||
remap->_return_type->new_type_is_atomic_string()) {
|
}
|
||||||
// Treat strings as a special case. We don't want to format the
|
|
||||||
// return expression.
|
if (track_interpreter) {
|
||||||
string return_expr = remap->call_function(out, 4, false, container, pexprs);
|
out << " in_interpreter = 0;\n";
|
||||||
CPPType *type = remap->_return_type->get_orig_type();
|
}
|
||||||
out << " ";
|
|
||||||
type->output_instance(out, "return_value", &parser);
|
if (!remap->_void_return &&
|
||||||
out << " = " << return_expr << ";\n";
|
remap->_return_type->new_type_is_atomic_string()) {
|
||||||
|
// Treat strings as a special case. We don't want to format the
|
||||||
if (track_interpreter) {
|
// return expression.
|
||||||
out << " in_interpreter = 1;\n";
|
string return_expr = remap->call_function(out, 4, false, container, pexprs);
|
||||||
}
|
CPPType *type = remap->_return_type->get_orig_type();
|
||||||
if (!extra_cleanup.empty()) {
|
out << " ";
|
||||||
out << " " << extra_cleanup << "\n";
|
type->output_instance(out, "return_value", &parser);
|
||||||
}
|
out << " = " << return_expr << ";\n";
|
||||||
|
|
||||||
return_expr = manage_return_value(out, 4, remap, "return_value");
|
if (track_interpreter) {
|
||||||
test_assert(out, 4);
|
out << " in_interpreter = 1;\n";
|
||||||
pack_return_value(out, 4, remap, return_expr);
|
}
|
||||||
|
if (!extra_cleanup.empty()) {
|
||||||
} else {
|
out << " " << extra_cleanup << "\n";
|
||||||
string return_expr = remap->call_function(out, 4, true, container, pexprs);
|
}
|
||||||
if (return_expr.empty()) {
|
|
||||||
if (track_interpreter) {
|
return_expr = manage_return_value(out, 4, remap, "return_value");
|
||||||
out << " in_interpreter = 1;\n";
|
test_assert(out, 4);
|
||||||
}
|
pack_return_value(out, 4, remap, return_expr);
|
||||||
if (!extra_cleanup.empty()) {
|
|
||||||
out << " " << extra_cleanup << "\n";
|
} else {
|
||||||
}
|
string return_expr = remap->call_function(out, 4, true, container, pexprs);
|
||||||
test_assert(out, 4);
|
if (return_expr.empty()) {
|
||||||
out << " return Py_BuildValue(\"\");\n";
|
if (track_interpreter) {
|
||||||
|
out << " in_interpreter = 1;\n";
|
||||||
} else {
|
}
|
||||||
CPPType *type = remap->_return_type->get_temporary_type();
|
if (!extra_cleanup.empty()) {
|
||||||
out << " ";
|
out << " " << extra_cleanup << "\n";
|
||||||
type->output_instance(out, "return_value", &parser);
|
}
|
||||||
out << " = " << return_expr << ";\n";
|
test_assert(out, 4);
|
||||||
if (track_interpreter) {
|
out << " return Py_BuildValue(\"\");\n";
|
||||||
out << " in_interpreter = 1;\n";
|
|
||||||
}
|
} else {
|
||||||
if (!extra_cleanup.empty()) {
|
CPPType *type = remap->_return_type->get_temporary_type();
|
||||||
out << " " << extra_cleanup << "\n";
|
out << " ";
|
||||||
}
|
type->output_instance(out, "return_value", &parser);
|
||||||
|
out << " = " << return_expr << ";\n";
|
||||||
return_expr = manage_return_value(out, 4, remap, "return_value");
|
if (track_interpreter) {
|
||||||
test_assert(out, 4);
|
out << " in_interpreter = 1;\n";
|
||||||
pack_return_value(out, 4, remap, remap->_return_type->temporary_to_return(return_expr));
|
}
|
||||||
}
|
if (!extra_cleanup.empty()) {
|
||||||
}
|
out << " " << extra_cleanup << "\n";
|
||||||
|
}
|
||||||
out << " }\n";
|
|
||||||
|
return_expr = manage_return_value(out, 4, remap, "return_value");
|
||||||
out << " return (PyObject *)NULL;\n";
|
test_assert(out, 4);
|
||||||
out << "}\n\n";
|
pack_return_value(out, 4, remap, remap->_return_type->temporary_to_return(return_expr));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
// Function: InterfaceMakerPythonSimple::pack_return_value
|
out << " }\n";
|
||||||
// Access: Private
|
|
||||||
// Description: Outputs a command to pack the indicated expression,
|
out << " return (PyObject *)NULL;\n";
|
||||||
// of the return_type type, as a Python return value.
|
out << "}\n\n";
|
||||||
////////////////////////////////////////////////////////////////////
|
}
|
||||||
void InterfaceMakerPythonSimple::
|
|
||||||
pack_return_value(ostream &out, int indent_level,
|
////////////////////////////////////////////////////////////////////
|
||||||
FunctionRemap *remap, string return_expr) {
|
// Function: InterfaceMakerPythonSimple::pack_return_value
|
||||||
CPPType *orig_type = remap->_return_type->get_orig_type();
|
// Access: Private
|
||||||
CPPType *type = remap->_return_type->get_new_type();
|
// Description: Outputs a command to pack the indicated expression,
|
||||||
|
// of the return_type type, as a Python return value.
|
||||||
if (remap->_return_type->new_type_is_atomic_string())
|
////////////////////////////////////////////////////////////////////
|
||||||
{
|
void InterfaceMakerPythonSimple::
|
||||||
if (TypeManager::is_char_pointer(orig_type)) {
|
pack_return_value(ostream &out, int indent_level,
|
||||||
indent(out, indent_level)
|
FunctionRemap *remap, string return_expr) {
|
||||||
<< "return PyString_FromString(" << return_expr << ");\n";
|
CPPType *orig_type = remap->_return_type->get_orig_type();
|
||||||
|
CPPType *type = remap->_return_type->get_new_type();
|
||||||
} else {
|
|
||||||
indent(out, indent_level)
|
if (remap->_return_type->new_type_is_atomic_string())
|
||||||
<< "return PyString_FromStringAndSize("
|
{
|
||||||
<< return_expr << ".data(), " << return_expr << ".length());\n";
|
if (TypeManager::is_char_pointer(orig_type)) {
|
||||||
}
|
indent(out, indent_level)
|
||||||
|
<< "return PyString_FromString(" << return_expr << ");\n";
|
||||||
} else if (TypeManager::is_unsigned_longlong(type))
|
|
||||||
{
|
} else {
|
||||||
indent(out, indent_level)
|
indent(out, indent_level)
|
||||||
<< "return PyLong_FromUnsignedLongLong(" << return_expr << ");\n";
|
<< "return PyString_FromStringAndSize("
|
||||||
|
<< return_expr << ".data(), " << return_expr << ".length());\n";
|
||||||
} else if (TypeManager::is_longlong(type))
|
}
|
||||||
{
|
|
||||||
indent(out, indent_level)
|
} else if (TypeManager::is_unsigned_longlong(type))
|
||||||
<< "return PyLong_FromLongLong(" << return_expr << ");\n";
|
{
|
||||||
|
indent(out, indent_level)
|
||||||
} else if (TypeManager::is_integer(type)) {
|
<< "return PyLong_FromUnsignedLongLong(" << return_expr << ");\n";
|
||||||
indent(out, indent_level)
|
|
||||||
<< "return PyInt_FromLong(" << return_expr << ");\n";
|
} else if (TypeManager::is_longlong(type))
|
||||||
|
{
|
||||||
} else if (TypeManager::is_float(type)) {
|
indent(out, indent_level)
|
||||||
indent(out, indent_level)
|
<< "return PyLong_FromLongLong(" << return_expr << ");\n";
|
||||||
<< "return PyFloat_FromDouble(" << return_expr << ");\n";
|
|
||||||
|
#ifndef USE_PYTHON_2_2_OR_EARLIER
|
||||||
} else if (TypeManager::is_char_pointer(type)) {
|
} else if (TypeManager::is_unsigned_integer(type)) {
|
||||||
indent(out, indent_level)
|
indent(out, indent_level)
|
||||||
<< "return PyString_FromString(" << return_expr << ");\n";
|
<< "return PyLong_FromUnsignedLong(" << return_expr << ");\n";
|
||||||
|
#endif
|
||||||
} else if (TypeManager::is_pointer_to_PyObject(type)) {
|
|
||||||
indent(out, indent_level)
|
} else if (TypeManager::is_integer(type)) {
|
||||||
<< "return " << return_expr << ";\n";
|
indent(out, indent_level)
|
||||||
|
<< "return PyInt_FromLong(" << return_expr << ");\n";
|
||||||
} else if (TypeManager::is_pointer(type)) {
|
|
||||||
indent(out, indent_level)
|
} else if (TypeManager::is_float(type)) {
|
||||||
<< "return PyInt_FromLong((int)" << return_expr << ");\n";
|
indent(out, indent_level)
|
||||||
|
<< "return PyFloat_FromDouble(" << return_expr << ");\n";
|
||||||
} else {
|
|
||||||
// Return None.
|
} else if (TypeManager::is_char_pointer(type)) {
|
||||||
indent(out, indent_level)
|
indent(out, indent_level)
|
||||||
<< "return Py_BuildValue(\"\");\n";
|
<< "return PyString_FromString(" << return_expr << ");\n";
|
||||||
}
|
|
||||||
}
|
} else if (TypeManager::is_pointer_to_PyObject(type)) {
|
||||||
|
indent(out, indent_level)
|
||||||
|
<< "return " << return_expr << ";\n";
|
||||||
|
|
||||||
|
} else if (TypeManager::is_pointer(type)) {
|
||||||
|
indent(out, indent_level)
|
||||||
|
<< "return PyInt_FromLong((int)" << return_expr << ");\n";
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Return None.
|
||||||
|
indent(out, indent_level)
|
||||||
|
<< "return Py_BuildValue(\"\");\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user