Patchwork [4,of,7,V2] diffhelpers: use PYMODULEINIT

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

Comments

Jun Wu - May 13, 2017, 6:55 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1494290124 25200
#      Mon May 08 17:35:24 2017 -0700
# Node ID bdb69cf7f0ff217074288b5f21bdfb28860358a0
# Parent  2387f3cfbf1ef2b8cfec514cc558d94dc257a219
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r bdb69cf7f0ff
diffhelpers: use PYMODULEINIT

The exception code was cleaned up a bit so it is also attached to the module
in Python 2.

Patch

diff --git a/mercurial/diffhelpers.c b/mercurial/diffhelpers.c
--- a/mercurial/diffhelpers.c
+++ b/mercurial/diffhelpers.c
@@ -165,35 +165,13 @@  static PyMethodDef methods[] = {
 };
 
-#ifdef IS_PY3K
-static struct PyModuleDef diffhelpers_module = {
-	PyModuleDef_HEAD_INIT,
-	"diffhelpers",
-	diffhelpers_doc,
-	-1,
-	methods
-};
-
-PyMODINIT_FUNC PyInit_diffhelpers(void)
+static int postinit(PyObject *mod)
 {
-	PyObject *m;
-
-	m = PyModule_Create(&diffhelpers_module);
-	if (m == NULL)
-		return NULL;
+	diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
+					       NULL, NULL);
+	if (!diffhelpers_Error)
+		return -1;
+	Py_INCREF(diffhelpers_Error);
+	return PyModule_AddObject(mod, "diffhelpersError", diffhelpers_Error);
+}
 
-	diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
-											NULL, NULL);
-	Py_INCREF(diffhelpers_Error);
-	PyModule_AddObject(m, "diffhelpersError", diffhelpers_Error);
-
-	return m;
-}
-#else
-PyMODINIT_FUNC
-initdiffhelpers(void)
-{
-	Py_InitModule3("diffhelpers", methods, diffhelpers_doc);
-	diffhelpers_Error = PyErr_NewException("diffhelpers.diffhelpersError",
-	                                        NULL, NULL);
-}
-#endif
+PYMODULEINIT(diffhelpers, methods, diffhelpers_doc, 1, SKIP, postinit(m));