Mercurial > cpython-lru_cache-weakref
diff Python/_warnings.c @ 83687:8a5bebea9fec
Issue #1545463: At shutdown, defer finalization of codec modules so that stderr remains usable.
(should fix Windows buildbot failures on test_gc)
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Wed, 08 May 2013 13:23:25 +0200 |
| parents | c19b0ae5cd91 |
| children | 9213313b1a6f |
line wrap: on
line diff
--- a/Python/_warnings.c Wed May 08 11:16:33 2013 +0300 +++ b/Python/_warnings.c Wed May 08 13:23:25 2013 +0200 @@ -800,8 +800,8 @@ goto exit; if (module_str != NULL) { module = PyUnicode_FromString(module_str); - if (module == NULL) - goto exit; + if (module == NULL) + goto exit; } if (category == NULL) @@ -820,6 +820,49 @@ return ret; } +int +PyErr_WarnExplicitFormat(PyObject *category, + const char *filename_str, int lineno, + const char *module_str, PyObject *registry, + const char *format, ...) +{ + PyObject *message; + PyObject *module = NULL; + PyObject *filename = PyUnicode_DecodeFSDefault(filename_str); + int ret = -1; + va_list vargs; + + if (filename == NULL) + goto exit; + if (module_str != NULL) { + module = PyUnicode_FromString(module_str); + if (module == NULL) + goto exit; + } + +#ifdef HAVE_STDARG_PROTOTYPES + va_start(vargs, format); +#else + va_start(vargs); +#endif + message = PyUnicode_FromFormatV(format, vargs); + if (message != NULL) { + PyObject *res; + res = warn_explicit(category, message, filename, lineno, + module, registry, NULL); + Py_DECREF(message); + if (res != NULL) { + Py_DECREF(res); + ret = 0; + } + } + va_end(vargs); +exit: + Py_XDECREF(module); + Py_XDECREF(filename); + return ret; +} + PyDoc_STRVAR(warn_doc, "Issue a warning, or maybe ignore it or raise an exception.");
