From 2e1595a4d07eaa3434f7e1a451bcf01cfad6f0e1 Mon Sep 17 00:00:00 2001 From: Alec Cooper Date: Sun, 24 Jan 2016 19:18:00 -0500 Subject: [PATCH] When possible, use PyInt rather than PyLong This is especially important for the unsigned long typemap, which is used by the size_t typemap, which is in turn used for lengths of std containers etc. In Python2, len requires old-style classes' __len__ method return a PyIntObject rather than a PyLongObject, so this supports that requirement. --- Lib/python/pyprimtypes.swg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/python/pyprimtypes.swg b/Lib/python/pyprimtypes.swg index 2ef09a1ba..fb5bbf6df 100644 --- a/Lib/python/pyprimtypes.swg +++ b/Lib/python/pyprimtypes.swg @@ -67,7 +67,7 @@ SWIGINTERNINLINE PyObject* /* long */ %fragment(SWIG_From_frag(long),"header") { - %define_as(SWIG_From_dec(long), PyLong_FromLong) + %define_as(SWIG_From_dec(long), PyInt_FromLong) } %fragment(SWIG_AsVal_frag(long),"header", @@ -123,7 +123,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(unsigned long)(unsigned long value) { return (value > LONG_MAX) ? - PyLong_FromUnsignedLong(value) : PyLong_FromLong(%numeric_cast(value,long)); + PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long)); } } @@ -186,7 +186,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(long long)(long long value) { return ((value < LONG_MIN) || (value > LONG_MAX)) ? - PyLong_FromLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); + PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long)); } %#endif } @@ -244,7 +244,7 @@ SWIGINTERNINLINE PyObject* SWIG_From_dec(unsigned long long)(unsigned long long value) { return (value > LONG_MAX) ? - PyLong_FromUnsignedLongLong(value) : PyLong_FromLong(%numeric_cast(value,long)); + PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long)); } %#endif }