Patchwork [7,of,7,V2] parsers: use PYMODULEINIT

login
register
mail settings
Submitter Jun Wu
Date May 13, 2017, 6:55 p.m.
Message ID <d449ad60b6ae74ddf7a6.1494701729@x1c>
Download mbox | patch
Permalink /patch/20603/
State Superseded
Headers show

Comments

Jun Wu - May 13, 2017, 6:55 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1494290762 25200
#      Mon May 08 17:46:02 2017 -0700
# Node ID d449ad60b6ae74ddf7a6765ab2687a91435c62e9
# Parent  86b0d4567e2f7876a492ab2e60220cadb8191625
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r d449ad60b6ae
parsers: use PYMODULEINIT

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -2855,5 +2855,5 @@  void dirs_module_init(PyObject *mod);
 void manifest_module_init(PyObject *mod);
 
-static void module_init(PyObject *mod)
+static int module_init(PyObject *mod)
 {
 	/* This module constant has two purposes.  First, it lets us unit test
@@ -2873,5 +2873,5 @@  static void module_init(PyObject *mod)
 	if (PyType_Ready(&indexType) < 0 ||
 	    PyType_Ready(&dirstateTupleType) < 0)
-		return;
+		return -1;
 	Py_INCREF(&indexType);
 	PyModule_AddObject(mod, "index", (PyObject *)&indexType);
@@ -2884,4 +2884,5 @@  static void module_init(PyObject *mod)
 	if (nullentry)
 		PyObject_GC_UnTrack(nullentry);
+	return 0;
 }
 
@@ -2912,32 +2913,4 @@  static int check_python_version(void)
 }
 
-#ifdef IS_PY3K
-static struct PyModuleDef parsers_module = {
-	PyModuleDef_HEAD_INIT,
-	"parsers",
-	parsers_doc,
-	-1,
-	methods
-};
-
-PyMODINIT_FUNC PyInit_parsers(void)
-{
-	PyObject *mod;
-
-	if (check_python_version() == -1)
-		return NULL;
-	mod = PyModule_Create(&parsers_module);
-	module_init(mod);
-	return mod;
-}
-#else
-PyMODINIT_FUNC initparsers(void)
-{
-	PyObject *mod;
-
-	if (check_python_version() == -1)
-		return;
-	mod = Py_InitModule3("parsers", methods, parsers_doc);
-	module_init(mod);
-}
-#endif
+PYMODULEINIT(parsers, methods, parsers_doc, 1, check_python_version(),
+	     module_init(m));