Skip to content

Commit d624835

Browse files
committed
Make thread-safe, presumably
1 parent b6fda10 commit d624835

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

Objects/exceptions.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,14 +2706,24 @@ static PyObject *
27062706
AttributeError_str(PyObject *op)
27072707
{
27082708
PyAttributeErrorObject *self = PyAttributeErrorObject_CAST(op);
2709-
if (!self->obj || !self->name || PyTuple_GET_SIZE(self->args) > 1
2709+
PyObject *ret, *arg;
2710+
Py_BEGIN_CRITICAL_SECTION(self);
2711+
if (
2712+
!self->obj || !self->name || !PyUnicode_Check(self->name)
2713+
|| PyTuple_GET_SIZE(self->args) > 1
27102714
|| (PyTuple_GET_SIZE(self->args) == 1
2711-
&& !PyUnicode_Equal(PyTuple_GET_ITEM(self->args, 0), self->name)))
2712-
{
2713-
return BaseException_str(op);
2715+
&& PyUnicode_Check(arg = PyTuple_GET_ITEM(self->args, 0))
2716+
&& !PyUnicode_Equal(arg, self->name))
2717+
) {
2718+
ret = BaseException_str(op);
2719+
}
2720+
else {
2721+
ret = PyUnicode_FromFormat("%R has no attribute '%U'",
2722+
self->obj, self->name);
27142723
}
2715-
return PyUnicode_FromFormat("%R has no attribute '%U'",
2716-
self->obj, self->name);
2724+
Py_END_CRITICAL_SECTION();
2725+
return ret;
2726+
27172727
}
27182728

27192729
static int

0 commit comments

Comments
 (0)