comparison Python/errors.c @ 76388:bf23a6c215f6

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.
author Brian Curtin <brian@python.org>
date Wed, 18 Apr 2012 08:30:51 -0500
parents 7a32b9380ffd
children e8c87226bcb3
comparison
equal deleted inserted replaced
76385:6762b943ee59 76388:bf23a6c215f6
588 PyObject * 588 PyObject *
589 PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) 589 PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
590 { 590 {
591 PyObject *args, *kwargs, *error; 591 PyObject *args, *kwargs, *error;
592 592
593 if (msg == NULL)
594 return NULL;
595
593 args = PyTuple_New(1); 596 args = PyTuple_New(1);
594 if (args == NULL) 597 if (args == NULL)
595 return NULL; 598 return NULL;
596 599
597 kwargs = PyDict_New(); 600 kwargs = PyDict_New();
598 if (args == NULL) 601 if (kwargs == NULL)
599 return NULL; 602 return NULL;
600 603
601 if (name == NULL) 604 if (name == NULL) {
605 Py_INCREF(Py_None);
602 name = Py_None; 606 name = Py_None;
603 607 }
604 if (path == NULL) 608
609 if (path == NULL) {
610 Py_INCREF(Py_None);
605 path = Py_None; 611 path = Py_None;
612 }
606 613
607 Py_INCREF(msg); 614 Py_INCREF(msg);
608 PyTuple_SetItem(args, 0, msg); 615 PyTuple_SetItem(args, 0, NULL);//msg);
609 PyDict_SetItemString(kwargs, "name", name); 616 PyDict_SetItemString(kwargs, "name", name);
610 PyDict_SetItemString(kwargs, "path", path); 617 PyDict_SetItemString(kwargs, "path", path);
611
612 /* args must at least be an empty tuple */
613 if (args == NULL)
614 args = PyTuple_New(0);
615 618
616 error = PyObject_Call(PyExc_ImportError, args, kwargs); 619 error = PyObject_Call(PyExc_ImportError, args, kwargs);
617 if (error!= NULL) { 620 if (error!= NULL) {
618 PyErr_SetObject((PyObject *) Py_TYPE(error), error); 621 PyErr_SetObject((PyObject *) Py_TYPE(error), error);
619 Py_DECREF(error); 622 Py_DECREF(error);