Commit 9a9ed566 authored by Stefan Behnel's avatar Stefan Behnel

simplify (and centralise) module cleanup code generation for tuple constants

parent d037a456
......@@ -557,9 +557,6 @@ class GlobalState(object):
def get_cached_constants_writer(self):
return self.parts['cached_constants']
def get_globals_cleanup_writer(self):
return self.parts['cleanup_globals']
def get_int_const(self, str_value, longness=False):
longness = bool(longness)
try:
......@@ -568,9 +565,14 @@ class GlobalState(object):
c = self.new_int_const(str_value, longness)
return c
def get_py_const(self, type, prefix=''):
def get_py_const(self, type, prefix='', cleanup_level=None):
# create a new Python object constant
return self.new_py_const(type, prefix)
const = self.new_py_const(type, prefix)
if cleanup_level is not None \
and cleanup_level >= Options.generate_cleanup_code:
cleanup_writer = self.parts['cleanup_globals']
cleanup_writer.put_xdecref_clear(const.cname, type, nanny=False)
return const
def get_string_const(self, text):
# return a C string constant, creating a new one if necessary
......@@ -962,8 +964,8 @@ class CCodeWriter(object):
def get_py_num(self, str_value, longness):
return self.globalstate.get_int_const(str_value, longness).cname
def get_py_const(self, type, prefix=''):
return self.globalstate.get_py_const(type, prefix).cname
def get_py_const(self, type, prefix='', cleanup_level=None):
return self.globalstate.get_py_const(type, prefix, cleanup_level).cname
def get_string_const(self, text):
return self.globalstate.get_string_const(text).cname
......@@ -983,9 +985,6 @@ class CCodeWriter(object):
def get_cached_constants_writer(self):
return self.globalstate.get_cached_constants_writer()
def get_globals_cleanup_writer(self):
return self.globalstate.get_globals_cleanup_writer()
# code generation
def putln(self, code = "", safe=False):
......
......@@ -3963,10 +3963,7 @@ class TupleNode(SequenceNode):
if self.is_literal:
# non-empty cached tuple => result is global constant,
# creation code goes into separate code writer
self.result_code = code.get_py_const(py_object_type, 'tuple_')
if Options.generate_cleanup_code >= 2:
cleanup_writer = code.get_globals_cleanup_writer()
cleanup_writer.put_xdecref_clear(self.result(), py_object_type, nanny=False)
self.result_code = code.get_py_const(py_object_type, 'tuple_', cleanup_level=2)
code = code.get_cached_constants_writer()
code.mark_pos(self.pos)
......
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