[Python-Dev] [Python-checkins] r43028 - python/trunk/Modules/_ctypes/cfield.c

Tim Peters tim.peters at gmail.com
Wed Mar 15 09:41:20 CET 2006

>> Author: thomas.heller
>> Date: Tue Mar 14 21:39:27 2006
>> New Revision: 43028
>> Modified:
>>    python/trunk/Modules/_ctypes/cfield.c
>> Log:
>> Cast an Py_ssize_t 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 = PyString_FromFormat("<Field type=%s,
ofs=%d:%d, bits=%d>",
>> -                                            name, self->offset, size, bits);
>> +                                            name,
(int)self->offset, size, bits);
>>         else
>>                 result = PyString_FromFormat("<Field type=%s,
ofs=%d, size=%d>",
>> -                                            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 MS_WIN64.  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




in the format.  I'm going to check that change in now, but don't make
me do it again :-)

More information about the Python-Dev mailing list