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
54cbd0e8
Commit
54cbd0e8
authored
Aug 23, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix segfault & fix test
parent
349dd60e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
41 deletions
+52
-41
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+14
-5
tests/errors/e_cython_parallel_pyobject_reduction.pyx
tests/errors/e_cython_parallel_pyobject_reduction.pyx
+0
-16
tests/run/memoryview.pyx
tests/run/memoryview.pyx
+18
-10
tests/run/memslice.pyx
tests/run/memslice.pyx
+20
-10
No files found.
Cython/Utility/MemoryView.pyx
View file @
54cbd0e8
...
@@ -158,7 +158,7 @@ cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, char *
...
@@ -158,7 +158,7 @@ cdef array array_cwrapper(tuple shape, Py_ssize_t itemsize, char *format, char *
return
result
return
result
##########
View.MemoryView
##########
##########
########## View.MemoryView ##########
##########
import
cython
import
cython
...
@@ -180,6 +180,7 @@ cdef extern from *:
...
@@ -180,6 +180,7 @@ cdef extern from *:
void
Py_INCREF
(
object
)
void
Py_INCREF
(
object
)
void
Py_DECREF
(
object
)
void
Py_DECREF
(
object
)
void
Py_XINCREF
(
object
)
ctypedef
struct
PyObject
ctypedef
struct
PyObject
...
@@ -197,6 +198,10 @@ cdef extern from *:
...
@@ -197,6 +198,10 @@ cdef extern from *:
void
__PYX_INC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
void
__PYX_INC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
void
__PYX_XDEC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
void
__PYX_XDEC_MEMVIEW
({{
memviewslice_name
}}
*
memslice
,
int
have_gil
)
ctypedef
struct
__pyx_buffer
"Py_buffer"
:
PyObject
*
obj
PyObject
*
Py_None
@
cname
(
'__pyx_MemviewEnum'
)
@
cname
(
'__pyx_MemviewEnum'
)
cdef
class
Enum
(
object
):
cdef
class
Enum
(
object
):
...
@@ -246,6 +251,9 @@ cdef class memoryview(object):
...
@@ -246,6 +251,9 @@ cdef class memoryview(object):
if
type
(
self
)
is
memoryview
or
obj
is
not
None
:
if
type
(
self
)
is
memoryview
or
obj
is
not
None
:
__Pyx_GetBuffer
(
obj
,
&
self
.
view
,
flags
)
__Pyx_GetBuffer
(
obj
,
&
self
.
view
,
flags
)
if
<
PyObject
*>
self
.
view
.
obj
==
NULL
:
(
<
__pyx_buffer
*>
&
self
.
view
).
obj
=
Py_None
Py_INCREF
(
None
)
self
.
lock
=
PyThread_allocate_lock
()
self
.
lock
=
PyThread_allocate_lock
()
if
self
.
lock
==
NULL
:
if
self
.
lock
==
NULL
:
...
@@ -320,6 +328,8 @@ cdef class memoryview(object):
...
@@ -320,6 +328,8 @@ cdef class memoryview(object):
itemp
[
i
]
=
c
itemp
[
i
]
=
c
def
__getbuffer__
(
self
,
Py_buffer
*
info
,
int
flags
):
def
__getbuffer__
(
self
,
Py_buffer
*
info
,
int
flags
):
# Note: self.view.obj must not be NULL
Py_INCREF
(
self
.
view
.
obj
)
info
[
0
]
=
self
.
view
info
[
0
]
=
self
.
view
info
.
obj
=
self
info
.
obj
=
self
...
@@ -333,10 +343,6 @@ cdef class memoryview(object):
...
@@ -333,10 +343,6 @@ cdef class memoryview(object):
property
object
:
property
object
:
@
cname
(
'__pyx_memoryview__get__object'
)
@
cname
(
'__pyx_memoryview__get__object'
)
def
__get__
(
self
):
def
__get__
(
self
):
if
(
self
.
obj
is
None
and
<
PyObject
*>
self
.
view
.
obj
!=
NULL
and
self
.
view
.
obj
is
not
None
):
return
<
object
>
self
.
view
.
obj
return
self
.
obj
return
self
.
obj
property
shape
:
property
shape
:
...
@@ -459,6 +465,7 @@ cdef memoryview memview_slice(memoryview memview, object indices):
...
@@ -459,6 +465,7 @@ cdef memoryview memview_slice(memoryview memview, object indices):
cdef
extern
from
"stdlib.h"
:
cdef
extern
from
"stdlib.h"
:
void
abort
()
nogil
void
abort
()
nogil
void
printf
(
char
*
s
,
...)
nogil
cdef
extern
from
"stdio.h"
:
cdef
extern
from
"stdio.h"
:
ctypedef
struct
FILE
ctypedef
struct
FILE
...
@@ -715,6 +722,8 @@ cdef memoryview_fromslice({{memviewslice_name}} *memviewslice,
...
@@ -715,6 +722,8 @@ cdef memoryview_fromslice({{memviewslice_name}} *memviewslice,
result
.
view
=
memviewslice
.
memview
.
view
result
.
view
=
memviewslice
.
memview
.
view
result
.
view
.
buf
=
<
void
*>
memviewslice
.
data
result
.
view
.
buf
=
<
void
*>
memviewslice
.
data
result
.
view
.
ndim
=
ndim
result
.
view
.
ndim
=
ndim
(
<
__pyx_buffer
*>
&
result
.
view
).
obj
=
Py_None
Py_INCREF
(
None
)
result
.
view
.
shape
=
<
Py_ssize_t
*>
result
.
from_slice
.
shape
result
.
view
.
shape
=
<
Py_ssize_t
*>
result
.
from_slice
.
shape
result
.
view
.
strides
=
<
Py_ssize_t
*>
result
.
from_slice
.
strides
result
.
view
.
strides
=
<
Py_ssize_t
*>
result
.
from_slice
.
strides
...
...
tests/errors/e_cython_parallel_pyobject_reduction.pyx
deleted
100644 → 0
View file @
349dd60e
# mode: error
from
cython.parallel
cimport
prange
def
invalid_closure_reduction
():
sum
=
0
def
inner
():
nonlocal
sum
cdef
int
i
for
i
in
prange
(
10
,
nogil
=
True
):
with
gil
:
sum
+=
i
_ERRORS
=
u"""
e_cython_parallel_pyobject_reduction.pyx:10:23: Python objects cannot be reductions
"""
tests/run/memoryview.pyx
View file @
54cbd0e8
...
@@ -588,13 +588,16 @@ def assign_temporary_to_object(object[:] mslice):
...
@@ -588,13 +588,16 @@ def assign_temporary_to_object(object[:] mslice):
buf
=
mslice
buf
=
mslice
buf
[
1
]
=
{
3
-
2
:
2
+
(
2
*
4
)
-
2
}
buf
[
1
]
=
{
3
-
2
:
2
+
(
2
*
4
)
-
2
}
def
print_
int_offsets
(
*
args
):
def
print_
offsets
(
*
args
,
size
=
0
,
newline
=
True
):
for
item
in
args
:
for
item
in
args
:
print
item
/
size
of
(
int
)
,
print
item
/
size
,
print
if
newline
:
print
def
test_generic_slicing
(
arg
):
def
print_int_offsets
(
*
args
,
newline
=
True
):
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
def
test_generic_slicing
(
arg
,
indirect
=
False
):
"""
"""
Test simple slicing
Test simple slicing
>>> test_generic_slicing(IntMockBuffer("A", range(8 * 14 * 11), shape=(8, 14, 11)))
>>> test_generic_slicing(IntMockBuffer("A", range(8 * 14 * 11), shape=(8, 14, 11)))
...
@@ -614,7 +617,7 @@ def test_generic_slicing(arg):
...
@@ -614,7 +617,7 @@ def test_generic_slicing(arg):
Test indirect slicing
Test indirect slicing
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(5, 3, 4)))
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(5, 3, 4))
, indirect=True
)
acquired A
acquired A
(2, 0, 2)
(2, 0, 2)
0 1 -1
0 1 -1
...
@@ -623,10 +626,10 @@ def test_generic_slicing(arg):
...
@@ -623,10 +626,10 @@ def test_generic_slicing(arg):
>>> stride1 = 21 * 14
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> stride2 = 21
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(9, 14, 21)))
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(9, 14, 21))
, indirect=True
)
acquired A
acquired A
(3, 9, 2)
(3, 9, 2)
2
0 1 -1
1
0 1 -1
released A
released A
"""
"""
...
@@ -635,9 +638,14 @@ def test_generic_slicing(arg):
...
@@ -635,9 +638,14 @@ def test_generic_slicing(arg):
b
=
a
[
2
:
8
:
2
,
-
4
:
1
:
-
1
,
1
:
3
]
b
=
a
[
2
:
8
:
2
,
-
4
:
1
:
-
1
,
1
:
3
]
print
b
.
shape
print
b
.
shape
if
b
.
suboffsets
[
0
]
<
0
:
print_int_offsets
(
*
b
.
strides
)
if
indirect
:
print_int_offsets
(
*
b
.
suboffsets
)
print
b
.
suboffsets
[
0
]
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
sizeof
(
int
),
print
b
.
suboffsets
[
2
]
else
:
print_int_offsets
(
b
.
strides
[
0
],
b
.
strides
[
1
],
b
.
strides
[
2
])
print_int_offsets
(
b
.
suboffsets
[
0
],
b
.
suboffsets
[
1
],
b
.
suboffsets
[
2
])
cdef
int
i
,
j
,
k
cdef
int
i
,
j
,
k
for
i
in
range
(
b
.
shape
[
0
]):
for
i
in
range
(
b
.
shape
[
0
]):
...
...
tests/run/memslice.pyx
View file @
54cbd0e8
...
@@ -1162,14 +1162,17 @@ def test_cdef_function2():
...
@@ -1162,14 +1162,17 @@ def test_cdef_function2():
cdef
_function2
(
global_A
,
global_B
)
cdef
_function2
(
global_A
,
global_B
)
def
print_
int_offsets
(
*
args
):
def
print_
offsets
(
*
args
,
size
=
0
,
newline
=
True
):
for
item
in
args
:
for
item
in
args
:
print
item
/
size
of
(
int
)
,
print
item
/
size
,
print
if
newline
:
print
def
print_int_offsets
(
*
args
,
newline
=
True
):
print_offsets
(
*
args
,
size
=
sizeof
(
int
),
newline
=
newline
)
@
testcase
@
testcase
def
test_generic_slicing
(
arg
):
def
test_generic_slicing
(
arg
,
indirect
=
False
):
"""
"""
Test simple slicing
Test simple slicing
>>> test_generic_slicing(IntMockBuffer("A", range(8 * 14 * 11), shape=(8, 14, 11)))
>>> test_generic_slicing(IntMockBuffer("A", range(8 * 14 * 11), shape=(8, 14, 11)))
...
@@ -1189,7 +1192,7 @@ def test_generic_slicing(arg):
...
@@ -1189,7 +1192,7 @@ def test_generic_slicing(arg):
Test indirect slicing
Test indirect slicing
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> L = [[range(k * 12 + j * 4, k * 12 + j * 4 + 4) for j in xrange(3)] for k in xrange(5)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(5, 3, 4)))
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(5, 3, 4))
, indirect=True
)
acquired A
acquired A
2 0 2
2 0 2
0 1 -1
0 1 -1
...
@@ -1198,10 +1201,10 @@ def test_generic_slicing(arg):
...
@@ -1198,10 +1201,10 @@ def test_generic_slicing(arg):
>>> stride1 = 21 * 14
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> stride2 = 21
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> L = [[range(k * stride1 + j * stride2, k * stride1 + j * stride2 + 21) for j in xrange(14)] for k in xrange(9)]
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(9, 14, 21)))
>>> test_generic_slicing(IntMockBuffer("A", L, shape=(9, 14, 21))
, indirect=True
)
acquired A
acquired A
3 9 2
3 9 2
2
0 1 -1
1
0 1 -1
released A
released A
"""
"""
...
@@ -1209,9 +1212,14 @@ def test_generic_slicing(arg):
...
@@ -1209,9 +1212,14 @@ def test_generic_slicing(arg):
cdef
int
[::
view
.
generic
,
::
view
.
generic
,
:]
b
=
a
[
2
:
8
:
2
,
-
4
:
1
:
-
1
,
1
:
3
]
cdef
int
[::
view
.
generic
,
::
view
.
generic
,
:]
b
=
a
[
2
:
8
:
2
,
-
4
:
1
:
-
1
,
1
:
3
]
print
b
.
shape
[
0
],
b
.
shape
[
1
],
b
.
shape
[
2
]
print
b
.
shape
[
0
],
b
.
shape
[
1
],
b
.
shape
[
2
]
if
b
.
suboffsets
[
0
]
<
0
:
if
indirect
:
print
b
.
suboffsets
[
0
]
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
sizeof
(
int
),
print
b
.
suboffsets
[
2
]
else
:
print_int_offsets
(
b
.
strides
[
0
],
b
.
strides
[
1
],
b
.
strides
[
2
])
print_int_offsets
(
b
.
strides
[
0
],
b
.
strides
[
1
],
b
.
strides
[
2
])
print_int_offsets
(
b
.
suboffsets
[
0
],
b
.
suboffsets
[
1
],
b
.
suboffsets
[
2
])
print_int_offsets
(
b
.
suboffsets
[
0
],
b
.
suboffsets
[
1
],
b
.
suboffsets
[
2
])
cdef
int
i
,
j
,
k
cdef
int
i
,
j
,
k
for
i
in
range
(
b
.
shape
[
0
]):
for
i
in
range
(
b
.
shape
[
0
]):
...
@@ -1250,7 +1258,9 @@ def test_indirect_slicing(arg):
...
@@ -1250,7 +1258,9 @@ def test_indirect_slicing(arg):
cdef
int
[::
view
.
indirect
,
::
view
.
indirect
]
c
=
b
[...,
0
]
cdef
int
[::
view
.
indirect
,
::
view
.
indirect
]
c
=
b
[...,
0
]
print
b
.
shape
[
0
],
b
.
shape
[
1
],
b
.
shape
[
2
]
print
b
.
shape
[
0
],
b
.
shape
[
1
],
b
.
shape
[
2
]
print_int_offsets
(
b
.
suboffsets
[
0
],
b
.
suboffsets
[
1
],
b
.
suboffsets
[
2
])
print
b
.
suboffsets
[
0
]
/
sizeof
(
int
*
),
print
b
.
suboffsets
[
1
]
/
sizeof
(
int
),
print
b
.
suboffsets
[
2
]
print
b
[
4
,
2
,
1
]
print
b
[
4
,
2
,
1
]
print
c
[
4
,
2
]
print
c
[
4
,
2
]
...
...
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