mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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.
This commit is contained in:
parent
d6c33fbd34
commit
a6192635f1
4 changed files with 303 additions and 197 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue