Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
5197f5cf
Commit
5197f5cf
authored
Aug 03, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memslice decref old item on item assignment
parent
efc2e33d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
12 deletions
+29
-12
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+6
-6
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+6
-4
Cython/Utility/MemoryView_C.c
Cython/Utility/MemoryView_C.c
+1
-0
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+16
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
5197f5cf
...
@@ -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
:
...
...
Cython/Utility/MemoryView.pyx
View file @
5197f5cf
...
@@ -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
...
...
Cython/Utility/MemoryView_C.c
View file @
5197f5cf
...
@@ -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
;
}
}
tests/run/memoryview.pyx
View file @
5197f5cf
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment