diff options
author | Brian Curtin <brian@python.org> | 2012-04-17 21:57:09 (GMT) |
---|---|---|
committer | Brian Curtin <brian@python.org> | 2012-04-17 21:57:09 (GMT) |
commit | 09b86d1196427f2028d7e072b106847d8c693815 (patch) | |
tree | c06e9fe5b6a732d07f2987ff86081165bd69ebf5 /Python/errors.c | |
parent | fba807ac44ff6804dd1be7c3962fc3455c8e7763 (diff) | |
download | cpython-09b86d1196427f2028d7e072b106847d8c693815.zip cpython-09b86d1196427f2028d7e072b106847d8c693815.tar.gz cpython-09b86d1196427f2028d7e072b106847d8c693815.tar.bz2 |
Fix #14600. Correct reference handling and naming of ImportError convenience function
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/Python/errors.c b/Python/errors.c index 345a345..a49cde6 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -586,50 +586,43 @@ PyObject *PyErr_SetFromWindowsErrWithUnicodeFilename( #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 must at least be an empty tuple */ + args = PyTuple_New(1); 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); - } + return NULL; - return NULL; -} + kwargs = PyDict_New(); + if (args == NULL) + return NULL; -PyObject * -PyErr_SetFromImportErrorWithNameAndPath(PyObject *msg, - PyObject *name, PyObject *path) -{ - PyObject *args = PyTuple_New(1); - PyObject *kwargs = PyDict_New(); - PyObject *result; + 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); - result = PyErr_SetExcWithArgsKwargs(PyExc_ImportError, args, kwargs); + /* args must at least be an empty tuple */ + if (args == NULL) + args = PyTuple_New(0); + + error = PyObject_Call(PyExc_ImportError, args, kwargs); + if (error!= NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(error), error); + Py_DECREF(error); + } Py_DECREF(args); Py_DECREF(kwargs); - return result; -} - -PyObject * -PyErr_SetFromImportErrorWithName(PyObject *msg, PyObject *name) -{ - return PyErr_SetFromImportErrorWithNameAndPath(msg, name, NULL); + return NULL; } void |