Patchwork [6,of,7,V2] osutil: use PYMODULEINIT

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

Comments

Jun Wu - May 13, 2017, 6:55 p.m.
# HG changeset patch
# User Jun Wu <quark@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

Patch

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);