-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Debug mode: check correct HPyContext usage #363
Conversation
1027249
to
a8a4b8e
Compare
a8a4b8e
to
8784bea
Compare
This has a merge conflict. Is it ready for review? |
3550d56
to
5c2e64c
Compare
I've rebased the PR and it's ready for a review now. |
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.
Besides my concern about code duplication (see comment below), looks like a very good debug mode feature.
hpy/debug/src/debug_ctx_cpython.c
Outdated
DHPy dh_result = f(dctx, dh_self); | ||
DHPy_close_and_check(dctx, dh_self); | ||
|
||
HPyContext *next_dctx = hpy_debug_get_next_dctx_from_cache(dctx); |
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.
That's a lot of code duplication. I think we could pull the temporary debug context setup and tear down code out of the switch if we use break
instead of return
at the end of the cases.
We then only need to use next_dctx
for opening and closing the argument handles like dh_self
.
Or do I miss something?
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.
Fixed. We cannot really pull out the whole thing, because in a->result
variable a
is a different struct every time, but I pulled as much as I could. Also used the new helpers in the autogenerated code.
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.
lgtm
8ce9712
to
76fef11
Compare
@antocuni would you have some spare cycles for a review :-)? |
This has conflicts. |
Co-authored-by: Stepan Sindelar <[email protected]>
76fef11
to
96fe058
Compare
Proactively rebased on top of #402 to streamline merging of both PRs |
Could you describe under what cases the checks might fail? What is the scenario that would cause someone to get the wrong context? |
What this aims to prevent is a situation when someone misunderstands the contract of HPy and stashes context into some global variable to read it later in a context of another new Python->HPy call. For example, in the test: on this line it uses global variable |
Thanks @steve-s |
Based on WIP in #350 done with @nirit100 at the HPy sprint
is_valid
and all the context functions check this flag as the first thing.is_valid
flagdebug_ctx_CallRealFunctionFromTrampoline
) takes next context from the buffer, setsis_valid=false
for the previous context andis_valid=true
for the context to be used (after the call the flags are reverted back)