summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-03-30 17:31:46 (GMT)
committerGitHub <noreply@github.com>2017-03-30 17:31:46 (GMT)
commit8b8bde44f3912d8b2df5591ffc31d2d8c6dcca6c (patch)
treedbbba7ea81cac0fe4ccbc5cec45227a50decf3f3 /Python
parentc90ff1b78cb79bc3762184e03fa81f11984aaa45 (diff)
downloadcpython-8b8bde44f3912d8b2df5591ffc31d2d8c6dcca6c.zip
cpython-8b8bde44f3912d8b2df5591ffc31d2d8c6dcca6c.tar.gz
cpython-8b8bde44f3912d8b2df5591ffc31d2d8c6dcca6c.tar.bz2
bpo-29935: Fixed error messages in the index() method of tuple, list and deque (#887) (#907) (#909)
when pass indices of wrong type. (cherry picked from commit d4edfc9abffca965e76ebc5957a92031a4d6c4d4) (cherry picked from commit bf4bb2e43030661e568d5d4b046e8b9351cc164c)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 9ae8653..3070a90 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5098,14 +5098,10 @@ ext_call_fail:
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);
@@ -5123,6 +5119,26 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
return 1;
}
+int
+_PyEval_SliceIndexNotNone(PyObject *v, Py_ssize_t *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;
+}
+
+
#define CANNOT_CATCH_MSG "catching classes that do not inherit from "\
"BaseException is not allowed"