diff options
author | Brett Cannon <bcannon@gmail.com> | 2008-04-12 23:44:07 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2008-04-12 23:44:07 (GMT) |
commit | e9746890388178bb1e4cdad3c0586bf1862c3727 (patch) | |
tree | 77e228e19ac5673aac13dac8292281fc9a3010ab /Python/errors.c | |
parent | e6c03033afc58804cfdb143bef67e9cd37e25507 (diff) | |
download | cpython-e9746890388178bb1e4cdad3c0586bf1862c3727.zip cpython-e9746890388178bb1e4cdad3c0586bf1862c3727.tar.gz cpython-e9746890388178bb1e4cdad3c0586bf1862c3727.tar.bz2 |
Re-implement the 'warnings' module in C. This allows for usage of the
'warnings' code in places where it was previously not possible (e.g., the
parser). It could also potentially lead to a speed-up in interpreter start-up
if the C version of the code (_warnings) is imported over the use of the
Python version in key places.
Closes issue #1631171.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/Python/errors.c b/Python/errors.c index 1c29160..8951d57 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -641,81 +641,6 @@ PyErr_WriteUnraisable(PyObject *obj) extern PyObject *PyModule_GetWarningsModule(void); -/* Function to issue a warning message; may raise an exception. */ -int -PyErr_WarnEx(PyObject *category, const char *message, Py_ssize_t stack_level) -{ - PyObject *dict, *func = NULL; - PyObject *warnings_module = PyModule_GetWarningsModule(); - - if (warnings_module != NULL) { - dict = PyModule_GetDict(warnings_module); - if (dict != NULL) - func = PyDict_GetItemString(dict, "warn"); - } - if (func == NULL) { - PySys_WriteStderr("warning: %s\n", message); - return 0; - } - else { - PyObject *res; - - if (category == NULL) - category = PyExc_RuntimeWarning; - res = PyObject_CallFunction(func, "sOn", - message, category, stack_level); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; - } -} - -/* PyErr_Warn is only for backwards compatability and will be removed. - Use PyErr_WarnEx instead. */ - -#undef PyErr_Warn - -PyAPI_FUNC(int) -PyErr_Warn(PyObject *category, char *message) -{ - return PyErr_WarnEx(category, message, 1); -} - -/* Warning with explicit origin */ -int -PyErr_WarnExplicit(PyObject *category, const char *message, - const char *filename, int lineno, - const char *module, PyObject *registry) -{ - PyObject *mod, *dict, *func = NULL; - - mod = PyImport_ImportModuleNoBlock("warnings"); - if (mod != NULL) { - dict = PyModule_GetDict(mod); - func = PyDict_GetItemString(dict, "warn_explicit"); - Py_DECREF(mod); - } - if (func == NULL) { - PySys_WriteStderr("warning: %s\n", message); - return 0; - } - else { - PyObject *res; - - if (category == NULL) - category = PyExc_RuntimeWarning; - if (registry == NULL) - registry = Py_None; - res = PyObject_CallFunction(func, "sOsizO", message, category, - filename, lineno, module, registry); - if (res == NULL) - return -1; - Py_DECREF(res); - return 0; - } -} - /* Set file and line information for the current exception. If the exception is not a SyntaxError, also sets additional attributes |