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
This commit is contained in:
Vadim Zeitlin 2012-11-09 17:57:42 +00:00
commit 0ca11c8b6f
2 changed files with 8 additions and 1 deletions

View file

@ -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;