Browse Source

interrogate: set tp_base to DTOOL_SUPER_BASE and tp_basicsize to 0

The tp_basicsize field, as well as a few others, seem to be inherited from whatever is set in tp_base.  In absence of a tp_base, Python will set it to PyBaseObject_Type, which is not at all correct for Panda types.
rdb 6 years ago
parent
commit
d2bd4181e0
1 changed files with 2 additions and 3 deletions
  1. 2 3
      dtool/src/interrogate/interfaceMakerPythonNative.cxx

+ 2 - 3
dtool/src/interrogate/interfaceMakerPythonNative.cxx

@@ -2874,7 +2874,7 @@ write_module_class(ostream &out, Object *obj) {
   // const char *tp_name;
   out << "    \"" << _def->module_name << "." << export_class_name << "\",\n";
   // Py_ssize_t tp_basicsize;
-  out << "    sizeof(Dtool_PyInstDef),\n";
+  out << "    0, // tp_basicsize\n"; // inherited from tp_base
   // Py_ssize_t tp_itemsize;
   out << "    0, // tp_itemsize\n";
 
@@ -3137,9 +3137,8 @@ write_module_class(ostream &out, Object *obj) {
     }
 
     out << "    Dtool_" << ClassName << "._PyType.tp_bases = PyTuple_Pack(" << bases.size() << baseargs << ");\n";
-  } else {
-    out << "    Dtool_" << ClassName << "._PyType.tp_base = (PyTypeObject *)Dtool_GetSuperBase();\n";
   }
+  out << "    Dtool_" << ClassName << "._PyType.tp_base = (PyTypeObject *)Dtool_GetSuperBase();\n";
 
   int num_nested = obj->_itype.number_of_nested_types();
   int num_dict_items = 1;