You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The reason will be displayed to describe this comment to others. Learn more.
This is dangerous. You are preparing a tuple with nkeys but then you are filling it calling PyObject_CallFunctionObjArgs, which can execute arbitrary Python code. At this point, the tuple is tracked by the GC so code executed by PyObject_CallFunctionObjArgs could see the tuple half-initialized (the same if there is a gc pass). The same thing applies to anything done meanwhile the tuple is not ready that can call into arbitrary Python.
The reason will be displayed to describe this comment to others. Learn more.
Another option it to untrack the tuple after its creation and track it back when is ready. Be careful because some APIs can retrack it (like resizing the tuple). I would recommend to add some asserts to check that is untracked where is supposed to be if you decide to go this way.
The reason will be displayed to describe this comment to others. Learn more.
Well, because this isn't actually what we're doing here... it's just approximately equivalent Python code to help explain the behavior, which can be a bit subtle. Call it pseudocode, if you want.
Setting up an exception handler and actually performing all of this logic in Pythonland is needlessly complicated for what we're trying to do.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is dangerous. You are preparing a tuple with
nkeys
but then you are filling it callingPyObject_CallFunctionObjArgs
, which can execute arbitrary Python code. At this point, the tuple is tracked by the GC so code executed byPyObject_CallFunctionObjArgs
could see the tuple half-initialized (the same if there is a gc pass). The same thing applies to anything done meanwhile the tuple is not ready that can call into arbitrary Python.Uh oh!
There was an error while loading. Please reload this page.
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.
I see. So is filling it withNone
the right thing to do here, or can we cheat and just untrack/retrack?Uh oh!
There was an error while loading. Please reload this page.
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.
Actually, filling it with
None
can lead to problems (as we've seen before). So should we just untrack it temporarily?I guess we could just fill a list and convert it to a tuple, too.
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.
Okay, I just went with list -> tuple for both. Let me know if you prefer something else.
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.
Another option it to untrack the tuple after its creation and track it back when is ready. Be careful because some APIs can retrack it (like resizing the tuple). I would recommend to add some asserts to check that is untracked where is supposed to be if you decide to go this way.