diff options
author | Inada Naoki <songofacandy@gmail.com> | 2021-04-02 08:38:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 08:38:59 (GMT) |
commit | bec8c787ec72d73b39011bde3f3a93e9bb1174b7 (patch) | |
tree | a0d1831f0beb98ae9996ae257dc8bf43b2c8512e /Modules | |
parent | 8bbfeb3330c10d52274bb85fce59ae614f0500bf (diff) | |
download | cpython-bec8c787ec72d73b39011bde3f3a93e9bb1174b7.zip cpython-bec8c787ec72d73b39011bde3f3a93e9bb1174b7.tar.gz cpython-bec8c787ec72d73b39011bde3f3a93e9bb1174b7.tar.bz2 |
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.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/_iomodule.c | 6 | ||||
-rw-r--r-- | Modules/_io/textio.c | 24 |
2 files changed, 17 insertions, 13 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 652c2ce..170dea4 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -532,8 +532,10 @@ _io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel) if (encoding == NULL || encoding == Py_None) { PyInterpreterState *interp = _PyInterpreterState_GET(); if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) { - PyErr_WarnEx(PyExc_EncodingWarning, - "'encoding' argument not specified", stacklevel); + if (PyErr_WarnEx(PyExc_EncodingWarning, + "'encoding' argument not specified", stacklevel)) { + return NULL; + } } Py_INCREF(_PyIO_str_locale); return _PyIO_str_locale; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 6f89a87..eb05ae1 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) { @@ -1124,17 +1137,6 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, 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; state = IO_STATE(); |