Commit 61ee2ad0 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Buffers: More stable buffer release code

parent a313eb32
......@@ -157,8 +157,7 @@ def put_acquire_arg_buffer(entry, code, pos):
# entry.buffer_aux.buffer_info_var.cname))
def get_release_buffer_code(entry):
return "if (%s != Py_None) __Pyx_ReleaseBuffer(%s, &%s)" % (
entry.cname,
return "__Pyx_ReleaseBuffer(%s, &%s)" % (
entry.cname,
entry.buffer_aux.buffer_info_var.cname)
......@@ -190,11 +189,8 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
if is_initialized:
# Release any existing buffer
code.put('if (%s != Py_None) ' % lhs_cname)
code.begin_block();
code.putln('__Pyx_ReleaseBuffer(%s, &%s);' % (
lhs_cname, bufstruct))
code.end_block()
# Acquire
retcode_cname = code.funcstate.allocate_temp(PyrexTypes.c_int_type)
code.putln("%s = %s;" % (retcode_cname, getbuffer % rhs_cname))
......@@ -558,6 +554,7 @@ static INLINE const char* __Pyx_BufferTypestringCheckEndian(const char* ts); /*p
static void __Pyx_BufferNdimError(Py_buffer* buffer, int expected_ndim); /*proto*/
""", """
static INLINE void __Pyx_ReleaseBuffer(PyObject* obj, Py_buffer* info) {
if (info->buf == NULL) return;
if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
PyObject_ReleaseBuffer(obj, info);
}
......
......@@ -900,6 +900,8 @@ class FuncDefNode(StatNode, BlockNode):
for entry in lenv.var_entries:
if entry.type.is_pyobject and entry.init_to_none and entry.used:
code.put_init_var_to_py_none(entry)
if entry.type.is_buffer and entry.buffer_aux.buffer_info_var.used:
code.putln("%s.buf = NULL;" % entry.buffer_aux.buffer_info_var.cname)
# ----- Check and convert arguments
self.generate_argument_type_tests(code)
# ----- Function body
......@@ -2047,8 +2049,11 @@ class CClassDefNode(ClassDefNode):
# body StatNode or None
# entry Symtab.Entry
# base_type PyExtensionType or None
# bufferdefaults dict or None Declares defaults for a buffer
child_attrs = ["body"]
bufferdefaults = None
def analyse_declarations(self, env):
#print "CClassDefNode.analyse_declarations:", self.class_name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment