Explorar el Código

Various interrogate improvements

rdb hace 10 años
padre
commit
da3f642902

+ 9 - 3
dtool/src/interrogate/functionRemap.cxx

@@ -226,7 +226,8 @@ call_function(ostream &out, int indent_level, bool convert_result,
       return_expr = get_call_str(container, pexprs);
 
     } else {
-      if (_return_type->return_value_should_be_simple()) {
+      //if (_return_type->return_value_should_be_simple()) {
+      if (false) {
         // We have to assign the result to a temporary first; this makes
         // it a bit easier on poor old VC++.
         InterfaceMaker::indent(out, indent_level);
@@ -361,7 +362,7 @@ make_wrapper_entry(FunctionIndex function_index) {
 
 ////////////////////////////////////////////////////////////////////
 //     Function: FunctionRemap::get_call_str
-//       Access: Private
+//       Access: Public
 //  Description: Returns a string suitable for calling the wrapped
 //               function.  If pexprs is nonempty, it represents
 //               the list of expressions that will evaluate to each
@@ -417,7 +418,12 @@ get_call_str(const string &container, const vector_string &pexprs) const {
       } else if (_has_this && !container.empty()) {
         // If we have a "this" parameter, the calling convention is also
         // a bit different.
-        call << "(" << container << ")->" << _cppfunc->get_local_name();
+        if (container == "local_this") {
+          // This isn't important, it just looks a bit prettier.
+          call << container << "->" << _cppfunc->get_local_name();
+        } else {
+          call << "(" << container << ")->" << _cppfunc->get_local_name();
+        }
 
       } else {
         call << _cppfunc->get_local_name(&parser);

+ 3 - 1
dtool/src/interrogate/functionRemap.h

@@ -61,6 +61,8 @@ public:
 
   FunctionWrapperIndex make_wrapper_entry(FunctionIndex function_index);
 
+  string get_call_str(const string &container, const vector_string &pexprs) const;
+
   class Parameter {
   public:
     bool _has_name;
@@ -131,8 +133,8 @@ public:
   CPPFunctionType *_ftype;
 
   bool _is_valid;
+
 private:
-  string get_call_str(const string &container, const vector_string &pexprs) const;
   string get_parameter_expr(int n, const vector_string &pexprs) const;
   bool setup_properties(const InterrogateFunction &ifunc, InterfaceMaker *interface_maker);
 };

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 452 - 209
dtool/src/interrogate/interfaceMakerPythonNative.cxx


+ 13 - 3
dtool/src/interrogate/interfaceMakerPythonNative.h

@@ -112,10 +112,16 @@ private:
     WrapperType _wrapper_type;
     int _min_version;
     Function *_func;
+    string _wrapper_name;
     set<FunctionRemap*> _remaps;
   };
 
+  typedef std::map<string, SlottedFunctionDef> SlottedFunctions;
+
   static bool get_slotted_function_def(Object *obj, Function *func, FunctionRemap *remap, SlottedFunctionDef &def);
+  static void write_function_slot(ostream &out, int indent_level,
+                                  const SlottedFunctions &slots,
+                                  const string &slot, const string &def = "0");
 
   void write_prototype_for_name(ostream &out, Function *func, const std::string &name);
   void write_prototype_for(ostream &out, Function *func);
@@ -138,7 +144,7 @@ private:
                              bool coercion_allowed, bool report_errors,
                              ArgsType args_type, int return_flags,
                              bool check_exceptions = true,
-                             bool verify_const = false,
+                             bool verify_const = true,
                              const string &first_expr = string());
 
   void write_function_instance(ostream &out, FunctionRemap *remap,
@@ -150,11 +156,14 @@ private:
                                const string &first_pexpr = string());
 
   void error_return(ostream &out, int indent_level, int return_flags);
+  void error_raise_return(ostream &out, int indent_level, int return_flags,
+                          const string &exc_type, const string &message,
+                          const string &format_args = "");
   void pack_return_value(ostream &out, int indent_level, FunctionRemap *remap,
                          std::string return_expr);
 
   void write_make_seq(ostream &out, Object *obj, const std::string &ClassName,
-                      MakeSeq *make_seq);
+                      const std::string &cClassName, MakeSeq *make_seq);
 
   void write_class_prototypes(ostream &out) ;
   void write_class_declarations(ostream &out, ostream *out_h, Object *obj);
@@ -190,7 +199,8 @@ public:
   int NeedsAReprFunction(const InterrogateType &itype_class);
   bool NeedsARichCompareFunction(const InterrogateType &itype_class);
 
-  void output_quoted(ostream &out, int indent_level, const std::string &str);
+  void output_quoted(ostream &out, int indent_level, const std::string &str,
+                     bool first_line=true);
 
   // stash the forward declarations for this compile pass..
   std::set<CPPType *> _external_imports;

+ 8 - 1
dtool/src/interrogate/parameterRemapConcreteToPointer.cxx

@@ -43,7 +43,14 @@ ParameterRemapConcreteToPointer(CPPType *orig_type) :
 ////////////////////////////////////////////////////////////////////
 void ParameterRemapConcreteToPointer::
 pass_parameter(ostream &out, const string &variable_name) {
-  out << "*" << variable_name;
+  if (variable_name.size() > 1 && variable_name[0] == '&') {
+    // Prevent generating something like *&param
+    // Also, if this is really some local type, we can presumably
+    // just move it?
+    out << "MOVE(" << variable_name.substr(1) << ")";
+  } else {
+    out << "*" << variable_name;
+  }
 }
 
 ////////////////////////////////////////////////////////////////////

+ 10 - 1
dtool/src/interrogate/parameterRemapReferenceToPointer.cxx

@@ -42,7 +42,16 @@ ParameterRemapReferenceToPointer(CPPType *orig_type) :
 ////////////////////////////////////////////////////////////////////
 void ParameterRemapReferenceToPointer::
 pass_parameter(ostream &out, const string &variable_name) {
-  out << "*" << variable_name;
+  if (variable_name.size() > 1 && variable_name[0] == '&') {
+    // Prevent generating something like *&param
+    // Also, if this is really some local type, we can presumably just
+    // move it?  This is only relevant if this parameter is an rvalue
+    // reference, but CPPParser can't know that, and it might have an overload
+    // that takes an rvalue reference.  It shouldn't hurt either way.
+    out << "MOVE(" << variable_name.substr(1) << ")";
+  } else {
+    out << "*" << variable_name;
+  }
 }
 
 ////////////////////////////////////////////////////////////////////

+ 33 - 3
dtool/src/interrogate/typeManager.cxx

@@ -1115,7 +1115,7 @@ is_unsigned_integer(CPPType *type) {
 //     Function: TypeManager::is_size
 //       Access: Public, Static
 //  Description: Returns true if the indicated type is the "size_t"
-//               type.
+//               type, or a const size_t, or a typedef to either.
 ////////////////////////////////////////////////////////////////////
 bool TypeManager::
 is_size(CPPType *type) {
@@ -1124,8 +1124,38 @@ is_size(CPPType *type) {
     return is_size(type->as_const_type()->_wrapped_around);
 
   case CPPDeclaration::ST_typedef:
-    return is_integer(type->as_typedef_type()->_type) &&
-                      type->get_simple_name() == "size_t";
+    if (type->get_simple_name() == "size_t") {
+      return is_integer(type->as_typedef_type()->_type);
+    } else {
+      return is_size(type->as_typedef_type()->_type);
+    }
+
+  default:
+    break;
+  }
+
+  return false;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: TypeManager::is_ssize
+//       Access: Public, Static
+//  Description: Returns true if the indicated type is the "ssize_t"
+//               type, or a const ssize_t, or a typedef to either.
+////////////////////////////////////////////////////////////////////
+bool TypeManager::
+is_ssize(CPPType *type) {
+  switch (type->get_subtype()) {
+  case CPPDeclaration::ST_const:
+    return is_ssize(type->as_const_type()->_wrapped_around);
+
+  case CPPDeclaration::ST_typedef:
+    if (type->get_simple_name() == "Py_ssize_t" ||
+        type->get_simple_name() == "ssize_t") {
+      return is_integer(type->as_typedef_type()->_type);
+    } else {
+      return is_ssize(type->as_typedef_type()->_type);
+    }
 
   default:
     break;

+ 1 - 0
dtool/src/interrogate/typeManager.h

@@ -88,6 +88,7 @@ public:
   static bool is_integer(CPPType *type);
   static bool is_unsigned_integer(CPPType *type);
   static bool is_size(CPPType *type);
+  static bool is_ssize(CPPType *type);
   static bool is_short(CPPType *type);
   static bool is_unsigned_short(CPPType *type);
   static bool is_longlong(CPPType *type);

+ 64 - 11
dtool/src/interrogatedb/dtool_super_base.cxx

@@ -15,7 +15,7 @@
 #include "py_panda.h"
 
 #ifdef HAVE_PYTHON
-  
+
 class EmptyClass {
 };
 Define_Module_Class_Private(dtoolconfig, DTOOL_SUPER_BASE, EmptyClass, DTOOL_SUPER_BASE111);
@@ -30,7 +30,7 @@ PyMethodDef Dtool_Methods_DTOOL_SUPER_BASE[] = {
   { NULL, NULL }
 };
 
-static Py_hash_t DTool_HashKey_Methods_DTOOL_SUPER_BASE(PyObject *self) {
+static Py_hash_t Dtool_HashKey_DTOOL_SUPER_BASE(PyObject *self) {
   void *local_this = DTOOL_Call_GetPointerThis(self);
   if (local_this == NULL) {
     return -1;
@@ -46,15 +46,6 @@ EXPCL_DTOOLCONFIG void Dtool_PyModuleClassInit_DTOOL_SUPER_BASE(PyObject *module
     Dtool_DTOOL_SUPER_BASE.As_PyTypeObject().tp_dict = PyDict_New();
     PyDict_SetItemString(Dtool_DTOOL_SUPER_BASE.As_PyTypeObject().tp_dict, "DtoolClassDict", Dtool_DTOOL_SUPER_BASE.As_PyTypeObject().tp_dict);
 
-    // __hash__
-    Dtool_DTOOL_SUPER_BASE.As_PyTypeObject().tp_hash = &DTool_HashKey_Methods_DTOOL_SUPER_BASE;
-#if PY_MAJOR_VERSION >= 3
-    // Python 3 removed the regular tp_compare function - there is only tp_richcompare.
-    Dtool_DTOOL_SUPER_BASE.As_PyTypeObject().tp_richcompare = &DTOOL_PyObject_RichCompare;
-#else
-    Dtool_DTOOL_SUPER_BASE.As_PyTypeObject().tp_compare = &DTOOL_PyObject_Compare;
-#endif
-
     if (PyType_Ready(&Dtool_DTOOL_SUPER_BASE.As_PyTypeObject()) < 0) {
       PyErr_SetString(PyExc_TypeError, "PyType_Ready(Dtool_DTOOL_SUPER_BASE)");
       return;
@@ -83,4 +74,66 @@ int Dtool_Init_DTOOL_SUPER_BASE(PyObject *self, PyObject *args, PyObject *kwds)
   return -1;
 }
 
+EXPORT_THIS Dtool_PyTypedObject Dtool_DTOOL_SUPER_BASE = {
+  {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    "dtoolconfig.DTOOL_SUPER_BASE",
+    sizeof(Dtool_PyInstDef),
+    0,
+    &Dtool_FreeInstance_DTOOL_SUPER_BASE,
+    0,
+    0,
+    0,
+#if PY_MAJOR_VERSION >= 3
+    0,
+#else
+    &DTOOL_PyObject_Compare,
+#endif
+    0,
+    0,
+    0,
+    0,
+    &Dtool_HashKey_DTOOL_SUPER_BASE,
+    0,
+    0,
+    PyObject_GenericGetAttr,
+    PyObject_GenericSetAttr,
+    0,
+    (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES),
+    0,
+    0,
+    0,
+#if PY_MAJOR_VERSION >= 3
+    &DTOOL_PyObject_RichCompare,
+#else
+    0,
+#endif
+    0,
+    0,
+    0,
+    Dtool_Methods_DTOOL_SUPER_BASE,
+    standard_type_members,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    Dtool_Init_DTOOL_SUPER_BASE,
+    PyType_GenericAlloc,
+    Dtool_new_DTOOL_SUPER_BASE,
+    PyObject_Del,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+    0,
+  },
+  Dtool_UpcastInterface_DTOOL_SUPER_BASE,
+  Dtool_DowncastInterface_DTOOL_SUPER_BASE,
+  TypeHandle::none(),
+};
+
 #endif  // HAVE_PYTHON

+ 146 - 44
dtool/src/interrogatedb/py_panda.cxx

@@ -70,13 +70,13 @@ void DTOOL_Call_ExtractThisPointerForType(PyObject *self, Dtool_PyTypedObject *c
 //               wrong type, raises an AttributeError.
 ////////////////////////////////////////////////////////////////////
 bool Dtool_Call_ExtractThisPointer(PyObject *self, Dtool_PyTypedObject &classdef, void **answer) {
-  if (self != NULL && DtoolCanThisBeAPandaInstance(self)) {
-    *answer = ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self, &classdef);
-    return true;
+  if (self == NULL || !DtoolCanThisBeAPandaInstance(self)) {
+    Dtool_Raise_TypeError("C++ object is not yet constructed, or already destructed.");
+    return false;
   }
 
-  PyErr_SetString(PyExc_AttributeError, "C++ object is not yet constructed, or already destructed.");
-  return false;
+  *answer = ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self, &classdef);
+  return true;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -93,9 +93,9 @@ bool Dtool_Call_ExtractThisPointer(PyObject *self, Dtool_PyTypedObject &classdef
 bool Dtool_Call_ExtractThisPointer_NonConst(PyObject *self, Dtool_PyTypedObject &classdef,
                                             void **answer, const char *method_name) {
 
-  if (self != NULL && DtoolCanThisBeAPandaInstance(self)) {
-    *answer = ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self, &classdef);
-    return true;
+  if (self == NULL || !DtoolCanThisBeAPandaInstance(self)) {
+    Dtool_Raise_TypeError("C++ object is not yet constructed, or already destructed.");
+    return false;
   }
 
   if (((Dtool_PyInstDef *)self)->_is_const) {
@@ -106,6 +106,7 @@ bool Dtool_Call_ExtractThisPointer_NonConst(PyObject *self, Dtool_PyTypedObject
     return false;
   }
 
+  *answer = ((Dtool_PyInstDef *)self)->_My_Type->_Dtool_UpcastInterface(self, &classdef);
   return true;
 }
 
@@ -145,7 +146,7 @@ DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
   //}
   if (self == NULL) {
     if (report_errors) {
-      PyErr_SetString(PyExc_TypeError, "self is NULL");
+      return Dtool_Raise_TypeError("self is NULL");
     }
     return NULL;
   }
@@ -159,18 +160,16 @@ DTOOL_Call_GetPointerThisClass(PyObject *self, Dtool_PyTypedObject *classdef,
       }
 
       if (report_errors) {
-        PyErr_Format(PyExc_TypeError,
-                     "%s() argument %d may not be const",
-                     function_name.c_str(), param);
+        return PyErr_Format(PyExc_TypeError,
+                            "%s() argument %d may not be const",
+                            function_name.c_str(), param);
       }
-
       return NULL;
     }
   }
 
   if (report_errors) {
-    Dtool_Raise_ArgTypeError(self, param, function_name.c_str(), classdef->_PyType.tp_name);
-    return NULL;
+    return Dtool_Raise_ArgTypeError(self, param, function_name.c_str(), classdef->_PyType.tp_name);
   }
 
   return NULL;
@@ -183,7 +182,6 @@ void *DTOOL_Call_GetPointerThis(PyObject *self) {
       return pyself->_ptr_to_object;
     }
   }
-
   return NULL;
 }
 
@@ -206,27 +204,130 @@ bool Dtool_CheckErrorOccurred() {
   if (_PyErr_OCCURRED()) {
     return true;
   }
-  Notify *notify = Notify::ptr();
-  if (notify->has_assert_failed()) {
-    PyErr_SetString(PyExc_AssertionError, notify->get_assert_error_message().c_str());
-    notify->clear_assert_failed();
+  if (Notify::ptr()->has_assert_failed()) {
+    Dtool_Raise_AssertionError();
     return true;
   }
   return false;
 }
 #endif  // NDEBUG
 
+////////////////////////////////////////////////////////////////////
+//     Function: Dtool_Raise_AssertionError
+//  Description: Raises an AssertionError containing the last thrown
+//               assert message, and clears the assertion flag.
+//               Returns NULL.
+////////////////////////////////////////////////////////////////////
+PyObject *Dtool_Raise_AssertionError() {
+  Notify *notify = Notify::ptr();
+#if PY_MAJOR_VERSION >= 3
+  PyObject *message = PyUnicode_FromString(notify->get_assert_error_message().c_str());
+#else
+  PyObject *message = PyString_FromString(notify->get_assert_error_message().c_str());
+#endif
+  Py_INCREF(PyExc_AssertionError);
+  PyErr_Restore(PyExc_AssertionError, message, (PyObject *)NULL);
+  notify->clear_assert_failed();
+  return NULL;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Dtool_Raise_TypeError
+//  Description: Raises a TypeError with the given message, and
+//               returns NULL.
+////////////////////////////////////////////////////////////////////
+PyObject *Dtool_Raise_TypeError(const char *message) {
+  // PyErr_Restore is what PyErr_SetString would have ended up calling
+  // eventually anyway, so we might as well just get to the point.
+  Py_INCREF(PyExc_TypeError);
+#if PY_MAJOR_VERSION >= 3
+  PyErr_Restore(PyExc_TypeError, PyUnicode_FromString(message), (PyObject *)NULL);
+#else
+  PyErr_Restore(PyExc_TypeError, PyString_FromString(message), (PyObject *)NULL);
+#endif
+  return NULL;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Dtool_Raise_ArgTypeError
 //  Description: Raises a TypeError of the form:
 //               function_name() argument n must be type, not type
 //               for a given object passed to a function.
+//
+//               Always returns NULL so that it can be conveniently
+//               used as a return expression for wrapper functions
+//               that return a PyObject pointer.
+////////////////////////////////////////////////////////////////////
+PyObject *Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *function_name, const char *type_name) {
+#if PY_MAJOR_VERSION >= 3
+  PyObject *message = PyUnicode_FromFormat(
+#else
+  PyObject *message = PyString_FromFormat(
+#endif
+    "%s() argument %d must be %s, not %s",
+    function_name, param, type_name,
+    Py_TYPE(obj)->tp_name);
+
+  Py_INCREF(PyExc_TypeError);
+  PyErr_Restore(PyExc_TypeError, message, (PyObject *)NULL);
+  return NULL;
+}
+
 ////////////////////////////////////////////////////////////////////
-void Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *function_name, const char *type_name) {
-  PyErr_Format(PyExc_TypeError,
-               "%s() argument %d must be %s, not %s",
-               function_name, param, type_name,
-               Py_TYPE(obj)->tp_name);
+//     Function: Dtool_Raise_BadArgumentsError
+//  Description: Raises a TypeError of the form:
+//               Arguments must match:
+//               <list of overloads>
+//
+//               However, in release builds, this instead is defined
+//               to a function that just prints out a generic
+//               message, to help reduce the amount of strings in
+//               the compiled library.
+//
+//               Always returns NULL so that it can be conveniently
+//               used as a return expression for wrapper functions
+//               that return a PyObject pointer.
+////////////////////////////////////////////////////////////////////
+PyObject *_Dtool_Raise_BadArgumentsError() {
+  return Dtool_Raise_TypeError("arguments do not match any function overload");
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Dtool_Return_None
+//  Description: Convenience method that checks for exceptions, and
+//               if one occurred, returns NULL, otherwise Py_None.
+////////////////////////////////////////////////////////////////////
+PyObject *_Dtool_Return_None() {
+  if (_PyErr_OCCURRED()) {
+    return NULL;
+  }
+#ifndef NDEBUG
+  if (Notify::ptr()->has_assert_failed()) {
+    return Dtool_Raise_AssertionError();
+  }
+#endif
+  Py_INCREF(Py_None);
+  return Py_None;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Dtool_Return_Bool
+//  Description: Convenience method that checks for exceptions, and
+//               if one occurred, returns NULL, otherwise the given
+//               boolean value as a PyObject *.
+////////////////////////////////////////////////////////////////////
+PyObject *Dtool_Return_Bool(bool value) {
+  if (_PyErr_OCCURRED()) {
+    return NULL;
+  }
+#ifndef NDEBUG
+  if (Notify::ptr()->has_assert_failed()) {
+    return Dtool_Raise_AssertionError();
+  }
+#endif
+  PyObject *result = (value ? Py_True : Py_False);
+  Py_INCREF(result);
+  return result;
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -236,11 +337,11 @@ void Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *function_nam
 //
 ////////////////////////////////////////////////////////////////////////
 PyObject *DTool_CreatePyInstanceTyped(void *local_this_in, Dtool_PyTypedObject &known_class_type, bool memory_rules, bool is_const, int type_index) {
-  if (local_this_in == NULL) {
-    // Let's not be stupid..
-    PyErr_SetString(PyExc_TypeError, "C Function Return Null 'this'");
-    return NULL;
-  }
+  // We can't do the NULL check here like in DTool_CreatePyInstance, since
+  // the caller will have to get the type index to pass to this function
+  // to begin with.  That code probably would have crashed by now if it was
+  // really NULL for whatever reason.
+  nassertr(local_this_in != NULL, NULL);
 
   /////////////////////////////////////////////////////
   // IF the class is possibly a run time typed object
@@ -293,8 +394,10 @@ PyObject *DTool_CreatePyInstanceTyped(void *local_this_in, Dtool_PyTypedObject &
 ////////////////////////////////////////////////////////////////////////
 PyObject *DTool_CreatePyInstance(void *local_this, Dtool_PyTypedObject &in_classdef, bool memory_rules, bool is_const) {
   if (local_this == NULL) {
-    PyErr_SetString(PyExc_TypeError, "C Function Return Null 'this'");
-    return NULL;
+    // This is actually a very common case, so let's allow this, but return
+    // Py_None consistently.  This eliminates code in the wrappers.
+    Py_INCREF(Py_None);
+    return Py_None;
   }
 
   Dtool_PyTypedObject *classdef = &in_classdef;
@@ -417,11 +520,10 @@ PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) {
 
   if (module == NULL) {
 #if PY_MAJOR_VERSION >= 3
-    PyErr_SetString(PyExc_TypeError, "PyModule_Create returned NULL");
+    return Dtool_Raise_TypeError("PyModule_Create returned NULL");
 #else
-    PyErr_SetString(PyExc_TypeError, "Py_InitModule returned NULL");
+    return Dtool_Raise_TypeError("Py_InitModule returned NULL");
 #endif
-    return NULL;
   }
 
   // the constant inits... enums, classes ...
@@ -430,7 +532,6 @@ PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) {
   }
 
   PyModule_AddIntConstant(module, "Dtool_PyNativeInterface", 1);
-
   return module;
 }
 
@@ -461,10 +562,10 @@ PyObject *Dtool_BorrowThisReference(PyObject *self, PyObject *args) {
         return Py_None;
       }
 
-      PyErr_Format(PyExc_TypeError, "types %s and %s do not match",
-                   Py_TYPE(from)->tp_name, Py_TYPE(to)->tp_name);
+      return PyErr_Format(PyExc_TypeError, "types %s and %s do not match",
+                          Py_TYPE(from)->tp_name, Py_TYPE(to)->tp_name);
     } else {
-      PyErr_SetString(PyExc_TypeError, "One of these does not appear to be DTOOL Instance ??");
+      return Dtool_Raise_TypeError("One of these does not appear to be DTOOL Instance ??");
     }
   }
   return (PyObject *) NULL;
@@ -479,16 +580,17 @@ PyObject *Dtool_AddToDictionary(PyObject *self1, PyObject *args) {
   PyObject *key;
   if (PyArg_ParseTuple(args, "OSO", &self, &key, &subject)) {
     PyObject *dict = ((PyTypeObject *)self)->tp_dict;
-    if (dict == NULL && !PyDict_Check(dict)) {
-      PyErr_SetString(PyExc_TypeError, "No dictionary On Object");
+    if (dict == NULL || !PyDict_Check(dict)) {
+      return Dtool_Raise_TypeError("No dictionary On Object");
     } else {
-      PyDict_SetItem(dict,key,subject);
+      PyDict_SetItem(dict, key, subject);
     }
   }
   if (PyErr_Occurred()) {
     return (PyObject *)NULL;
   }
-  return Py_BuildValue("");
+  Py_INCREF(Py_None);
+  return Py_None;
 }
 
 ///////////////////////////////////////////////////////////////////////////////////
@@ -653,7 +755,7 @@ PyObject *make_list_for_item(PyObject *self, const char *num_name,
       Py_DECREF(list);
       return NULL;
     }
-    PyList_SetItem(list, i, element);
+    PyList_SET_ITEM(list, i, element);
   }
   return list;
 }

+ 35 - 65
dtool/src/interrogatedb/py_panda.h

@@ -115,7 +115,7 @@ inline PyObject* doPy_RETURN_FALSE()
 #define PyLongOrInt_FromLong PyLong_FromLong
 #define PyLongOrInt_FromUnsignedLong PyLong_FromUnsignedLong
 #define PyInt_Check PyLong_Check
-#define PyInt_AsLong PyLong_Aslong
+#define PyInt_AsLong PyLong_AsLong
 #define PyInt_AS_LONG PyLong_AS_LONG
 #else
 #define PyLongOrInt_Check(x) (PyInt_Check(x) || PyLong_Check(x))
@@ -165,14 +165,14 @@ typedef void *(*DowncastFunction)(void *, Dtool_PyTypedObject *);
 struct Dtool_PyInstDef {
   PyObject_HEAD
 
-  // Pointer to the underlying C++ object.
-  void *_ptr_to_object;
-
   // This is a pointer to the Dtool_PyTypedObject type.  It's tempting
   // not to store this and to instead use PY_TYPE(self) and upcast that,
   // but that breaks when someone inherits from our class in Python.
   struct Dtool_PyTypedObject *_My_Type;
 
+  // Pointer to the underlying C++ object.
+  void *_ptr_to_object;
+
   // This is always set to PY_PANDA_SIGNATURE, so that we can quickly
   // detect whether an object is a Panda object.
   unsigned short _signature;
@@ -208,64 +208,10 @@ struct Dtool_PyTypedObject {
   inline PyObject &As_PyObject() { return (PyObject &)_PyType; };
 };
 
-////////////////////////////////////////////////////////////////////////
-// Macros from Hell..  May want to just add this to the code generator..
-////////////////////////////////////////////////////////////////////////
-#define Define_Dtool_PyTypedObject(MODULE_NAME, CLASS_NAME, PUBLIC_NAME) \
-  EXPORT_THIS Dtool_PyTypedObject Dtool_##CLASS_NAME =                  \
-    {                                                                   \
-      {                                                                 \
-        PyVarObject_HEAD_INIT(NULL, 0)                                  \
-        #MODULE_NAME "." #PUBLIC_NAME,       /*type name with module */ \
-        sizeof(Dtool_PyInstDef),                /* tp_basicsize */      \
-        0,                                      /* tp_itemsize */       \
-        &Dtool_FreeInstance_##CLASS_NAME,       /* tp_dealloc */        \
-        0,                                      /* tp_print */          \
-        0,                                      /* tp_getattr */        \
-        0,                                      /* tp_setattr */        \
-        0,                                      /* tp_compare */        \
-        0,                                      /* tp_repr */           \
-        &Dtool_PyNumberMethods_##CLASS_NAME,    /* tp_as_number */      \
-        &Dtool_PySequenceMethods_##CLASS_NAME,  /* tp_as_sequence */    \
-        &Dtool_PyMappingMethods_##CLASS_NAME,   /* tp_as_mapping */     \
-        0,                                      /* tp_hash */           \
-        0,                                      /* tp_call */           \
-        0,                                      /* tp_str */            \
-        PyObject_GenericGetAttr,                /* tp_getattro */       \
-        PyObject_GenericSetAttr,                /* tp_setattro */       \
-        &Dtool_PyBufferProcs_##CLASS_NAME,      /* tp_as_buffer */      \
-        (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES), /* tp_flags */ \
-        0,                                      /* tp_doc */            \
-        0,                                      /* tp_traverse */       \
-        0,                                      /* tp_clear */          \
-        0,                                      /* tp_richcompare */    \
-        0,                                      /* tp_weaklistoffset */ \
-        0,                                      /* tp_iter */           \
-        0,                                      /* tp_iternext */       \
-        Dtool_Methods_##CLASS_NAME,             /* tp_methods */        \
-        standard_type_members,                  /* tp_members */        \
-        0,                                      /* tp_getset */         \
-        0,                                      /* tp_base */           \
-        0,                                      /* tp_dict */           \
-        0,                                      /* tp_descr_get */      \
-        0,                                      /* tp_descr_set */      \
-        0,                                      /* tp_dictoffset */     \
-        Dtool_Init_##CLASS_NAME,                /* tp_init */           \
-        PyType_GenericAlloc,                    /* tp_alloc */          \
-        Dtool_new_##CLASS_NAME,                 /* tp_new */            \
-        PyObject_Del,                           /* tp_free */           \
-      },                                                                \
-      Dtool_UpcastInterface_##CLASS_NAME,                               \
-      Dtool_DowncastInterface_##CLASS_NAME,                             \
-      TypeHandle::none(),                                               \
-    };
-
-#define Define_Dtool_Class(MODULE_NAME, CLASS_NAME, PUBLIC_NAME)        \
-  static PyNumberMethods Dtool_PyNumberMethods_##CLASS_NAME = {0};      \
-  static PySequenceMethods Dtool_PySequenceMethods_##CLASS_NAME = {0};  \
-  static PyMappingMethods Dtool_PyMappingMethods_##CLASS_NAME = {0};    \
-  static PyBufferProcs Dtool_PyBufferProcs_##CLASS_NAME = {0};          \
-  Define_Dtool_PyTypedObject(MODULE_NAME, CLASS_NAME, PUBLIC_NAME)
+// This is now simply a forward declaration.  The actual definition is created
+// by the code generator.
+#define Define_Dtool_Class(MODULE_NAME, CLASS_NAME, PUBLIC_NAME) \
+  extern Dtool_PyTypedObject Dtool_##CLASS_NAME;
 
 ////////////////////////////////////////////////////////////////////////
 //  More Macro(s) to Implement class functions.. Usually used if C++ needs type information
@@ -326,6 +272,12 @@ static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
   Py_TYPE(self)->tp_free(self);\
 }
 
+#define Define_Dtool_Simple_FreeInstance(CLASS_NAME, CNAME)\
+static void Dtool_FreeInstance_##CLASS_NAME(PyObject *self) {\
+  ((Dtool_InstDef_##CLASS_NAME *)self)->_value.~##CLASS_NAME();\
+  Py_TYPE(self)->tp_free(self);\
+}
+
 ////////////////////////////////////////////////////////////////////////
 /// Simple Recognition Functions..
 ////////////////////////////////////////////////////////////////////////
@@ -385,7 +337,27 @@ template<class T> INLINE bool DTOOL_Call_ExtractThisPointer(PyObject *self, T *&
 EXPCL_DTOOLCONFIG bool Dtool_CheckErrorOccurred();
 #endif
 
-EXPCL_DTOOLCONFIG void Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *function_name, const char *type_name);
+EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_AssertionError();
+EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_TypeError(const char *message);
+EXPCL_DTOOLCONFIG PyObject *Dtool_Raise_ArgTypeError(PyObject *obj, int param, const char *function_name, const char *type_name);
+
+EXPCL_DTOOLCONFIG PyObject *_Dtool_Raise_BadArgumentsError();
+#ifdef NDEBUG
+// Define it to a function that just prints a generic message.
+#define Dtool_Raise_BadArgumentsError(x) _Dtool_Raise_BadArgumentsError()
+#else
+// Expand this to a TypeError listing all of the overloads.
+#define Dtool_Raise_BadArgumentsError(x) Dtool_Raise_TypeError("Arguments must match:\n" x)
+#endif
+
+EXPCL_DTOOLCONFIG PyObject *_Dtool_Return_None();
+EXPCL_DTOOLCONFIG PyObject *Dtool_Return_Bool(bool value);
+
+#ifdef NDEBUG
+#define Dtool_Return_None() (_PyErr_OCCURRED() != NULL ? NULL : (Py_INCREF(Py_None), Py_None))
+#else
+#define Dtool_Return_None() _Dtool_Return_None()
+#endif
 
 ////////////////////////////////////////////////////////////////////////
 //  Function : DTool_CreatePyInstanceTyped
@@ -436,7 +408,6 @@ template<class T> INLINE PyObject *DTool_CreatePyInstanceTyped(T *obj, bool memo
 
 #define Define_Module_Class_Internal(MODULE_NAME,CLASS_NAME,CNAME)\
 extern EXPORT_THIS   Dtool_PyTypedObject Dtool_##CLASS_NAME;\
-extern struct        PyMethodDef Dtool_Methods_##CLASS_NAME[];\
 int         Dtool_Init_##CLASS_NAME(PyObject *self, PyObject *args, PyObject *kwds);\
 PyObject *  Dtool_new_##CLASS_NAME(PyTypeObject *type, PyObject *args, PyObject *kwds);\
 void  *     Dtool_UpcastInterface_##CLASS_NAME(PyObject *self, Dtool_PyTypedObject *requested_type);\
@@ -470,7 +441,6 @@ Define_Dtool_new(CLASS_NAME,CNAME)\
 Define_Dtool_FreeInstanceRef(CLASS_NAME,CNAME)\
 Define_Dtool_Class(MODULE_NAME,CLASS_NAME,PUBLIC_NAME)
 
-
 ///////////////////////////////////////////////////////////////////////////////
 /// Th Finalizer for simple instances..
 ///////////////////////////////////////////////////////////////////////////////

+ 3 - 3
dtool/src/parser-inc/windows.h

@@ -26,7 +26,7 @@ typedef long DWORD;
 typedef long LONG;
 typedef long UINT;
 typedef unsigned long ULONG;
-typedef signed __int64 LONGLONG;
+typedef signed long long LONGLONG;
 typedef long HRESULT;
 typedef int CRITICAL_SECTION;
 typedef int HANDLE;
@@ -45,12 +45,12 @@ typedef struct _STICKYKEYS STICKYKEYS;
 typedef struct _TOGGLEKEYS TOGGLEKEYS;
 typedef struct _FILTERKEYS FILTERKEYS;
 
-#define CALLBACK 
+#define CALLBACK
 
 #define WINAPI
 
 union LARGE_INTEGER {
-  __int64 QuadPart;
+  long long QuadPart;
 };
 
 class IGraphBuilder;

+ 2 - 10
dtool/src/parser-inc/winsock2.h

@@ -2,16 +2,8 @@
 #define _WINSOCK2API_
 #define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */
 
-typedef int SOCKET ;
+typedef int SOCKET;
 
-struct sockaddr_in
-{
-};
-
-
-typedef struct fd_set {
-        unsigned int fd_count;               /* how many are SET? */
-        SOCKET  fd_array[10];   /* an array of SOCKETs */
-} fd_set;
+struct sockaddr_in;
 
 #endif

+ 4 - 0
dtool/src/pystub/pystub.cxx

@@ -123,6 +123,7 @@ extern "C" {
   EXPCL_PYSTUB int PySequence_Tuple(...);
   EXPCL_PYSTUB int PyString_AsString(...);
   EXPCL_PYSTUB int PyString_AsStringAndSize(...);
+  EXPCL_PYSTUB int PyString_FromFormat(...);
   EXPCL_PYSTUB int PyString_FromString(...);
   EXPCL_PYSTUB int PyString_FromStringAndSize(...);
   EXPCL_PYSTUB int PyString_InternFromString(...);
@@ -155,6 +156,7 @@ extern "C" {
   EXPCL_PYSTUB int PyUnicode_AsUTF8AndSize(...);
   EXPCL_PYSTUB int PyUnicode_AsWideChar(...);
   EXPCL_PYSTUB int PyUnicode_AsWideCharString(...);
+  EXPCL_PYSTUB int PyUnicode_FromFormat(...);
   EXPCL_PYSTUB int PyUnicode_FromString(...);
   EXPCL_PYSTUB int PyUnicode_FromStringAndSize(...);
   EXPCL_PYSTUB int PyUnicode_FromWideChar(...);
@@ -311,6 +313,7 @@ int PySequence_Size(...) { return 0; }
 int PySequence_Tuple(...) { return 0; }
 int PyString_AsString(...) { return 0; }
 int PyString_AsStringAndSize(...) { return 0; }
+int PyString_FromFormat(...) { return 0; }
 int PyString_FromString(...) { return 0; }
 int PyString_FromStringAndSize(...) { return 0; }
 int PyString_InternFromString(...) { return 0; }
@@ -343,6 +346,7 @@ int PyUnicode_AsUTF8(...) { return 0; }
 int PyUnicode_AsUTF8AndSize(...) { return 0; }
 int PyUnicode_AsWideChar(...) { return 0; }
 int PyUnicode_AsWideCharString(...) { return 0; }
+int PyUnicode_FromFormat(...) { return 0; }
 int PyUnicode_FromString(...) { return 0; }
 int PyUnicode_FromStringAndSize(...) { return 0; }
 int PyUnicode_FromWideChar(...) { return 0; }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio