Patchwork [5,of,7,V2] mpatch: use PYMODULEINIT

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

Comments

Jun Wu - May 13, 2017, 6:55 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1494290506 25200
#      Mon May 08 17:41:46 2017 -0700
# Node ID 5575f6c5d732a74001bcd96273b12d4d3f555649
# Parent  bdb69cf7f0ff217074288b5f21bdfb28860358a0
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5575f6c5d732
mpatch: use PYMODULEINIT

A side effect of the clean up is mercurial.mpatch.mpatchError gets exposed,
which seems to be a good thing.

Patch

diff --git a/mercurial/mpatch_module.c b/mercurial/mpatch_module.c
--- a/mercurial/mpatch_module.c
+++ b/mercurial/mpatch_module.c
@@ -161,35 +161,13 @@  static PyMethodDef methods[] = {
 };
 
-#ifdef IS_PY3K
-static struct PyModuleDef mpatch_module = {
-	PyModuleDef_HEAD_INIT,
-	"mpatch",
-	mpatch_doc,
-	-1,
-	methods
-};
-
-PyMODINIT_FUNC PyInit_mpatch(void)
+static int postinit(PyObject *mod)
 {
-	PyObject *m;
-
-	m = PyModule_Create(&mpatch_module);
-	if (m == NULL)
-		return NULL;
-
 	mpatch_Error = PyErr_NewException("mercurial.mpatch.mpatchError",
 					  NULL, NULL);
+	if (!mpatch_Error)
+		return -1;
 	Py_INCREF(mpatch_Error);
-	PyModule_AddObject(m, "mpatchError", mpatch_Error);
-
-	return m;
+	return PyModule_AddObject(mod, "mpatchError", mpatch_Error);
 }
-#else
-PyMODINIT_FUNC
-initmpatch(void)
-{
-	Py_InitModule3("mpatch", methods, mpatch_doc);
-	mpatch_Error = PyErr_NewException("mercurial.mpatch.mpatchError",
-					  NULL, NULL);
-}
-#endif
+
+PYMODULEINIT(mpatch, methods, mpatch_doc, 1, SKIP, postinit(m));