[PATCH 02 of 11] py3: add PY23() macro to switch string literal depending on python version

Gregory Szorc gregory.szorc at gmail.com
Sat Mar 3 10:14:55 EST 2018


On Sat, Mar 3, 2018 at 8:27 AM, Yuya Nishihara <yuya at tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1520074721 18000
> #      Sat Mar 03 05:58:41 2018 -0500
> # Node ID 42b8b2c1eb3b5c70e50e68c68e0c8dc9776f14de
> # Parent  39f26de931737db2ee20b90925f7b3eb56423a89
> py3: add PY23() macro to switch string literal depending on python version
>
> I have no better idea to work around the bytes-unicode divergence of
> Py_BuildValue(). Maybe we can write a code transformer for C extensions? :)
>

There's no unified way to write the code. I used inline #ifdef in
python-zstandard. I like the use of a macro to make the switching inline.


>
> diff --git a/mercurial/cext/util.h b/mercurial/cext/util.h
> --- a/mercurial/cext/util.h
> +++ b/mercurial/cext/util.h
> @@ -14,6 +14,13 @@
>  #define IS_PY3K
>  #endif
>
> +/* helper to switch things like string literal depending on Python
> version */
> +#ifdef IS_PY3K
> +#define PY23(py2, py3) py3
> +#else
> +#define PY23(py2, py3) py2
> +#endif
> +
>  /* clang-format off */
>  typedef struct {
>         PyObject_HEAD
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20180303/1ef3ce20/attachment.html>


More information about the Mercurial-devel mailing list