From bec8c787ec72d73b39011bde3f3a93e9bb1174b7 Mon Sep 17 00:00:00 2001 From: Inada Naoki Date: Fri, 2 Apr 2021 17:38:59 +0900 Subject: bpo-43510: Fix emitting EncodingWarning from _io module. (GH-25146) I forget to check PyErr_WarnEx() return value. But it will fail when -Werror is used. --- Modules/_io/textio.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'Modules/_io/textio.c') diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 6f89a879c9..eb05ae1a16 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1085,6 +1085,19 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, self->ok = 0; self->detached = 0; + if (encoding == NULL) { + PyInterpreterState *interp = _PyInterpreterState_GET(); + if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) { + if (PyErr_WarnEx(PyExc_EncodingWarning, + "'encoding' argument not specified", 1)) { + return -1; + } + } + } + else if (strcmp(encoding, "locale") == 0) { + encoding = NULL; + } + if (errors == Py_None) { errors = _PyUnicode_FromId(&PyId_strict); /* borrowed */ if (errors == NULL) { @@ -1123,17 +1136,6 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, self->encodefunc = NULL; self->b2cratio = 0.0; - if (encoding == NULL) { - PyInterpreterState *interp = _PyInterpreterState_GET(); - if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) { - PyErr_WarnEx(PyExc_EncodingWarning, - "'encoding' argument not specified", 1); - } - } - else if (strcmp(encoding, "locale") == 0) { - encoding = NULL; - } - if (encoding == NULL) { /* Try os.device_encoding(fileno) */ PyObject *fileno; -- cgit v1.2.1