summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2016-04-25 19:56:15 -0600
committerCharles Harris <charlesr.harris@gmail.com>2016-04-25 19:56:15 -0600
commit1b6831be8dc33308e77f3d3253f5ee777e3bb178 (patch)
treec8a18ee26a3be2ebafc73e044ca3eee045458b27
parentda6e4c71aa229b8bdb18d643456cda4594e6384a (diff)
parent5cdb06038fdff4a6e4e74d5b70936d3bfbdde3d1 (diff)
downloadnumpy-1b6831be8dc33308e77f3d3253f5ee777e3bb178.tar.gz
Merge pull request #7568 from mlamarre/fix_swig_py3_overflow
Fix a false positive OverflowError in Python 3.x when value above 0x7…
-rw-r--r--tools/swig/pyfragments.swg21
1 files changed, 14 insertions, 7 deletions
diff --git a/tools/swig/pyfragments.swg b/tools/swig/pyfragments.swg
index b5decf12c..901e6ed9d 100644
--- a/tools/swig/pyfragments.swg
+++ b/tools/swig/pyfragments.swg
@@ -75,15 +75,22 @@
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
{
PyArray_Descr * ulongDescr = PyArray_DescrNewFromType(NPY_ULONG);
- if (PyInt_Check(obj)) {
+ %#if PY_VERSION_HEX < 0x03000000
+ if (PyInt_Check(obj))
+ {
long v = PyInt_AsLong(obj);
- if (v >= 0) {
- if (val) *val = v;
- return SWIG_OK;
- } else {
- return SWIG_OverflowError;
+ if (v >= 0)
+ {
+ if (val) *val = v;
+ return SWIG_OK;
+ }
+ else
+ {
+ return SWIG_OverflowError;
}
- } else if (PyLong_Check(obj)) {
+ } else
+ %#endif
+ if (PyLong_Check(obj)) {
unsigned long v = PyLong_AsUnsignedLong(obj);
if (!PyErr_Occurred()) {
if (val) *val = v;