# HG changeset patch
# User Jun Wu <qu...@fb.com>
# Date 1494290506 25200
#      Mon May 08 17:41:46 2017 -0700
# Node ID 219c4e0d41d807078e3cc9663da11243e81625dd
# Parent  4bd6bf0ecf1ba186851ba6fa3776561b67fe6a7c
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 219c4e0d41d8
mpatch: use PYMODULEINIT

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

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, NULL, postinit);
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to