diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2020-06-25 20:52:11 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2020-06-25 20:52:11 +0200 |
commit | 30f616cdaafe7626e0903ba20e2b3592aebc28b3 (patch) | |
tree | 3ab88c01bbad69384fc48d7721c8e8a6aabcf782 | |
parent | df0047fab9648dab22861243cbf09aaa23e4a6f5 (diff) | |
download | cython-30f616cdaafe7626e0903ba20e2b3592aebc28b3.tar.gz |
Validate that all temps were correctly released at the end of a function.
-rw-r--r-- | Cython/Compiler/Code.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 6f507eb66..03e4b3fe6 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -735,6 +735,20 @@ class FunctionState(object): self.should_declare_error_indicator = False self.uses_error_indicator = False + # safety checks + + def validate_exit(self): + # validate that all allocated temps have been freed + if self.temps_allocated: + leftovers = set(self.all_managed_temps()).difference(self.all_free_managed_temps()) + if leftovers: + msg = "Temps left over at end of '%s': %s" % ( + self.scope.name, + ', '.join(map(str, sorted(leftovers, key=operator.itemgetter(0)))), + ) + print(msg) + #raise RuntimeError(msg) + # labels def new_label(self, name=None): @@ -1860,6 +1874,7 @@ class CCodeWriter(object): self.funcstate = FunctionState(self, scope=scope) def exit_cfunc_scope(self): + self.funcstate.validate_exit() self.funcstate = None # constant handling |