summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2018-03-02 18:49:20 +0100
committerStefan Behnel <stefan_ml@behnel.de>2018-03-02 18:49:20 +0100
commitc872937f6c8a784b06b274b8d280ebc5aa806bc4 (patch)
tree667734dfbcd6e6cab5be863c494ebbe7962733ef /Cython/Compiler/ModuleNode.py
parent40d2c8345d046ae2a08df1156420ef601c2920f8 (diff)
downloadcython-c872937f6c8a784b06b274b8d280ebc5aa806bc4.tar.gz
Work around BPO-32973: CPython 3 can rerun the module PyInit function if the extension module is re-imported under a different name.
https://bugs.python.org/issue32973
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r--Cython/Compiler/ModuleNode.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index 7cee61d3a..31266ec80 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -2322,6 +2322,12 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
Naming.module_cname,
Naming.pymodinit_module_arg,
))
+ code.putln("#elif PY_MAJOR_VERSION >= 3")
+ # Hack: enforce single initialisation also on reimports under different names on Python 3 (with PEP 3121/489).
+ code.putln("if (%s) return __Pyx_NewRef(%s);" % (
+ Naming.module_cname,
+ Naming.module_cname,
+ ))
code.putln("#endif")
if profile or linetrace: