-
Notifications
You must be signed in to change notification settings - Fork 11
[fix] Null-guard the cling.printValue lookup in op_str #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
conrade-ctc
wants to merge
1
commit into
compiler-research:main
Choose a base branch
from
chicagotrading:opstr-null-guard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| #ifndef CPYRT_COMPATIBILITY_H | ||
| #define CPYRT_COMPATIBILITY_H | ||
|
|
||
| #include "Python.h" | ||
|
|
||
| #include "cppjit_interop.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace cppjit::cpyrt::compat { | ||
|
|
||
| inline PyObject* GetClingPrintValue() { | ||
| #ifdef CPPJIT_USE_CLING | ||
| static PyObject* printValue = nullptr; | ||
| if (printValue) | ||
| return printValue; | ||
|
|
||
| PyObject* gbl = | ||
| PyDict_GetItemString(PySys_GetObject((char*)"modules"), "cppjit.gbl"); | ||
| PyObject* cling = gbl ? PyObject_GetAttrString(gbl, (char*)"cling") : nullptr; | ||
| printValue = | ||
| cling ? PyObject_GetAttrString(cling, (char*)"printValue") : nullptr; | ||
| Py_XDECREF(cling); | ||
|
|
||
| if (printValue) { | ||
| Py_DECREF(printValue); // make borrowed | ||
| if (!PyCallable_Check(printValue)) | ||
| printValue = nullptr; | ||
| } | ||
|
|
||
| if (!printValue) | ||
| PyErr_Clear(); | ||
|
|
||
| return printValue; | ||
| #else | ||
| return nullptr; | ||
| #endif | ||
| } | ||
|
|
||
| // Interpreter::toString is an assert(0) stub (CppInterOp#1100); skip it. | ||
| inline std::string ObjToString(interop::TCppScope_t /*klass*/, | ||
| interop::TCppObject_t /*obj*/) { | ||
| return ""; | ||
| } | ||
|
|
||
| } // namespace cppjit::cpyrt::compat | ||
|
|
||
| #endif // CPYRT_COMPATIBILITY_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have existing tests that are marked crashing with clang-repl due to ToString. I am not sure if adding a Python test that spawns a process guaranteed to crash is a good idea, especially since this does not live on the API surface, and this test suite is meant to be user-facing. Imo this can be moved into a CppInterOp only reproducer. If
compat::GetClingPrintValue()returns null, can we prevent the crash and gracefully error out instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null return was already safe.
op_strfalls through to the generic repr there.The crash the test caught happens one step earlier.
op_strcallsCpp::ObjToString, andInterpreter::toStringis anassert(0)stub. It aborts with assertions on and returns""without them. The stub is not backend specific, so the existing markers say "and on Cling".I moved that call behind the same compatibility header and made it return the empty string on every build, so
op_strreaches the generic repr everywhere. #1100 turns the helper back into a one-line forward.The subprocess test is gone. The new
test53runs in process and checks thatstr(obj)equalsrepr(obj). The three xfail markers that named this crash now pass on an assertions-on build, so I removed them.