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
d4edfc9a
Commit
d4edfc9a
authored
Mar 30, 2017
by
Serhiy Storchaka
Committed by
GitHub
Mar 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-29935: Fixed error messages in the index() method of tuple, list and deque (#887)
when pass indices of wrong type.
parent
762ec97e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
19 deletions
+31
-19
Include/ceval.h
Include/ceval.h
+1
-1
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_collectionsmodule.c
Modules/_collectionsmodule.c
+2
-2
Objects/clinic/listobject.c.h
Objects/clinic/listobject.c.h
+2
-2
Objects/clinic/tupleobject.c.h
Objects/clinic/tupleobject.c.h
+2
-2
Objects/tupleobject.c
Objects/tupleobject.c
+3
-3
Python/ceval.c
Python/ceval.c
+16
-7
Tools/clinic/clinic.py
Tools/clinic/clinic.py
+2
-2
No files found.
Include/ceval.h
View file @
d4edfc9a
...
...
@@ -223,7 +223,7 @@ PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
#ifndef Py_LIMITED_API
PyAPI_FUNC
(
int
)
_PyEval_SliceIndex
(
PyObject
*
,
Py_ssize_t
*
);
PyAPI_FUNC
(
int
)
_PyEval_SliceIndex
Or
None
(
PyObject
*
,
Py_ssize_t
*
);
PyAPI_FUNC
(
int
)
_PyEval_SliceIndex
Not
None
(
PyObject
*
,
Py_ssize_t
*
);
PyAPI_FUNC
(
void
)
_PyEval_SignalAsyncExc
(
void
);
#endif
...
...
Misc/NEWS
View file @
d4edfc9a
...
...
@@ -10,6 +10,9 @@ What's New in Python 3.7.0 alpha 1?
Core and Builtins
-----------------
- bpo-29935: Fixed error messages in the index() method of tuple, list and deque
when pass indices of wrong type.
- bpo-29816: Shift operation now has less opportunity to raise OverflowError.
ValueError always is raised rather than OverflowError for negative counts.
Shifting zero with non-negative count always returns zero.
...
...
Modules/_collectionsmodule.c
View file @
d4edfc9a
...
...
@@ -1066,8 +1066,8 @@ deque_index(dequeobject *deque, PyObject **args, Py_ssize_t nargs,
return
NULL
;
}
if
(
!
_PyArg_ParseStack
(
args
,
nargs
,
"O|O&O&:index"
,
&
v
,
_PyEval_SliceIndex
,
&
start
,
_PyEval_SliceIndex
,
&
stop
))
{
_PyEval_SliceIndex
NotNone
,
&
start
,
_PyEval_SliceIndex
NotNone
,
&
stop
))
{
return
NULL
;
}
...
...
Objects/clinic/listobject.c.h
View file @
d4edfc9a
...
...
@@ -196,7 +196,7 @@ list_index(PyListObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kwna
Py_ssize_t
stop
=
PY_SSIZE_T_MAX
;
if
(
!
_PyArg_ParseStack
(
args
,
nargs
,
"O|O&O&:index"
,
&
value
,
_PyEval_SliceIndex
,
&
start
,
_PyEval_SliceIndex
,
&
stop
))
{
&
value
,
_PyEval_SliceIndex
NotNone
,
&
start
,
_PyEval_SliceIndexNotNone
,
&
stop
))
{
goto
exit
;
}
...
...
@@ -297,4 +297,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return
list___reversed___impl
(
self
);
}
/*[clinic end generated code: output=
2a3b75efcf858ed5
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
71deae70ca0e6799
input=a9049054013a1b77]*/
Objects/clinic/tupleobject.c.h
View file @
d4edfc9a
...
...
@@ -26,7 +26,7 @@ tuple_index(PyTupleObject *self, PyObject **args, Py_ssize_t nargs, PyObject *kw
Py_ssize_t
stop
=
PY_SSIZE_T_MAX
;
if
(
!
_PyArg_ParseStack
(
args
,
nargs
,
"O|O&O&:index"
,
&
value
,
_PyEval_SliceIndex
,
&
start
,
_PyEval_SliceIndex
,
&
stop
))
{
&
value
,
_PyEval_SliceIndex
NotNone
,
&
start
,
_PyEval_SliceIndexNotNone
,
&
stop
))
{
goto
exit
;
}
...
...
@@ -99,4 +99,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
{
return
tuple___getnewargs___impl
(
self
);
}
/*[clinic end generated code: output=
561a3654411d2225
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
145bcfff64e8c809
input=a9049054013a1b77]*/
Objects/tupleobject.c
View file @
d4edfc9a
...
...
@@ -534,8 +534,8 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n)
tuple.index
value: object
start:
object(converter="_PyEval_SliceIndex", type="Py_ssize_t"
) = 0
stop:
object(converter="_PyEval_SliceIndex", type="Py_ssize_t"
, c_default="PY_SSIZE_T_MAX") = sys.maxsize
start:
slice_index(accept={int}
) = 0
stop:
slice_index(accept={int}
, c_default="PY_SSIZE_T_MAX") = sys.maxsize
/
Return first index of value.
...
...
@@ -546,7 +546,7 @@ Raises ValueError if the value is not present.
static
PyObject
*
tuple_index_impl
(
PyTupleObject
*
self
,
PyObject
*
value
,
Py_ssize_t
start
,
Py_ssize_t
stop
)
/*[clinic end generated code: output=07b6f9f3cb5c33eb input=
28890d4bec234471
]*/
/*[clinic end generated code: output=07b6f9f3cb5c33eb input=
fb39e9874a21fe3f
]*/
{
Py_ssize_t
i
;
...
...
Python/ceval.c
View file @
d4edfc9a
...
...
@@ -4892,14 +4892,10 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
and silently boost values less than -PY_SSIZE_T_MAX-1 to -PY_SSIZE_T_MAX-1.
Return 0 on error, 1 on success.
*/
/* Note: If v is NULL, return success without storing into *pi. This
is because_PyEval_SliceIndex() is called by apply_slice(), which can be
called by the SLICE opcode with v and/or w equal to NULL.
*/
int
_PyEval_SliceIndex
(
PyObject
*
v
,
Py_ssize_t
*
pi
)
{
if
(
v
!=
NULL
)
{
if
(
v
!=
Py_None
)
{
Py_ssize_t
x
;
if
(
PyIndex_Check
(
v
))
{
x
=
PyNumber_AsSsize_t
(
v
,
NULL
);
...
...
@@ -4918,9 +4914,22 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
}
int
_PyEval_SliceIndex
Or
None
(
PyObject
*
v
,
Py_ssize_t
*
pi
)
_PyEval_SliceIndex
Not
None
(
PyObject
*
v
,
Py_ssize_t
*
pi
)
{
return
v
==
Py_None
||
_PyEval_SliceIndex
(
v
,
pi
);
Py_ssize_t
x
;
if
(
PyIndex_Check
(
v
))
{
x
=
PyNumber_AsSsize_t
(
v
,
NULL
);
if
(
x
==
-
1
&&
PyErr_Occurred
())
return
0
;
}
else
{
PyErr_SetString
(
PyExc_TypeError
,
"slice indices must be integers or "
"have an __index__ method"
);
return
0
;
}
*
pi
=
x
;
return
1
;
}
...
...
Tools/clinic/clinic.py
View file @
d4edfc9a
...
...
@@ -2670,9 +2670,9 @@ class slice_index_converter(CConverter):
def
converter_init
(
self
,
*
,
accept
=
{
int
,
NoneType
}):
if
accept
==
{
int
}:
self
.
converter
=
'_PyEval_SliceIndex'
self
.
converter
=
'_PyEval_SliceIndex
NotNone
'
elif
accept
==
{
int
,
NoneType
}:
self
.
converter
=
'_PyEval_SliceIndex
OrNone
'
self
.
converter
=
'_PyEval_SliceIndex'
else
:
fail
(
"slice_index_converter: illegal 'accept' argument "
+
repr
(
accept
))
...
...
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