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.
This commit is contained in:
parent
8dcbbe8b6c
commit
2e1595a4d0
1 changed files with 4 additions and 4 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue