Skip to content

Commit

Permalink
Defer initialisation of global variables until the module is actually…
Browse files Browse the repository at this point in the history
… created

That way we have a properly initialized module when we call "to_python"

Fix #2190
  • Loading branch information
serge-sans-paille committed Dec 13, 2024
1 parent 7c588d4 commit 092d09f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pythran/cxxgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,7 @@ def add_function_to(self, to, func, name, ctypes, signature):
self.functions.setdefault(name, []).append(func_descriptor)

def add_global_var(self, name, init):
self.global_vars.append(name)
self.python_implems.append(Assign('static PyObject* ' + name,
'to_python({})'.format(init)))
self.global_vars.append((name, 'to_python({})'.format(init)))

def __str__(self):
"""Generate (i.e. yield) the source code of the
Expand All @@ -592,9 +590,9 @@ def __str__(self):
themethods = []
theextraobjects = []
theoverloads = []
for vname in self.global_vars:
for vname, vinit in self.global_vars:
theextraobjects.append(
'PyModule_AddObject(theModule, "{0}", {0});'.format(vname))
'PyModule_AddObject(theModule, "{0}", {1});'.format(vname, vinit))

for fname, overloads in self.functions.items():
tryall = []
Expand Down

0 comments on commit 092d09f

Please sign in to comment.