diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 16487b2a6..0e03d22aa 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -365,26 +365,35 @@ SwigPyObjectType(void) { #if PY_VERSION_HEX < 0x030B00A5 SWIGINTERN PyDescrObject * -PyDescr_New(PyTypeObject *descr_type, PyTypeObject *type, const char *name) { - - assert(name != NULL); - assert(name != NULL); +PyDescr_New(PyTypeObject *descr_type, PyTypeObject *type, const char *name) +{ + assert(descr_type != NULL); + assert(type != NULL); + assert(name != NULL); - PyObject *name_obj = PyUnicode_InternFromString(name); - if (name_obj == NULL) { - return NULL; - } + PyObject *name_obj; +#if PY_MAJOR_VERSION >= 3 + name_obj = PyUnicode_InternFromString(name); +#else + name_obj = PyString_InternFromString(name); +#endif + if (name_obj == NULL) { + return NULL; + } - PyDescrObject *descr = (PyDescrObject *)PyType_GenericAlloc(descr_type, 0); - if (descr == NULL) { - return NULL; - } + PyDescrObject *descr = (PyDescrObject *)PyType_GenericAlloc(descr_type, 0); + if (descr == NULL) { + Py_DECREF(name_obj); + return NULL; + } - Py_XINCREF(type) - descr->d_type = type; - descr->d_name = name_obj; - descr->d_qualname = NULL; - return descr; + descr->d_type = (PyTypeObject*)Py_NewRef(type); + descr->d_name = name_obj; + // PyDescrObject.d_qualname was added to Python 3.3.0a1 +#if PY_VERSION_HEX >= 0x030300A1 + descr->d_qualname = NULL; +#endif + return descr; } #endif