Skip to content

Commit 8c29de3

Browse files
committed
Avoid nesting critical sections!
1 parent e99d875 commit 8c29de3

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

Objects/exceptions.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,21 +2706,22 @@ static PyObject *
27062706
AttributeError_str(PyObject *op)
27072707
{
27082708
PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op);
2709-
PyObject *ret, *arg;
2709+
PyObject *ret = NULL, *arg;
27102710
Py_BEGIN_CRITICAL_SECTION(self);
27112711
if (
2712-
!self->obj || !self->name || !PyUnicode_Check(self->name)
2713-
|| (PyTuple_GET_SIZE(self->args) == 1
2714-
&& PyUnicode_Check(arg = PyTuple_GET_ITEM(self->args, 0))
2715-
&& !PyUnicode_Equal(arg, self->name))
2716-
|| PyTuple_GET_SIZE(self->args) != 0
2712+
self->obj && self->name && PyUnicode_Check(self->name)
2713+
&& ((PyTuple_GET_SIZE(self->args) == 1
2714+
&& PyUnicode_Check(arg = PyTuple_GET_ITEM(self->args, 0))
2715+
&& PyUnicode_Equal(arg, self->name))
2716+
|| PyTuple_GET_SIZE(self->args) == 0)
27172717
) {
2718-
ret = BaseException_str(op);
2719-
} else {
27202718
ret = PyUnicode_FromFormat("%R has no attribute '%U'",
27212719
self->obj, self->name);
27222720
}
27232721
Py_END_CRITICAL_SECTION();
2722+
if (!ret) {
2723+
ret = BaseException_str(op);
2724+
}
27242725
return ret;
27252726
}
27262727

0 commit comments

Comments
 (0)