[Python-Dev] [Python-checkins] r43028 - python/trunk/Modules/_ctypes/cfield.c (original) (raw)
Tim Peters tim.peters at gmail.com
Wed Mar 15 09:41:20 CET 2006
- Previous message: [Python-Dev] [Python-checkins] Python Regression Test Failuresrefleak (1)
- Next message: [Python-Dev] [Python-checkins] r43028 - python/trunk/Modules/_ctypes/cfield.c
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: thomas.heller Date: Tue Mar 14 21:39:27 2006 New Revision: 43028
Modified: python/trunk/Modules/ctypes/cfield.c Log: Cast an Pyssizet to int, to avoid a compiler warning. Modified: python/trunk/Modules/ctypes/cfield.c ============================================================================== --- python/trunk/Modules/ctypes/cfield.c (original) +++ python/trunk/Modules/ctypes/cfield.c Tue Mar 14 21:39:27 2006 @@ -251,10 +251,10 @@ if (bits) _result = PyStringFromFormat("", - name, self->offset, size, bits); + name, (int)self->offset, size, bits); else _result = PyStringFromFormat("", - name, self->offset, size); + name, (int)self->offset, size); return result; }
[Neal Norwitz]
This isn't exactly correct. On a 64-bit system, the value will be cast into a 32-bit integer. This is true for both Win64 and Unix. If you change the cast to a long and use %ld (lowercase ell), that will work correctly on Unix, but not Win64. To always display the correct value on all platforms, you need an #ifdef MSWIN64. For Windows, you use %Id (that's a capital letter eye) and reference the value without a cast. For Unix, you use %ld (lowercase ell), and cast the value to a (long) to avoid a warning.
I'm copying this to python-dev because it's important people understand this :-): all of the above is kinda true but irrelevant. Martin already checked in a patch so that PyString_FromFormat() understands the C99 "z" qualifier on all platforms. So the correct way to repair this one wasn't to add a cast, and much less to add an #ifdef, it was to change
ofs=%d
to
ofs=%zd
in the format. I'm going to check that change in now, but don't make me do it again :-)
- Previous message: [Python-Dev] [Python-checkins] Python Regression Test Failuresrefleak (1)
- Next message: [Python-Dev] [Python-checkins] r43028 - python/trunk/Modules/_ctypes/cfield.c
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]