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
Gwenaël Samain
cython
Commits
eedd37bc
Commit
eedd37bc
authored
Aug 06, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Buffers: Correct order of buffer argument typetest/acquisition
parent
4f8cc889
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
5 deletions
+55
-5
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+4
-2
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+51
-3
No files found.
Cython/Compiler/Nodes.py
View file @
eedd37bc
...
...
@@ -894,8 +894,6 @@ class FuncDefNode(StatNode, BlockNode):
for
entry
in
lenv
.
arg_entries
:
if
entry
.
type
.
is_pyobject
and
lenv
.
control_flow
.
get_state
((
entry
.
name
,
'source'
))
!=
'arg'
:
code
.
put_var_incref
(
entry
)
if
entry
.
type
.
is_buffer
:
Buffer
.
put_acquire_arg_buffer
(
entry
,
code
,
self
.
pos
)
# ----- Initialise local variables
for
entry
in
lenv
.
var_entries
:
if
entry
.
type
.
is_pyobject
and
entry
.
init_to_none
and
entry
.
used
:
...
...
@@ -904,6 +902,10 @@ class FuncDefNode(StatNode, BlockNode):
code
.
putln
(
"%s.buf = NULL;"
%
entry
.
buffer_aux
.
buffer_info_var
.
cname
)
# ----- Check and convert arguments
self
.
generate_argument_type_tests
(
code
)
# ----- Acquire buffer arguments
for
entry
in
lenv
.
arg_entries
:
if
entry
.
type
.
is_buffer
:
Buffer
.
put_acquire_arg_buffer
(
entry
,
code
,
self
.
pos
)
# ----- Function body
self
.
body
.
generate_execution_code
(
code
)
# ----- Default return value
...
...
tests/run/bufaccess.pyx
View file @
eedd37bc
...
...
@@ -709,10 +709,8 @@ def printbuf_cytypedef2(object[cytypedef2] buf, shape):
print
#
# Testcase support code
# Testcase support code
(more tests below!, because of scope rules)
#
...
...
@@ -896,6 +894,9 @@ cdef class UnsignedShortMockBuffer(MockBuffer):
cdef
get_itemsize
(
self
):
return
sizeof
(
unsigned
short
)
cdef
get_default_format
(
self
):
return
"=H"
cdef
class
IntStridedMockBuffer
(
MockBuffer
):
cdef
__cythonbufferdefaults__
=
{
"mode"
:
"strided"
}
cdef
class
ErrorBuffer
:
cdef
object
label
...
...
@@ -908,3 +909,50 @@ cdef class ErrorBuffer:
def
__releasebuffer__
(
MockBuffer
self
,
Py_buffer
*
buffer
):
raise
Exception
(
"releasing %s"
%
self
.
label
)
#
# Typed buffers
#
@
testcase
def
typedbuffer1
(
obj
):
"""
>>> typedbuffer1(IntMockBuffer("A", range(10)))
acquired A
released A
>>> typedbuffer1(None)
>>> typedbuffer1(4)
Traceback (most recent call last):
...
TypeError: Cannot convert int to bufaccess.IntMockBuffer
"""
cdef
IntMockBuffer
[
int
,
1
]
buf
=
obj
@
testcase
def
typedbuffer2
(
IntMockBuffer
[
int
,
1
]
obj
):
"""
>>> typedbuffer2(IntMockBuffer("A", range(10)))
acquired A
released A
>>> typedbuffer2(None)
>>> typedbuffer2(4)
Traceback (most recent call last):
...
TypeError: Argument 'obj' has incorrect type (expected bufaccess.IntMockBuffer, got int)
"""
pass
#
# Test __cythonbufferdefaults__
#
@
testcase
def
bufdefaults1
(
IntStridedMockBuffer
[
int
,
1
]
buf
):
"""
>>> A = IntStridedMockBuffer("A", range(10))
>>> bufdefaults1(A)
acquired A
released A
>>> A.recieved_flags
['FORMAT', 'ND', 'STRIDES']
"""
pass
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