Skip to content

Add output_length to _Py_EncodeLocaleEx() - #158680

Merged
vstinner merged 16 commits into
python:mainfrom
vstinner:encode_locale
Oct 4, 2026
Merged

vstinner merged 16 commits into
python:mainfrom
vstinner:encode_locale

Conversation

@vstinner

@vstinner vstinner commented Oct 3, 2026

Copy link
Copy Markdown
Member

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().

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.
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()
@read-the-docs-community

read-the-docs-community Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34932645 | 📁 Comparing 2102314 against main (9d22a53)

  🔍 Preview build  

1 file changed
± c-api/sys.html

@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 4, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 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.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 4, 2026
@vstinner

vstinner commented Oct 4, 2026

Copy link
Copy Markdown
Member Author

Good, the test suite passed on almost all CIs. And the few failures are unrelated to this change.

buildbot/aarch64 CentOS9 Refleaks PR
buildbot/aarch64 Fedora Stable Refleaks PR
buildbot/AMD64 CentOS9 NoGIL Refleaks PR
buildbot/AMD64 FreeBSD Refleaks PR
buildbot/ARM64 MacOS M1 Refleaks NoGIL PR
buildbot/s390x Fedora Stable Refleaks PR
buildbot/s390x RHEL9 Refleaks PR

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.

buildbot/AMD64 Windows PGO NoGIL Tailcall PR

Unrelated test_external_inspection issue: see #158574.

@vstinner
vstinner merged commit d19febb into python:main Oct 4, 2026
142 of 157 checks passed
@vstinner
vstinner deleted the encode_locale branch October 4, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants