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
6e8dd308
Commit
6e8dd308
authored
May 09, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow 'not None' declaration for memoryview slice arguments
parent
a7b2a8d3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
4 deletions
+19
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+11
-4
tests/run/memslice.pyx
tests/run/memslice.pyx
+8
-0
No files found.
Cython/Compiler/Nodes.py
View file @
6e8dd308
...
...
@@ -1833,7 +1833,12 @@ class FuncDefNode(StatNode, BlockNode):
def
generate_arg_none_check
(
self
,
arg
,
code
):
# Generate None check for one argument.
code
.
putln
(
'if (unlikely(((PyObject *)%s) == Py_None)) {'
%
arg
.
entry
.
cname
)
if
arg
.
type
.
is_memoryviewslice
:
cname
=
"%s.memview"
%
arg
.
entry
.
cname
else
:
cname
=
arg
.
entry
.
cname
code
.
putln
(
'if (unlikely(((PyObject *)%s) == Py_None)) {'
%
cname
)
code
.
putln
(
'''PyErr_Format(PyExc_TypeError, "Argument '%s' must not be None"); %s'''
%
(
arg
.
name
,
code
.
error_goto
(
arg
.
pos
)))
...
...
@@ -2979,13 +2984,13 @@ class DefNode(FuncDefNode):
arg
.
needs_conversion
=
0
arg
.
needs_type_test
=
0
arg
.
is_generic
=
1
if
arg
.
type
.
is_pyobject
or
arg
.
type
.
is_buffer
:
if
arg
.
type
.
is_pyobject
or
arg
.
type
.
is_buffer
or
arg
.
type
.
is_memoryviewslice
:
if
arg
.
or_none
:
arg
.
accept_none
=
True
elif
arg
.
not_none
:
arg
.
accept_none
=
False
elif
(
arg
.
type
.
is_extension_type
or
arg
.
type
.
is_builtin_type
or
arg
.
type
.
is_buffer
):
or
arg
.
type
.
is_buffer
or
arg
.
type
.
is_memoryviewslice
):
if
arg
.
default
and
arg
.
default
.
constant_result
is
None
:
# special case: def func(MyType obj = None)
arg
.
accept_none
=
True
...
...
@@ -4029,7 +4034,9 @@ class DefNodeWrapper(FuncDefNode):
for
arg
in
self
.
args
:
if
arg
.
needs_type_test
:
self
.
generate_arg_type_test
(
arg
,
code
)
elif
not
arg
.
accept_none
and
arg
.
type
.
is_pyobject
:
elif
not
arg
.
accept_none
and
(
arg
.
type
.
is_pyobject
or
arg
.
type
.
is_buffer
or
arg
.
type
.
is_memoryviewslice
):
self
.
generate_arg_none_check
(
arg
,
code
)
def
error_value
(
self
):
...
...
tests/run/memslice.pyx
View file @
6e8dd308
...
...
@@ -2195,6 +2195,14 @@ def test_noneslice_nogil_check_none(double[:] m):
return
is_none
,
not_none
@
testcase
def
test_noneslice_not_none
(
double
[:]
m
not
None
):
"""
>>> test_noneslice_not_none(None)
Traceback (most recent call last):
TypeError: Argument 'm' must not be None
"""
def
get_int
():
return
10
...
...
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