From: Lisandro Dalcin Date: Wed, 9 Feb 2011 16:49:22 +0000 (-0300) Subject: Python 3.2 now uses new C integral type Py_hash_t X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e5778e2079c1b80e63256e02bbcfac401c357a8c;p=cython.git Python 3.2 now uses new C integral type Py_hash_t --- diff --git a/Cython/Compiler/Builtin.py b/Cython/Compiler/Builtin.py index 296f1cd3..65a7ddb3 100644 --- a/Cython/Compiler/Builtin.py +++ b/Cython/Compiler/Builtin.py @@ -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', "", "", ""), diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 7d90bc8a..07220260 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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(""" diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 6ed25191..3bc6a1ff 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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': diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index 9bb26c42..d6bf22e8 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -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 *);