Add output_length to _Py_EncodeLocaleEx() - #158680
Conversation
Add output_length to _Py_EncodeLocaleEx(), _Py_EncodeUTF8Ex(), encode_current_locale() and encode_ascii(). So unicode_encode_locale() and wstr_to_utf8() can use the output_length, instead of having to compute strlen(). * Add encode_current_locale_impl() to simplify encode_current_locale(). * _Py_EncodeLocaleEx() now sets error_pos and reason if it fails with -1 or -3. * Add tests on Py_EncodeLocale() and Py_DecodeLocale() functions in test_codecs. * Remove reason parameter of _Py_EncodeUTF8Ex(), encode_current_locale() and encode_ascii().
Also revert an useless change
_Py_EncodeUTF8Ex() now uses size_t instead of Py_ssize_t to iterate on the input string. On error, encode_current_locale_impl() now returns ENCODE_ERROR (new constant) instead of DECODE_ERROR. Add comments on the 3 encode functions.
Add more comments.
Check error pos in decode tests.
* Rename _Py_EncodeLocaleEx() to _Py_EncodeLocale() * Rename _Py_DecodeLocaleEx() to _Py_DecodeLocale() * Rename _Py_DecodeUTF8Ex() to _Py_DecodeUTF8() * Rename _Py_EncodeUTF8Ex() to _Py_EncodeUTF8()
Documentation build overview
|
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit 2102314 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158680%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
Good, the test suite passed on almost all CIs. And the few failures are unrelated to this change.
All these Refleak failures have the same root cause: test_capi leaks. In fact, it's a recent regression on the main branch. I wrote #158806 to fix the leak.
Unrelated test_external_inspection issue: see #158574. |
Add output_length to _Py_EncodeLocaleEx(), _Py_EncodeUTF8Ex(), encode_current_locale() and encode_ascii(). So
unicode_encode_locale() and wstr_to_utf8() can use the output_length, instead of having to compute strlen().