-
-
Notifications
You must be signed in to change notification settings - Fork 217
protect module method and function results while wrapping in invoke #1494
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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.
Do we cast the result of
Shield<SEXP>back toSEXPin other spots?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.
Only one other spot:
Environment::assign()has a dedicatedShield<SEXP>overload casting back with(SEXP)(Environment.h:193, added in 8670bb6) -- required there because the templatedassign(const WRAPPABLE&)out-matches theSEXPoverload for aShieldargument (deduction ignoresoperator SEXP()) and its implementation would otherwise recurse. Everywhere elseShieldfeeds plainSEXP-taking C functions, where the implicit conversion applies and no cast is needed.Strictly, the cast here isn't required:
List::create()takesconst T&andwrap()has a convertible-to-SEXP fallback, so the uncast form compiles and behaves correctly (verified, including under gctorture) --Vector::create()itself relies on that path when assigning itsShielded names viares.attr("names"). But with the cast,_["result"]instantiates thenamed_object<SEXP>specialization rather than a genericnamed_object<Shield<SEXP>>, keeping this on the standard exact-SEXPpaths, so I'd prefer to keep it.I also checked whether other module-code sites need the same protect-then-cast treatment:
invoke_notvoid()andgetProperty()return the raw result directly with no allocation afterward, andModule::get_function()'screate()arguments are all rooted (XPtrvia the preserve list,formalsis a storedRcpp::List), so these two sites appear to be the only ones with the unprotected window.