mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-118331: Don't raise an error if tuple allocation fails when clearing weakrefs (#118338)
It's not safe to raise an exception in `PyObject_ClearWeakRefs()` if one is not already set, since it may be called by `_Py_Dealloc()`, which requires that the active exception does not change. Additionally, make sure we clear the weakrefs even when tuple allocation fails.
This commit is contained in:
parent
444ac0b7a6
commit
43fa76638f
2 changed files with 29 additions and 1 deletions
|
|
@ -1016,7 +1016,9 @@ PyObject_ClearWeakRefs(PyObject *object)
|
|||
PyObject *exc = PyErr_GetRaisedException();
|
||||
PyObject *tuple = PyTuple_New(num_weakrefs * 2);
|
||||
if (tuple == NULL) {
|
||||
_PyErr_ChainExceptions1(exc);
|
||||
_PyWeakref_ClearWeakRefsExceptCallbacks(object);
|
||||
PyErr_WriteUnraisable(NULL);
|
||||
PyErr_SetRaisedException(exc);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue