summaryrefslogtreecommitdiff
path: root/tools/swig
diff options
context:
space:
mode:
authorMathieu Lamarre <mathieu@vlam3d.com>2016-04-22 11:32:48 -0400
committerMathieu Lamarre <mathieu@vlam3d.com>2016-04-22 11:32:48 -0400
commit5cdb06038fdff4a6e4e74d5b70936d3bfbdde3d1 (patch)
treec8a18ee26a3be2ebafc73e044ca3eee045458b27 /tools/swig
parentda6e4c71aa229b8bdb18d643456cda4594e6384a (diff)
downloadnumpy-5cdb06038fdff4a6e4e74d5b70936d3bfbdde3d1.tar.gz
Fix a false positive OverflowError in Python 3.x when value above 0x7FFFFFF are passed to a function accepting "unsigned int".
This a port of a fix in pyprimtype.swg from which several code snippets where copy pasted into swig/pyfragments.swg. Please see SWIG changes log (2015-12-23) for more details: http://www.swig.org/Release/CHANGES.current 2015-12-23: ahnolds [Python] Fixes for conversion of signed and unsigned integer types ...
Diffstat (limited to 'tools/swig')
-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;