Skip to content

Commit 3586d7c

Browse files
cmaloneyclaude
andcommitted
gh-157407: Use _PyUnicode_AsUTF8NoNUL for AC 's' and 'z' converters
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 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>
1 parent ee1bbf0 commit 3586d7c

47 files changed

Lines changed: 310 additions & 1108 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Include/internal/pycore_unicodeobject.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ extern void _PyUnicode_InternStatic(PyInterpreterState *interp, PyObject **);
450450
extern void _PyUnicode_ClearInterned(PyInterpreterState *interp);
451451

452452
// Like PyUnicode_AsUTF8(), but check for embedded null characters.
453-
// Export for '_sqlite3' shared extension.
453+
// Export for '_sqlite3' shared extension, and for the Argument Clinic code
454+
// generated for the 's' and 'z' converters, which many shared extensions use.
454455
PyAPI_FUNC(const char *) _PyUnicode_AsUTF8NoNUL(PyObject *);
455456

456457

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Argument Clinic now calls the internal function ``_PyUnicode_AsUTF8NoNUL()`` for
2+
``s`` and ``z`` converters instead of writing equivalent code inline to reduce
3+
the generated ``.text`` segment.

‎Modules/_ctypes/clinic/_ctypes.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_ctypes/clinic/callproc.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/_iomodule.c.h‎

Lines changed: 6 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/fileio.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/textio.c.h‎

Lines changed: 5 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_io/clinic/winconsoleio.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_multiprocessing/clinic/multiprocessing.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Modules/_multiprocessing/clinic/semaphore.c.h‎

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)