summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-01-29 15:53:03 (GMT)
committerGitHub <noreply@github.com>2021-01-29 15:53:03 (GMT)
commita6192635f1e62af2bb8a435487ebb51800edd671 (patch)
treea1c012c74a7d78b53300300c217428710da5477b /Objects/bytearrayobject.c
parentd6c33fbd346765c6a8654dccacb2338006bf2b47 (diff)
downloadcpython-a6192635f1e62af2bb8a435487ebb51800edd671.zip
cpython-a6192635f1e62af2bb8a435487ebb51800edd671.tar.gz
cpython-a6192635f1e62af2bb8a435487ebb51800edd671.tar.bz2
bpo-42979: Use _Py_CheckSlotResult() to check slots result (GH-24356)
When Python is built in debug mode (with C assertions), calling a type slot like sq_length (__len__() in Python) now fails with a fatal error if the slot succeeded with an exception set, or failed with no exception set. The error message contains the slot, the type name, and the current exception (if an exception is set). * Check the result of all slots using _Py_CheckSlotResult(). * No longer pass op_name to ternary_op() in release mode. * Replace operator with dunder Python method name in error messages. For example, replace "*" with "__mul__". * Fix compiler_exit_scope() when an exception is set. * Fix bytearray.extend() when an exception is set: don't call bytearray_setslice() with an exception set.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 2eaca5c..a4c10d6 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1736,6 +1736,11 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
}
Py_DECREF(it);
+ if (PyErr_Occurred()) {
+ Py_DECREF(bytearray_obj);
+ return NULL;
+ }
+
/* Resize down to exact size. */
if (PyByteArray_Resize((PyObject *)bytearray_obj, len) < 0) {
Py_DECREF(bytearray_obj);
@@ -1748,10 +1753,7 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
}
Py_DECREF(bytearray_obj);
- if (PyErr_Occurred()) {
- return NULL;
- }
-
+ assert(!PyErr_Occurred());
Py_RETURN_NONE;
}