Skip to content

Commit 3a30ef3

Browse files
committed
Py_DECREF and early exit logic
1 parent 3e57fba commit 3a30ef3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Objects/exceptions.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,9 @@ ImportError_repr(PyObject *self)
18691869
{
18701870
int hasargs = PyTuple_GET_SIZE(((PyBaseExceptionObject *)self)->args) != 0;
18711871
PyImportErrorObject *exc = PyImportErrorObject_CAST(self);
1872+
if (exc->name == NULL && exc->path == NULL) {
1873+
return BaseException_repr(self);
1874+
}
18721875
PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
18731876
if (writer == NULL) {
18741877
goto error;
@@ -1880,10 +1883,10 @@ ImportError_repr(PyObject *self)
18801883
if (PyUnicodeWriter_WriteSubstring(
18811884
writer, r, 0, PyUnicode_GET_LENGTH(r) - 1) < 0)
18821885
{
1883-
Py_XDECREF(r);
1886+
Py_DECREF(r);
18841887
goto error;
18851888
}
1886-
Py_XDECREF(r);
1889+
Py_DECREF(r);
18871890
if (exc->name) {
18881891
if (hasargs) {
18891892
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {

0 commit comments

Comments
 (0)