self.is_temp = 0
else:
self.is_temp = 1
- if Options.intern_names:
- env.use_utility_code(get_name_interned_utility_code)
- else:
- env.use_utility_code(get_name_utility_code)
+ env.use_utility_code(get_name_interned_utility_code)
def analyse_entry(self, env):
#print "NameNode.analyse_entry:", self.name ###
self.type = type
if entry.is_pyglobal or entry.is_builtin:
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):
#print "NameNode.check_identifier_kind:", self.entry.name ###
namespace = Naming.builtins_cname
else: # entry.is_pyglobal
namespace = entry.namespace_cname
- if Options.intern_names:
- code.putln(
- '%s = __Pyx_GetName(%s, %s); %s' % (
- self.result_code,
- namespace,
- self.interned_cname,
- 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)))
+ code.putln(
+ '%s = __Pyx_GetName(%s, %s); %s' % (
+ self.result_code,
+ namespace,
+ self.interned_cname,
+ code.error_goto_if_null(self.result_code, self.pos)))
elif entry.is_local and False:
# control flow not good enough yet
assigned = entry.scope.control_flow.get_state((entry.name, 'initalized'), self.pos)
if entry.is_member:
# 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
- if Options.intern_names:
- code.put_error_if_neg(self.pos,
- 'PyDict_SetItem(%s->tp_dict, %s, %s)' % (
- namespace,
- self.interned_cname,
- rhs.py_result()))
- else:
- code.put_error_if_neg(self.pos,
- 'PyDict_SetItemString(%s->tp_dict, %s, %s)' % (
- namespace,
- entry.name,
- rhs.py_result()))
-
+ code.put_error_if_neg(self.pos,
+ 'PyDict_SetItem(%s->tp_dict, %s, %s)' % (
+ namespace,
+ self.interned_cname,
+ rhs.py_result()))
else:
- if Options.intern_names:
- code.put_error_if_neg(self.pos,
- 'PyObject_SetAttr(%s, %s, %s)' % (
- namespace,
- self.interned_cname,
- rhs.py_result()))
- else:
- code.put_error_if_neg(self.pos,
- 'PyObject_SetAttrString(%s, "%s", %s)' % (
- namespace,
- entry.name,
- rhs.py_result()))
+ code.put_error_if_neg(self.pos,
+ 'PyObject_SetAttr(%s, %s, %s)' % (
+ namespace,
+ self.interned_cname,
+ rhs.py_result()))
if debug_disposal_code:
print("NameNode.generate_assignment_code:")
print("...generating disposal code for %s" % rhs)
if obj_type.is_pyobject:
self.type = py_object_type
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:
if not obj_type.is_error:
error(self.pos,
def generate_result_code(self, code):
if self.is_py_attr:
- if Options.intern_names:
- code.putln(
- '%s = PyObject_GetAttr(%s, %s); %s' % (
- self.result_code,
- self.obj.py_result(),
- self.interned_attr_cname,
- 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)))
+ code.putln(
+ '%s = PyObject_GetAttr(%s, %s); %s' % (
+ self.result_code,
+ self.obj.py_result(),
+ self.interned_attr_cname,
+ code.error_goto_if_null(self.result_code, self.pos)))
def generate_assignment_code(self, rhs, code):
self.obj.generate_evaluation_code(code)
if self.is_py_attr:
- if Options.intern_names:
- code.put_error_if_neg(self.pos,
- 'PyObject_SetAttr(%s, %s, %s)' % (
- self.obj.py_result(),
- self.interned_attr_cname,
- 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()))
+ code.put_error_if_neg(self.pos,
+ 'PyObject_SetAttr(%s, %s, %s)' % (
+ self.obj.py_result(),
+ self.interned_attr_cname,
+ rhs.py_result()))
rhs.generate_disposal_code(code)
else:
select_code = self.result_code
def generate_deletion_code(self, code):
self.obj.generate_evaluation_code(code)
if self.is_py_attr:
- if Options.intern_names:
- code.put_error_if_neg(self.pos,
- 'PyObject_DelAttr(%s, %s)' % (
- self.obj.py_result(),
- self.interned_attr_cname))
- else:
- code.put_error_if_neg(self.pos,
- 'PyObject_DelAttrString(%s, "%s")' % (
- self.obj.py_result(),
- self.attribute))
+ code.put_error_if_neg(self.pos,
+ 'PyObject_DelAttr(%s, %s)' % (
+ self.obj.py_result(),
+ self.interned_attr_cname))
else:
error(self.pos, "Cannot delete C attribute of extension type")
self.obj.generate_disposal_code(code)
#
#------------------------------------------------------------------------------------
-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 = [
"""
static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
self.entry.as_variable = self.py_func.entry
# Reset scope entry the above cfunction
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:
self.override = OverrideCheckNode(self.pos, py_func = self.py_func)
self.body = StatListNode(self.pos, stats=[self.override, self.body])
code.putln("else if (unlikely(Py_TYPE(%s)->tp_dictoffset != 0)) {" % self_arg)
err = code.error_goto_if_null(self_arg, self.pos)
# 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))
- else:
- code.putln('%s = PyObject_GetAttrString(%s, "%s"); %s' % (self.func_node.result_code, self_arg, self.py_func.entry.name, err))
+ code.putln("%s = PyObject_GetAttr(%s, %s); %s" % (self.func_node.result_code, self_arg, self.py_func.interned_attr_cname, err))
# 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_overridden = '(PyCFunction_GET_FUNCTION(%s) != (void *)&%s)' % (self.func_node.result_code, self.py_func.entry.func_cname)
self.item.allocate_temp(env)
self.interned_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.release_target_temp(env) # was release_temp ?!?
self.module.release_temp(env)
def generate_execution_code(self, code):
self.module.generate_evaluation_code(code)
- if Options.intern_names:
- for cname, target in self.interned_items:
- code.putln(
- '%s = PyObject_GetAttr(%s, %s); %s' % (
- self.item.result_code,
- self.module.py_result(),
- cname,
- code.error_goto_if_null(self.item.result_code, self.pos)))
- 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)
+ for cname, target in self.interned_items:
+ code.putln(
+ '%s = PyObject_GetAttr(%s, %s); %s' % (
+ self.item.result_code,
+ self.module.py_result(),
+ cname,
+ code.error_goto_if_null(self.item.result_code, self.pos)))
+ target.generate_assignment_code(self.item, code)
self.module.generate_disposal_code(code)
#------------------------------------------------------------------------------------