X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d02ea46cad50bf1bec81a8d5bcaa495b22f98057..f303d69f934a76c56e14713a0748fdd10635e462:/wxPython/src/_core_api.i?ds=inline diff --git a/wxPython/src/_core_api.i b/wxPython/src/_core_api.i index 940ec32ba3..153124b842 100644 --- a/wxPython/src/_core_api.i +++ b/wxPython/src/_core_api.i @@ -21,7 +21,7 @@ // in the wrapper code. #include -WX_DECLARE_STRING_HASH_MAP( swig_type_info*, wxPyTypeInfoHashMap ); + WX_DECLARE_STRING_HASH_MAP( swig_type_info*, wxPyTypeInfoHashMap ); // Maintains a hashmap of className to swig_type_info pointers. Given the @@ -106,8 +106,9 @@ PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) { PyObject* robj = NULL; swig_type_info* swigType = wxPyFindSwigType(className); - wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyConvertSwigPtr")); + wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyMakeSwigPtr")); +#if SWIG_VERSION < 0x010328 #ifdef SWIG_COBJECT_TYPES robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)swigType->name); #else @@ -117,11 +118,40 @@ PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) { PyString_FromString(result) : 0; } #endif - +#else // SWIG_VERSION >= 1.3.28 + robj = PySwigObject_New(ptr, swigType, 0); +#endif return robj; } +// Python's PyInstance_Check does not return True for instances of new-style +// classes. This should get close enough for both new and old classes but I +// should re-evaluate the need for doing instance checks... +bool wxPyInstance_Check(PyObject* obj) { + return PyObject_HasAttrString(obj, "__class__") != 0; +} + + + +// This one checks if the object is an instance of a SWIG proxy class (it has +// a .this attribute, and the .this attribute is a PySwigObject.) +bool wxPySwigInstance_Check(PyObject* obj) { + static PyObject* this_str = NULL; + if (this_str == NULL) + this_str = PyString_FromString("this"); + + PyObject* this_attr = PyObject_GetAttr(obj, this_str); + if (this_attr) { + bool retval = (PySwigObject_Check(this_attr) != 0); + Py_DECREF(this_attr); + return retval; + } + + PyErr_Clear(); + return false; +} + // Export a C API in a struct. Other modules will be able to load this from