From ea85d044d1b063134c332c720b9e26d326af2ba2 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Mon, 2 Nov 2009 20:23:01 +0100 Subject: [PATCH] Fix #444 (utility code not pulled in in corner case) --- Cython/Compiler/Buffer.py | 5 +++-- Cython/Compiler/Nodes.py | 6 +++--- tests/compile/bufaccess_noassignT444.pyx | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 tests/compile/bufaccess_noassignT444.pyx diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index b297ad15..e807d428 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -245,8 +245,9 @@ def put_acquire_arg_buffer(entry, code, pos): # need to care about the buffer then. put_unpack_buffer_aux_into_scope(buffer_aux, entry.type.mode, code) -def get_release_buffer_code(entry): - return "__Pyx_SafeReleaseBuffer(&%s)" % entry.buffer_aux.buffer_info_var.cname +def put_release_buffer_code(code, entry): + code.globalstate.use_utility_code(acquire_utility_code) + code.putln("__Pyx_SafeReleaseBuffer(&%s);" % entry.buffer_aux.buffer_info_var.cname) def get_getbuffer_call(code, obj_cname, buffer_aux, buffer_type): ndim = buffer_type.ndim diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 8b37eb86..b192eefc 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1142,8 +1142,8 @@ class FuncDefNode(StatNode, BlockNode): code.globalstate.use_utility_code(restore_exception_utility_code) code.putln("{ PyObject *__pyx_type, *__pyx_value, *__pyx_tb;") code.putln("__Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);") - for entry in lenv.buffer_entries: - code.putln("%s;" % Buffer.get_release_buffer_code(entry)) + for entry in lenv.buffer_entries: + Buffer.put_release_buffer_code(code, entry) #code.putln("%s = 0;" % entry.cname) code.putln("__Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}") @@ -1185,7 +1185,7 @@ class FuncDefNode(StatNode, BlockNode): code.put_label(code.return_label) for entry in lenv.buffer_entries: if entry.used: - code.putln("%s;" % Buffer.get_release_buffer_code(entry)) + Buffer.put_release_buffer_code(code, entry) if is_getbuffer_slot: self.getbuffer_normal_cleanup(code) # ----- Return cleanup for both error and no-error return diff --git a/tests/compile/bufaccess_noassignT444.pyx b/tests/compile/bufaccess_noassignT444.pyx new file mode 100644 index 00000000..061a4e2d --- /dev/null +++ b/tests/compile/bufaccess_noassignT444.pyx @@ -0,0 +1,4 @@ + +def test(): + cdef object[int] not_assigned_to + not_assigned_to[2] = 3 -- 2.26.2