summaryrefslogtreecommitdiff
path: root/Cython/Utility/ModuleSetupCode.c
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2012-05-12 07:32:32 +0200
committerStefan Behnel <stefan_ml@behnel.de>2012-05-12 07:32:32 +0200
commitdf26fdeb9e9bd16a9b4efffe161f791d7cb451a7 (patch)
treee9eacf6a0f4bf4c3a8e2fab21132737491bfbc0f /Cython/Utility/ModuleSetupCode.c
parenta3a35f918c870d7da55180c87a14f3c592b764d1 (diff)
downloadcython-df26fdeb9e9bd16a9b4efffe161f791d7cb451a7.tar.gz
more correct fake implementation of PyNumber_Index() and PyIndex_Check() for Py2.4
Diffstat (limited to 'Cython/Utility/ModuleSetupCode.c')
-rw-r--r--Cython/Utility/ModuleSetupCode.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index 307cafea9..e727ec542 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -47,8 +47,11 @@
#define PY_FORMAT_SIZE_T ""
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
#define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
- #define PyNumber_Index(o) PyNumber_Int(o)
- #define PyIndex_Check(o) PyNumber_Check(o)
+ #define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? \
+ PyNumber_Int(o) \
+ : (PyErr_Format(PyExc_TypeError, "expected index value, got %.200s", \
+ Py_TYPE(o)->tp_name), NULL))
+ #define PyIndex_Check(o) (PyNumber_Check(o) && !PyFloat_Check(o) && !PyComplex_Check(o))
#define PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#define __PYX_BUILD_PY_SSIZE_T "i"
#else