Skip to content

[cpyrt] Accept a Python string from the pretty printer in op_str - #121

Open
aaronj0 wants to merge 1 commit into
compiler-research:mainfrom
aaronj0:op-str-python-str-result
Open

aaronj0 wants to merge 1 commit into
compiler-research:mainfrom
aaronj0:op-str-python-str-result

Conversation

@aaronj0

@aaronj0 aaronj0 commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

A std::string executor may hand back a Python str rather than a proxy. In ROOT's case we always return a Python str. op_str cast the result to CPPInstance unconditionally and read through it. Take the text from either shape, and treat the generic "{not representable}" fallback as in the case of an address-only result, so op_str falls through to the generic repr instead of crashing.

@aaronj0
aaronj0 requested a review from guitargeek September 29, 2026 15:24
A std::string executor may hand back a Python str rather than a proxy;
op_str cast the result to CPPInstance unconditionally and read through
it. Take the text from either shape, and treat the generic
"{not representable}" fallback like an address-only result so op_str
falls through to the generic repr.
@aaronj0
aaronj0 force-pushed the op-str-python-str-result branch from 67275a4 to ac9d79c Compare September 30, 2026 07:54

@guitargeek guitargeek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Thanks

@vgvassilev

Copy link
Copy Markdown
Contributor

Is this worth a test?

@aaronj0

aaronj0 commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

Is this worth a test?

Currently we can't assert that in the upstream test suite since it's only on the ROOT side that cppjit always converted the returned value to Python string. Here is the patch: root-project/root@5a4bbac which, even before the migration, was tracked against cppyy. I do not think that behaviour is something upstreamable for now, but what this patch does is protect us with a check instead of assuming that the return value is a CppInstance of std::string and crashing.

@vgvassilev

Copy link
Copy Markdown
Contributor

Is this worth a test?

Currently we can't assert that in the upstream test suite since it's only on the ROOT side that cppjit always converted the returned value to Python string. Here is the patch: root-project/root@5a4bbac which, even before the migration, was tracked against cppyy. I do not think that behaviour is something upstreamable for now, but what this patch does is protect us with a check instead of assuming that the return value is a CppInstance of std::string and crashing.

Isn’t the last statement contradicting the first? If we can trigger this only through a ROOT patch that is not upstreamable why upstreaming dead code.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants