From 3a85de47fa4ce3ec6fa46a84de78f8e18727d99e Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 20 Nov 2009 16:02:06 -0500 Subject: Start trying to fixup module initialization --- 2to3c | 3 ++- fixes/init-module.cocci | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 fixes/init-module.cocci 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 + + ... +} -- cgit