Commit 85cfe7d8 authored by Stefan Behnel's avatar Stefan Behnel

honour wraparound option in object slicing code

parent fc193531
...@@ -3678,12 +3678,13 @@ class SliceIndexNode(ExprNode): ...@@ -3678,12 +3678,13 @@ class SliceIndexNode(ExprNode):
(has_c_start, has_c_stop, c_start, c_stop, (has_c_start, has_c_stop, c_start, c_stop,
py_start, py_stop, py_slice) = self.get_slice_config() py_start, py_stop, py_slice) = self.get_slice_config()
code.putln( code.putln(
"%s = __Pyx_PyObject_GetSlice(%s, %s, %s, %s, %s, %s, %d, %d); %s" % ( "%s = __Pyx_PyObject_GetSlice(%s, %s, %s, %s, %s, %s, %d, %d, %d); %s" % (
result, result,
self.base.py_result(), self.base.py_result(),
c_start, c_stop, c_start, c_stop,
py_start, py_stop, py_slice, py_start, py_stop, py_slice,
has_c_start, has_c_stop, has_c_start, has_c_stop,
bool(code.globalstate.directives['wraparound']),
code.error_goto_if_null(result, self.pos))) code.error_goto_if_null(result, self.pos)))
else: else:
if self.base.type is list_type: if self.base.type is list_type:
...@@ -3713,12 +3714,13 @@ class SliceIndexNode(ExprNode): ...@@ -3713,12 +3714,13 @@ class SliceIndexNode(ExprNode):
(has_c_start, has_c_stop, c_start, c_stop, (has_c_start, has_c_stop, c_start, c_stop,
py_start, py_stop, py_slice) = self.get_slice_config() py_start, py_stop, py_slice) = self.get_slice_config()
code.put_error_if_neg(self.pos, code.put_error_if_neg(self.pos,
"__Pyx_PyObject_SetSlice(%s, %s, %s, %s, %s, %s, %s, %d, %d)" % ( "__Pyx_PyObject_SetSlice(%s, %s, %s, %s, %s, %s, %s, %d, %d, %d)" % (
self.base.py_result(), self.base.py_result(),
rhs.py_result(), rhs.py_result(),
c_start, c_stop, c_start, c_stop,
py_start, py_stop, py_slice, py_start, py_stop, py_slice,
has_c_start, has_c_stop)) has_c_start, has_c_stop,
bool(code.globalstate.directives['wraparound'])))
else: else:
start_offset = '' start_offset = ''
if self.start: if self.start:
...@@ -3754,11 +3756,12 @@ class SliceIndexNode(ExprNode): ...@@ -3754,11 +3756,12 @@ class SliceIndexNode(ExprNode):
(has_c_start, has_c_stop, c_start, c_stop, (has_c_start, has_c_stop, c_start, c_stop,
py_start, py_stop, py_slice) = self.get_slice_config() py_start, py_stop, py_slice) = self.get_slice_config()
code.put_error_if_neg(self.pos, code.put_error_if_neg(self.pos,
"__Pyx_PyObject_DelSlice(%s, %s, %s, %s, %s, %s, %d, %d)" % ( "__Pyx_PyObject_DelSlice(%s, %s, %s, %s, %s, %s, %d, %d, %d)" % (
self.base.py_result(), self.base.py_result(),
c_start, c_stop, c_start, c_stop,
py_start, py_stop, py_slice, py_start, py_stop, py_slice,
has_c_start, has_c_stop)) has_c_start, has_c_stop,
bool(code.globalstate.directives['wraparound'])))
self.generate_subexpr_disposal_code(code) self.generate_subexpr_disposal_code(code)
self.free_subexpr_temps(code) self.free_subexpr_temps(code)
......
...@@ -451,16 +451,16 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i, ...@@ -451,16 +451,16 @@ static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
PyObject** py_start, PyObject** py_stop, PyObject** py_slice, PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
int has_cstart, int has_cstop); int has_cstart, int has_cstop, int wraparound);
{{else}} {{else}}
#define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop) \ #define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound) \
__Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop) __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)
// we pass pointer addresses to show the C compiler what is NULL and what isn't // we pass pointer addresses to show the C compiler what is NULL and what isn't
static CYTHON_INLINE int __Pyx_PyObject_SetSlice( static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop, PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop,
PyObject** py_start, PyObject** py_stop, PyObject** py_slice, PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
int has_cstart, int has_cstop); int has_cstart, int has_cstop, int wraparound);
{{endif}} {{endif}}
/////////////// SliceObject /////////////// /////////////// SliceObject ///////////////
...@@ -473,7 +473,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( ...@@ -473,7 +473,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop, PyObject* obj, PyObject* value, Py_ssize_t cstart, Py_ssize_t cstop,
{{endif}} {{endif}}
PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
int has_cstart, int has_cstop) { int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
PyMappingMethods* mp; PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence; PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
...@@ -492,7 +492,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice( ...@@ -492,7 +492,7 @@ static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
} else } else
cstop = PY_SSIZE_T_MAX; cstop = PY_SSIZE_T_MAX;
} }
if (unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) { if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
Py_ssize_t l = ms->sq_length(obj); Py_ssize_t l = ms->sq_length(obj);
if (likely(l >= 0)) { if (likely(l >= 0)) {
if (cstop < 0) { if (cstop < 0) {
......
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