use PyBytes_Type instead of PyString_Type in the generated sources, PyBytes fix for...
authorStefan Behnel <scoder@users.berlios.de>
Fri, 30 May 2008 10:29:27 +0000 (12:29 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 30 May 2008 10:29:27 +0000 (12:29 +0200)
Cython/Compiler/Builtin.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Symtab.py

index f9c6605f37cbee2e16db093ee91be8115cb21fbe..94106760107c2197615a6b11fc56b9c8f8a83572 100644 (file)
@@ -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",    []),
index 418af3cee9b11b757b38dd1a36b39a10f677cc90..066bc568b47b9e6ace0bd454fc3c12923c6aa638 100644 (file)
@@ -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<PyList_GET_SIZE(list); i++) {
         name = PyTuple_GET_ITEM(PyList_GET_ITEM(list, i), 0);
         item = PyTuple_GET_ITEM(PyList_GET_ITEM(list, i), 1);
-        if (%s(item, name, PyString_AsString(name)) < 0) goto bad;
+#if PY_MAJOR_VERSION < 3
+        s = PyString_AsString(name);
+#else
+        s = PyUnicode_AsString(name);
+#endif
+        if (!s) goto bad;
+        if (%(IMPORT_STAR_SET)s(item, name, s) < 0) goto bad;
     }
     ret = 0;
     
@@ -2172,4 +2185,5 @@ bad:
     Py_XDECREF(list);
     return ret;
 }
-""" % ( Naming.import_star, Naming.import_star_set )
+""" % {'IMPORT_STAR'     : Naming.import_star,
+       'IMPORT_STAR_SET' : Naming.import_star_set }
index 1fa1ede66ca6c74d953af350c783fab3e6cffa5f..3a0921e1e7c235798cbd9c9d19f2c0d31f2c6f52 100644 (file)
@@ -652,7 +652,7 @@ class BuiltinScope(Scope):
         "long":   ["((PyObject*)&PyLong_Type)", py_object_type],
         "float":  ["((PyObject*)&PyFloat_Type)", py_object_type],
         
-        "str":    ["((PyObject*)&PyString_Type)", py_object_type],
+        "str":    ["((PyObject*)&PyBytes_Type)", py_object_type],
         "unicode":["((PyObject*)&PyUnicode_Type)", py_object_type],
         "tuple":  ["((PyObject*)&PyTuple_Type)", py_object_type],
         "list":   ["((PyObject*)&PyList_Type)", py_object_type],