Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
df26fdeb
Commit
df26fdeb
authored
May 12, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more correct fake implementation of PyNumber_Index() and PyIndex_Check() for Py2.4
parent
a3a35f91
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
Cython/Utility/ModuleSetupCode.c
Cython/Utility/ModuleSetupCode.c
+5
-2
tests/run/unportable_capi_functions.pyx
tests/run/unportable_capi_functions.pyx
+37
-0
No files found.
Cython/Utility/ModuleSetupCode.c
View file @
df26fdeb
...
@@ -47,8 +47,11 @@
...
@@ -47,8 +47,11 @@
#define PY_FORMAT_SIZE_T ""
#define PY_FORMAT_SIZE_T ""
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
#define PyInt_FromSsize_t(z) PyInt_FromLong(z)
#define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
#define PyInt_AsSsize_t(o) __Pyx_PyInt_AsInt(o)
#define PyNumber_Index(o) PyNumber_Int(o)
#define PyNumber_Index(o) ((PyNumber_Check(o) && !PyFloat_Check(o)) ? \
#define PyIndex_Check(o) PyNumber_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 PyErr_WarnEx(category, message, stacklevel) PyErr_Warn(category, message)
#define __PYX_BUILD_PY_SSIZE_T "i"
#define __PYX_BUILD_PY_SSIZE_T "i"
#else
#else
...
...
tests/run/unportable_capi_functions.pyx
0 → 100644
View file @
df26fdeb
# mode: run
# tag: portability
# test some C-API functions that Cython replaces for portability reasons
from
cpython.number
cimport
PyNumber_Index
,
PyIndex_Check
def
number_index
(
x
):
"""
>>> number_index(1)
1
>>> try: number_index(1.1)
... except TypeError: pass
... else: print "FAILED"
>>> try: number_index(1j)
... except TypeError: pass
... else: print "FAILED"
>>> try: number_index('abc')
... except TypeError: pass
... else: print "FAILED"
"""
# was not available in Py2.4
return
PyNumber_Index
(
x
)
def
index_check
(
x
):
"""
>>> index_check(1)
True
>>> index_check(1.1)
False
>>> index_check(1j)
False
>>> index_check('abc')
False
"""
# was not available in Py2.4
return
PyIndex_Check
(
x
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment