Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b879fe82
Commit
b879fe82
authored
Apr 08, 2017
by
Serhiy Storchaka
Committed by
GitHub
Apr 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand the PySlice_GetIndicesEx macro. (#1023)
parent
205e00c5
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
47 additions
and
45 deletions
+47
-45
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+4
-6
Modules/_elementtree.c
Modules/_elementtree.c
+6
-6
Modules/_testbuffer.c
Modules/_testbuffer.c
+4
-3
Modules/arraymodule.c
Modules/arraymodule.c
+6
-5
Modules/mmapmodule.c
Modules/mmapmodule.c
+4
-5
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+6
-6
Objects/bytesobject.c
Objects/bytesobject.c
+3
-3
Objects/listobject.c
Objects/listobject.c
+6
-4
Objects/memoryobject.c
Objects/memoryobject.c
+2
-2
Objects/tupleobject.c
Objects/tupleobject.c
+3
-3
Objects/unicodeobject.c
Objects/unicodeobject.c
+3
-2
No files found.
Modules/_ctypes/_ctypes.c
View file @
b879fe82
...
...
@@ -4277,11 +4277,10 @@ Array_subscript(PyObject *myself, PyObject *item)
PyObject
*
np
;
Py_ssize_t
start
,
stop
,
step
,
slicelen
,
cur
,
i
;
if
(
PySlice_GetIndicesEx
(
item
,
self
->
b_length
,
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelen
=
PySlice_AdjustIndices
(
self
->
b_length
,
&
start
,
&
stop
,
step
);
stgdict
=
PyObject_stgdict
((
PyObject
*
)
self
);
assert
(
stgdict
);
/* Cannot be NULL for array object instances */
...
...
@@ -4418,11 +4417,10 @@ Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value)
else
if
(
PySlice_Check
(
item
))
{
Py_ssize_t
start
,
stop
,
step
,
slicelen
,
otherlen
,
i
,
cur
;
if
(
PySlice_GetIndicesEx
(
item
,
self
->
b_length
,
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelen
=
PySlice_AdjustIndices
(
self
->
b_length
,
&
start
,
&
stop
,
step
);
if
((
step
<
0
&&
start
<
stop
)
||
(
step
>
0
&&
start
>
stop
))
stop
=
start
;
...
...
Modules/_elementtree.c
View file @
b879fe82
...
...
@@ -1740,11 +1740,11 @@ element_subscr(PyObject* self_, PyObject* item)
if
(
!
self
->
extra
)
return
PyList_New
(
0
);
if
(
PySlice_GetIndicesEx
(
item
,
self
->
extra
->
length
,
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelen
=
PySlice_AdjustIndices
(
self
->
extra
->
length
,
&
start
,
&
stop
,
step
);
if
(
slicelen
<=
0
)
return
PyList_New
(
0
);
...
...
@@ -1796,11 +1796,11 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value)
return
-
1
;
}
if
(
PySlice_GetIndicesEx
(
item
,
self
->
extra
->
length
,
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelen
=
PySlice_AdjustIndices
(
self
->
extra
->
length
,
&
start
,
&
stop
,
step
);
if
(
value
==
NULL
)
{
/* Delete slice */
...
...
Modules/_testbuffer.c
View file @
b879fe82
...
...
@@ -1715,10 +1715,10 @@ init_slice(Py_buffer *base, PyObject *key, int dim)
{
Py_ssize_t
start
,
stop
,
step
,
slicelength
;
if
(
PySlice_GetIndicesEx
(
key
,
base
->
shape
[
dim
],
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
key
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelength
=
PySlice_AdjustIndices
(
base
->
shape
[
dim
],
&
start
,
&
stop
,
step
);
if
(
base
->
suboffsets
==
NULL
||
dim
==
0
)
{
...
...
@@ -1935,9 +1935,10 @@ slice_indices(PyObject *self, PyObject *args)
"first argument must be a slice object"
);
return
NULL
;
}
if
(
PySlice_
GetIndicesEx
(
key
,
len
,
&
s
[
0
],
&
s
[
1
],
&
s
[
2
],
&
s
[
3
])
<
0
)
{
if
(
PySlice_
Unpack
(
key
,
&
s
[
0
],
&
s
[
1
],
&
s
[
2
])
<
0
)
{
return
NULL
;
}
s
[
3
]
=
PySlice_AdjustIndices
(
len
,
&
s
[
0
],
&
s
[
1
],
s
[
2
]);
ret
=
PyTuple_New
(
4
);
if
(
ret
==
NULL
)
...
...
Modules/arraymodule.c
View file @
b879fe82
...
...
@@ -2289,10 +2289,11 @@ array_subscr(arrayobject* self, PyObject* item)
arrayobject
*
ar
;
int
itemsize
=
self
->
ob_descr
->
itemsize
;
if
(
PySlice_GetIndicesEx
(
item
,
Py_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelength
=
PySlice_AdjustIndices
(
Py_SIZE
(
self
),
&
start
,
&
stop
,
step
);
if
(
slicelength
<=
0
)
{
return
newarrayobject
(
&
Arraytype
,
0
,
self
->
ob_descr
);
...
...
@@ -2360,11 +2361,11 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
return
(
*
self
->
ob_descr
->
setitem
)(
self
,
i
,
value
);
}
else
if
(
PySlice_Check
(
item
))
{
if
(
PySlice_GetIndicesEx
(
item
,
Py_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelength
=
PySlice_AdjustIndices
(
Py_SIZE
(
self
),
&
start
,
&
stop
,
step
);
}
else
{
PyErr_SetString
(
PyExc_TypeError
,
...
...
Modules/mmapmodule.c
View file @
b879fe82
...
...
@@ -778,10 +778,10 @@ mmap_subscript(mmap_object *self, PyObject *item)
else
if
(
PySlice_Check
(
item
))
{
Py_ssize_t
start
,
stop
,
step
,
slicelen
;
if
(
PySlice_GetIndicesEx
(
item
,
self
->
size
,
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelen
=
PySlice_AdjustIndices
(
self
->
size
,
&
start
,
&
stop
,
step
);
if
(
slicelen
<=
0
)
return
PyBytes_FromStringAndSize
(
""
,
0
);
...
...
@@ -904,11 +904,10 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value)
Py_ssize_t
start
,
stop
,
step
,
slicelen
;
Py_buffer
vbuf
;
if
(
PySlice_GetIndicesEx
(
item
,
self
->
size
,
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelen
=
PySlice_AdjustIndices
(
self
->
size
,
&
start
,
&
stop
,
step
);
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
"mmap object doesn't support slice deletion"
);
...
...
Objects/bytearrayobject.c
View file @
b879fe82
...
...
@@ -400,11 +400,11 @@ bytearray_subscript(PyByteArrayObject *self, PyObject *index)
}
else
if
(
PySlice_Check
(
index
))
{
Py_ssize_t
start
,
stop
,
step
,
slicelength
,
cur
,
i
;
if
(
PySlice_GetIndicesEx
(
index
,
PyByteArray_GET_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
index
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelength
=
PySlice_AdjustIndices
(
PyByteArray_GET_SIZE
(
self
),
&
start
,
&
stop
,
step
);
if
(
slicelength
<=
0
)
return
PyByteArray_FromStringAndSize
(
""
,
0
);
...
...
@@ -630,11 +630,11 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
}
}
else
if
(
PySlice_Check
(
index
))
{
if
(
PySlice_GetIndicesEx
(
index
,
PyByteArray_GET_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelen
)
<
0
)
{
if
(
PySlice_Unpack
(
index
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelen
=
PySlice_AdjustIndices
(
PyByteArray_GET_SIZE
(
self
),
&
start
,
&
stop
,
step
);
}
else
{
PyErr_Format
(
PyExc_TypeError
,
...
...
Objects/bytesobject.c
View file @
b879fe82
...
...
@@ -1683,11 +1683,11 @@ bytes_subscript(PyBytesObject* self, PyObject* item)
char
*
result_buf
;
PyObject
*
result
;
if
(
PySlice_GetIndicesEx
(
item
,
PyBytes_GET_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelength
=
PySlice_AdjustIndices
(
PyBytes_GET_SIZE
(
self
),
&
start
,
&
stop
,
step
);
if
(
slicelength
<=
0
)
{
return
PyBytes_FromStringAndSize
(
""
,
0
);
...
...
Objects/listobject.c
View file @
b879fe82
...
...
@@ -2486,10 +2486,11 @@ list_subscript(PyListObject* self, PyObject* item)
PyObject
*
it
;
PyObject
**
src
,
**
dest
;
if
(
PySlice_GetIndicesEx
(
item
,
Py_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelength
=
PySlice_AdjustIndices
(
Py_SIZE
(
self
),
&
start
,
&
stop
,
step
);
if
(
slicelength
<=
0
)
{
return
PyList_New
(
0
);
...
...
@@ -2535,10 +2536,11 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
else
if
(
PySlice_Check
(
item
))
{
Py_ssize_t
start
,
stop
,
step
,
slicelength
;
if
(
PySlice_GetIndicesEx
(
item
,
Py_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelength
=
PySlice_AdjustIndices
(
Py_SIZE
(
self
),
&
start
,
&
stop
,
step
);
if
(
step
==
1
)
return
list_ass_slice
(
self
,
start
,
stop
,
value
);
...
...
Objects/memoryobject.c
View file @
b879fe82
...
...
@@ -2285,10 +2285,10 @@ init_slice(Py_buffer *base, PyObject *key, int dim)
{
Py_ssize_t
start
,
stop
,
step
,
slicelength
;
if
(
PySlice_GetIndicesEx
(
key
,
base
->
shape
[
dim
],
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
key
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
-
1
;
}
slicelength
=
PySlice_AdjustIndices
(
base
->
shape
[
dim
],
&
start
,
&
stop
,
step
);
if
(
base
->
suboffsets
==
NULL
||
dim
==
0
)
{
...
...
Objects/tupleobject.c
View file @
b879fe82
...
...
@@ -758,11 +758,11 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
PyObject
*
it
;
PyObject
**
src
,
**
dest
;
if
(
PySlice_GetIndicesEx
(
item
,
PyTuple_GET_SIZE
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelength
=
PySlice_AdjustIndices
(
PyTuple_GET_SIZE
(
self
),
&
start
,
&
stop
,
step
);
if
(
slicelength
<=
0
)
{
return
PyTuple_New
(
0
);
...
...
Objects/unicodeobject.c
View file @
b879fe82
...
...
@@ -13996,10 +13996,11 @@ unicode_subscript(PyObject* self, PyObject* item)
int
src_kind
,
dest_kind
;
Py_UCS4
ch
,
max_char
,
kind_limit
;
if
(
PySlice_GetIndicesEx
(
item
,
PyUnicode_GET_LENGTH
(
self
),
&
start
,
&
stop
,
&
step
,
&
slicelength
)
<
0
)
{
if
(
PySlice_Unpack
(
item
,
&
start
,
&
stop
,
&
step
)
<
0
)
{
return
NULL
;
}
slicelength
=
PySlice_AdjustIndices
(
PyUnicode_GET_LENGTH
(
self
),
&
start
,
&
stop
,
step
);
if
(
slicelength
<=
0
)
{
_Py_RETURN_UNICODE_EMPTY
();
...
...
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