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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xavier Thompson
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
Show 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 *
return
result
##########
View.MemoryView
##########
##########
########## View.MemoryView ##########
##########
import
cython
...
...
@@ -180,6 +180,7 @@ cdef extern from *:
void
Py_INCREF
(
object
)
void
Py_DECREF
(
object
)
void
Py_XINCREF
(
object
)
ctypedef
struct
PyObject
...
...
@@ -197,6 +198,10 @@ cdef extern from *:
void
__PYX_INC_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'
)
cdef
class
Enum
(
object
):
...
...
@@ -246,6 +251,9 @@ cdef class memoryview(object):
if
type
(
self
)
is
memoryview
or
obj
is
not
None
:
__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
()
if
self
.
lock
==
NULL
:
...
...
@@ -320,6 +328,8 @@ cdef class memoryview(object):
itemp
[
i
]
=
c
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
.
obj
=
self
...
...
@@ -333,10 +343,6 @@ cdef class memoryview(object):
property
object
:
@
cname
(
'__pyx_memoryview__get__object'
)
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
property
shape
:
...
...
@@ -459,6 +465,7 @@ cdef memoryview memview_slice(memoryview memview, object indices):
cdef
extern
from
"stdlib.h"
:
void
abort
()
nogil
void
printf
(
char
*
s
,
...)
nogil
cdef
extern
from
"stdio.h"
:
ctypedef
struct
FILE
...
...
@@ -715,6 +722,8 @@ cdef memoryview_fromslice({{memviewslice_name}} *memviewslice,
result
.
view
=
memviewslice
.
memview
.
view
result
.
view
.
buf
=
<
void
*>
memviewslice
.
data
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
.
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):
buf
=
mslice
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
:
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_generic_slicing(IntMockBuffer("A", range(8 * 14 * 11), shape=(8, 14, 11)))
...
...
@@ -614,7 +617,7 @@ def test_generic_slicing(arg):
Test indirect slicing
>>> 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
(2, 0, 2)
0 1 -1
...
...
@@ -623,10 +626,10 @@ def test_generic_slicing(arg):
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> 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
(3, 9, 2)
2
0 1 -1
1
0 1 -1
released A
"""
...
...
@@ -635,9 +638,14 @@ def test_generic_slicing(arg):
b
=
a
[
2
:
8
:
2
,
-
4
:
1
:
-
1
,
1
:
3
]
print
b
.
shape
if
b
.
suboffsets
[
0
]
<
0
:
print_int_offsets
(
*
b
.
strides
)
print_int_offsets
(
*
b
.
suboffsets
)
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
.
suboffsets
[
0
],
b
.
suboffsets
[
1
],
b
.
suboffsets
[
2
])
cdef
int
i
,
j
,
k
for
i
in
range
(
b
.
shape
[
0
]):
...
...
tests/run/memslice.pyx
View file @
54cbd0e8
...
...
@@ -1162,14 +1162,17 @@ def test_cdef_function2():
cdef
_function2
(
global_A
,
global_B
)
def
print_
int_offsets
(
*
args
):
def
print_
offsets
(
*
args
,
size
=
0
,
newline
=
True
):
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
def
test_generic_slicing
(
arg
):
def
test_generic_slicing
(
arg
,
indirect
=
False
):
"""
Test simple slicing
>>> test_generic_slicing(IntMockBuffer("A", range(8 * 14 * 11), shape=(8, 14, 11)))
...
...
@@ -1189,7 +1192,7 @@ def test_generic_slicing(arg):
Test indirect slicing
>>> 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
2 0 2
0 1 -1
...
...
@@ -1198,10 +1201,10 @@ def test_generic_slicing(arg):
>>> stride1 = 21 * 14
>>> stride2 = 21
>>> 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
3 9 2
2
0 1 -1
1
0 1 -1
released A
"""
...
...
@@ -1209,7 +1212,12 @@ def test_generic_slicing(arg):
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
]
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
.
suboffsets
[
0
],
b
.
suboffsets
[
1
],
b
.
suboffsets
[
2
])
...
...
@@ -1250,7 +1258,9 @@ def test_indirect_slicing(arg):
cdef
int
[::
view
.
indirect
,
::
view
.
indirect
]
c
=
b
[...,
0
]
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
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