Commit 7498f3c2 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Buffer stuff: Patching suboffsets back to NULL if that was what we retrieved,...

Buffer stuff: Patching suboffsets back to NULL if that was what we retrieved, just to be more predictable.
parent 998c14d2
...@@ -157,7 +157,7 @@ def put_acquire_arg_buffer(entry, code, pos): ...@@ -157,7 +157,7 @@ def put_acquire_arg_buffer(entry, code, pos):
# entry.buffer_aux.buffer_info_var.cname)) # entry.buffer_aux.buffer_info_var.cname))
def get_release_buffer_code(entry): 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.cname, entry.cname,
entry.buffer_aux.buffer_info_var.cname) entry.buffer_aux.buffer_info_var.cname)
...@@ -192,7 +192,7 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type, ...@@ -192,7 +192,7 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
# Release any existing buffer # Release any existing buffer
code.put('if (%s != Py_None) ' % lhs_cname) code.put('if (%s != Py_None) ' % lhs_cname)
code.begin_block(); code.begin_block();
code.putln('PyObject_ReleaseBuffer(%s, &%s);' % ( code.putln('__Pyx_ReleaseBuffer(%s, &%s);' % (
lhs_cname, bufstruct)) lhs_cname, bufstruct))
code.end_block() code.end_block()
# Acquire # Acquire
...@@ -551,11 +551,17 @@ static void __Pyx_RaiseBufferIndexError(int axis) { ...@@ -551,11 +551,17 @@ static void __Pyx_RaiseBufferIndexError(int axis) {
# exporter. # exporter.
# #
acquire_utility_code = ["""\ acquire_utility_code = ["""\
static INLINE void __Pyx_ReleaseBuffer(PyObject* obj, Py_buffer* info);
static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf); /*proto*/ static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf); /*proto*/
static INLINE const char* __Pyx_ConsumeWhitespace(const char* ts); /*proto*/ static INLINE const char* __Pyx_ConsumeWhitespace(const char* ts); /*proto*/
static INLINE const char* __Pyx_BufferTypestringCheckEndian(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 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) { static INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
buf->buf = NULL; buf->buf = NULL;
buf->strides = __Pyx_zeros; buf->strides = __Pyx_zeros;
......
...@@ -354,7 +354,6 @@ def get_int_2d(object[int, 2] buf, int i, int j): ...@@ -354,7 +354,6 @@ def get_int_2d(object[int, 2] buf, int i, int j):
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: Out of bounds on buffer access (axis 1) IndexError: Out of bounds on buffer access (axis 1)
""" """
return buf[i, j] return buf[i, j]
...@@ -500,6 +499,10 @@ def strided(object[int, 1, 'strided'] buf): ...@@ -500,6 +499,10 @@ def strided(object[int, 1, 'strided'] buf):
2 2
>>> A.recieved_flags >>> A.recieved_flags
['FORMAT', 'ND', 'STRIDES'] ['FORMAT', 'ND', 'STRIDES']
Check that the suboffsets were patched back prior to release.
>>> A.release_ok
True
""" """
return buf[2] return buf[2]
...@@ -663,11 +666,12 @@ cdef class MockBuffer: ...@@ -663,11 +666,12 @@ cdef class MockBuffer:
cdef Py_ssize_t* suboffsets cdef Py_ssize_t* suboffsets
cdef object label, log cdef object label, log
cdef readonly object recieved_flags cdef readonly object recieved_flags, release_ok
cdef public object fail cdef public object fail
def __init__(self, label, data, shape=None, strides=None, format=None): def __init__(self, label, data, shape=None, strides=None, format=None):
self.label = label self.label = label
self.release_ok = True
self.log = "" self.log = ""
self.itemsize = self.get_itemsize() self.itemsize = self.get_itemsize()
if format is None: format = self.get_default_format() if format is None: format = self.get_default_format()
...@@ -776,6 +780,8 @@ cdef class MockBuffer: ...@@ -776,6 +780,8 @@ cdef class MockBuffer:
self.log += msg + "\n" self.log += msg + "\n"
def __releasebuffer__(MockBuffer self, Py_buffer* buffer): def __releasebuffer__(MockBuffer self, Py_buffer* buffer):
if buffer.suboffsets != self.suboffsets:
self.release_ok = False
msg = "released %s" % self.label msg = "released %s" % self.label
print msg print msg
self.log += msg + "\n" self.log += msg + "\n"
......
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