[PATCH 1 of 7] util.h: Utility macros for handling different Python APIs

Eric Eisner ede at mit.edu
Thu Jun 10 12:36:23 CDT 2010


On Thu, Jun 10, 2010 at 06:39, Renato Cunha <renatoc at gmail.com> wrote:
> +#if PY_MAJOR_VERSION >= 3
> +
> +#define IS_PY3K
> +#define PYBYTES_SIZE PyBytes_Size
> +#define PYINT_FROMLONG PyLong_FromLong
> +#define PYBYTES_RESIZE _PyBytes_Resize
> +#define PYBYTES_GET_SIZE PyBytes_GET_SIZE
> +#define PYBYTES_AS_STRING PyBytes_AsString
> +#define PYBYTES_FROM_STRING PyBytes_FromString
> +#define PYBYTES_FROM_STRING_AND_SIZE PyBytes_FromStringAndSize
> +
> +#else // Python version < 3.0
> +
> +#define PYBYTES_SIZE PyString_Size
> +#define PYINT_FROMLONG PyInt_FromLong
> +#define PYBYTES_RESIZE _PyString_Resize
> +#define PYBYTES_GET_SIZE PyString_GET_SIZE
> +#define PYBYTES_AS_STRING PyString_AsString
> +#define PYBYTES_FROM_STRING PyString_FromString
> +#define PYBYTES_FROM_STRING_AND_SIZE PyString_FromStringAndSize
> +
> +#endif // PY_MAJOR_VERSION

Is there a reason that these names are in all caps to be different
from both python2 and python3? Couldn't the #define statements be used
to make the C code look like either python2 or python3 (preferably),
but work under both?

If possible, this could make future versions of the code already
compatible with idiomatic python3.

-Eric


More information about the Mercurial-devel mailing list