Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 76379:7a32b9380ffd
Fix #14600. Correct reference handling and naming of ImportError convenience function
| author | Brian Curtin <brian@python.org> |
|---|---|
| date | Tue, 17 Apr 2012 16:57:09 -0500 |
| parents | 6825fd9b00ed |
| children | bf23a6c215f6 |
comparison
equal
deleted
inserted
replaced
| 76378:3d4922cf0d65 | 76379:7a32b9380ffd |
|---|---|
| 584 return result; | 584 return result; |
| 585 } | 585 } |
| 586 #endif /* MS_WINDOWS */ | 586 #endif /* MS_WINDOWS */ |
| 587 | 587 |
| 588 PyObject * | 588 PyObject * |
| 589 PyErr_SetExcWithArgsKwargs(PyObject *exc, PyObject *args, PyObject *kwargs) | 589 PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) |
| 590 { | 590 { |
| 591 PyObject *val; | 591 PyObject *args, *kwargs, *error; |
| 592 | |
| 593 args = PyTuple_New(1); | |
| 594 if (args == NULL) | |
| 595 return NULL; | |
| 596 | |
| 597 kwargs = PyDict_New(); | |
| 598 if (args == NULL) | |
| 599 return NULL; | |
| 600 | |
| 601 if (name == NULL) | |
| 602 name = Py_None; | |
| 603 | |
| 604 if (path == NULL) | |
| 605 path = Py_None; | |
| 606 | |
| 607 Py_INCREF(msg); | |
| 608 PyTuple_SetItem(args, 0, msg); | |
| 609 PyDict_SetItemString(kwargs, "name", name); | |
| 610 PyDict_SetItemString(kwargs, "path", path); | |
| 592 | 611 |
| 593 /* args must at least be an empty tuple */ | 612 /* args must at least be an empty tuple */ |
| 594 if (args == NULL) | 613 if (args == NULL) |
| 595 args = PyTuple_New(0); | 614 args = PyTuple_New(0); |
| 596 | 615 |
| 597 val = PyObject_Call(exc, args, kwargs); | 616 error = PyObject_Call(PyExc_ImportError, args, kwargs); |
| 598 if (val != NULL) { | 617 if (error!= NULL) { |
| 599 PyErr_SetObject((PyObject *) Py_TYPE(val), val); | 618 PyErr_SetObject((PyObject *) Py_TYPE(error), error); |
| 600 Py_DECREF(val); | 619 Py_DECREF(error); |
| 601 } | 620 } |
| 602 | |
| 603 return NULL; | |
| 604 } | |
| 605 | |
| 606 PyObject * | |
| 607 PyErr_SetFromImportErrorWithNameAndPath(PyObject *msg, | |
| 608 PyObject *name, PyObject *path) | |
| 609 { | |
| 610 PyObject *args = PyTuple_New(1); | |
| 611 PyObject *kwargs = PyDict_New(); | |
| 612 PyObject *result; | |
| 613 | |
| 614 if (path == NULL) | |
| 615 path = Py_None; | |
| 616 | |
| 617 PyTuple_SetItem(args, 0, msg); | |
| 618 PyDict_SetItemString(kwargs, "name", name); | |
| 619 PyDict_SetItemString(kwargs, "path", path); | |
| 620 | |
| 621 result = PyErr_SetExcWithArgsKwargs(PyExc_ImportError, args, kwargs); | |
| 622 | 621 |
| 623 Py_DECREF(args); | 622 Py_DECREF(args); |
| 624 Py_DECREF(kwargs); | 623 Py_DECREF(kwargs); |
| 625 | 624 |
| 626 return result; | 625 return NULL; |
| 627 } | |
| 628 | |
| 629 PyObject * | |
| 630 PyErr_SetFromImportErrorWithName(PyObject *msg, PyObject *name) | |
| 631 { | |
| 632 return PyErr_SetFromImportErrorWithNameAndPath(msg, name, NULL); | |
| 633 } | 626 } |
| 634 | 627 |
| 635 void | 628 void |
| 636 _PyErr_BadInternalCall(const char *filename, int lineno) | 629 _PyErr_BadInternalCall(const char *filename, int lineno) |
| 637 { | 630 { |
