From 24d1ae0fc8a9d2943bd31824d0eba840c492088a Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 31 Oct 2007 18:46:51 -0700 Subject: [PATCH] Re-enable __index__ for Py_ssize_t, fix refcount error in that function --- Cython/Compiler/Nodes.py | 9 ++++++++- Cython/Compiler/PyrexTypes.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) 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): -- 2.26.2