[Cython] Fix integer width constant names in stdint.pxd

Mansour Moufid mansourmoufid at gmail.com
Tue Jan 3 02:37:34 CET 2012


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'
255
65535
-1
-1

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
integers?

Thanks,
Mansour


More information about the cython-devel mailing list