[Cython] Fix integer width constant names in stdint.pxd
dalcinl at gmail.com
Tue Jan 3 02:48:40 CET 2012
On 2 January 2012 22:37, Mansour Moufid <mansourmoufid at gmail.com> wrote:
> Now my issue is as follows.
> (I CCed the cython-users list if this question is more appropriate there.)
> I have a simple file, int.pyx:
> from libc.stdint cimport *
> print long(UINT8_MAX)
> print long(UINT16_MAX)
> print long(UINT32_MAX)
> print long(UINT64_MAX)
> with the usual setup.py stuff. Compiling and running:
> $ python setup.py build_ext --inplace
> int.c:566:3: warning: overflow in implicit constant conversion [-Woverflow]
> $ python -c 'import int'
> So obviously there are overflows here. Checking int.c, I see:
> /* "int.pyx":2
> * from libc.stdint cimport *
> * print long(UINT8_MAX) # <<<<<<<<<<<<<<
> * print long(UINT16_MAX)
> * print long(UINT32_MAX)
> __pyx_t_1 = PyInt_FromLong(UINT8_MAX);
> and so on...
> PyInt_FromLong is used for all these constants, regardless of
> signedness or width, so any argument larger than LONG_MAX overflows,
> *before* being converted to the arbitrary-size Python integer type.
> I don't know if this is a bug, or if I'm overlooking something. Is
> there a way for me to use these constants with Python's arbitrary-size
All these constants are declared as "enum", so Cython promotes them to
"int". Once again, Cython should have something like a "const" type
qualifier to poperly declare these compile-time constants.
As workaround, you could explicitly cast the constants like this
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
More information about the cython-devel