[PATCH 1 of 7 V2] util: add a macro initializing CPython modules
Yuya Nishihara
yuya at tcha.org
Sat May 13 23:57:57 EDT 2017
On Sat, 13 May 2017 11:55:23 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1494288921 25200
> # Mon May 08 17:15:21 2017 -0700
> # Node ID 55ae1324c950e76270ccb0f68c098513bc36fc91
> # Parent 78496ac300255e9996b3e282086661afc08af37c
> # Available At https://bitbucket.org/quark-zju/hg-draft
> # hg pull https://bitbucket.org/quark-zju/hg-draft -r 55ae1324c950
> util: add a macro initializing CPython modules
> +#define PYMODULEINIT(name, methods, doc, version, precheck, postinit) \
> + PyMODINIT_FUNC (init ## name)(void) \
> + { \
> + PyObject *m; \
> + if ((precheck) == -1) \
> + return; \
> + m = Py_InitModule3(#name, methods, doc); \
> + if (m == NULL) \
> + return; \
> + if (PyModule_AddIntConstant(m, "version", version) == -1) \
> + return; \
> + (void)postinit; \
> + }
> +#endif
Maybe I'm a bit conservative about a macro use, but my concern here is, it's
so easy to make postinint never be called.
PYMODULEINIT(parsers, methods, parsers_doc, 1, check_python_version(),
module_init)
More information about the Mercurial-devel
mailing list