# entry.buffer_aux.buffer_info_var.cname))
def get_release_buffer_code(entry):
- return "if (%s != Py_None) PyObject_ReleaseBuffer(%s, &%s)" % (
+ return "if (%s != Py_None) __Pyx_ReleaseBuffer(%s, &%s)" % (
entry.cname,
entry.cname,
entry.buffer_aux.buffer_info_var.cname)
# Release any existing buffer
code.put('if (%s != Py_None) ' % lhs_cname)
code.begin_block();
- code.putln('PyObject_ReleaseBuffer(%s, &%s);' % (
+ code.putln('__Pyx_ReleaseBuffer(%s, &%s);' % (
lhs_cname, bufstruct))
code.end_block()
# Acquire
# exporter.
#
acquire_utility_code = ["""\
+static INLINE void __Pyx_ReleaseBuffer(PyObject* obj, Py_buffer* info);
static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf); /*proto*/
static INLINE const char* __Pyx_ConsumeWhitespace(const char* ts); /*proto*/
static INLINE const char* __Pyx_BufferTypestringCheckEndian(const char* ts); /*proto*/
static void __Pyx_BufferNdimError(Py_buffer* buffer, int expected_ndim); /*proto*/
""", """
+static INLINE void __Pyx_ReleaseBuffer(PyObject* obj, Py_buffer* info) {
+ if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
+ PyObject_ReleaseBuffer(obj, info);
+}
+
static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
buf->buf = NULL;
buf->strides = __Pyx_zeros;
Traceback (most recent call last):
...
IndexError: Out of bounds on buffer access (axis 1)
-
"""
return buf[i, j]
2
>>> A.recieved_flags
['FORMAT', 'ND', 'STRIDES']
+
+ Check that the suboffsets were patched back prior to release.
+ >>> A.release_ok
+ True
"""
return buf[2]
cdef Py_ssize_t* suboffsets
cdef object label, log
- cdef readonly object recieved_flags
+ cdef readonly object recieved_flags, release_ok
cdef public object fail
def __init__(self, label, data, shape=None, strides=None, format=None):
self.label = label
+ self.release_ok = True
self.log = ""
self.itemsize = self.get_itemsize()
if format is None: format = self.get_default_format()
self.log += msg + "\n"
def __releasebuffer__(MockBuffer self, Py_buffer* buffer):
+ if buffer.suboffsets != self.suboffsets:
+ self.release_ok = False
msg = "released %s" % self.label
print msg
self.log += msg + "\n"