Python 3.2 now uses new C integral type Py_hash_t
authorLisandro Dalcin <dalcinl@gmail.com>
Wed, 9 Feb 2011 16:49:22 +0000 (13:49 -0300)
committerLisandro Dalcin <dalcinl@gmail.com>
Wed, 9 Feb 2011 16:49:22 +0000 (13:49 -0300)
Cython/Compiler/Builtin.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/PyrexTypes.py
Cython/Compiler/TypeSlots.py

index 296f1cd3d1e86989f9fa8eedd60987a3bab03f53..65a7ddb3d1f128a17d334db685dc1b92fcda1902 100644 (file)
@@ -366,7 +366,7 @@ builtin_function_table = [
     BuiltinFunction('getattr3',   "OOO",  "O",     "__Pyx_GetAttr3",     "getattr",
                     utility_code = getattr3_utility_code), # Pyrex compatibility
     BuiltinFunction('hasattr',    "OO",   "b",     "PyObject_HasAttr"),
-    BuiltinFunction('hash',       "O",    "l",     "PyObject_Hash"),
+    BuiltinFunction('hash',       "O",    "h",     "PyObject_Hash"),
     #('hex',       "",     "",      ""),
     #('id',        "",     "",      ""),
     #('input',     "",     "",      ""),
index 7d90bc8aeaff8830b74580cd8850fd3a768fa8a4..07220260cde3af8c5ad2f854548fe879aded810f 100644 (file)
@@ -610,6 +610,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
   #define PyBoolObject                 PyLongObject
 #endif
 
+#if PY_VERSION_HEX < 0x03020000
+  typedef long Py_hash_t;
+  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
+  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
+#else
+  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
+  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
+#endif
+
 """)
 
         code.put("""
index 6ed25191c00ed831ec1229be4a2f16181983478e..3bc6a1ffe98610924589b5b12afd10c1c08b67d6 100755 (executable)
@@ -1056,6 +1056,14 @@ static CYTHON_INLINE Py_UNICODE __Pyx_PyObject_AsPy_UNICODE(PyObject* x) {
 ''')
 
 
+class CPyHashTType(CIntType):
+
+    to_py_function = "__Pyx_PyInt_FromHash_t"
+    from_py_function = "__Pyx_PyInt_AsHash_t"
+
+    def sign_and_name(self):
+        return "Py_hash_t"
+
 class CPySSizeTType(CIntType):
 
     to_py_function = "PyInt_FromSsize_t"
@@ -2381,6 +2389,7 @@ c_returncode_type =  CReturnCodeType(RANK_INT)
 c_bint_type =        CBIntType(RANK_INT)
 c_py_unicode_type =  CPyUnicodeIntType(RANK_INT-0.5, UNSIGNED)
 c_py_ucs4_type =     CPyUCS4IntType(RANK_LONG-0.5, UNSIGNED)
+c_py_hash_t_type =   CPyHashTType(RANK_LONG+0.5, SIGNED)
 c_py_ssize_t_type =  CPySSizeTType(RANK_LONG+0.5, SIGNED)
 c_ssize_t_type =     CSSizeTType(RANK_LONG+0.5, SIGNED)
 c_size_t_type =      CSizeTType(RANK_LONG+0.5, UNSIGNED)
@@ -2443,6 +2452,7 @@ modifiers_and_name_to_type = {
     (1,  0, "bint"):       c_bint_type,
     (0,  0, "Py_UNICODE"): c_py_unicode_type,
     (0,  0, "Py_UCS4"):    c_py_ucs4_type,
+    (2,  0, "Py_hash_t"):  c_py_hash_t_type,
     (2,  0, "Py_ssize_t"): c_py_ssize_t_type,
     (2,  0, "ssize_t") :   c_ssize_t_type,
     (0,  0, "size_t") :    c_size_t_type,
@@ -2692,6 +2702,8 @@ def parse_basic_type(name):
         signed = 0
     elif name == 'Py_UCS4':
         signed = 0
+    elif name == 'Py_hash_t':
+        signed = 2
     elif name == 'Py_ssize_t':
         signed = 2
     elif name == 'ssize_t':
index 9bb26c429cb9716f87eb2a06bb4ffd49a97be23a..d6bf22e82565fd8c9f3cdbde5fdc3ec862ea40ce 100644 (file)
@@ -32,6 +32,7 @@ class Signature(object):
     #    'b'  bint
     #    'I'  int *
     #    'l'  long
+    #    'h'  Py_hash_t
     #    'z'  Py_ssize_t
     #    'Z'  Py_ssize_t *
     #    's'  char *
@@ -52,6 +53,7 @@ class Signature(object):
         'b': PyrexTypes.c_bint_type,
         'I': PyrexTypes.c_int_ptr_type,
         'l': PyrexTypes.c_long_type,
+        'h': PyrexTypes.c_py_hash_t_type,
         'z': PyrexTypes.c_py_ssize_t_type,
         'Z': PyrexTypes.c_py_ssize_t_ptr_type,
         's': PyrexTypes.c_char_ptr_type,
@@ -69,6 +71,7 @@ class Signature(object):
         'b': "-1",
         'l': "-1",
         'r': "-1",
+        'h': "-1",
         'z': "-1",
     }
 
@@ -534,7 +537,7 @@ setattrofunc = Signature("TOO", 'r')       # typedef int (*setattrofunc)(PyObjec
 delattrofunc = Signature("TO", 'r')
 cmpfunc = Signature("TO", "i")             # typedef int (*cmpfunc)(PyObject *, PyObject *);
 reprfunc = Signature("T", "O")             # typedef PyObject *(*reprfunc)(PyObject *);
-hashfunc = Signature("T", "l")             # typedef long (*hashfunc)(PyObject *);
+hashfunc = Signature("T", "h")             # typedef Py_hash_t (*hashfunc)(PyObject *);
                                            # typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
 richcmpfunc = Signature("OOi", "O")        # typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
 getiterfunc = Signature("T", "O")          # typedef PyObject *(*getiterfunc) (PyObject *);