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