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

Neal Norwitz nnorwitz at gmail.com
Wed Mar 15 09:16:01 CET 2006


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.

n
--
On 3/14/06, thomas.heller <python-checkins at python.org> wrote:
> 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;
>  }


More information about the Python-checkins mailing list