PyErr_Warn
Jane Austine
janeaustine50 at hotmail.com
Wed Mar 19 07:59:23 EST 2003
Please someone demystify PyErr_Warn...
First the context of the problem:
I'm using bsddb module with Python2.3a2.
I run the script with -Wi arg so that no warnings show up. However, I
found some warning messages recorded in my log:
warning: DB_INCOMPLETE: Cache flush was unable to complete
Tracking down the source code, I noticed that I came from the
following
code in _bsddb.c file:
----
#if PYTHON_API_VERSION >= 1010
exceptionRaised = PyErr_Warn(PyExc_RuntimeWarning,
errTxt);
#else
fprintf(stderr, errTxt);
fprintf(stderr, "\n");
#endif
----
Since the api version is higher than 1010, PyErr_Warn must have been
called.
In errors.c file:
----
int
PyErr_Warn(PyObject *category, char *message)
{
PyObject *dict, *func = NULL;
if (PyModule_WarningsModule != NULL) {
dict = PyModule_GetDict(PyModule_WarningsModule);
func = PyDict_GetItemString(dict, "warn");
}
if (func == NULL) {
PySys_WriteStderr("warning: %s\n", message);
return 0;
}
else {
PyObject *args, *res;
if (category == NULL)
category = PyExc_RuntimeWarning;
args = Py_BuildValue("(sO)", message, category);
if (args == NULL)
return -1;
res = PyEval_CallObject(func, args);
Py_DECREF(args);
if (res == NULL)
----
It seems like "func == NULL" is true and the message is thrown to the
stderr at the time.
Now the question:
Why is the func(warnings.warn) NULL in this case? What does that mean?
When is it supposed to be NULL?
Thank you in advance,
Jane.
More information about the Python-list
mailing list