Repository: cython/cython

Issue:
[BUG] in 3.0.0x, embed multi modules cause  errors : redefinition of ‘PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject*)’

**Describe the bug**
in embed mode, I created three cython modules, "network, engine , market" , after compiled,   include the head files in main 
#include "engine/engine.h"
#include "engine/market.h"
#include "engine/network.h"
all the generated head files  defined same function: __PYX_WARN_IF_INIT_CALLED will cause redefinition errors 


**To Reproduce**
In file included from /home/arthur/work/aule/src/main.cpp:11:
/home/arthur/work/aule/./engine/market.h:46:18: error: redefinition of ‘PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject*)’
   46 | static PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject* res) {
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/arthur/work/aule/src/main.cpp:10:
/home/arthur/work/aule/./engine/engine.h:75:18: note: ‘PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject*)’ previously defined here
   75 | static PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject* res) {
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/arthur/work/aule/src/main.cpp:12:
/home/arthur/work/aule/./engine/network.h:46:18: error: redefinition of ‘PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject*)’
   46 | static PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject* res) {
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/arthur/work/aule/src/main.cpp:10:
/home/arthur/work/aule/./engine/engine.h:75:18: note: ‘PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject*)’ previously defined here
   75 | static PyObject* __PYX_WARN_IF_INIT_CALLED(PyObject* res) {
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/xengine.dir/build.make:193: CMakeFiles/xengine.dir/src/main.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:324: CMakeFiles/xengine.dir/all] Error 2

**Expected behavior**
should the generated head file use different names? 


**Environment (please complete the following information):**
 - OS: Ubuntu 20.04
 - Python version 3.9.6 
 - Cython version 3.0.0x 
 - gcc version  (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

**Additional context**
I  set up a demo here ,   https://github.com/cagev/cythonembeddemo  



Discussion:
I suspect the function definition of `__PYX_WARN_IF_INIT_CALLED` should either be in a little include-guard. Or it should be renamed `__PYX_WARN_IF_<module name>_INIT_CALLED`. Either would work

Resolving patch:
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -311,12 +311,12 @@ def h_entries(entries, api=0, pxd=0):
             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')
 


Test patch:
diff --git a/tests/run/include_multiple_modules.srctree b/tests/run/include_multiple_modules.srctree
new file mode 100644
--- /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