diff options
author | da-woods <dw-git@d-woods.co.uk> | 2021-07-23 19:20:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-23 20:20:15 +0200 |
commit | d6625e2b6c7d8bbb5fa5b17b90d748ede44150cb (patch) | |
tree | 2952ceba890b5093fa3d9eb0aa2bc58cf78bb903 | |
parent | e46e9dd7c37d8d7ad432a94fff5daafa7fa444e3 (diff) | |
download | cython-d6625e2b6c7d8bbb5fa5b17b90d748ede44150cb.tar.gz |
Make __PYX_WARN_IF_INIT_CALLED name unique per-module in generated header files (GH-4309)
Fixes https://github.com/cython/cython/issues/4308
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 6 | ||||
-rw-r--r-- | tests/run/include_multiple_modules.srctree | 31 |
2 files changed, 34 insertions, 3 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 596a81920..d0687624f 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -311,12 +311,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): h_code_main.putln('__declspec(deprecated(%s)) __inline' % ( warning_string.as_c_string_literal())) h_code_main.putln('#endif') - h_code_main.putln("static PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject* res) {") + h_code_main.putln("static PyObject* __PYX_WARN_IF_%s_INIT_CALLED(PyObject* res) {" % py3_mod_func_name) h_code_main.putln("return res;") h_code_main.putln("}") # Function call is converted to warning macro; uncalled (pointer) is not - h_code_main.putln('#define %s() __PYX_WARN_IF_INIT_CALLED(%s())' % ( - py3_mod_func_name, py3_mod_func_name)) + h_code_main.putln('#define %s() __PYX_WARN_IF_%s_INIT_CALLED(%s())' % ( + py3_mod_func_name, py3_mod_func_name, py3_mod_func_name)) h_code_main.putln('#endif') h_code_main.putln('#endif') diff --git a/tests/run/include_multiple_modules.srctree b/tests/run/include_multiple_modules.srctree new file mode 100644 index 000000000..0bd768301 --- /dev/null +++ b/tests/run/include_multiple_modules.srctree @@ -0,0 +1,31 @@ +PYTHON setup.py build_ext --inplace + +############# setup.py ############# + +from Cython.Build.Dependencies import cythonize +from distutils.core import setup + +setup( + ext_modules = cythonize(["a.pyx", "b.pyx", "include_both.pyx"]), + ) + +############# a.pyx ############### + +cdef public f(): + pass + +############# b.pyx ############### + +cdef public g(): + pass + +############# include_both.pyx #### + +# This is just checking that a and b don't duplicate any names +# and thus it's possible to include them both in one place + +cdef extern from "a.h": + pass + +cdef extern from "b.h": + pass |