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
Boxiang Sun
cython
Commits
65364b1b
Commit
65364b1b
authored
May 06, 2009
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wraparound directive implemented
parent
78ce65af
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
5 deletions
+26
-5
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+3
-3
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-1
Cython/Compiler/Options.py
Cython/Compiler/Options.py
+2
-1
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+20
-0
No files found.
Cython/Compiler/Buffer.py
View file @
65364b1b
...
@@ -330,7 +330,7 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
...
@@ -330,7 +330,7 @@ def put_assign_to_buffer(lhs_cname, rhs_cname, buffer_aux, buffer_type,
code
.
putln
(
"}"
)
# Release stack
code
.
putln
(
"}"
)
# Release stack
def
put_buffer_lookup_code
(
entry
,
index_signeds
,
index_cnames
,
option
s
,
pos
,
code
):
def
put_buffer_lookup_code
(
entry
,
index_signeds
,
index_cnames
,
directive
s
,
pos
,
code
):
"""
"""
Generates code to process indices and calculate an offset into
Generates code to process indices and calculate an offset into
a buffer. Returns a C string which gives a pointer which can be
a buffer. Returns a C string which gives a pointer which can be
...
@@ -345,9 +345,9 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, options, pos, cod
...
@@ -345,9 +345,9 @@ def put_buffer_lookup_code(entry, index_signeds, index_cnames, options, pos, cod
"""
"""
bufaux
=
entry
.
buffer_aux
bufaux
=
entry
.
buffer_aux
bufstruct
=
bufaux
.
buffer_info_var
.
cname
bufstruct
=
bufaux
.
buffer_info_var
.
cname
negative_indices
=
entry
.
type
.
negative_indices
negative_indices
=
directives
[
'wraparound'
]
and
entry
.
type
.
negative_indices
if
option
s
[
'boundscheck'
]:
if
directive
s
[
'boundscheck'
]:
# Check bounds and fix negative indices.
# Check bounds and fix negative indices.
# We allocate a temporary which is initialized to -1, meaning OK (!).
# We allocate a temporary which is initialized to -1, meaning OK (!).
# If an error occurs, the temp is set to the dimension index the
# If an error occurs, the temp is set to the dimension index the
...
...
Cython/Compiler/ExprNodes.py
View file @
65364b1b
...
@@ -1958,7 +1958,7 @@ class IndexNode(ExprNode):
...
@@ -1958,7 +1958,7 @@ class IndexNode(ExprNode):
return
Buffer
.
put_buffer_lookup_code
(
entry
=
self
.
base
.
entry
,
return
Buffer
.
put_buffer_lookup_code
(
entry
=
self
.
base
.
entry
,
index_signeds
=
[
i
.
type
.
signed
for
i
in
self
.
indices
],
index_signeds
=
[
i
.
type
.
signed
for
i
in
self
.
indices
],
index_cnames
=
index_temps
,
index_cnames
=
index_temps
,
option
s
=
code
.
globalstate
.
directives
,
directive
s
=
code
.
globalstate
.
directives
,
pos
=
self
.
pos
,
code
=
code
)
pos
=
self
.
pos
,
code
=
code
)
def
put_nonecheck
(
self
,
code
):
def
put_nonecheck
(
self
,
code
):
...
...
Cython/Compiler/Options.py
View file @
65364b1b
...
@@ -54,7 +54,7 @@ c_line_in_traceback = 1
...
@@ -54,7 +54,7 @@ c_line_in_traceback = 1
embed
=
False
embed
=
False
# Declare
pragma
s
# Declare
compiler directive
s
option_defaults
=
{
option_defaults
=
{
'boundscheck'
:
True
,
'boundscheck'
:
True
,
'nonecheck'
:
False
,
'nonecheck'
:
False
,
...
@@ -64,6 +64,7 @@ option_defaults = {
...
@@ -64,6 +64,7 @@ option_defaults = {
'cdivision'
:
True
,
# Will be False in 0.12
'cdivision'
:
True
,
# Will be False in 0.12
'cdivision_warnings'
:
False
,
'cdivision_warnings'
:
False
,
'always_allow_keywords'
:
False
,
'always_allow_keywords'
:
False
,
'wraparound'
:
True
}
}
# Override types possibilities above, if needed
# Override types possibilities above, if needed
...
...
tests/run/bufaccess.pyx
View file @
65364b1b
...
@@ -478,6 +478,26 @@ def no_negative_indices(object[int, negative_indices=False] buf, int idx):
...
@@ -478,6 +478,26 @@ def no_negative_indices(object[int, negative_indices=False] buf, int idx):
"""
"""
return
buf
[
idx
]
return
buf
[
idx
]
@
testcase
@
cython
.
wraparound
(
False
)
def
wraparound_directive
(
object
[
int
]
buf
,
int
pos_idx
,
int
neg_idx
):
"""
Again, the most interesting thing here is to inspect the C source.
>>> A = IntMockBuffer(None, range(4))
>>> wraparound_directive(A, 2, -1)
5
>>> wraparound_directive(A, -1, 2)
Traceback (most recent call last):
...
IndexError: Out of bounds on buffer access (axis 0)
"""
cdef
int
byneg
with
cython
.
wraparound
(
True
):
byneg
=
buf
[
neg_idx
]
return
buf
[
pos_idx
]
+
byneg
#
#
# Test which flags are passed.
# Test which flags are passed.
#
#
...
...
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