[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#186916: Updated pygame



Le jeu 17/04/2003 à 19:21, Kalle Olavi Niemitalo a écrit :
> I think I have tracked down the cause of the exception.  It
> occurs when mode_ok() in display.c calls PyArg_ParseTuple() to
> parse the argument list given from the Python side.  The
> arguments should match the format "(ii)|ii": first a tuple of two
> ints, and then two optional ints.  The integers in the tuple are
> 800 and 600, as expected.  However, the next one is 2147483648L,
> which does not fit in int.  Python can store this value because
> it uses longs internally, but converting it to int for the C
> code causes the exception.

This one looks very tricky, and is likely to happen on all 64 bit
arches. I found this prototype in the python sources : 
extern DL_IMPORT(int) PyModule_AddIntConstant(PyObject *, char *, long);
While the documentation talks about ints, it actually reads longs, which
becomes truly annoying in the case of pygame, where we use
SDL_FULLSCREEN, which is 0x80000000. On 32 bit arches, it gives
-2147483648 for an int as well as a long. But with 64 bits, the long
becomes 2147483648, which is a wrong value.
Maybe an ugly cast in pygame would work, e.g. :
-PyModule_AddIntConstant(module, "FULLSCREEN", SDL_FULLSCREEN);
+PyModule_AddIntConstant(module, "FULLSCREEN", (int) SDL_FULLSCREEN);
(not sure this is the exact thing to do, but here is the spirit)

Cc'ing debian-python.

> On x86, int and long are equivalent.  I presume that the value
> then wraps around to -2147483648 already before it is converted
> to int, so the exception is avoided.

Exactly.

Thanks for your help, Kalle. You got it straight to the point.
-- 
 .''`.           Josselin Mouette        /\./\
: :' :           josselin.mouette@ens-lyon.org
`. `'                        joss@debian.org
  `-  Debian GNU/Linux -- The power of freedom

Attachment: signature.asc
Description: PGP signature


Reply to: