summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x2to3c3
-rw-r--r--fixes/init-module.cocci31
2 files changed, 33 insertions, 1 deletions
diff --git a/2to3c b/2to3c
index 2be282d..ede6fb2 100755
--- a/2to3c
+++ b/2to3c
@@ -4,7 +4,8 @@ def get_fixers():
from fixes.typeobject import FixTypeobjectInitializers
from fixes import CocciFix
fixes = [FixTypeobjectInitializers()]
- for filename in ['RO.cocci', 'int-to-long.cocci', 'ob_type.cocci', 'repr.cocci']:
+ for filename in ['RO.cocci', 'int-to-long.cocci', 'ob_type.cocci',
+ 'repr.cocci', 'init-module.cocci']:
fixes.append(CocciFix(filename))
return fixes
diff --git a/fixes/init-module.cocci b/fixes/init-module.cocci
new file mode 100644
index 0000000..fb59f45
--- /dev/null
+++ b/fixes/init-module.cocci
@@ -0,0 +1,31 @@
+@@
+type T;
+identifier FN;
+identifier MOD_VAR;
+expression MODULE_NAME, MODULE_METHODS, MODULE_DOC;
+@@
++ #if PY_MAJOR_VERSION >= 3
++static struct PyModuleDef moduledef = {
++ PyModuleDef_HEAD_INIT,
++ MODULE_NAME, /* m_name */
++ MODULE_DOC, /* m_doc */
++ 0, /* m_size */
++ MODULE_METHODS, /* m_methods */
++ NULL, /* m_reload */
++ NULL, /* m_traverse */
++ NULL, /* m_clear */
++ NULL, /* m_free */
++};
++ #endif
+
+T FN(void) {
+ ...
+
++ #if PY_MAJOR_VERSION >= 3
++ MOD_VAR = PyModule_Create(&moduledef);
++ #else
+ MOD_VAR = Py_InitModule3(MODULE_NAME, MODULE_METHODS, MODULE_DOC);
++ #endif
+
+ ...
+}