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
9a7d4405
Commit
9a7d4405
authored
May 09, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor None checking code -- use NoneCheckNode everywhere
parent
3bbf6177
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
171 additions
and
148 deletions
+171
-148
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+84
-77
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-0
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+0
-21
tests/run/memslice.pyx
tests/run/memslice.pyx
+4
-50
tests/run/nonecheck.pyx
tests/run/nonecheck.pyx
+82
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
9a7d4405
This diff is collapsed.
Click to expand it.
Cython/Compiler/Nodes.py
View file @
9a7d4405
...
@@ -127,6 +127,7 @@ class Node(object):
...
@@ -127,6 +127,7 @@ class Node(object):
is_name
=
0
is_name
=
0
is_none
=
0
is_none
=
0
is_nonecheck
=
0
is_literal
=
0
is_literal
=
0
is_terminator
=
0
is_terminator
=
0
temps
=
None
temps
=
None
...
...
Cython/Utility/ObjectHandling.c
View file @
9a7d4405
/////////////// RaiseNoneAttrError.proto ///////////////
static
CYTHON_INLINE
void
__Pyx_RaiseNoneAttributeError
(
const
char
*
attrname
);
/////////////// RaiseNoneAttrError ///////////////
static
CYTHON_INLINE
void
__Pyx_RaiseNoneAttributeError
(
const
char
*
attrname
)
{
PyErr_Format
(
PyExc_AttributeError
,
"'NoneType' object has no attribute '%s'"
,
attrname
);
}
/////////////// RaiseNoneIndexingError.proto ///////////////
static
CYTHON_INLINE
void
__Pyx_RaiseNoneIndexingError
(
void
);
/////////////// RaiseNoneIndexingError ///////////////
static
CYTHON_INLINE
void
__Pyx_RaiseNoneIndexingError
(
void
)
{
PyErr_SetString
(
PyExc_TypeError
,
"'NoneType' object is not subscriptable"
);
}
/////////////// RaiseNoneIterError.proto ///////////////
/////////////// RaiseNoneIterError.proto ///////////////
static
CYTHON_INLINE
void
__Pyx_RaiseNoneNotIterableError
(
void
);
static
CYTHON_INLINE
void
__Pyx_RaiseNoneNotIterableError
(
void
);
...
...
tests/run/memslice.pyx
View file @
9a7d4405
...
@@ -2120,6 +2120,10 @@ def test_dtype_object_scalar_assignment():
...
@@ -2120,6 +2120,10 @@ def test_dtype_object_scalar_assignment():
#
#
### Test slices that are set to None
### Test slices that are set to None
#
#
# for none memoryview slice attribute testing, slicing, indexing, etc, see
# nonecheck.pyx
@
testcase
@
testcase
def
test_coerce_to_from_None
(
double
[:]
m1
,
double
[:]
m2
=
None
):
def
test_coerce_to_from_None
(
double
[:]
m1
,
double
[:]
m2
=
None
):
"""
"""
...
@@ -2130,56 +2134,6 @@ def test_coerce_to_from_None(double[:] m1, double[:] m2 = None):
...
@@ -2130,56 +2134,6 @@ def test_coerce_to_from_None(double[:] m1, double[:] m2 = None):
"""
"""
return
m1
,
m2
return
m1
,
m2
@
testcase
def
test_noneslice_attrib
(
double
[:]
m
):
"""
>>> test_noneslice_attrib(None)
'NoneType' object has no attribute 'copy'
'NoneType' object has no attribute 'T'
"""
cdef
double
[:]
m2
with
cython
.
nonecheck
(
True
):
try
:
m2
=
m
.
copy
()
except
Exception
,
e
:
print
e
.
args
[
0
]
try
:
m2
=
m
.
T
except
Exception
,
e
:
print
e
.
args
[
0
]
@
testcase
def
test_noneslice_index
(
double
[:]
m
):
"""
>>> test_noneslice_index(None)
Cannot index None memoryview slice
Cannot index None memoryview slice
Cannot index None memoryview slice
Cannot index None memoryview slice
"""
with
cython
.
nonecheck
(
True
):
try
:
a
=
m
[
10
]
except
Exception
,
e
:
print
e
.
args
[
0
]
try
:
b
=
m
[:]
except
Exception
,
e
:
print
e
.
args
[
0
]
try
:
m
[
10
]
=
2
except
Exception
,
e
:
print
e
.
args
[
0
]
try
:
m
[:]
=
2
except
Exception
,
e
:
print
e
.
args
[
0
]
@
testcase
@
testcase
def
test_noneslice_compare
(
double
[:]
m
):
def
test_noneslice_compare
(
double
[:]
m
):
"""
"""
...
...
tests/run/nonecheck.pyx
View file @
9a7d4405
...
@@ -88,3 +88,85 @@ def check_buffer_set(object[int] buf):
...
@@ -88,3 +88,85 @@ def check_buffer_set(object[int] buf):
TypeError: 'NoneType' object is not subscriptable
TypeError: 'NoneType' object is not subscriptable
"""
"""
buf
[
0
]
=
1
buf
[
0
]
=
1
@
cython
.
nonecheck
(
True
)
def
test_memslice_get
(
double
[:]
buf
):
"""
>>> test_memslice_get(None)
Traceback (most recent call last):
TypeError: Cannot index None memoryview slice
"""
return
buf
[
0
]
@
cython
.
nonecheck
(
True
)
def
test_memslice_set
(
double
[:]
buf
):
"""
>>> test_memslice_set(None)
Traceback (most recent call last):
TypeError: Cannot index None memoryview slice
"""
buf
[
0
]
=
1.0
@
cython
.
nonecheck
(
True
)
def
test_memslice_copy
(
double
[:]
buf
):
"""
>>> test_memslice_copy(None)
Traceback (most recent call last):
AttributeError: Cannot access 'copy' attribute of None memoryview slice
"""
cdef
double
[:]
copy
=
buf
.
copy
()
@
cython
.
nonecheck
(
True
)
def
test_memslice_transpose
(
double
[:]
buf
):
"""
>>> test_memslice_transpose(None)
Traceback (most recent call last):
AttributeError: Cannot transpose None memoryview slice
"""
cdef
double
[:]
T
=
buf
.
T
@
cython
.
nonecheck
(
True
)
def
test_memslice_shape
(
double
[:]
buf
):
"""
>>> test_memslice_shape(None)
Traceback (most recent call last):
AttributeError: Cannot access 'shape' attribute of None memoryview slice
"""
cdef
Py_ssize_t
extent
=
buf
.
shape
[
0
]
@
cython
.
nonecheck
(
True
)
def
test_memslice_slice
(
double
[:]
buf
):
"""
>>> test_memslice_slice(None)
Traceback (most recent call last):
TypeError: Cannot slice None memoryview slice
"""
cdef
double
[:]
sliced
=
buf
[
1
:]
@
cython
.
nonecheck
(
True
)
def
test_memslice_slice2
(
double
[:]
buf
):
"""
Should this raise an error? It may not slice at all.
>>> test_memslice_slice(None)
Traceback (most recent call last):
TypeError: Cannot slice None memoryview slice
"""
cdef
double
[:]
sliced
=
buf
[:]
@
cython
.
nonecheck
(
True
)
def
test_memslice_slice_assign
(
double
[:]
buf
):
"""
>>> test_memslice_slice_assign(None)
Traceback (most recent call last):
TypeError: Cannot assign to None memoryview slice
"""
buf
[...]
=
2
@
cython
.
nonecheck
(
True
)
def
test_memslice_slice_assign2
(
double
[:]
buf
):
"""
>>> test_memslice_slice_assign2(None)
Traceback (most recent call last):
TypeError: Cannot slice None memoryview slice
"""
buf
[:]
=
buf
[::
-
1
]
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