From 82cdadca2360d0df924e9fd68de0e1af6fd6f4a4 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 30 May 2008 12:29:27 +0200 Subject: [PATCH] use PyBytes_Type instead of PyString_Type in the generated sources, PyBytes fix for Py2.6, unicode fixes for star imports --- Cython/Compiler/Builtin.py | 2 +- Cython/Compiler/ModuleNode.py | 22 ++++++++++++++++++---- Cython/Compiler/Symtab.py | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index f9c6605f..94106760 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -82,7 +82,7 @@ builtin_function_table = [ builtin_types_table = [ ("type", "PyType_Type", []), -# ("str", "PyString_Type", []), +# ("str", "PyBytes_Type", []), ("unicode", "PyUnicode_Type", []), ("file", "PyFile_Type", []), # ("slice", "PySlice_Type", []), diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 418af3ce..066bc568 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -425,7 +425,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("#if PY_MAJOR_VERSION >= 3") code.putln(" #define PyBaseString_Type PyUnicode_Type") - code.putln(" #define PyString_Type PyBytes_Type") code.putln(" #define PyInt_Type PyLong_Type") code.putln(" #define PyInt_Check(op) PyLong_Check(op)") code.putln(" #define PyInt_CheckExact(op) PyLong_CheckExact(op)") @@ -440,6 +439,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln(" #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask") code.putln(" #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask") code.putln(" #define PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)") + code.putln("#else") + code.putln(" #define PyBytes_Type PyString_Type") code.putln("#endif") code.putln("#if PY_MAJOR_VERSION >= 3") @@ -2124,8 +2125,13 @@ __Pyx_import_all_from(PyObject *locals, PyObject *v) break; } if (skip_leading_underscores && +#if PY_MAJOR_VERSION < 3 PyString_Check(name) && PyString_AS_STRING(name)[0] == '_') +#else + PyUnicode_Check(name) && + PyUnicode_AS_UNICODE(name)[0] == '_') +#endif { Py_DECREF(name); continue; @@ -2147,10 +2153,11 @@ __Pyx_import_all_from(PyObject *locals, PyObject *v) } -static int %s(PyObject* m) { +static int %(IMPORT_STAR)s(PyObject* m) { int i; int ret = -1; + char* s; PyObject *locals = 0; PyObject *list = 0; PyObject *name; @@ -2163,7 +2170,13 @@ static int %s(PyObject* m) { for(i=0; i