Submitter | Yuya Nishihara |
---|---|
Date | March 3, 2018, 1:27 p.m. |
Message ID | <42b8b2c1eb3b5c70e50e.1520083655@mimosa> |
Download | mbox | patch |
Permalink | /patch/28767/ |
State | Accepted |
Headers | show |
Comments
On Sat, Mar 3, 2018 at 8:27 AM, Yuya Nishihara <yuya@tcha.org> wrote: > # HG changeset patch > # User Yuya Nishihara <yuya@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@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel >
Patch
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