From d8f054f3c9409cdf6b3c590fc8c22c0885301767 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 10 Sep 2008 16:39:36 +0200 Subject: [PATCH] cleanup of __Pyx_ImportType() to allow constifying the imported class name string --- Cython/Compiler/ModuleNode.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 6429f85b..b772c2c5 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1987,29 +1987,29 @@ bad: type_import_utility_code = [ """ -static PyTypeObject *__Pyx_ImportType(const char *module_name, char *class_name, long size); /*proto*/ +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size); /*proto*/ """,""" #ifndef __PYX_HAVE_RT_ImportType #define __PYX_HAVE_RT_ImportType -static PyTypeObject *__Pyx_ImportType(const char *module_name, char *class_name, +static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, long size) { PyObject *py_module = 0; PyObject *result = 0; PyObject *py_name = 0; + py_module = __Pyx_ImportModule(module_name); + if (!py_module) + goto bad; #if PY_MAJOR_VERSION < 3 - py_name = PyString_FromString(module_name); + py_name = PyString_FromString(class_name); #else - py_name = PyUnicode_FromString(module_name); + py_name = PyUnicode_FromString(class_name); #endif if (!py_name) goto bad; - - py_module = __Pyx_ImportModule(module_name); - if (!py_module) - goto bad; - result = PyObject_GetAttrString(py_module, class_name); + result = PyObject_GetAttr(py_module, py_name); + Py_DECREF(py_name); if (!result) goto bad; if (!PyType_Check(result)) { @@ -2026,7 +2026,6 @@ static PyTypeObject *__Pyx_ImportType(const char *module_name, char *class_name, } return (PyTypeObject *)result; bad: - Py_XDECREF(py_name); Py_XDECREF(result); return 0; } -- 2.26.2