diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-12-18 00:17:41 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-12-18 00:17:41 (GMT) |
commit | f8eac00779c4a3c66a85a3737f0977bb54305e05 (patch) | |
tree | 1b49c9167cf5f26ebd5b1208b1b342329f845069 /Objects/stringlib | |
parent | e010fc029daa0a445c9d7ab78d4cd4f12b42a991 (diff) | |
download | cpython-f8eac00779c4a3c66a85a3737f0977bb54305e05.zip cpython-f8eac00779c4a3c66a85a3737f0977bb54305e05.tar.gz cpython-f8eac00779c4a3c66a85a3737f0977bb54305e05.tar.bz2 |
Issue #13623: Fix a performance regression introduced by issue #12170 in
bytes.find() and handle correctly OverflowError (raise the same ValueError than
the error for -1).
Diffstat (limited to 'Objects/stringlib')
-rw-r--r-- | Objects/stringlib/find.h | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h index 26b6ce4..518e012 100644 --- a/Objects/stringlib/find.h +++ b/Objects/stringlib/find.h @@ -186,27 +186,34 @@ STRINGLIB(parse_args_finds_byte)(const char *function_name, PyObject *args, { PyObject *tmp_subobj; Py_ssize_t ival; + PyObject *err; if(!STRINGLIB(parse_args_finds)(function_name, args, &tmp_subobj, start, end)) return 0; - ival = PyNumber_AsSsize_t(tmp_subobj, PyExc_ValueError); - if (ival == -1 && PyErr_Occurred()) { - PyErr_Clear(); + if (!PyNumber_Check(tmp_subobj)) { *subobj = tmp_subobj; + return 1; } - else { - /* The first argument was an integer */ - if(ival < 0 || ival > 255) { - PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); - return 0; + + ival = PyNumber_AsSsize_t(tmp_subobj, PyExc_OverflowError); + if (ival == -1) { + err = PyErr_Occurred(); + if (err && !PyErr_GivenExceptionMatches(err, PyExc_OverflowError)) { + PyErr_Clear(); + *subobj = tmp_subobj; + return 1; } + } - *subobj = NULL; - *byte = (char)ival; + if (ival < 0 || ival > 255) { + PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)"); + return 0; } + *subobj = NULL; + *byte = (char)ival; return 1; } |