Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 94c001b

Browse files
committed
Fix email post-commit review comments.
Add INCREFs, fix args->kwargs, and a second args==NULL check was removed, left over from a merger with another function. Instead, checking msg==NULL does what that used to do in a roundabout way.
1 parent 03c7ed1 commit 94c001b

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

Python/errors.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,29 +590,32 @@ PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
590590
{
591591
PyObject *args, *kwargs, *error;
592592

593+
if (msg == NULL)
594+
return NULL;
595+
593596
args = PyTuple_New(1);
594597
if (args == NULL)
595598
return NULL;
596599

597600
kwargs = PyDict_New();
598-
if (args == NULL)
601+
if (kwargs == NULL)
599602
return NULL;
600603

601-
if (name == NULL)
604+
if (name == NULL) {
605+
Py_INCREF(Py_None);
602606
name = Py_None;
607+
}
603608

604-
if (path == NULL)
609+
if (path == NULL) {
610+
Py_INCREF(Py_None);
605611
path = Py_None;
612+
}
606613

607614
Py_INCREF(msg);
608-
PyTuple_SetItem(args, 0, msg);
615+
PyTuple_SetItem(args, 0, NULL);//msg);
609616
PyDict_SetItemString(kwargs, "name", name);
610617
PyDict_SetItemString(kwargs, "path", path);
611618

612-
/* args must at least be an empty tuple */
613-
if (args == NULL)
614-
args = PyTuple_New(0);
615-
616619
error = PyObject_Call(PyExc_ImportError, args, kwargs);
617620
if (error!= NULL) {
618621
PyErr_SetObject((PyObject *) Py_TYPE(error), error);

0 commit comments

Comments
 (0)