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

Re: Bug#186916: Updated pygame



Josselin Mouette <joss@debian.org> writes:

> 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.

I disagree.  <SDL/SDL_video.h> declares SDL_VideoModeOK as:

extern DECLSPEC int SDLCALL SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags);

SDL takes the flags as an unsigned integer; 2147483648 is
entirely correct there.

How should this value be represented in the Python side?
Consider how Python handles hexadecimal constants.  On i386:

| kalle@Astalo:~$ python
| Python 2.2.2 (#1, Mar 29 2003, 19:44:37) 
| [GCC 3.2.3 20030316 (Debian prerelease)] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> 0x7fffffff
| 2147483647
| >>> 0x80000000
| -2147483648
| >>> 0xffffffff
| -1
| >>> 0x100000000
| 4294967296L
| >>> 0x7fffffffffffffff
| 9223372036854775807L
| >>> 0x8000000000000000
| 9223372036854775808L
| >>> 0xffffffffffffffff
| 18446744073709551615L
| >>> 0x10000000000000000
| 18446744073709551616L
| >>> 

But on alpha:

| kalle@Saastamoduuli:~$ python
| Python 2.2.2 (#1, Apr 17 2003, 18:40:10) 
| [GCC 3.2.3 20030407 (Debian prerelease)] on linux2
| Type "help", "copyright", "credits" or "license" for more information.
| >>> 0x7fffffff
| 2147483647
| >>> 0x80000000
| 2147483648
| >>> 0xffffffff
| 4294967295
| >>> 0x100000000
| 4294967296
| >>> 0x7fffffffffffffff
| 9223372036854775807
| >>> 0x8000000000000000
| -9223372036854775808
| >>> 0xffffffffffffffff
| -1
| >>> 0x10000000000000000
| 18446744073709551616L
| >>> 

Hexadecimal constants are typically used for bit masks.  It seems
Python preserves the bits that probably matter, but sacrifices
others in order to fit the value in a machine integer.

I think this means:

* SDL_FULLSCREEN should be mapped to the same value as
  0x80000000: that is, -2147483648 on 32-bit and 2147483648 on
  64-bit platforms.

* Code that decodes bit masks passed from Python should ignore
  the high bits that Python does not attempt to preserve.
  In pygame, mode_ok() should decode the value as a long int
  so that the exception will not occur.



Reply to: