Commit 5197f5cf authored by Mark Florisson's avatar Mark Florisson

memslice decref old item on item assignment

parent efc2e33d
......@@ -4029,12 +4029,12 @@ class AttributeNode(ExprNode):
code.put_gotref(self.py_result())
elif self.type.is_memoryviewslice:
if self.initialized_check:
code.putln(textwrap.dedent('''
if (unlikely(!%s.memview)) {
PyErr_SetString(PyExc_AttributeError,
"Memoryview is not initialized");
%s
}''' % (self.result(), code.error_goto(self.pos))))
code.putln(
'if (unlikely(!%s.memview)) {'
'PyErr_SetString(PyExc_AttributeError,'
'"Memoryview is not initialized");'
'%s'
'}' % (self.result(), code.error_goto(self.pos)))
#code.putln("%s = %s;" % (self.result(),
# self.calculate_result_code()))
else:
......
......@@ -310,9 +310,9 @@ cdef class _memoryviewslice(memoryview):
cdef convert_item_to_object(self, char *itemp):
if self.to_object_func != NULL:
self.to_object_func(itemp)
return self.to_object_func(itemp)
else:
memoryview.convert_item_to_object(self, itemp)
return memoryview.convert_item_to_object(self, itemp)
cdef assign_item_from_object(self, char *itemp, object value):
if self.to_dtype_func != NULL:
......@@ -328,7 +328,8 @@ cdef memoryview_cwrapper(object o, int flags):
@cname('__pyx_memoryview_fromslice')
cdef memoryview_from_memslice_cwrapper(
{{memviewslice_name}} *memviewslice, object orig_obj, int flags, int cur_ndim,
object (*to_object_func)(char *), int (*to_dtype_func)(char *, object)):
object (*to_object_func)(char *),
int (*to_dtype_func)(char *, object) except 0):
cdef _memoryviewslice result = _memoryviewslice(orig_obj, flags)
cdef int new_ndim = result.view.ndim - cur_ndim
......@@ -340,6 +341,7 @@ cdef memoryview_from_memslice_cwrapper(
result.view.ndim = cur_ndim
result.to_object_func = to_object_func
result.to_dtype_func = to_dtype_func
return result
......@@ -382,7 +384,7 @@ cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index, int dim
if index < 0:
raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
if index > shape:
if index >= shape:
raise IndexError("Out of bounds on buffer access (axis %d)" % dim)
resultp = bufp + index * stride
......
......@@ -452,6 +452,7 @@ PyObject *{{get_function}}(const char *itemp) {
int {{set_function}}(const char *itemp, PyObject *obj) {
Py_INCREF(obj);
Py_DECREF(*(PyObject **) itemp);
*(PyObject **) itemp = obj;
return 1;
}
......@@ -127,7 +127,7 @@ def test_cdef_attribute():
print ExtClass().mview
'''
def basic_struct(MyStruct[:] mslice):
"""
See also buffmt.pyx
......@@ -218,7 +218,7 @@ def complex_struct_inplace(LongComplex[:] mslice):
buf[0].real += 1
buf[0].imag += 2
print buf[0].real, buf[0].imag
'''
#
# Getting items and index bounds checking
#
......@@ -227,6 +227,8 @@ def get_int_2d(int[:, :] mslice, int i, int j):
>>> C = IntMockBuffer("C", range(6), (2,3))
>>> get_int_2d(C, 1, 1)
acquired C
acquired C
released C
released C
4
......@@ -342,6 +344,8 @@ def writable(unsigned short int[:, :, :] mslice):
>>> R = UnsignedShortMockBuffer("R", range(27), shape=(3, 3, 3))
>>> writable(R)
acquired R
acquired R
released R
released R
>>> [str(x) for x in R.recieved_flags] # Py2/3
['FORMAT', 'ND', 'STRIDES', 'WRITABLE']
......@@ -354,6 +358,8 @@ def strided(int[:] mslice):
>>> A = IntMockBuffer("A", range(4))
>>> strided(A)
acquired A
acquired A
released A
released A
2
......@@ -412,12 +418,16 @@ def generic(int[::view.generic, ::view.generic] mslice1,
>>> generic(A, B)
acquired A
acquired B
acquired A
acquired B
4
4
10
11
released A
released B
released A
released B
"""
buf1, buf2 = mslice1, mslice2
......@@ -438,12 +448,16 @@ def generic_contig(int[::view.generic_contiguous, :] mslice1,
>>> generic_contig(A, B)
acquired A
acquired B
acquired A
acquired B
4
4
10
11
released A
released B
released A
released B
"""
buf1, buf2 = mslice1, mslice2
......
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