Skip to content

gh-155742: Use PyBytesWriter in json _match_number_unicode() - #155744

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:json_writer
Closed

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:json_writer

Conversation

@vstinner

@vstinner vstinner commented Aug 13, 2026

Copy link
Copy Markdown
Member

Replace soft deprecated PyBytes_FromStringAndSize() with PyBytesWriter.

Use PyBytesWriter_Create() for the float code path, or PyMem_Malloc() for the int code path.

Replace soft deprecated PyBytes_FromStringAndSize() with
PyBytesWriter.

Use PyBytesWriter_Create() for the float code path, or PyMem_Malloc()
for the int code path.
Comment thread Modules/_json.c
}
else {
writer = NULL;
buf = PyMem_Malloc(n + 1);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

PyLong_FromString() doesn't need a bytes object, just a C string (char*). But maybe the PyLong code path should also use PyBytesWriter to simplify the code.

@vstinner

vstinner commented Sep 3, 2026

Copy link
Copy Markdown
Member Author

The alternative to creating a temporary bytes object is... to not create a Python object at all :-) I wrote PR gh-156897 for that.

@vstinner

Copy link
Copy Markdown
Member Author

I close this PR since PR #156897 seems to be a better approach.

@vstinner vstinner closed this Sep 17, 2026
@vstinner
vstinner deleted the json_writer branch September 17, 2026 15:09
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.

1 participant