define PyBytes_XXX for Py<2.6 and use these through the codebase
authorLisandro Dalcin <dalcinl@gmail.com>
Fri, 16 Apr 2010 13:31:25 +0000 (10:31 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Fri, 16 Apr 2010 13:31:25 +0000 (10:31 -0300)
Cython/Compiler/ExprNodes.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Optimize.py
Cython/Compiler/PyrexTypes.py

index 4f104a9c117963b52307f0d4d7b6a353a8589b88..dda284c70a77bee7d745af5400e0d23332b269bf 100755 (executable)
@@ -2262,14 +2262,14 @@ class SliceIndexNode(ExprNode):
         if self.base.type.is_string:
             if self.stop is None:
                 code.putln(
-                    "%s = __Pyx_PyBytes_FromString(%s + %s); %s" % (
+                    "%s = PyBytes_FromString(%s + %s); %s" % (
                         self.result(),
                         self.base.result(),
                         self.start_code(),
                         code.error_goto_if_null(self.result(), self.pos)))
             else:
                 code.putln(
-                    "%s = __Pyx_PyBytes_FromStringAndSize(%s + %s, %s - %s); %s" % (
+                    "%s = PyBytes_FromStringAndSize(%s + %s, %s - %s); %s" % (
                         self.result(),
                         self.base.result(),
                         self.start_code(),
@@ -6107,7 +6107,7 @@ class CoerceToBooleanNode(CoercionNode):
     _special_builtins = {
         Builtin.list_type    : 'PyList_GET_SIZE',
         Builtin.tuple_type   : 'PyTuple_GET_SIZE',
-        Builtin.bytes_type   : '__Pyx_PyBytes_GET_SIZE',
+        Builtin.bytes_type   : 'PyBytes_GET_SIZE',
         Builtin.unicode_type : 'PyUnicode_GET_SIZE',
         }
 
index 9ef17f20aeba9d3f42c27ea6aa13a6fafe63bddc..641c080582d0bf2d2b9a83a0f4dc2c39f71ca97f 100644 (file)
@@ -522,11 +522,29 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
 
 #if PY_MAJOR_VERSION >= 3
   #define PyBaseString_Type            PyUnicode_Type
+  #define PyStringObject               PyUnicodeObject
   #define PyString_Type                PyUnicode_Type
+  #define PyString_Check               PyUnicode_Check
   #define PyString_CheckExact          PyUnicode_CheckExact
-#else
+#endif
+
+#if PY_VERSION_HEX < 0x02060000
+  #define PyBytesObject                PyStringObject
   #define PyBytes_Type                 PyString_Type
+  #define PyBytes_Check                PyString_Check
   #define PyBytes_CheckExact           PyString_CheckExact
+  #define PyBytes_FromString           PyString_FromString
+  #define PyBytes_FromStringAndSize    PyString_FromStringAndSize
+  #define PyBytes_FromFormat           PyString_FromFormat
+  #define PyBytes_DecodeEscape         PyString_DecodeEscape
+  #define PyBytes_AsString             PyString_AsString
+  #define PyBytes_AsStringAndSize      PyString_AsStringAndSize
+  #define PyBytes_Size                 PyString_Size
+  #define PyBytes_AS_STRING            PyString_AS_STRING
+  #define PyBytes_GET_SIZE             PyString_GET_SIZE
+  #define PyBytes_Repr                 PyString_Repr
+  #define PyBytes_Concat               PyString_Concat
+  #define PyBytes_ConcatAndDel         PyString_ConcatAndDel
 #endif
 
 #if PY_MAJOR_VERSION >= 3
@@ -1663,7 +1681,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         self.generate_filename_init_call(code)
 
         code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos)));
-        code.putln("%s = __Pyx_PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos)));
+        code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos)));
 
         code.putln("/*--- Library function declarations ---*/")
         env.generate_library_function_declarations(code)
index 625f10e11ad65fbf77058863ffee97b9c4d28b17..69a8ebf9ad11556f187b95874491902895e4fb81 100644 (file)
@@ -1359,7 +1359,7 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
     _map_to_capi_len_function = {
         Builtin.unicode_type   : "PyUnicode_GET_SIZE",
         Builtin.str_type       : "Py_SIZE", # works in Py2 and Py3
-        Builtin.bytes_type     : "__Pyx_PyBytes_GET_SIZE",
+        Builtin.bytes_type     : "PyBytes_GET_SIZE",
         Builtin.list_type      : "PyList_GET_SIZE",
         Builtin.tuple_type     : "PyTuple_GET_SIZE",
         Builtin.dict_type      : "PyDict_Size",
index 26e54343737f043672bb524e1e38a42485321d5c..6f29bbf95f79cad821a891fa75f4cce3d62ce6e6 100755 (executable)
@@ -1989,8 +1989,8 @@ class CStringType(object):
     is_string = 1
     is_unicode = 0
     
-    to_py_function = "__Pyx_PyBytes_FromString"
-    from_py_function = "__Pyx_PyBytes_AsString"
+    to_py_function = "PyBytes_FromString"
+    from_py_function = "PyBytes_AsString"
     exception_value = "NULL"
 
     def literal_code(self, value):
@@ -2455,20 +2455,8 @@ def typecast(to_type, from_type, expr_code):
 type_conversion_predeclarations = """
 /* Type Conversion Predeclarations */
 
-#if PY_MAJOR_VERSION < 3
-#define __Pyx_PyBytes_FromString          PyString_FromString
-#define __Pyx_PyBytes_FromStringAndSize   PyString_FromStringAndSize
-#define __Pyx_PyBytes_AsString            PyString_AsString
-#define __Pyx_PyBytes_GET_SIZE            PyString_GET_SIZE
-#else
-#define __Pyx_PyBytes_FromString          PyBytes_FromString
-#define __Pyx_PyBytes_FromStringAndSize   PyBytes_FromStringAndSize
-#define __Pyx_PyBytes_AsString            PyBytes_AsString
-#define __Pyx_PyBytes_GET_SIZE            PyBytes_GET_SIZE
-#endif
-
-#define __Pyx_PyBytes_FromUString(s)      __Pyx_PyBytes_FromString((char*)s)
-#define __Pyx_PyBytes_AsUString(s)        ((unsigned char*) __Pyx_PyBytes_AsString(s))
+#define __Pyx_PyBytes_FromUString(s) PyBytes_FromString((char*)s)
+#define __Pyx_PyBytes_AsUString(s)   ((unsigned char*) PyBytes_AsString(s))
 
 #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False))
 static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);