fix a crash with the python-obj, python and c interface makers

This commit is contained in:
rdb 2013-11-08 10:30:27 +00:00
parent c3e862a842
commit 52e4acc0ce
3 changed files with 59 additions and 64 deletions

View File

@ -156,6 +156,7 @@ check_protocols() {
} }
// Now are there any make_seq requests within this class? // Now are there any make_seq requests within this class?
if (_itype._cpptype != NULL) {
CPPStructType *stype = _itype._cpptype->as_struct_type(); CPPStructType *stype = _itype._cpptype->as_struct_type();
if (stype != (CPPStructType *)NULL) { if (stype != (CPPStructType *)NULL) {
CPPScope *scope = stype->get_scope(); CPPScope *scope = stype->get_scope();
@ -177,6 +178,7 @@ check_protocols() {
} }
} }
} }
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: InterfaceMaker::Object::is_static_method // Function: InterfaceMaker::Object::is_static_method
@ -246,27 +248,21 @@ void InterfaceMaker::
generate_wrappers() { generate_wrappers() {
InterrogateDatabase *idb = InterrogateDatabase::get_ptr(); InterrogateDatabase *idb = InterrogateDatabase::get_ptr();
// We use a while loop rather than a simple for loop, because we // We use a while loop rather than a simple for loop, because we
// might increase the number of types recursively during the // might increase the number of types recursively during the
// traversal. // traversal.
int ti = 0; int ti = 0;
while (ti < idb->get_num_all_types()) while (ti < idb->get_num_all_types()) {
{
TypeIndex type_index = idb->get_all_type(ti); TypeIndex type_index = idb->get_all_type(ti);
record_object(type_index); record_object(type_index);
if (interrogate_type_is_enum(ti)) {
if(interrogate_type_is_enum(ti))
{
int enum_count = interrogate_type_number_of_enum_values(ti); int enum_count = interrogate_type_number_of_enum_values(ti);
for(int xx = 0; xx< enum_count; xx++) for (int xx = 0; xx < enum_count; ++xx) {
{
// printf(" PyModule_AddIntConstant(module,\"%s\",%d)\n",interrogate_type_enum_value_name(ti,xx),interrogate_type_enum_value(ti,xx)); // printf(" PyModule_AddIntConstant(module,\"%s\",%d)\n",interrogate_type_enum_value_name(ti,xx),interrogate_type_enum_value(ti,xx));
} }
} }
++ti; ++ti;
// printf(" New Type %d\n",ti); // printf(" New Type %d\n",ti);
} }
@ -279,48 +275,37 @@ generate_wrappers() {
} }
int num_functions = idb->get_num_global_functions(); int num_functions = idb->get_num_global_functions();
for (int fi = 0; fi < num_functions; fi++) for (int fi = 0; fi < num_functions; fi++) {
{
FunctionIndex func_index = idb->get_global_function(fi); FunctionIndex func_index = idb->get_global_function(fi);
record_function(dummy_type, func_index); record_function(dummy_type, func_index);
} }
int num_manifests = idb->get_num_global_manifests(); int num_manifests = idb->get_num_global_manifests();
for (int mi = 0; mi < num_manifests; mi++) for (int mi = 0; mi < num_manifests; mi++) {
{
ManifestIndex manifest_index = idb->get_global_manifest(mi); ManifestIndex manifest_index = idb->get_global_manifest(mi);
const InterrogateManifest &iman = idb->get_manifest(manifest_index); const InterrogateManifest &iman = idb->get_manifest(manifest_index);
if (iman.has_getter()) if (iman.has_getter()) {
{
FunctionIndex func_index = iman.get_getter(); FunctionIndex func_index = iman.get_getter();
record_function(dummy_type, func_index); record_function(dummy_type, func_index);
} }
printf(" Manafests %d\n",mi); printf(" Manifests %d\n", mi);
} }
int num_elements = idb->get_num_global_elements(); int num_elements = idb->get_num_global_elements();
for (int ei = 0; ei < num_elements; ei++) for (int ei = 0; ei < num_elements; ei++) {
{
printf(" Element %d\n", ei); printf(" Element %d\n", ei);
ElementIndex element_index = idb->get_global_element(ei); ElementIndex element_index = idb->get_global_element(ei);
const InterrogateElement &ielement = idb->get_element(element_index); const InterrogateElement &ielement = idb->get_element(element_index);
if (ielement.has_getter()) if (ielement.has_getter()) {
{
FunctionIndex func_index = ielement.get_getter(); FunctionIndex func_index = ielement.get_getter();
record_function(dummy_type, func_index); record_function(dummy_type, func_index);
} }
if (ielement.has_setter()) if (ielement.has_setter()) {
{
FunctionIndex func_index = ielement.get_setter(); FunctionIndex func_index = ielement.get_setter();
record_function(dummy_type, func_index); record_function(dummy_type, func_index);
} }
} }
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -491,6 +476,19 @@ separate_overloading() {
return true; return true;
} }
////////////////////////////////////////////////////////////////////
// Function: InterfaceMaker::wrap_global_functions
// Access: Public, Virtual
// Description: This method should be overridden and redefined to
// return false for interfaces that don't support
// global functions and should therefore will only
// accept function remaps that have a class associated.
////////////////////////////////////////////////////////////////////
bool InterfaceMaker::
wrap_global_functions() {
return true;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: InterfaceMaker::get_function_remaps // Function: InterfaceMaker::get_function_remaps
// Access: Public // Access: Public
@ -625,21 +623,17 @@ record_function(const InterrogateType &itype, FunctionIndex func_index) {
Function *func = new Function(wrapper_name, itype, ifunc); Function *func = new Function(wrapper_name, itype, ifunc);
_functions.push_back(func); _functions.push_back(func);
// printf(" Function Name = %s\n", ifunc.get_name().c_str()); // printf(" Function Name = %s\n", ifunc.get_name().c_str());
// Now get all the valid FunctionRemaps for the function. // Now get all the valid FunctionRemaps for the function.
if (ifunc._instances != (InterrogateFunction::Instances *)NULL) if (ifunc._instances != (InterrogateFunction::Instances *)NULL) {
{
InterrogateFunction::Instances::const_iterator ii; InterrogateFunction::Instances::const_iterator ii;
for (ii = ifunc._instances->begin();ii != ifunc._instances->end();++ii) for (ii = ifunc._instances->begin(); ii != ifunc._instances->end(); ++ii) {
{
CPPInstance *cppfunc = (*ii).second; CPPInstance *cppfunc = (*ii).second;
CPPFunctionType *ftype = cppfunc->_type->as_function_type(); CPPFunctionType *ftype = cppfunc->_type->as_function_type();
int max_default_parameters = 0; int max_default_parameters = 0;
if (separate_overloading()) if (separate_overloading()) {
{
// Count up the number of default parameters this function might // Count up the number of default parameters this function might
// take. // take.
CPPParameterList *parameters = ftype->_parameters; CPPParameterList *parameters = ftype->_parameters;

View File

@ -54,7 +54,7 @@ public:
virtual void write_includes(ostream &out); virtual void write_includes(ostream &out);
virtual void write_prototypes(ostream &out, ostream *out_h); virtual void write_prototypes(ostream &out, ostream *out_h);
virtual void write_functions(ostream &out); virtual void write_functions(ostream &out);
virtual void write_module_support(ostream &out,ostream *out_h,InterrogateModuleDef *moduledefdef) {}; virtual void write_module_support(ostream &out, ostream *out_h, InterrogateModuleDef *def) {};
virtual void write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def); virtual void write_module(ostream &out, ostream *out_h, InterrogateModuleDef *def);
@ -62,6 +62,7 @@ public:
virtual bool synthesize_this_parameter(); virtual bool synthesize_this_parameter();
virtual bool separate_overloading(); virtual bool separate_overloading();
virtual bool wrap_global_functions();
void get_function_remaps(vector<FunctionRemap *> &remaps); void get_function_remaps(vector<FunctionRemap *> &remaps);