From: Robert Bradshaw <robertwb@math.washington.edu> Date: Thu, 1 Nov 2007 01:46:51 +0000 (-0700) Subject: Re-enable __index__ for Py_ssize_t, fix refcount error in that function X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=24d1ae0fc8a9d2943bd31824d0eba840c492088a;p=cython.git Re-enable __index__ for Py_ssize_t, fix refcount error in that function --- diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 00082716..da668aa2 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2934,7 +2934,14 @@ utility_function_predeclarations = \ typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ typedef struct {PyObject **p; char *s; long n; int is_unicode;} __Pyx_StringTabEntry; /*proto*/ -#define __pyx_PyIndex_AsSsize_t(b) PyInt_AsSsize_t(PyNumber_Index(b)) +static INLINE Py_ssize_t __pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject* x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} #define __Pyx_PyBool_FromLong(b) ((b) ? (Py_INCREF(Py_True), Py_True) : (Py_INCREF(Py_False), Py_False)) static INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index f5067241..3874474e 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -417,7 +417,7 @@ class CULongLongType(CUIntType): class CPySSizeTType(CIntType): to_py_function = "PyInt_FromSsize_t" - from_py_function = "PyInt_AsSsize_t" + from_py_function = "__pyx_PyIndex_AsSsize_t" class CFloatType(CNumericType):