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

login
register
mail settings
Submitter Jun Wu
Date May 9, 2017, 1:07 a.m.
Message ID <b9a58a643dcc103d122e.1494292048@x1c>
Download mbox | patch
Permalink /patch/20535/
State Superseded
Headers show

Comments

Jun Wu - May 9, 2017, 1:07 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1494290762 25200
#      Mon May 08 17:46:02 2017 -0700
# Node ID b9a58a643dcc103d122e02c66a4545820fa60807
# Parent  ad8cf58a8ba5bf96e6020eb88560c283eb7463c6
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r b9a58a643dcc
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);