[python-win32] Re: Errors (?) in win32con.py

Thomas Heller theller at python.net
Mon Sep 6 10:26:56 CEST 2004


"Mark Hammond" <mhammond at skippinet.com.au> writes:

> Thomas:
>> >Looking into the win32con.py source code:
>> >
>> >PY_0U = 5177344
>> >CDN_FIRST = (PY_0U-601)
>> >CDN_SELCHANGE = (CDN_FIRST - 1)
>> >
>> >I'm puzzled.  What is PY_0U?
>> >
>> >
>>
>> Interesting; I would call that a bug.  It's clearly an
>> attempt to render
>> the C unsigned constant 0U into Python, but you are correct: the
>> resulting values are not the same.  CDN_FIRST should be -601,
>> which is
>> FFFFFDA7, not 004FDA7.
>
> Yeah, I think that is correct.  I've no idea where PY_0U came from - quite
> possibly a very old h2py used way back when it was created.
>
>> Unfortunately, playing with this stuff runs into the new
>> FutureWarnings.  I would have guessed that
>>     PY_0U = 0x10000000L
>> would produce the best overall results.
>
> I'm not too happy promoting all these constants to longs just to prevent
> that warning.  These constants are 32 bit values used by the API rather than
> "numbers", so I took the approach of using their base 10 representation
> rather than using hex constants.  I think this whole int/long unification is
> a bit of a mess for people who actually *want* to use machine ints.

> I hope keeping my head in the sand that way doesn't expose my behind
> to being bitten later :)

> So for now, I think setting PY_OU = 0 is the most consistent thing.

I'm currently working on a better replacement for h2py.  A Python script
generates a c++ program, which uses overloaded functions, which in turn
generates a Python module.  Hehe - my first, actually useful c++ program.

This one

"""
#include <windows.h>
#include <limits.h>

#include "dumph.h"

int main()
{
  DUMP(CHAR_BIT);
  DUMP(SCHAR_MIN);
  DUMP(SCHAR_MAX);
  DUMP(UCHAR_MAX);
  DUMP(CHAR_MIN);
  DUMP(CHAR_MAX);
  DUMP(SHRT_MIN);
  DUMP(SHRT_MAX);
  DUMP(USHRT_MAX);
  DUMP(INT_MIN);
  DUMP(INT_MAX);
  DUMP(UINT_MAX);
  DUMP(LONG_MIN);
  DUMP(LONG_MAX);
  DUMP(ULONG_MAX);
  DUMP(_I8_MIN);
  DUMP(_I8_MAX);
  DUMP(_UI8_MAX);
  DUMP(_I16_MIN);
  DUMP(_I16_MAX);
  DUMP(_UI16_MAX);
  DUMP(_I32_MIN);
  DUMP(_I32_MAX);
  DUMP(_UI32_MAX);
  DUMP(_I64_MIN);
  DUMP(_I64_MAX);
  DUMP(_UI64_MAX);

  DUMP(MB_OK);
  DUMP(CDN_SELCHANGE);
  DUMP(RICHEDIT_CLASS);
  DUMP(RICHEDIT_CLASSA);
  DUMP(RICHEDIT_CLASSW);
  return 0;
}
"""

prints this, which seems to work correctly both in Python 2.3 and 2.4:

"""
CHAR_BIT = 8
SCHAR_MIN = -128
SCHAR_MAX = 127
UCHAR_MAX = 255
CHAR_MIN = -128
CHAR_MAX = 127
SHRT_MIN = -32768
SHRT_MAX = 32767
USHRT_MAX = 65535
INT_MIN = -2147483648
INT_MAX = 2147483647
UINT_MAX = 4294967295
LONG_MIN = -2147483648
LONG_MAX = 2147483647
ULONG_MAX = 4294967295
_I8_MIN = -128
_I8_MAX = 127
_UI8_MAX = 255
_I16_MIN = -32768
_I16_MAX = 32767
_UI16_MAX = 65535
_I32_MIN = -2147483648
_I32_MAX = 2147483647
_UI32_MAX = 4294967295
_I64_MIN = -9223372036854775808
_I64_MAX = 9223372036854775807
_UI64_MAX = 18446744073709551615
MB_OK = 0
CDN_SELCHANGE = 4294966694
RICHEDIT_CLASS = "RichEdit20A"
RICHEDIT_CLASSA = "RichEdit20A"
RICHEDIT_CLASSW = u"RichEdit20W"
"""

Maybe this program can then be used to recreate win32con.py.

Thomas



More information about the Python-win32 mailing list