[Python-Dev] Twisted and Python 2.5a0r43587

"Martin v. Löwis" martin at v.loewis.de
Tue Apr 4 22:36:01 CEST 2006


Thomas Wouters wrote:
> It's just too bad that it's an easily overlooked hint, and that you
> can't get that hint when compiling for 32-bit platforms.

That all depends on the compiler, of course. Both MSVC and the Intel
compiler support a /Wp64 flag, which tells you about "questionable"
conversions between types even if the types currently happen to be
the same.

Python's PC/pyconfig.h defines Py_ssize_t (indirectly) as

typedef _W64 int ssize_t;

where _W64 expands to __w64, which clues the compiler that ssize_t
(and thus Py_ssize_t) would be 64 bits on Win64, and that truncation
and pointer type conflicts can arise when this is mixed with int
(resp. int*).

This is the second part (you can get the hint on a 32-bit system
if you use the right compiler).

On the first issue, I wish it was possible to tell the compiler
that this kind of pointer conversion is really an error.

For gcc, this is possible to do: -pedantic-errors changes all
warnings that are considered "pedantic" to errors. A pedantic warning
is a diagnostic that ISO C requires from a conforming implementation.
The specific problem (converting type pointers in parameter passing
without explicit cast) is such a required diagnostic, and thus
causes compilation to abort.

Unfortunately, this option is *really* pedantic. It first complains
about "long long", which can be overridden with -std=gnu99; it then
aborts at

Objects/methodobject.c: In function 'meth_hash':
Objects/methodobject.c:232: error: ISO C forbids conversion of function
pointer to object pointer type

This kind of conversion is frequent in Python (e.g. in typeobject.c),
so for Python itself, this is no easy option. To fix that, Python
would have to replace void* with, say, void(*)(void) in all places
where it passes function pointers around.

> Extension
> writers with 64-bit hardware access and the desire to compile, let alone
> test, on said hardware is still rare. If we did make PY_SSIZE_T_CLEAN
> adjust all Py_ssize_t*-using functions (which would mean a *lot* of API
> duplication), we could add a #warning for every use of the old API
> calls, so everyone sees it, even on 32-bit platforms.

How would you do that? You could trigger a linker warning on platforms
that support that, but that would be different from #warning - I doubt
you can cause a compiler warning if a certain function is called.

Regards,
Martin


More information about the Python-Dev mailing list