fix: add life support to handles cast to string_view#6092
fix: add life support to handles cast to string_view#6092charlesbeattie wants to merge 3 commits into
Conversation
|
Looks fine to me. Ran a review with Claude Opus 4.8, below. 🤖 AI review 🤖
I've reviewed PR #6092. Here's my assessment. OverviewThe PR fixes a genuine use-after-free bug when casting Python objects to
The fix adds Correctness — looks right
Test coverage — goodThe test exercises all three newly-fixed paths (str → UTF-8, Minor suggestions (non-blocking)
RisksLow. The change is narrowly scoped, touches no ABI/internals, adds no overhead to the common Verdict: Solid, correct bug fix with appropriate test coverage. Approve, modulo confirming the changelog expectation. 🤖 Why does like 510 exist? 🤖
Good catch — line 510 ( What it does now
Why it existsIt's a leftover from Python 2 support. Before the Python 2 removal (commit // Python 2 era:
temp = reinterpret_steal<object>(PyUnicode_FromObject(load_src.ptr()));
...
load_src = temp; // now load_src != srcWhen a Python 2 Relevance to this PRIt's harmless but slightly inconsistent with the PR: the new UTF-8 path reads the buffer from Cleanest fix (independent of this PR, or folded into it): drop line 510 and replace the four |
Description
std::string_view is a reference type and therefore the handles are required to be put on life-support.
Suggested changelog entry:
Add life support to handles cast to string_view.