aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/_warnings.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Python/_warnings.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Python/_warnings.c')
-rw-r--r--contrib/tools/python3/src/Python/_warnings.c602
1 files changed, 301 insertions, 301 deletions
diff --git a/contrib/tools/python3/src/Python/_warnings.c b/contrib/tools/python3/src/Python/_warnings.c
index 4d07ed72fb..91a78fe72b 100644
--- a/contrib/tools/python3/src/Python/_warnings.c
+++ b/contrib/tools/python3/src/Python/_warnings.c
@@ -1,9 +1,9 @@
#include "Python.h"
-#include "pycore_initconfig.h"
-#include "pycore_interp.h" // PyInterpreterState.warnings
-#include "pycore_pyerrors.h"
-#include "pycore_pystate.h" // _PyThreadState_GET()
-#include "frameobject.h" // PyFrame_GetBack()
+#include "pycore_initconfig.h"
+#include "pycore_interp.h" // PyInterpreterState.warnings
+#include "pycore_pyerrors.h"
+#include "pycore_pystate.h" // _PyThreadState_GET()
+#include "frameobject.h" // PyFrame_GetBack()
#include "clinic/_warnings.c.h"
#define MODULE_NAME "_warnings"
@@ -18,141 +18,141 @@ _Py_IDENTIFIER(default);
_Py_IDENTIFIER(ignore);
#endif
-
-/*************************************************************************/
-
-typedef struct _warnings_runtime_state WarningsState;
-
-/* Forward declaration of the _warnings module definition. */
-static struct PyModuleDef warningsmodule;
-
-_Py_IDENTIFIER(__name__);
-
-/* Given a module object, get its per-module state. */
-static WarningsState *
-warnings_get_state(void)
-{
- PyThreadState *tstate = _PyThreadState_GET();
- if (tstate == NULL) {
- _PyErr_SetString(tstate, PyExc_RuntimeError,
- "warnings_get_state: could not identify "
- "current interpreter");
- return NULL;
- }
- return &tstate->interp->warnings;
-}
-
-/* Clear the given warnings module state. */
-static void
-warnings_clear_state(WarningsState *st)
-{
- Py_CLEAR(st->filters);
- Py_CLEAR(st->once_registry);
- Py_CLEAR(st->default_action);
-}
-
-#ifndef Py_DEBUG
-static PyObject *
-create_filter(PyObject *category, _Py_Identifier *id, const char *modname)
-{
- PyObject *modname_obj = NULL;
- PyObject *action_str = _PyUnicode_FromId(id);
- if (action_str == NULL) {
- return NULL;
- }
-
- /* Default to "no module name" for initial filter set */
- if (modname != NULL) {
- modname_obj = PyUnicode_InternFromString(modname);
- if (modname_obj == NULL) {
- return NULL;
- }
- } else {
- modname_obj = Py_None;
- Py_INCREF(modname_obj);
- }
-
- /* This assumes the line number is zero for now. */
- PyObject *filter = PyTuple_Pack(5, action_str, Py_None,
- category, modname_obj, _PyLong_Zero);
- Py_DECREF(modname_obj);
- return filter;
-}
-#endif
-
-static PyObject *
-init_filters(void)
-{
-#ifdef Py_DEBUG
- /* Py_DEBUG builds show all warnings by default */
- return PyList_New(0);
-#else
- /* Other builds ignore a number of warning categories by default */
- PyObject *filters = PyList_New(5);
- if (filters == NULL) {
- return NULL;
- }
-
- size_t pos = 0; /* Post-incremented in each use. */
- PyList_SET_ITEM(filters, pos++,
- create_filter(PyExc_DeprecationWarning, &PyId_default, "__main__"));
- PyList_SET_ITEM(filters, pos++,
- create_filter(PyExc_DeprecationWarning, &PyId_ignore, NULL));
- PyList_SET_ITEM(filters, pos++,
- create_filter(PyExc_PendingDeprecationWarning, &PyId_ignore, NULL));
- PyList_SET_ITEM(filters, pos++,
- create_filter(PyExc_ImportWarning, &PyId_ignore, NULL));
- PyList_SET_ITEM(filters, pos++,
- create_filter(PyExc_ResourceWarning, &PyId_ignore, NULL));
-
- for (size_t x = 0; x < pos; x++) {
- if (PyList_GET_ITEM(filters, x) == NULL) {
- Py_DECREF(filters);
- return NULL;
- }
- }
- return filters;
-#endif
-}
-
-/* Initialize the given warnings module state. */
+
+/*************************************************************************/
+
+typedef struct _warnings_runtime_state WarningsState;
+
+/* Forward declaration of the _warnings module definition. */
+static struct PyModuleDef warningsmodule;
+
+_Py_IDENTIFIER(__name__);
+
+/* Given a module object, get its per-module state. */
+static WarningsState *
+warnings_get_state(void)
+{
+ PyThreadState *tstate = _PyThreadState_GET();
+ if (tstate == NULL) {
+ _PyErr_SetString(tstate, PyExc_RuntimeError,
+ "warnings_get_state: could not identify "
+ "current interpreter");
+ return NULL;
+ }
+ return &tstate->interp->warnings;
+}
+
+/* Clear the given warnings module state. */
+static void
+warnings_clear_state(WarningsState *st)
+{
+ Py_CLEAR(st->filters);
+ Py_CLEAR(st->once_registry);
+ Py_CLEAR(st->default_action);
+}
+
+#ifndef Py_DEBUG
+static PyObject *
+create_filter(PyObject *category, _Py_Identifier *id, const char *modname)
+{
+ PyObject *modname_obj = NULL;
+ PyObject *action_str = _PyUnicode_FromId(id);
+ if (action_str == NULL) {
+ return NULL;
+ }
+
+ /* Default to "no module name" for initial filter set */
+ if (modname != NULL) {
+ modname_obj = PyUnicode_InternFromString(modname);
+ if (modname_obj == NULL) {
+ return NULL;
+ }
+ } else {
+ modname_obj = Py_None;
+ Py_INCREF(modname_obj);
+ }
+
+ /* This assumes the line number is zero for now. */
+ PyObject *filter = PyTuple_Pack(5, action_str, Py_None,
+ category, modname_obj, _PyLong_Zero);
+ Py_DECREF(modname_obj);
+ return filter;
+}
+#endif
+
+static PyObject *
+init_filters(void)
+{
+#ifdef Py_DEBUG
+ /* Py_DEBUG builds show all warnings by default */
+ return PyList_New(0);
+#else
+ /* Other builds ignore a number of warning categories by default */
+ PyObject *filters = PyList_New(5);
+ if (filters == NULL) {
+ return NULL;
+ }
+
+ size_t pos = 0; /* Post-incremented in each use. */
+ PyList_SET_ITEM(filters, pos++,
+ create_filter(PyExc_DeprecationWarning, &PyId_default, "__main__"));
+ PyList_SET_ITEM(filters, pos++,
+ create_filter(PyExc_DeprecationWarning, &PyId_ignore, NULL));
+ PyList_SET_ITEM(filters, pos++,
+ create_filter(PyExc_PendingDeprecationWarning, &PyId_ignore, NULL));
+ PyList_SET_ITEM(filters, pos++,
+ create_filter(PyExc_ImportWarning, &PyId_ignore, NULL));
+ PyList_SET_ITEM(filters, pos++,
+ create_filter(PyExc_ResourceWarning, &PyId_ignore, NULL));
+
+ for (size_t x = 0; x < pos; x++) {
+ if (PyList_GET_ITEM(filters, x) == NULL) {
+ Py_DECREF(filters);
+ return NULL;
+ }
+ }
+ return filters;
+#endif
+}
+
+/* Initialize the given warnings module state. */
+static int
+warnings_init_state(WarningsState *st)
+{
+ if (st->filters == NULL) {
+ st->filters = init_filters();
+ if (st->filters == NULL) {
+ goto error;
+ }
+ }
+
+ if (st->once_registry == NULL) {
+ st->once_registry = PyDict_New();
+ if (st->once_registry == NULL) {
+ goto error;
+ }
+ }
+
+ if (st->default_action == NULL) {
+ st->default_action = PyUnicode_FromString("default");
+ if (st->default_action == NULL) {
+ goto error;
+ }
+ }
+
+ st->filters_version = 0;
+
+ return 0;
+
+error:
+ warnings_clear_state(st);
+ return -1;
+}
+
+
+/*************************************************************************/
+
static int
-warnings_init_state(WarningsState *st)
-{
- if (st->filters == NULL) {
- st->filters = init_filters();
- if (st->filters == NULL) {
- goto error;
- }
- }
-
- if (st->once_registry == NULL) {
- st->once_registry = PyDict_New();
- if (st->once_registry == NULL) {
- goto error;
- }
- }
-
- if (st->default_action == NULL) {
- st->default_action = PyUnicode_FromString("default");
- if (st->default_action == NULL) {
- goto error;
- }
- }
-
- st->filters_version = 0;
-
- return 0;
-
-error:
- warnings_clear_state(st);
- return -1;
-}
-
-
-/*************************************************************************/
-
-static int
check_matched(PyObject *obj, PyObject *arg)
{
PyObject *result;
@@ -173,7 +173,7 @@ check_matched(PyObject *obj, PyObject *arg)
}
/* Otherwise assume a regex filter and call its match() method */
- result = _PyObject_CallMethodIdOneArg(obj, &PyId_match, arg);
+ result = _PyObject_CallMethodIdOneArg(obj, &PyId_match, arg);
if (result == NULL)
return -1;
@@ -215,7 +215,7 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import)
gone, then we can't even use PyImport_GetModule without triggering
an interpreter abort.
*/
- if (!_PyInterpreterState_GET()->modules) {
+ if (!_PyInterpreterState_GET()->modules) {
return NULL;
}
warnings_module = PyImport_GetModule(warnings_str);
@@ -230,7 +230,7 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import)
static PyObject *
-get_once_registry(WarningsState *st)
+get_once_registry(WarningsState *st)
{
PyObject *registry;
_Py_IDENTIFIER(onceregistry);
@@ -239,8 +239,8 @@ get_once_registry(WarningsState *st)
if (registry == NULL) {
if (PyErr_Occurred())
return NULL;
- assert(st->once_registry);
- return st->once_registry;
+ assert(st->once_registry);
+ return st->once_registry;
}
if (!PyDict_Check(registry)) {
PyErr_Format(PyExc_TypeError,
@@ -250,13 +250,13 @@ get_once_registry(WarningsState *st)
Py_DECREF(registry);
return NULL;
}
- Py_SETREF(st->once_registry, registry);
+ Py_SETREF(st->once_registry, registry);
return registry;
}
static PyObject *
-get_default_action(WarningsState *st)
+get_default_action(WarningsState *st)
{
PyObject *default_action;
_Py_IDENTIFIER(defaultaction);
@@ -266,8 +266,8 @@ get_default_action(WarningsState *st)
if (PyErr_Occurred()) {
return NULL;
}
- assert(st->default_action);
- return st->default_action;
+ assert(st->default_action);
+ return st->default_action;
}
if (!PyUnicode_Check(default_action)) {
PyErr_Format(PyExc_TypeError,
@@ -277,7 +277,7 @@ get_default_action(WarningsState *st)
Py_DECREF(default_action);
return NULL;
}
- Py_SETREF(st->default_action, default_action);
+ Py_SETREF(st->default_action, default_action);
return default_action;
}
@@ -291,10 +291,10 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
Py_ssize_t i;
PyObject *warnings_filters;
_Py_IDENTIFIER(filters);
- WarningsState *st = warnings_get_state();
- if (st == NULL) {
- return NULL;
- }
+ WarningsState *st = warnings_get_state();
+ if (st == NULL) {
+ return NULL;
+ }
warnings_filters = get_warnings_attr(&PyId_filters, 0);
if (warnings_filters == NULL) {
@@ -302,17 +302,17 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
return NULL;
}
else {
- Py_SETREF(st->filters, warnings_filters);
+ Py_SETREF(st->filters, warnings_filters);
}
- PyObject *filters = st->filters;
+ PyObject *filters = st->filters;
if (filters == NULL || !PyList_Check(filters)) {
PyErr_SetString(PyExc_ValueError,
MODULE_NAME ".filters must be a list");
return NULL;
}
- /* WarningsState.filters could change while we are iterating over it. */
+ /* WarningsState.filters could change while we are iterating over it. */
for (i = 0; i < PyList_GET_SIZE(filters); i++) {
PyObject *tmp_item, *action, *msg, *cat, *mod, *ln_obj;
Py_ssize_t ln;
@@ -373,7 +373,7 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno,
Py_DECREF(tmp_item);
}
- action = get_default_action(st);
+ action = get_default_action(st);
if (action != NULL) {
Py_INCREF(Py_None);
*item = Py_None;
@@ -393,20 +393,20 @@ already_warned(PyObject *registry, PyObject *key, int should_set)
if (key == NULL)
return -1;
- WarningsState *st = warnings_get_state();
- if (st == NULL) {
- return -1;
- }
- version_obj = _PyDict_GetItemIdWithError(registry, &PyId_version);
+ WarningsState *st = warnings_get_state();
+ if (st == NULL) {
+ return -1;
+ }
+ version_obj = _PyDict_GetItemIdWithError(registry, &PyId_version);
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
- || PyLong_AsLong(version_obj) != st->filters_version)
+ || PyLong_AsLong(version_obj) != st->filters_version)
{
if (PyErr_Occurred()) {
return -1;
}
PyDict_Clear(registry);
- version_obj = PyLong_FromLong(st->filters_version);
+ version_obj = PyLong_FromLong(st->filters_version);
if (version_obj == NULL)
return -1;
if (_PyDict_SetItemId(registry, &PyId_version, version_obj) < 0) {
@@ -416,15 +416,15 @@ already_warned(PyObject *registry, PyObject *key, int should_set)
Py_DECREF(version_obj);
}
else {
- already_warned = PyDict_GetItemWithError(registry, key);
+ already_warned = PyDict_GetItemWithError(registry, key);
if (already_warned != NULL) {
int rc = PyObject_IsTrue(already_warned);
if (rc != 0)
return rc;
}
- else if (PyErr_Occurred()) {
- return -1;
- }
+ else if (PyErr_Occurred()) {
+ return -1;
+ }
}
/* This warning wasn't found in the registry, set it. */
@@ -439,7 +439,7 @@ normalize_module(PyObject *filename)
{
PyObject *module;
int kind;
- const void *data;
+ const void *data;
Py_ssize_t len;
len = PyUnicode_GetLength(filename);
@@ -495,9 +495,9 @@ show_warning(PyObject *filename, int lineno, PyObject *text,
PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);
name = _PyObject_GetAttrId(category, &PyId___name__);
- if (name == NULL) {
+ if (name == NULL) {
goto error;
- }
+ }
f_stderr = _PySys_GetObjectId(&PyId_stderr);
if (f_stderr == NULL) {
@@ -523,7 +523,7 @@ show_warning(PyObject *filename, int lineno, PyObject *text,
/* Print " source_line\n" */
if (sourceline) {
int kind;
- const void *data;
+ const void *data;
Py_ssize_t i, len;
Py_UCS4 ch;
PyObject *truncated;
@@ -599,7 +599,7 @@ call_show_warning(PyObject *category, PyObject *text, PyObject *message,
if (msg == NULL)
goto error;
- res = PyObject_CallOneArg(show_fn, msg);
+ res = PyObject_CallOneArg(show_fn, msg);
Py_DECREF(show_fn);
Py_DECREF(msg);
@@ -656,11 +656,11 @@ warn_explicit(PyObject *category, PyObject *message,
text = PyObject_Str(message);
if (text == NULL)
goto cleanup;
- category = (PyObject*)Py_TYPE(message);
+ category = (PyObject*)Py_TYPE(message);
}
else {
text = message;
- message = PyObject_CallOneArg(category, message);
+ message = PyObject_CallOneArg(category, message);
if (message == NULL)
goto cleanup;
}
@@ -712,15 +712,15 @@ warn_explicit(PyObject *category, PyObject *message,
if (_PyUnicode_EqualToASCIIString(action, "once")) {
if (registry == NULL || registry == Py_None) {
- WarningsState *st = warnings_get_state();
- if (st == NULL) {
- goto cleanup;
- }
- registry = get_once_registry(st);
+ WarningsState *st = warnings_get_state();
+ if (st == NULL) {
+ goto cleanup;
+ }
+ registry = get_once_registry(st);
if (registry == NULL)
goto cleanup;
}
- /* WarningsState.once_registry[(text, category)] = 1 */
+ /* WarningsState.once_registry[(text, category)] = 1 */
rc = update_registry(registry, text, category, 0);
}
else if (_PyUnicode_EqualToASCIIString(action, "module")) {
@@ -782,21 +782,21 @@ is_internal_frame(PyFrameObject *frame)
Py_INCREF(bootstrap_string);
}
- if (frame == NULL) {
+ if (frame == NULL) {
+ return 0;
+ }
+
+ PyCodeObject *code = PyFrame_GetCode(frame);
+ PyObject *filename = code->co_filename;
+ Py_DECREF(code);
+
+ if (filename == NULL) {
return 0;
}
-
- PyCodeObject *code = PyFrame_GetCode(frame);
- PyObject *filename = code->co_filename;
- Py_DECREF(code);
-
- if (filename == NULL) {
- return 0;
- }
if (!PyUnicode_Check(filename)) {
return 0;
}
-
+
contains = PyUnicode_Contains(filename, importlib_string);
if (contains < 0) {
return 0;
@@ -818,9 +818,9 @@ static PyFrameObject *
next_external_frame(PyFrameObject *frame)
{
do {
- PyFrameObject *back = PyFrame_GetBack(frame);
- Py_DECREF(frame);
- frame = back;
+ PyFrameObject *back = PyFrame_GetBack(frame);
+ Py_DECREF(frame);
+ frame = back;
} while (frame != NULL && is_internal_frame(frame));
return frame;
@@ -832,19 +832,19 @@ static int
setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
PyObject **module, PyObject **registry)
{
- _Py_IDENTIFIER(__warningregistry__);
+ _Py_IDENTIFIER(__warningregistry__);
PyObject *globals;
- /* Setup globals, filename and lineno. */
- PyThreadState *tstate = _PyThreadState_GET();
- PyFrameObject *f = PyThreadState_GetFrame(tstate);
+ /* Setup globals, filename and lineno. */
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyFrameObject *f = PyThreadState_GetFrame(tstate);
// Stack level comparisons to Python code is off by one as there is no
// warnings-related stack level to avoid.
if (stack_level <= 0 || is_internal_frame(f)) {
while (--stack_level > 0 && f != NULL) {
- PyFrameObject *back = PyFrame_GetBack(f);
- Py_DECREF(f);
- f = back;
+ PyFrameObject *back = PyFrame_GetBack(f);
+ Py_DECREF(f);
+ f = back;
}
}
else {
@@ -854,18 +854,18 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
}
if (f == NULL) {
- globals = _PyInterpreterState_GET()->sysdict;
- *filename = PyUnicode_FromString("sys");
+ globals = _PyInterpreterState_GET()->sysdict;
+ *filename = PyUnicode_FromString("sys");
*lineno = 1;
}
else {
globals = f->f_globals;
- PyCodeObject *code = PyFrame_GetCode(f);
- *filename = code->co_filename;
- Py_DECREF(code);
- Py_INCREF(*filename);
+ PyCodeObject *code = PyFrame_GetCode(f);
+ *filename = code->co_filename;
+ Py_DECREF(code);
+ Py_INCREF(*filename);
*lineno = PyFrame_GetLineNumber(f);
- Py_DECREF(f);
+ Py_DECREF(f);
}
*module = NULL;
@@ -873,18 +873,18 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup registry. */
assert(globals != NULL);
assert(PyDict_Check(globals));
- *registry = _PyDict_GetItemIdWithError(globals, &PyId___warningregistry__);
+ *registry = _PyDict_GetItemIdWithError(globals, &PyId___warningregistry__);
if (*registry == NULL) {
int rc;
- if (_PyErr_Occurred(tstate)) {
- goto handle_error;
- }
+ if (_PyErr_Occurred(tstate)) {
+ goto handle_error;
+ }
*registry = PyDict_New();
if (*registry == NULL)
- goto handle_error;
+ goto handle_error;
- rc = _PyDict_SetItemId(globals, &PyId___warningregistry__, *registry);
+ rc = _PyDict_SetItemId(globals, &PyId___warningregistry__, *registry);
if (rc < 0)
goto handle_error;
}
@@ -892,13 +892,13 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
Py_INCREF(*registry);
/* Setup module. */
- *module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
+ *module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
- else if (_PyErr_Occurred(tstate)) {
- goto handle_error;
- }
+ else if (_PyErr_Occurred(tstate)) {
+ goto handle_error;
+ }
else {
*module = PyUnicode_FromString("<string>");
if (*module == NULL)
@@ -910,7 +910,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
handle_error:
Py_XDECREF(*registry);
Py_XDECREF(*module);
- Py_DECREF(*filename);
+ Py_DECREF(*filename);
return 0;
}
@@ -925,7 +925,7 @@ get_category(PyObject *message, PyObject *category)
return NULL;
if (rc == 1)
- category = (PyObject*)Py_TYPE(message);
+ category = (PyObject*)Py_TYPE(message);
else if (category == NULL || category == Py_None)
category = PyExc_UserWarning;
@@ -1016,7 +1016,7 @@ get_source_line(PyObject *module_globals, int lineno)
return NULL;
}
/* Call get_source() to get the source code. */
- source = PyObject_CallOneArg(get_source, module_name);
+ source = PyObject_CallOneArg(get_source, module_name);
Py_DECREF(get_source);
Py_DECREF(module_name);
if (!source) {
@@ -1085,11 +1085,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject *
warnings_filters_mutated(PyObject *self, PyObject *args)
{
- WarningsState *st = warnings_get_state();
- if (st == NULL) {
- return NULL;
- }
- st->filters_version++;
+ WarningsState *st = warnings_get_state();
+ if (st == NULL) {
+ return NULL;
+ }
+ st->filters_version++;
Py_RETURN_NONE;
}
@@ -1147,23 +1147,23 @@ PyErr_WarnFormat(PyObject *category, Py_ssize_t stack_level,
return res;
}
-static int
-_PyErr_WarnFormat(PyObject *source, PyObject *category, Py_ssize_t stack_level,
- const char *format, ...)
-{
- int res;
- va_list vargs;
-
-#ifdef HAVE_STDARG_PROTOTYPES
- va_start(vargs, format);
-#else
- va_start(vargs);
-#endif
- res = _PyErr_WarnFormatV(source, category, stack_level, format, vargs);
- va_end(vargs);
- return res;
-}
-
+static int
+_PyErr_WarnFormat(PyObject *source, PyObject *category, Py_ssize_t stack_level,
+ const char *format, ...)
+{
+ int res;
+ va_list vargs;
+
+#ifdef HAVE_STDARG_PROTOTYPES
+ va_start(vargs, format);
+#else
+ va_start(vargs);
+#endif
+ res = _PyErr_WarnFormatV(source, category, stack_level, format, vargs);
+ va_end(vargs);
+ return res;
+}
+
int
PyErr_ResourceWarning(PyObject *source, Py_ssize_t stack_level,
const char *format, ...)
@@ -1200,7 +1200,7 @@ PyErr_WarnEx(PyObject *category, const char *text, Py_ssize_t stack_level)
#undef PyErr_Warn
-int
+int
PyErr_Warn(PyObject *category, const char *text)
{
return PyErr_WarnEx(category, text, 1);
@@ -1320,7 +1320,7 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
int warned = 0;
PyObject *fn = get_warnings_attr(&PyId__warn_unawaited_coroutine, 1);
if (fn) {
- PyObject *res = PyObject_CallOneArg(fn, coro);
+ PyObject *res = PyObject_CallOneArg(fn, coro);
Py_DECREF(fn);
if (res || PyErr_ExceptionMatches(PyExc_RuntimeWarning)) {
warned = 1;
@@ -1332,9 +1332,9 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
PyErr_WriteUnraisable(coro);
}
if (!warned) {
- if (_PyErr_WarnFormat(coro, PyExc_RuntimeWarning, 1,
- "coroutine '%S' was never awaited",
- ((PyCoroObject *)coro)->cr_qualname) < 0)
+ if (_PyErr_WarnFormat(coro, PyExc_RuntimeWarning, 1,
+ "coroutine '%S' was never awaited",
+ ((PyCoroObject *)coro)->cr_qualname) < 0)
{
PyErr_WriteUnraisable(coro);
}
@@ -1342,11 +1342,11 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
}
PyDoc_STRVAR(warn_explicit_doc,
-"Low-level interface to warnings functionality.");
+"Low-level interface to warnings functionality.");
static PyMethodDef warnings_functions[] = {
WARNINGS_WARN_METHODDEF
- {"warn_explicit", (PyCFunction)(void(*)(void))warnings_warn_explicit,
+ {"warn_explicit", (PyCFunction)(void(*)(void))warnings_warn_explicit,
METH_VARARGS | METH_KEYWORDS, warn_explicit_doc},
{"_filters_mutated", (PyCFunction)warnings_filters_mutated, METH_NOARGS,
NULL},
@@ -1358,73 +1358,73 @@ static PyMethodDef warnings_functions[] = {
static struct PyModuleDef warningsmodule = {
PyModuleDef_HEAD_INIT,
- MODULE_NAME, /* m_name */
- warnings__doc__, /* m_doc */
- 0, /* m_size */
- warnings_functions, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL /* m_free */
+ MODULE_NAME, /* m_name */
+ warnings__doc__, /* m_doc */
+ 0, /* m_size */
+ warnings_functions, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL /* m_free */
};
-PyStatus
-_PyWarnings_InitState(PyThreadState *tstate)
-{
- if (warnings_init_state(&tstate->interp->warnings) < 0) {
- return _PyStatus_ERR("can't initialize warnings");
- }
- return _PyStatus_OK();
-}
-
-
+PyStatus
+_PyWarnings_InitState(PyThreadState *tstate)
+{
+ if (warnings_init_state(&tstate->interp->warnings) < 0) {
+ return _PyStatus_ERR("can't initialize warnings");
+ }
+ return _PyStatus_OK();
+}
+
+
PyMODINIT_FUNC
_PyWarnings_Init(void)
{
PyObject *m;
m = PyModule_Create(&warningsmodule);
- if (m == NULL) {
+ if (m == NULL) {
return NULL;
- }
+ }
- WarningsState *st = warnings_get_state();
- if (st == NULL) {
- goto error;
+ WarningsState *st = warnings_get_state();
+ if (st == NULL) {
+ goto error;
+ }
+ if (warnings_init_state(st) < 0) {
+ goto error;
}
- if (warnings_init_state(st) < 0) {
- goto error;
- }
- Py_INCREF(st->filters);
- if (PyModule_AddObject(m, "filters", st->filters) < 0) {
- goto error;
+ Py_INCREF(st->filters);
+ if (PyModule_AddObject(m, "filters", st->filters) < 0) {
+ goto error;
}
- Py_INCREF(st->once_registry);
- if (PyModule_AddObject(m, "_onceregistry", st->once_registry) < 0) {
- goto error;
+ Py_INCREF(st->once_registry);
+ if (PyModule_AddObject(m, "_onceregistry", st->once_registry) < 0) {
+ goto error;
+ }
+
+ Py_INCREF(st->default_action);
+ if (PyModule_AddObject(m, "_defaultaction", st->default_action) < 0) {
+ goto error;
}
- Py_INCREF(st->default_action);
- if (PyModule_AddObject(m, "_defaultaction", st->default_action) < 0) {
- goto error;
- }
-
return m;
-
-error:
- if (st != NULL) {
- warnings_clear_state(st);
- }
- Py_DECREF(m);
- return NULL;
+
+error:
+ if (st != NULL) {
+ warnings_clear_state(st);
+ }
+ Py_DECREF(m);
+ return NULL;
+}
+
+// We need this to ensure that warnings still work until late in finalization.
+void
+_PyWarnings_Fini(PyInterpreterState *interp)
+{
+ warnings_clear_state(&interp->warnings);
}
-
-// We need this to ensure that warnings still work until late in finalization.
-void
-_PyWarnings_Fini(PyInterpreterState *interp)
-{
- warnings_clear_state(&interp->warnings);
-}