removed 'intern_names' Option - always intern identifier-like strings
authorStefan Behnel <scoder@users.berlios.de>
Wed, 14 May 2008 16:19:04 +0000 (18:19 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 14 May 2008 16:19:04 +0000 (18:19 +0200)
Cython/Compiler/ExprNodes.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py
Cython/Compiler/Options.py
Cython/Compiler/Symtab.py

index 109a59c684c027ca10ed8e79db206513c010ab16..d05985598d9be43d7a16077cd663bb3a4b8de6bc 100644 (file)
@@ -865,10 +865,7 @@ class NameNode(AtomicExprNode):
                 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 ###
@@ -878,8 +875,7 @@ class NameNode(AtomicExprNode):
         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 ###
@@ -947,20 +943,12 @@ class NameNode(AtomicExprNode):
                 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)
@@ -983,32 +971,17 @@ class NameNode(AtomicExprNode):
             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)
@@ -2016,8 +1989,7 @@ class AttributeNode(ExprNode):
         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, 
@@ -2061,36 +2033,21 @@ class AttributeNode(ExprNode):
     
     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
@@ -2108,16 +2065,10 @@ class AttributeNode(ExprNode):
     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)
@@ -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 = [
 """
 static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/
index 1ef54be06742e7426fd6e000f68f2d2d6d0fa7f6..5528af4088e47bda4b986b1fb88ee9a68f7d89d1 100644 (file)
@@ -1560,23 +1560,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         # Lookup and cache builtin objects.
         if Options.cache_builtins:
             for entry in env.cached_builtins:
-                if Options.intern_names:
-                    #assert entry.interned_cname is not None
-                    code.putln(
-                        '%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
-                        entry.cname,
-                        Naming.builtins_cname,
-                        entry.interned_cname,
-                        entry.cname,
-                        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)))
+                #assert entry.interned_cname is not None
+                code.putln(
+                    '%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
+                    entry.cname,
+                    Naming.builtins_cname,
+                    entry.interned_cname,
+                    entry.cname,
+                    code.error_goto(entry.pos)))
     
     def generate_global_init_code(self, env, code):
         # Generate code to initialise global PyObject *
index e509ea49c9a660dfc74a878fc907c37f90679c87..e08cd219377db0fa8f00a6af41f22692bebfb3d7 100644 (file)
@@ -1084,8 +1084,7 @@ class CFuncDefNode(FuncDefNode):
             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])
@@ -1925,10 +1924,7 @@ class OverrideCheckNode(StatNode):
             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)
@@ -3683,8 +3679,7 @@ class FromImportStatNode(StatNode):
         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)
@@ -3692,24 +3687,14 @@ class FromImportStatNode(StatNode):
     
     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)
 
 #------------------------------------------------------------------------------------
index 2f9a7e4359cef8ca0563dfb033cca9f9b219c5fe..600864c176ee3535d812666991dc42e70cc9fd8e 100644 (file)
@@ -2,7 +2,6 @@
 #  Pyrex - Compilation-wide options
 #
 
-intern_names = 1    #  Intern global variable and attribute names
 cache_builtins = 1  #  Perform lookups on builtin names only once
 
 embed_pos_in_docstring = 0
index 0c023ad42f97c47c356ef6e10353effd586acea3..a0beb711255475218d00c20170f2afa7e37e334b 100644 (file)
@@ -1238,10 +1238,9 @@ class CClassScope(ClassScope):
                                   # I keep it in for now. is_member should be enough
                                   # later on
             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
-            
+
 
     def declare_pyfunction(self, name, pos):
         # Add an entry for a method.