Commit da870f24 authored by Stefan Behnel's avatar Stefan Behnel

removed 'intern_names' Option - always intern identifier-like strings

parent 51f5387d
...@@ -865,10 +865,7 @@ class NameNode(AtomicExprNode): ...@@ -865,10 +865,7 @@ class NameNode(AtomicExprNode):
self.is_temp = 0 self.is_temp = 0
else: else:
self.is_temp = 1 self.is_temp = 1
if Options.intern_names: env.use_utility_code(get_name_interned_utility_code)
env.use_utility_code(get_name_interned_utility_code)
else:
env.use_utility_code(get_name_utility_code)
def analyse_entry(self, env): def analyse_entry(self, env):
#print "NameNode.analyse_entry:", self.name ### #print "NameNode.analyse_entry:", self.name ###
...@@ -878,8 +875,7 @@ class NameNode(AtomicExprNode): ...@@ -878,8 +875,7 @@ class NameNode(AtomicExprNode):
self.type = type self.type = type
if entry.is_pyglobal or entry.is_builtin: if entry.is_pyglobal or entry.is_builtin:
assert type.is_pyobject, "Python global or builtin not a Python object" assert type.is_pyobject, "Python global or builtin not a Python object"
if Options.intern_names: self.interned_cname = self.entry.interned_cname = env.intern(self.entry.name)
self.interned_cname = self.entry.interned_cname = env.intern(self.entry.name)
def check_identifier_kind(self): def check_identifier_kind(self):
#print "NameNode.check_identifier_kind:", self.entry.name ### #print "NameNode.check_identifier_kind:", self.entry.name ###
...@@ -947,20 +943,12 @@ class NameNode(AtomicExprNode): ...@@ -947,20 +943,12 @@ class NameNode(AtomicExprNode):
namespace = Naming.builtins_cname namespace = Naming.builtins_cname
else: # entry.is_pyglobal else: # entry.is_pyglobal
namespace = entry.namespace_cname namespace = entry.namespace_cname
if Options.intern_names: code.putln(
code.putln( '%s = __Pyx_GetName(%s, %s); %s' % (
'%s = __Pyx_GetName(%s, %s); %s' % ( self.result_code,
self.result_code, namespace,
namespace, self.interned_cname,
self.interned_cname, code.error_goto_if_null(self.result_code, self.pos)))
code.error_goto_if_null(self.result_code, self.pos)))
else:
code.putln(
'%s = __Pyx_GetName(%s, "%s"); %s' % (
self.result_code,
namespace,
self.entry.name,
code.error_goto_if_null(self.result_code, self.pos)))
elif entry.is_local and False: elif entry.is_local and False:
# control flow not good enough yet # control flow not good enough yet
assigned = entry.scope.control_flow.get_state((entry.name, 'initalized'), self.pos) assigned = entry.scope.control_flow.get_state((entry.name, 'initalized'), self.pos)
...@@ -983,32 +971,17 @@ class NameNode(AtomicExprNode): ...@@ -983,32 +971,17 @@ class NameNode(AtomicExprNode):
if entry.is_member: if entry.is_member:
# if we entry is a member we have to cheat: SetAttr does not work # if we entry is a member we have to cheat: SetAttr does not work
# on types, so we create a descriptor which is then added to tp_dict # on types, so we create a descriptor which is then added to tp_dict
if Options.intern_names: code.put_error_if_neg(self.pos,
code.put_error_if_neg(self.pos, 'PyDict_SetItem(%s->tp_dict, %s, %s)' % (
'PyDict_SetItem(%s->tp_dict, %s, %s)' % ( namespace,
namespace, self.interned_cname,
self.interned_cname, rhs.py_result()))
rhs.py_result()))
else:
code.put_error_if_neg(self.pos,
'PyDict_SetItemString(%s->tp_dict, %s, %s)' % (
namespace,
entry.name,
rhs.py_result()))
else: else:
if Options.intern_names: code.put_error_if_neg(self.pos,
code.put_error_if_neg(self.pos, 'PyObject_SetAttr(%s, %s, %s)' % (
'PyObject_SetAttr(%s, %s, %s)' % ( namespace,
namespace, self.interned_cname,
self.interned_cname, rhs.py_result()))
rhs.py_result()))
else:
code.put_error_if_neg(self.pos,
'PyObject_SetAttrString(%s, "%s", %s)' % (
namespace,
entry.name,
rhs.py_result()))
if debug_disposal_code: if debug_disposal_code:
print("NameNode.generate_assignment_code:") print("NameNode.generate_assignment_code:")
print("...generating disposal code for %s" % rhs) print("...generating disposal code for %s" % rhs)
...@@ -2016,8 +1989,7 @@ class AttributeNode(ExprNode): ...@@ -2016,8 +1989,7 @@ class AttributeNode(ExprNode):
if obj_type.is_pyobject: if obj_type.is_pyobject:
self.type = py_object_type self.type = py_object_type
self.is_py_attr = 1 self.is_py_attr = 1
if Options.intern_names: self.interned_attr_cname = env.intern(self.attribute)
self.interned_attr_cname = env.intern(self.attribute)
else: else:
if not obj_type.is_error: if not obj_type.is_error:
error(self.pos, error(self.pos,
...@@ -2061,36 +2033,21 @@ class AttributeNode(ExprNode): ...@@ -2061,36 +2033,21 @@ class AttributeNode(ExprNode):
def generate_result_code(self, code): def generate_result_code(self, code):
if self.is_py_attr: if self.is_py_attr:
if Options.intern_names: code.putln(
code.putln( '%s = PyObject_GetAttr(%s, %s); %s' % (
'%s = PyObject_GetAttr(%s, %s); %s' % ( self.result_code,
self.result_code, self.obj.py_result(),
self.obj.py_result(), self.interned_attr_cname,
self.interned_attr_cname, code.error_goto_if_null(self.result_code, self.pos)))
code.error_goto_if_null(self.result_code, self.pos)))
else:
code.putln(
'%s = PyObject_GetAttrString(%s, "%s"); %s' % (
self.result_code,
self.obj.py_result(),
self.attribute,
code.error_goto_if_null(self.result_code, self.pos)))
def generate_assignment_code(self, rhs, code): def generate_assignment_code(self, rhs, code):
self.obj.generate_evaluation_code(code) self.obj.generate_evaluation_code(code)
if self.is_py_attr: if self.is_py_attr:
if Options.intern_names: code.put_error_if_neg(self.pos,
code.put_error_if_neg(self.pos, 'PyObject_SetAttr(%s, %s, %s)' % (
'PyObject_SetAttr(%s, %s, %s)' % ( self.obj.py_result(),
self.obj.py_result(), self.interned_attr_cname,
self.interned_attr_cname, rhs.py_result()))
rhs.py_result()))
else:
code.put_error_if_neg(self.pos,
'PyObject_SetAttrString(%s, "%s", %s)' % (
self.obj.py_result(),
self.attribute,
rhs.py_result()))
rhs.generate_disposal_code(code) rhs.generate_disposal_code(code)
else: else:
select_code = self.result_code select_code = self.result_code
...@@ -2108,16 +2065,10 @@ class AttributeNode(ExprNode): ...@@ -2108,16 +2065,10 @@ class AttributeNode(ExprNode):
def generate_deletion_code(self, code): def generate_deletion_code(self, code):
self.obj.generate_evaluation_code(code) self.obj.generate_evaluation_code(code)
if self.is_py_attr: if self.is_py_attr:
if Options.intern_names: code.put_error_if_neg(self.pos,
code.put_error_if_neg(self.pos, 'PyObject_DelAttr(%s, %s)' % (
'PyObject_DelAttr(%s, %s)' % ( self.obj.py_result(),
self.obj.py_result(), self.interned_attr_cname))
self.interned_attr_cname))
else:
code.put_error_if_neg(self.pos,
'PyObject_DelAttrString(%s, "%s")' % (
self.obj.py_result(),
self.attribute))
else: else:
error(self.pos, "Cannot delete C attribute of extension type") error(self.pos, "Cannot delete C attribute of extension type")
self.obj.generate_disposal_code(code) self.obj.generate_disposal_code(code)
...@@ -3904,19 +3855,6 @@ class CloneNode(CoercionNode): ...@@ -3904,19 +3855,6 @@ class CloneNode(CoercionNode):
# #
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
get_name_utility_code = [
"""
static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/
""","""
static PyObject *__Pyx_GetName(PyObject *dict, char *name) {
PyObject *result;
result = PyObject_GetAttrString(dict, name);
if (!result)
PyErr_SetString(PyExc_NameError, name);
return result;
}
"""]
get_name_interned_utility_code = [ get_name_interned_utility_code = [
""" """
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
......
...@@ -1560,23 +1560,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): ...@@ -1560,23 +1560,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# Lookup and cache builtin objects. # Lookup and cache builtin objects.
if Options.cache_builtins: if Options.cache_builtins:
for entry in env.cached_builtins: for entry in env.cached_builtins:
if Options.intern_names: #assert entry.interned_cname is not None
#assert entry.interned_cname is not None code.putln(
code.putln( '%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
'%s = __Pyx_GetName(%s, %s); if (!%s) %s' % ( entry.cname,
entry.cname, Naming.builtins_cname,
Naming.builtins_cname, entry.interned_cname,
entry.interned_cname, entry.cname,
entry.cname, code.error_goto(entry.pos)))
code.error_goto(entry.pos)))
else:
code.putln(
'%s = __Pyx_GetName(%s, "%s"); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
entry.name,
entry.cname,
code.error_goto(entry.pos)))
def generate_global_init_code(self, env, code): def generate_global_init_code(self, env, code):
# Generate code to initialise global PyObject * # Generate code to initialise global PyObject *
......
...@@ -1084,8 +1084,7 @@ class CFuncDefNode(FuncDefNode): ...@@ -1084,8 +1084,7 @@ class CFuncDefNode(FuncDefNode):
self.entry.as_variable = self.py_func.entry self.entry.as_variable = self.py_func.entry
# Reset scope entry the above cfunction # Reset scope entry the above cfunction
env.entries[name] = self.entry env.entries[name] = self.entry
if Options.intern_names: self.py_func.interned_attr_cname = env.intern(self.py_func.entry.name)
self.py_func.interned_attr_cname = env.intern(self.py_func.entry.name)
if not env.is_module_scope or Options.lookup_module_cpdef: if not env.is_module_scope or Options.lookup_module_cpdef:
self.override = OverrideCheckNode(self.pos, py_func = self.py_func) self.override = OverrideCheckNode(self.pos, py_func = self.py_func)
self.body = StatListNode(self.pos, stats=[self.override, self.body]) self.body = StatListNode(self.pos, stats=[self.override, self.body])
...@@ -1925,10 +1924,7 @@ class OverrideCheckNode(StatNode): ...@@ -1925,10 +1924,7 @@ class OverrideCheckNode(StatNode):
code.putln("else if (unlikely(Py_TYPE(%s)->tp_dictoffset != 0)) {" % self_arg) code.putln("else if (unlikely(Py_TYPE(%s)->tp_dictoffset != 0)) {" % self_arg)
err = code.error_goto_if_null(self_arg, self.pos) err = code.error_goto_if_null(self_arg, self.pos)
# need to get attribute manually--scope would return cdef method # need to get attribute manually--scope would return cdef method
if Options.intern_names: code.putln("%s = PyObject_GetAttr(%s, %s); %s" % (self.func_node.result_code, self_arg, self.py_func.interned_attr_cname, err))
code.putln("%s = PyObject_GetAttr(%s, %s); %s" % (self.func_node.result_code, self_arg, self.py_func.interned_attr_cname, err))
else:
code.putln('%s = PyObject_GetAttrString(%s, "%s"); %s' % (self.func_node.result_code, self_arg, self.py_func.entry.name, err))
# It appears that this type is not anywhere exposed in the Python/C API # It appears that this type is not anywhere exposed in the Python/C API
is_builtin_function_or_method = '(strcmp(Py_TYPE(%s)->tp_name, "builtin_function_or_method") == 0)' % self.func_node.result_code is_builtin_function_or_method = '(strcmp(Py_TYPE(%s)->tp_name, "builtin_function_or_method") == 0)' % self.func_node.result_code
is_overridden = '(PyCFunction_GET_FUNCTION(%s) != (void *)&%s)' % (self.func_node.result_code, self.py_func.entry.func_cname) is_overridden = '(PyCFunction_GET_FUNCTION(%s) != (void *)&%s)' % (self.func_node.result_code, self.py_func.entry.func_cname)
...@@ -3683,8 +3679,7 @@ class FromImportStatNode(StatNode): ...@@ -3683,8 +3679,7 @@ class FromImportStatNode(StatNode):
self.item.allocate_temp(env) self.item.allocate_temp(env)
self.interned_items = [] self.interned_items = []
for name, target in self.items: for name, target in self.items:
if Options.intern_names: self.interned_items.append((env.intern(name), target))
self.interned_items.append((env.intern(name), target))
target.analyse_target_expression(env, None) target.analyse_target_expression(env, None)
#target.release_target_temp(env) # was release_temp ?!? #target.release_target_temp(env) # was release_temp ?!?
self.module.release_temp(env) self.module.release_temp(env)
...@@ -3692,24 +3687,14 @@ class FromImportStatNode(StatNode): ...@@ -3692,24 +3687,14 @@ class FromImportStatNode(StatNode):
def generate_execution_code(self, code): def generate_execution_code(self, code):
self.module.generate_evaluation_code(code) self.module.generate_evaluation_code(code)
if Options.intern_names: for cname, target in self.interned_items:
for cname, target in self.interned_items: code.putln(
code.putln( '%s = PyObject_GetAttr(%s, %s); %s' % (
'%s = PyObject_GetAttr(%s, %s); %s' % ( self.item.result_code,
self.item.result_code, self.module.py_result(),
self.module.py_result(), cname,
cname, code.error_goto_if_null(self.item.result_code, self.pos)))
code.error_goto_if_null(self.item.result_code, self.pos))) target.generate_assignment_code(self.item, code)
target.generate_assignment_code(self.item, code)
else:
for name, target in self.items:
code.putln(
'%s = PyObject_GetAttrString(%s, "%s"); %s' % (
self.item.result_code,
self.module.py_result(),
name,
code.error_goto_if_null(self.item.result_code, self.pos)))
target.generate_assignment_code(self.item, code)
self.module.generate_disposal_code(code) self.module.generate_disposal_code(code)
#------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# Pyrex - Compilation-wide options # Pyrex - Compilation-wide options
# #
intern_names = 1 # Intern global variable and attribute names
cache_builtins = 1 # Perform lookups on builtin names only once cache_builtins = 1 # Perform lookups on builtin names only once
embed_pos_in_docstring = 0 embed_pos_in_docstring = 0
......
...@@ -1238,10 +1238,9 @@ class CClassScope(ClassScope): ...@@ -1238,10 +1238,9 @@ class CClassScope(ClassScope):
# I keep it in for now. is_member should be enough # I keep it in for now. is_member should be enough
# later on # later on
entry.namespace_cname = "(PyObject *)%s" % self.parent_type.typeptr_cname entry.namespace_cname = "(PyObject *)%s" % self.parent_type.typeptr_cname
if Options.intern_names: entry.interned_cname = self.intern(name)
entry.interned_cname = self.intern(name)
return entry return entry
def declare_pyfunction(self, name, pos): def declare_pyfunction(self, name, pos):
# Add an entry for a method. # Add an entry for a method.
......
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