Commit 455e0357 authored by Stefan Behnel's avatar Stefan Behnel

make cname prefixes of cached constants unique by type (avoid overlap with C string constants)

parent da38b212
......@@ -803,7 +803,7 @@ class StringConst(object):
else:
intern = False
if intern:
prefix = Naming.interned_str_prefix
prefix = Naming.interned_prefixes['str']
else:
prefix = Naming.py_const_prefix
......@@ -1120,11 +1120,10 @@ class GlobalState(object):
return self.new_const_cname(value=value)
def new_num_const_cname(self, value, py_type):
prefix = Naming.interned_int_prefix
if py_type == 'long':
value += 'L'
elif py_type == 'float':
prefix = Naming.interned_float_prefix
py_type = 'int'
prefix = Naming.interned_prefixes[py_type]
cname = "%s%s" % (prefix, value)
cname = cname.replace('+', '_').replace('-', 'neg_').replace('.', '_')
return cname
......@@ -1137,7 +1136,11 @@ class GlobalState(object):
counter = used[value] = used[value] + 1
name_suffix = '%s_%d' % (value, counter)
used[name_suffix] = 1
return "%s%s%s" % (Naming.const_prefix, prefix, name_suffix)
if prefix:
prefix = Naming.interned_prefixes[prefix]
else:
prefix = Naming.const_prefix
return "%s%s" % (prefix, name_suffix)
def add_cached_builtin_decl(self, entry):
if entry.is_builtin and entry.is_const:
......
......@@ -1344,7 +1344,7 @@ class UnicodeNode(ConstNode):
if self.contains_surrogates():
# surrogates are not really portable and cannot be
# decoded by the UTF-8 codec in Py3.3
self.result_code = code.get_py_const(py_object_type, 'ustring_')
self.result_code = code.get_py_const(py_object_type, 'ustring')
data_cname = code.get_pyunicode_ptr_const(self.value)
code = code.get_cached_constants_writer()
code.mark_pos(self.pos)
......@@ -4193,7 +4193,7 @@ class SliceNode(ExprNode):
def generate_result_code(self, code):
if self.is_literal:
self.result_code = code.get_py_const(py_object_type, 'slice_', cleanup_level=2)
self.result_code = code.get_py_const(py_object_type, 'slice', cleanup_level=2)
code = code.get_cached_constants_writer()
code.mark_pos(self.pos)
......@@ -6217,7 +6217,7 @@ class TupleNode(SequenceNode):
return
if self.is_partly_literal:
# underlying tuple is const, but factor is not
tuple_target = code.get_py_const(py_object_type, 'tuple_', cleanup_level=2)
tuple_target = code.get_py_const(py_object_type, 'tuple', cleanup_level=2)
const_code = code.get_cached_constants_writer()
const_code.mark_pos(self.pos)
self.generate_sequence_packing_code(const_code, tuple_target, plain=True)
......@@ -6230,7 +6230,7 @@ class TupleNode(SequenceNode):
elif 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_', cleanup_level=2)
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)
self.generate_sequence_packing_code(code)
......@@ -7602,7 +7602,7 @@ class CodeObjectNode(ExprNode):
return self.result_code
def generate_result_code(self, code):
self.result_code = code.get_py_const(py_object_type, 'codeobj_', cleanup_level=2)
self.result_code = code.get_py_const(py_object_type, 'codeobj', cleanup_level=2)
code = code.get_cached_constants_writer()
code.mark_pos(self.pos)
......
......@@ -29,9 +29,6 @@ label_prefix = pyrex_prefix + "L"
pymethdef_prefix = pyrex_prefix + "mdef_"
methtab_prefix = pyrex_prefix + "methods_"
memtab_prefix = pyrex_prefix + "members_"
interned_str_prefix = pyrex_prefix + "n_"
interned_int_prefix = pyrex_prefix + "int_"
interned_float_prefix = pyrex_prefix + "float_"
objstruct_prefix = pyrex_prefix + "obj_"
typeptr_prefix = pyrex_prefix + "ptype_"
prop_set_prefix = pyrex_prefix + "setprop_"
......@@ -54,6 +51,16 @@ module_is_main = pyrex_prefix + "module_is_main_"
defaults_struct_prefix = pyrex_prefix + "defaults"
dynamic_args_cname = pyrex_prefix + "dynamic_args"
interned_prefixes = {
'str': pyrex_prefix + "n_",
'int': pyrex_prefix + "int_",
'float': pyrex_prefix + "float_",
'tuple': pyrex_prefix + "tuple_",
'codeobj': pyrex_prefix + "codeobj_",
'slice': pyrex_prefix + "slice_",
'ustring': pyrex_prefix + "ustring_",
}
args_cname = pyrex_prefix + "args"
generator_cname = pyrex_prefix + "generator"
sent_value_cname = pyrex_prefix + "sent_value"
......
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