From: Dag Sverre Seljebotn Date: Fri, 1 Aug 2008 21:49:28 +0000 (+0200) Subject: Fixed bug related to non-usage of local buffer variable X-Git-Tag: 0.9.8.1~49^2~38 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=47563ef69923cdf5154a685faf52efe8bc55ffd1;p=cython.git Fixed bug related to non-usage of local buffer variable --- diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 11e1e500..b77b594d 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -63,8 +63,8 @@ class IntroduceBufferAuxiliaryVars(CythonTransform): cname = scope.mangle(Naming.bufstruct_prefix, name) bufinfo = scope.declare_var(name="$%s" % cname, cname=cname, type=PyrexTypes.c_py_buffer_type, pos=node.pos) - - bufinfo.used = True + if entry.is_arg: + bufinfo.used = True # otherwise, NameNode will mark whether it is used def var(prefix, idx, initval): cname = scope.mangle(prefix, "%d_%s" % (idx, name)) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 92d74e1b..61064d0f 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -935,7 +935,8 @@ class FuncDefNode(StatNode, BlockNode): # goto statement in error cleanup above code.put_label(code.return_label) for entry in lenv.buffer_entries: - code.putln("%s;" % Buffer.get_release_buffer_code(entry)) + if entry.used: + code.putln("%s;" % Buffer.get_release_buffer_code(entry)) # ----- Return cleanup for both error and no-error return code.put_label(code.return_from_error_cleanup_label) if not Options.init_local_none: diff --git a/tests/run/bufaccess.pyx b/tests/run/bufaccess.pyx index fab8b855..d61ae74f 100644 --- a/tests/run/bufaccess.pyx +++ b/tests/run/bufaccess.pyx @@ -34,6 +34,15 @@ def testcas(a): # Buffer acquire and release tests # +@testcase +def nousage(): + """ + >>> True + True + """ + cdef object[int, 2] buf + # this used not to compile + @testcase def acquire_release(o1, o2): """