From 0ca11c8b6fce3d974a53b2e4aa86b84157ff0ef5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 9 Nov 2012 17:57:42 +0000 Subject: [PATCH] Fix overflow with parameters > LONG_MAX with Python 3. The typemap incorrectly called PyInt_AsLong() if PyInt_Check() passed, but this check is the same as PyLong_Check() for Python 3 and so the correct PyLong_AsUnsignedLong() function was never called. As a consequence, passing any value greater than LONG_MAX (e.g. 0x87654321 on 32 bit architectures) to a function taking unsigned int, unsigned long or size_t parameter failed with an overflow error being generated. Fix this by simply disabling the part of the code dealing with PyInts for Python 3 as there is no distinction between PyInt and PyLong there any more. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13877 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 4 ++++ Lib/python/pyprimtypes.swg | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.current b/CHANGES.current index d36e76d62..913951fec 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -4,6 +4,10 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.9 (in progress) =========================== + +2012-11-09: vzeitlin + [Python] Fix overflow when passing values greater than LONG_MAX from Python 3 for parameters with unsigned long C type. + 2012-10-26: wsfulton Fix director typemap searching so that a typemap specified with a name will be correctly matched. Previously the name was ignored during the typemap search. Applies to the following list of typemaps: diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 290f9312f..3fbd86a21 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -109,6 +109,7 @@ SWIG_From_dec(unsigned long)(unsigned long value) SWIGINTERN int SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) { +%#if PY_VERSION_HEX < 0x03000000 if (PyInt_Check(obj)) { long v = PyInt_AsLong(obj); if (v >= 0) { @@ -117,7 +118,9 @@ SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val) } 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;