[3.13] Fix Unicode encode_wstr_utf8() (#127420) (#127505)

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:03 +01:00 committed by GitHub
parent 585d48f001
commit 943e57e1ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15633,7 +15633,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) {