Commit a4e9888c authored by Stefan Behnel's avatar Stefan Behnel

Enforce single module initialisation despite PEP 489 allowing to re-execute a module.

parent cf6935df
......@@ -694,7 +694,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.put(Nodes.branch_prediction_macros)
code.putln('static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }')
code.putln('')
code.putln('static PyObject *%s;' % env.module_cname)
code.putln('static PyObject *%s = NULL;' % env.module_cname)
code.putln('static PyObject *%s;' % env.module_dict_cname)
code.putln('static PyObject *%s;' % Naming.builtins_cname)
code.putln('static PyObject *%s;' % Naming.cython_runtime_cname)
......@@ -2274,6 +2274,15 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.globalstate.use_utility_code(UtilityCode.load_cached("Profile", "Profile.c"))
code.put_declare_refcount_context()
code.putln("#if CYTHON_PEP489_MULTI_PHASE_INIT")
# Hack: enforce single initialisation.
code.putln("if (%s && %s == %s) return 0;" % (
Naming.module_cname,
Naming.module_cname,
Naming.pymodinit_module_arg,
))
code.putln("#endif")
if profile or linetrace:
tempdecl_code.put_trace_declarations()
code.put_trace_frame_init()
......
......@@ -753,6 +753,10 @@ static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const ch
static PyObject* ${pymodule_create_func_cname}(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
PyObject *module = NULL, *moddict, *modname;
// For now, we only have exactly one module instance.
if (${module_cname})
return __Pyx_NewRef({module_cname});
modname = PyObject_GetAttrString(spec, "name");
if (unlikely(!modname)) goto bad;
......
......@@ -350,8 +350,6 @@ VER_DEP_MODULES = {
'run.mod__spec__',
'run.pep526_variable_annotations', # typing module
]),
(99,): (operator.lt, lambda x: x in ['run.mod__spec__', # actually Py3.5, but currently disabled
]),
}
INCLUDE_DIRS = [ d for d in os.getenv('INCLUDE', '').split(os.pathsep) if d ]
......
......@@ -12,6 +12,9 @@ temp_sideeffects_T654 # not really a bug, Cython warns about it
inherited_final_method
cimport_alias_subclass
# PEP-489 is currently disabled
run.mod__spec__
# CPython regression tests that don't current work:
pyregr.test_signal
pyregr.test_capi
......
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