summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-30 15:29:23 (GMT)
committerGitHub <noreply@github.com>2017-03-30 15:29:23 (GMT)
commitd4edfc9abffca965e76ebc5957a92031a4d6c4d4 (patch)
treed985a5ba3c7dd8ec3183014962d650724f61ece9 /Python/ceval.c
parent762ec97ea68a1126b8855996c61fa8239dc9fff7 (diff)
downloadcpython-d4edfc9abffca965e76ebc5957a92031a4d6c4d4.zip
cpython-d4edfc9abffca965e76ebc5957a92031a4d6c4d4.tar.gz
cpython-d4edfc9abffca965e76ebc5957a92031a4d6c4d4.tar.bz2
bpo-29935: Fixed error messages in the index() method of tuple, list and deque (#887)
when pass indices of wrong type.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index e7ee772..afd305c 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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_SliceIndexOrNone(PyObject *v, Py_ssize_t *pi)
+_PyEval_SliceIndexNotNone(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;
}