[3.12] Fix Unicode encode_wstr_utf8() (#127420) (#127504)

Fix Unicode encode_wstr_utf8() (#127420)

Raise RuntimeError instead of RuntimeWarning.

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Bénédikt Tran 2024-12-02 13:24:26 +01:00 committed by GitHub
parent 828db9016b
commit 9f0d6b71d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15446,7 +15446,7 @@ encode_wstr_utf8(wchar_t *wstr, char **str, const char *name)
int res;
res = _Py_EncodeUTF8Ex(wstr, str, NULL, NULL, 1, _Py_ERROR_STRICT);
if (res == -2) {
PyErr_Format(PyExc_RuntimeWarning, "cannot decode %s", name);
PyErr_Format(PyExc_RuntimeError, "cannot encode %s", name);
return -1;
}
if (res < 0) {