[PATCH 4 of 7] diffhelpers: use PYMODULEINIT
Jun Wu
quark at fb.com
Mon May 8 21:07:25 EDT 2017
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1494290124 25200
# Mon May 08 17:35:24 2017 -0700
# Node ID 4bd6bf0ecf1ba186851ba6fa3776561b67fe6a7c
# Parent 04056409e50d16af48c92d69d81733bd04fed01c
# Available At https://bitbucket.org/quark-zju/hg-draft
# hg pull https://bitbucket.org/quark-zju/hg-draft -r 4bd6bf0ecf1b
diffhelpers: use PYMODULEINIT
The exception code was cleaned up a bit so it is also attached to the module
in Python 2.
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, NULL, postinit);
More information about the Mercurial-devel
mailing list