[Python-checkins] CVS: python/dist/src/Python errors.c,2.60,2.61

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 28 Feb 2001 13:46:26 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv28882

Modified Files:
	errors.c 
Log Message:
Add PyErr_WarnExplicit(), which calls warnings.warn_explicit(), with
explicit filename, lineno etc. arguments.


Index: errors.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/errors.c,v
retrieving revision 2.60
retrieving revision 2.61
diff -C2 -r2.60 -r2.61
*** errors.c	2001/02/28 17:47:12	2.60
--- errors.c	2001/02/28 21:46:24	2.61
***************
*** 624,627 ****
--- 624,669 ----
  }
  
+ 
+ /* Warning with explicit origin */
+ int
+ PyErr_WarnExplicit(PyObject *category, char *message,
+ 		   char *filename, int lineno,
+ 		   char *module, PyObject *registry)
+ {
+ 	PyObject *mod, *dict, *func = NULL;
+ 
+ 	mod = PyImport_ImportModule("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 *args, *res;
+ 
+ 		if (category == NULL)
+ 			category = PyExc_RuntimeWarning;
+ 		if (registry == NULL)
+ 			registry = Py_None;
+ 		args = Py_BuildValue("(sOsizO)", message, category,
+ 				     filename, lineno, module, registry);
+ 		if (args == NULL)
+ 			return -1;
+ 		res = PyEval_CallObject(func, args);
+ 		Py_DECREF(args);
+ 		if (res == NULL)
+ 			return -1;
+ 		Py_DECREF(res);
+ 		return 0;
+ 	}
+ }
+ 
+ 
+ /* XXX There's a comment missing here */
+ 
  void
  PyErr_SyntaxLocation(char *filename, int lineno)