Commit 9e04e1ee authored by da-woods's avatar da-woods Committed by GitHub

Generate a compiler warning on calls to PyInit_ModuleName() (GH-3582)

For Py3.5+, where inittab should really be used instead. For GCC, Clang, MSVC and C++14
parent d5eca087
...@@ -233,8 +233,32 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -233,8 +233,32 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
h_code.putln('#error "Unicode module names are not supported in Python 2";') h_code.putln('#error "Unicode module names are not supported in Python 2";')
h_code.putln("PyMODINIT_FUNC init%s(void);" % py2_mod_name) h_code.putln("PyMODINIT_FUNC init%s(void);" % py2_mod_name)
h_code.putln("#else") h_code.putln("#else")
h_code.putln("PyMODINIT_FUNC %s(void);" % self.mod_init_func_cname('PyInit', env)) py3_mod_func_name = self.mod_init_func_cname('PyInit', env)
h_code.putln("#endif") warning_string = EncodedString('Use PyImport_AppendInittab("%s", %s) instead of calling %s directly.' % (
py2_mod_name, py3_mod_func_name, py3_mod_func_name))
h_code.putln('/* WARNING: %s from Python 3.5 */' % warning_string.rstrip('.'))
h_code.putln("PyMODINIT_FUNC %s(void);" % py3_mod_func_name)
h_code.putln("")
h_code.putln("#if PY_VERSION_HEX >= 0x03050000 "
"&& (defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) "
"|| (defined(__cplusplus) && __cplusplus >= 201402L))")
h_code.putln("#if defined(__cplusplus) && __cplusplus >= 201402L")
h_code.putln("[[deprecated(%s)]] inline" % warning_string.as_c_string_literal())
h_code.putln("#elif defined(__GNUC__) || defined(__clang__)")
h_code.putln('__attribute__ ((__deprecated__(%s), __unused__)) __inline__' % (
warning_string.as_c_string_literal()))
h_code.putln("#elif defined(_MSC_VER)")
h_code.putln('__declspec(deprecated(%s)) __inline' % (
warning_string.as_c_string_literal()))
h_code.putln('#endif')
h_code.putln("static PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject* res) {")
h_code.putln("return res;")
h_code.putln("}")
# Function call is converted to warning macro; uncalled (pointer) is not
h_code.putln('#define %s() __PYX_WARN_IF_INIT_CALLED(%s())' % (
py3_mod_func_name, py3_mod_func_name))
h_code.putln('#endif')
h_code.putln('#endif')
h_code.putln("") h_code.putln("")
h_code.putln("#endif /* !%s */" % h_guard) h_code.putln("#endif /* !%s */" % h_guard)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment