Mercurial > cpython-lru_cache-weakref
diff 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 |
line wrap: on
line diff
--- a/Python/errors.c Tue Apr 17 19:58:50 2012 +0200 +++ b/Python/errors.c Tue Apr 17 16:57:09 2012 -0500 @@ -586,50 +586,43 @@ #endif /* MS_WINDOWS */ PyObject * -PyErr_SetExcWithArgsKwargs(PyObject *exc, PyObject *args, PyObject *kwargs) +PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path) { - PyObject *val; + PyObject *args, *kwargs, *error; + + args = PyTuple_New(1); + if (args == NULL) + return NULL; + + kwargs = PyDict_New(); + if (args == NULL) + return NULL; + + if (name == NULL) + name = Py_None; + + if (path == NULL) + path = Py_None; + + Py_INCREF(msg); + PyTuple_SetItem(args, 0, msg); + PyDict_SetItemString(kwargs, "name", name); + PyDict_SetItemString(kwargs, "path", path); /* args must at least be an empty tuple */ if (args == NULL) args = PyTuple_New(0); - val = PyObject_Call(exc, args, kwargs); - if (val != NULL) { - PyErr_SetObject((PyObject *) Py_TYPE(val), val); - Py_DECREF(val); + error = PyObject_Call(PyExc_ImportError, args, kwargs); + if (error!= NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(error), error); + Py_DECREF(error); } - return NULL; -} - -PyObject * -PyErr_SetFromImportErrorWithNameAndPath(PyObject *msg, - PyObject *name, PyObject *path) -{ - PyObject *args = PyTuple_New(1); - PyObject *kwargs = PyDict_New(); - PyObject *result; - - if (path == NULL) - path = Py_None; - - PyTuple_SetItem(args, 0, msg); - PyDict_SetItemString(kwargs, "name", name); - PyDict_SetItemString(kwargs, "path", path); - - result = PyErr_SetExcWithArgsKwargs(PyExc_ImportError, args, kwargs); - Py_DECREF(args); Py_DECREF(kwargs); - return result; -} - -PyObject * -PyErr_SetFromImportErrorWithName(PyObject *msg, PyObject *name) -{ - return PyErr_SetFromImportErrorWithNameAndPath(msg, name, NULL); + return NULL; } void
