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
0e71f50a
Commit
0e71f50a
authored
Sep 25, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nonecheck directive for buffer accesses
parent
a5e1aea2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+20
-0
tests/run/nonecheck.pyx
tests/run/nonecheck.pyx
+18
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
0e71f50a
...
@@ -1498,6 +1498,8 @@ class IndexNode(ExprNode):
...
@@ -1498,6 +1498,8 @@ class IndexNode(ExprNode):
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
if
self
.
is_buffer_access
:
if
self
.
is_buffer_access
:
if
code
.
globalstate
.
directives
[
'nonecheck'
]:
self
.
put_nonecheck
(
code
)
ptrcode
=
self
.
buffer_lookup_code
(
code
)
ptrcode
=
self
.
buffer_lookup_code
(
code
)
code
.
putln
(
"%s = *%s;"
%
(
code
.
putln
(
"%s = *%s;"
%
(
self
.
result
(),
self
.
result
(),
...
@@ -1541,6 +1543,8 @@ class IndexNode(ExprNode):
...
@@ -1541,6 +1543,8 @@ class IndexNode(ExprNode):
def
generate_buffer_setitem_code
(
self
,
rhs
,
code
,
op
=
""
):
def
generate_buffer_setitem_code
(
self
,
rhs
,
code
,
op
=
""
):
# Used from generate_assignment_code and InPlaceAssignmentNode
# Used from generate_assignment_code and InPlaceAssignmentNode
if
code
.
globalstate
.
directives
[
'nonecheck'
]:
self
.
put_nonecheck
(
code
)
ptrexpr
=
self
.
buffer_lookup_code
(
code
)
ptrexpr
=
self
.
buffer_lookup_code
(
code
)
if
self
.
buffer_type
.
dtype
.
is_pyobject
:
if
self
.
buffer_type
.
dtype
.
is_pyobject
:
# Must manage refcounts. Decref what is already there
# Must manage refcounts. Decref what is already there
...
@@ -1607,6 +1611,13 @@ class IndexNode(ExprNode):
...
@@ -1607,6 +1611,13 @@ class IndexNode(ExprNode):
options
=
code
.
globalstate
.
directives
,
options
=
code
.
globalstate
.
directives
,
pos
=
self
.
pos
,
code
=
code
)
pos
=
self
.
pos
,
code
=
code
)
def
put_nonecheck
(
self
,
code
):
code
.
globalstate
.
use_utility_code
(
raise_noneindex_error_utility_code
)
code
.
putln
(
"if (%s) {"
%
code
.
unlikely
(
"%s == Py_None"
)
%
self
.
base
.
result_as
(
PyrexTypes
.
py_object_type
))
code
.
putln
(
"__Pyx_RaiseNoneIndexingError();"
)
code
.
putln
(
code
.
error_goto
(
self
.
pos
))
code
.
putln
(
"}"
)
class
SliceIndexNode
(
ExprNode
):
class
SliceIndexNode
(
ExprNode
):
# 2-element slice indexing
# 2-element slice indexing
#
#
...
@@ -4587,3 +4598,12 @@ static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname) {
...
@@ -4587,3 +4598,12 @@ static INLINE void __Pyx_RaiseNoneAttributeError(char* attrname) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname);
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname);
}
}
"""
]
"""
]
raise_noneindex_error_utility_code
=
[
"""
static INLINE void __Pyx_RaiseNoneIndexingError();
"""
,
"""
static INLINE void __Pyx_RaiseNoneIndexingError() {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is unsubscriptable");
}
"""
]
tests/run/nonecheck.pyx
View file @
0e71f50a
...
@@ -32,6 +32,16 @@ Traceback (most recent call last):
...
@@ -32,6 +32,16 @@ Traceback (most recent call last):
...
...
AttributeError: 'NoneType' object has no attribute 'a'
AttributeError: 'NoneType' object has no attribute 'a'
>>> check_buffer_get(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is unsubscriptable
>>> check_buffer_set(None)
Traceback (most recent call last):
...
TypeError: 'NoneType' object is unsubscriptable
"""
"""
cimport
cython
cimport
cython
...
@@ -70,3 +80,11 @@ def check_and_assign(MyClass var):
...
@@ -70,3 +80,11 @@ def check_and_assign(MyClass var):
var
=
None
var
=
None
print
var
.
a
print
var
.
a
@
cython
.
nonecheck
(
True
)
def
check_buffer_get
(
object
[
int
]
buf
):
return
buf
[
0
]
@
cython
.
nonecheck
(
True
)
def
check_buffer_set
(
object
[
int
]
buf
):
buf
[
0
]
=
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