Skip to content

_remote_debugging: Use PyBytesWriter in read_py_bytes() - #162110

Merged
pablogsal merged 1 commit into
python:mainfrom
maurycy:rd-bytes-writer
Nov 16, 2026
Merged

pablogsal merged 1 commit into
python:mainfrom
maurycy:rd-bytes-writer

Conversation

@maurycy

@maurycy maurycy commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Replace manual buffer allocation, termination, and cleanup in read_py_bytes() with PyBytesWriter. Add coverage for empty line tables.

Not sure if issue worthy?

@maurycy

maurycy commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

cc @vstinner

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! This removes the extra buffer and keeps the error cleanup correct.

@pablogsal
pablogsal enabled auto-merge (squash) November 16, 2026 12:07
@pablogsal
pablogsal merged commit be3dfe5 into python:main Nov 16, 2026
66 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @maurycy for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 16, 2026

Copy link
Copy Markdown

GH-162114 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 16, 2026
pablogsal pushed a commit that referenced this pull request Nov 16, 2026
…2110)

Use PyBytesWriter to construct remote bytes objects. Remove the separate raw buffer allocation, copy, and cleanup.
(cherry picked from commit be3dfe5)

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
@vstinner

Copy link
Copy Markdown
Member

cc @vstinner

Post-merge review: LGTM! The modified function requires less code to handle error which is a good thing!

I'm not sure why the previous code used buf[len] = '\0'; before calling PyBytes_FromStringAndSize(buf, len): this function doesn't require buf to end with a NULL byte. So it's ok to remove this code.

I'm surprised that such kind code is backported to 3.15 stable branch, but that it's up to @pablogsal to decide how to maintain this code in multiple branches :-)

The new test_self_trace_with_empty_linetable() test seems to be unrelated PyBytesWriter usage.

@maurycy
maurycy deleted the rd-bytes-writer branch November 16, 2026 15:24
@maurycy

maurycy commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

@vstinner Thank you for taking a look! 💚 I'm either not sure myself why there was buf[len] = '\0';. As for the test, the idea was to ensure I don't break an edge case (empty bytes).

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