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