[PATCH 6 of 7 V2] osutil: use PYMODULEINIT

Jun Wu quark at fb.com
Sat May 13 14:55:28 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1494288978 25200
#      Mon May 08 17:16:18 2017 -0700
# Node ID 86b0d4567e2f7876a492ab2e60220cadb8191625
# Parent  5575f6c5d732a74001bcd96273b12d4d3f555649
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 86b0d4567e2f
osutil: use PYMODULEINIT

diff --git a/mercurial/osutil.c b/mercurial/osutil.c
--- a/mercurial/osutil.c
+++ b/mercurial/osutil.c
@@ -1302,27 +1302,7 @@ static PyMethodDef methods[] = {
 };
 
-#ifdef IS_PY3K
-static struct PyModuleDef osutil_module = {
-	PyModuleDef_HEAD_INIT,
-	"osutil",
-	osutil_doc,
-	-1,
-	methods
-};
+static int precheck(void) {
+	return PyType_Ready(&listdir_stat_type);
+}
 
-PyMODINIT_FUNC PyInit_osutil(void)
-{
-	if (PyType_Ready(&listdir_stat_type) < 0)
-		return NULL;
-
-	return PyModule_Create(&osutil_module);
-}
-#else
-PyMODINIT_FUNC initosutil(void)
-{
-	if (PyType_Ready(&listdir_stat_type) == -1)
-		return;
-
-	Py_InitModule3("osutil", methods, osutil_doc);
-}
-#endif
+PYMODULEINIT(osutil, methods, osutil_doc, 1, precheck(), SKIP);


More information about the Mercurial-devel mailing list