summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-10-17 23:05:19 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2013-10-17 23:05:19 +0300
commitae48164c19d799b10981ee6d48207f971be026cd (patch)
tree9d648169bfd47390b1ad883bc4b54590daaccdb1 /Python/_warnings.c
parenta51097fdd9d0177b4d856ac1eaa59bc32fb49cc5 (diff)
parent68fc44960e7e678d7dd31f7676df51045d6a38f9 (diff)
downloadcpython-ae48164c19d799b10981ee6d48207f971be026cd.tar.gz
Issue #19276: Fixed the wave module on 64-bit big-endian platforms.
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c84
1 files changed, 68 insertions, 16 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index f33e477ad7..b8d4bb61de 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -283,9 +283,9 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
PyFile_WriteString(source_line_str, f_stderr);
PyFile_WriteString("\n", f_stderr);
}
- else
- if (_Py_DisplaySourceLine(f_stderr, filename, lineno, 2) < 0)
- return;
+ else {
+ _Py_DisplaySourceLine(f_stderr, filename, lineno, 2);
+ }
PyErr_Clear();
}
@@ -707,14 +707,14 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
/* Handle the warning. */
returned = warn_explicit(category, message, filename, lineno, module,
- registry, source_line);
+ registry, source_line);
Py_DECREF(source_list);
return returned;
}
standard_call:
return warn_explicit(category, message, filename, lineno, module,
- registry, NULL);
+ registry, NULL);
}
@@ -786,11 +786,26 @@ PyErr_Warn(PyObject *category, char *text)
/* Warning with explicit origin */
int
+PyErr_WarnExplicitObject(PyObject *category, PyObject *message,
+ PyObject *filename, int lineno,
+ PyObject *module, PyObject *registry)
+{
+ PyObject *res;
+ if (category == NULL)
+ category = PyExc_RuntimeWarning;
+ res = warn_explicit(category, message, filename, lineno,
+ module, registry, NULL);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return 0;
+}
+
+int
PyErr_WarnExplicit(PyObject *category, const char *text,
const char *filename_str, int lineno,
const char *module_str, PyObject *registry)
{
- PyObject *res;
PyObject *message = PyUnicode_FromString(text);
PyObject *filename = PyUnicode_DecodeFSDefault(filename_str);
PyObject *module = NULL;
@@ -800,18 +815,12 @@ PyErr_WarnExplicit(PyObject *category, const char *text,
goto exit;
if (module_str != NULL) {
module = PyUnicode_FromString(module_str);
- if (module == NULL)
- goto exit;
+ if (module == NULL)
+ goto exit;
}
- if (category == NULL)
- category = PyExc_RuntimeWarning;
- res = warn_explicit(category, message, filename, lineno, module, registry,
- NULL);
- if (res == NULL)
- goto exit;
- Py_DECREF(res);
- ret = 0;
+ ret = PyErr_WarnExplicitObject(category, message, filename, lineno,
+ module, registry);
exit:
Py_XDECREF(message);
@@ -820,6 +829,49 @@ PyErr_WarnExplicit(PyObject *category, const char *text,
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.");