Skip to content

gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters - #158210

Open
cmaloney wants to merge 3 commits into
python:mainfrom
cmaloney:clinic-s-z-asutf8nonul
Open

cmaloney wants to merge 3 commits into
python:mainfrom
cmaloney:clinic-s-z-asutf8nonul

Conversation

@cmaloney

@cmaloney cmaloney commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

The code was doing the same as the helper added in GH-111957 but inline. That resulted in significantly more .text for most functions. Refactor the Argument Clinic converters code to deduplicate a bit while keeping generated code close to original.

On my Linux x64 box this reduces .text by ~6200 bytes in a clang release build (no PGO or LTO). Performance is flat.

The helper was already exported for _sqlite3, update the comment that it is used in AC generated code as well.

cc: @eendebakpt , @methane . Found this while working on moving str to Argument Clinic generated code. The call + local rather than pointer to stack member, particularly when -fstack-protector-strong is set as some distros do, gets a lot shorter.

…ters

The code was doing the same as the helper added in pythonGH-111957 but inline.
That resulted in significantly more `.text` for most functions. Refactor
the Arguemnt Clinic converters code to deduplicate a bit while keeping
generated code close to original.

On my Linux x64 box this reduces `.text` by ~6200 bytes in a clang
release build (no PGO or LTO). Performance is flat.

The helper was already exported for `_sqlite3`, update the comment that
it is used in AC generated code as well.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@@ -0,0 +1,3 @@
Argument Clinic now calls the internal function ``_PyUnicode_AsUTF8NoNUL()`` for
``s`` and ``z`` converters instead of writing equivalent code inline to reduce
the generated ``.text`` segment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the generated ``.text`` segment.
the code size of generated argument parsers.

(or even omit the news entry, as there are just implementation details)

Comment thread Include/internal/pycore_unicodeobject.h Outdated
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
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.

3 participants