fix unused access to optimise builtin methods which could lead to invalid C code...
authorStefan Behnel <stefan_ml@behnel.de>
Mon, 11 Mar 2013 19:06:22 +0000 (20:06 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Mon, 11 Mar 2013 19:06:22 +0000 (20:06 +0100)
Cython/Compiler/ExprNodes.py
tests/run/bound_builtin_methods_T589.pyx

index 7579d19..5297f93 100755 (executable)
@@ -5135,8 +5135,13 @@ class AttributeNode(ExprNode):
                 return "((struct %s *)%s%s%s)->%s" % (
                     obj.type.vtabstruct_cname, obj_code, self.op,
                     obj.type.vtabslot_cname, self.member)
-            else:
+            elif self.result_is_used:
                 return self.member
+            # Generating no code at all for unused access to optimised builtin
+            # methods fixes the problem that some optimisations only exist as
+            # macros, i.e. there is no function pointer to them, so we would
+            # generate invalid C code here.
+            return
         elif obj.type.is_complex:
             return "__Pyx_C%s(%s)" % (self.member.upper(), obj_code)
         else:
index 8896eae..6e13cfc 100644 (file)
@@ -4,6 +4,7 @@ cimport cython
 
 _set = set # CPython may not define it (in Py2.3), but Cython does :)
 
+
 def test_set_clear_bound():
     """
     >>> type(test_set_clear_bound()) is _set
@@ -19,6 +20,7 @@ def test_set_clear_bound():
 text = u'ab jd  sdflk as sa  sadas asdas fsdf '
 pipe_sep = u'|'
 
+
 @cython.test_assert_path_exists(
     "//SimpleCallNode",
     "//SimpleCallNode//NameNode")
@@ -34,3 +36,17 @@ def test_unicode_join_bound(unicode sep, l):
     """
     join = sep.join
     return join(l)
+
+
+def test_unicode_join_bound_no_assignment(unicode sep):
+    """
+    >>> test_unicode_join_bound_no_assignment(text)
+    """
+    sep.join
+
+
+def test_dict_items_bound_no_assignment(dict d):
+    """
+    >>> test_dict_items_bound_no_assignment({1:2})
+    """
+    d.items