Skip to content

Commit f45a561

Browse files
committed
Issue python#27809: PyErr_SetImportError() uses fast call
1 parent 3a84097 commit f45a561

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

Python/errors.c

+8-14
Original file line numberDiff line numberDiff line change
@@ -699,18 +699,14 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename(
699699
PyObject *
700700
PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
701701
{
702-
PyObject *args, *kwargs, *error;
702+
PyObject *kwargs, *error;
703703

704-
if (msg == NULL)
705-
return NULL;
706-
707-
args = PyTuple_New(1);
708-
if (args == NULL)
704+
if (msg == NULL) {
709705
return NULL;
706+
}
710707

711708
kwargs = PyDict_New();
712709
if (kwargs == NULL) {
713-
Py_DECREF(args);
714710
return NULL;
715711
}
716712

@@ -722,22 +718,20 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
722718
path = Py_None;
723719
}
724720

725-
Py_INCREF(msg);
726-
PyTuple_SET_ITEM(args, 0, msg);
727-
728-
if (PyDict_SetItemString(kwargs, "name", name) < 0)
721+
if (PyDict_SetItemString(kwargs, "name", name) < 0) {
729722
goto done;
730-
if (PyDict_SetItemString(kwargs, "path", path) < 0)
723+
}
724+
if (PyDict_SetItemString(kwargs, "path", path) < 0) {
731725
goto done;
726+
}
732727

733-
error = PyObject_Call(PyExc_ImportError, args, kwargs);
728+
error = _PyObject_FastCallDict(PyExc_ImportError, &msg, 1, kwargs);
734729
if (error != NULL) {
735730
PyErr_SetObject((PyObject *)Py_TYPE(error), error);
736731
Py_DECREF(error);
737732
}
738733

739734
done:
740-
Py_DECREF(args);
741735
Py_DECREF(kwargs);
742736
return NULL;
743737
}

0 commit comments

Comments
 (0)