[Python-Dev] Pep 353: Py_ssize_t advice

"Martin v. Löwis" martin at v.loewis.de
Fri Sep 22 22:14:42 CEST 2006


David Abrahams schrieb:
>   #if PY_VERSION_HEX < 0x02050000
>   typedef int Py_ssize_t;
>   #define PY_SSIZE_T_MAX INT_MAX
>   #define PY_SSIZE_T_MIN INT_MIN
>   #endif
> 
> I just wanted to point out that this advice could lead to library
> header collisions when multiple 3rd parties decide to follow it.  I
> suggest it be changed to something like:
> 
>   #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)

Strictly speaking, this shouldn't be necessary. C allows redefinition
of an object-like macro if the replacement list is identical (for
some definition of identical which applies if the fragment is
copied literally from the PEP).

So I assume you had non-identical replacement list? Can you share
what alternative definition you were using?

In any case, I still think this is good practice, so I added it
to the PEP.

> (C++ allows restating of typedefs; if C allows it, that should be
> something like):

C also allows this; yet, our advise would be that these three
names get always defined together - if that is followed, having
a single guard macro should suffice. PY_SSIZE_T_MIN, as you propose,
should be sufficient.

Regards,
Martin



More information about the Python-Dev mailing list