#805 SWIG_AsVal_int doesn't report overflow correctly

python (259)

I am upgrading my software (Maya 3D) to use SWIG 1.3.31 from an older version. Some of my unit tests are failing after the upgrade because SWIG is now throwing RuntimeErrors where it used to throw OverflowErrors. SWIG should be throwing Overflow errors my test.

The problem is in SWIG_AsVal_int. It is doing this:

long v;
int res = SWIG_AsVal_long (obj, &v);
if (SWIG_IsOK(res)) {
if ((v < INT_MIN || v > INT_MAX)) {
return SWIG_OverflowError;
} else {

The problem is that on 32-bit systems, and Windows 64-bit, a long and an int are the same type. So, we never get to the overflow check because the value in "res" is going to be false if the Python number is to big.

And SWIG_AsVal_long does not correctly report the overflow either.

The number I am using in my test is 4000000000, which will fit in an unsigned int, but not a regular int...



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks