diff Python/errors.c @ 46414:840064802952 legacy-trunk

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.
author Brett Cannon <bcannon@gmail.com>
date Sat, 12 Apr 2008 23:44:07 +0000
parents 0cbe94bea2c7
children 4fe192d48960
line wrap: on
line diff
--- a/Python/errors.c	Sat Apr 12 22:24:04 2008 +0000
+++ b/Python/errors.c	Sat Apr 12 23:44:07 2008 +0000
@@ -641,81 +641,6 @@
 
 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