Commit 7e653adb authored by Stefan Behnel's avatar Stefan Behnel

Clarify the documented semantics of "wraparound(False)" when bounds checks are enabled.

parent 7de1010c
...@@ -451,17 +451,25 @@ Cython code. Here is the list of currently supported directives: ...@@ -451,17 +451,25 @@ Cython code. Here is the list of currently supported directives:
([]-operator) in the code will not cause any IndexErrors to be ([]-operator) in the code will not cause any IndexErrors to be
raised. Lists, tuples, and strings are affected only if the index raised. Lists, tuples, and strings are affected only if the index
can be determined to be non-negative (or if ``wraparound`` is False). can be determined to be non-negative (or if ``wraparound`` is False).
Conditions Conditions which would normally trigger an IndexError may instead cause
which would normally trigger an IndexError may instead cause
segfaults or data corruption if this is set to False. segfaults or data corruption if this is set to False.
Default is True. Default is True.
``wraparound`` (True / False) ``wraparound`` (True / False)
In Python arrays can be indexed relative to the end. For example In Python, arrays and sequences can be indexed relative to the end.
A[-1] indexes the last value of a list. In C negative indexing is For example, A[-1] indexes the last value of a list.
not supported. If set to False, Cython will neither check for nor In C, negative indexing is not supported.
correctly handle negative indices, possibly causing segfaults or If set to False, Cython is allowed to neither check for nor correctly
data corruption. handle negative indices, possibly causing segfaults or data corruption.
If bounds checks are enabled (the default, see ``boundschecks`` above),
negative indexing will usually raise an ``IndexError`` for indices that
Cython evaluates itself.
However, these cases can be difficult to recognise in user code to
distinguish them from indexing or slicing that is evaluated by the
underlying Python array or sequence object and thus continues to support
wrap-around indices.
It is therefore safest to apply this option only to code that does not
process negative indices at all.
Default is True. Default is True.
``initializedcheck`` (True / False) ``initializedcheck`` (True / False)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment