From e118e5498942a52ea3f83f88cf17b28b1ece608b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 12 May 2010 21:01:34 +0200 Subject: [PATCH] fix star import utility code in Py3 --- Cython/Compiler/ModuleNode.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 967c2af8..d112d512 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2453,6 +2453,9 @@ static int %(IMPORT_STAR)s(PyObject* m) { char* s; PyObject *locals = 0; PyObject *list = 0; +#if PY_MAJOR_VERSION >= 3 + PyObject *utf8_name = 0; +#endif PyObject *name; PyObject *item; @@ -2463,19 +2466,26 @@ static int %(IMPORT_STAR)s(PyObject* m) { for(i=0; i= 3 + utf8_name = PyUnicode_AsUTF8String(name); + if (!utf8_name) goto bad; + s = PyBytes_AS_STRING(utf8_name); + if (%(IMPORT_STAR_SET)s(item, name, s) < 0) goto bad; + Py_DECREF(utf8_name); utf8_name = 0; #else - s = PyUnicode_AsString(name); -#endif + s = PyString_AsString(name); if (!s) goto bad; if (%(IMPORT_STAR_SET)s(item, name, s) < 0) goto bad; +#endif } ret = 0; bad: Py_XDECREF(locals); Py_XDECREF(list); +#if PY_MAJOR_VERSION >= 3 + Py_XDECREF(utf8_name); +#endif return ret; } """ % {'IMPORT_STAR' : Naming.import_star, -- 2.26.2