[Python-3000] Int and Long unification (was Re: Help replacing Py_FindMethod)
"Martin v. Löwis"
martin at v.loewis.de
Sat Jul 19 15:56:00 CEST 2008
> (since PyInt_* functions don't exist in Python 3.0).
Some PyInt_ functions exist in intobject.h, which you need to include
explicitly.
> But
> since an integer fails "PyLong_Check()" in Python 2.*, how can I check
> for integers portably between Python 2.[3-6] and Python 3.0?. I would
> like to avoid conditional compilation, if possible.
Depends on what you want to test. If anything that has nb_int available
is sufficient, check for presence of nb_int. If you only want to test
for int-or-long, use intobject.h, and write
if (PyInt_Check(o) || PyLong_Check(o))
If you don't want to use intobject.h, write
#ifndef PyInt_Check
#define PyInt_Check(x) PyLong_Check(x)
#endif
at the top, then use the same if block.
HTH,
Martin
More information about the Python-3000
mailing list