From 91d8543209490ba9ae797c403e40913c1f956c51 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Mon, 11 Mar 2013 20:06:22 +0100 Subject: [PATCH] fix unused access to optimise builtin methods which could lead to invalid C code being generated --- Cython/Compiler/ExprNodes.py | 7 ++++++- tests/run/bound_builtin_methods_T589.pyx | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 7579d19..5297f93 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -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: diff --git a/tests/run/bound_builtin_methods_T589.pyx b/tests/run/bound_builtin_methods_T589.pyx index 8896eae..6e13cfc 100644 --- a/tests/run/bound_builtin_methods_T589.pyx +++ b/tests/run/bound_builtin_methods_T589.pyx @@ -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 -- 2.7.4