Repository navigation
run the module body only once per dll - #1528
Open
kevinushey wants to merge 1 commit into
Open
kevinushey wants to merge 1 commit into
kevinushey wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1527. Stacked on #1526 (same macro); the base branch is
bugfix/module-boot-exceptions, so the diff here only shows this change. Once #1526 is merged I'll retarget this tomaster.Module("name", PACKAGE = ...)calls the module's boot function every time it is given a module name, and the boot function re-ran theRCPP_MODULEbody each time. The body adds to astatic Rcpp::Modulethat lives as long as the DLL, so every load appended another copy of each constructor and method overload, which shows up inshow()and leaks. See #1527 for the reprex.Change (
inst/include/Rcpp/Module.h,RCPP_MODULE):static boolflag next to the staticRcpp::Modulerecords that the body has completed; later calls of the boot function skip the body and just return the module pointer. The flag lives in the same DLL instance as the module object, so a DLL that is unloaded and loaded again starts over with a fresh module and flag, as it should.As with #1526, this is confined to the macro and applies once a package is rebuilt.
Test (
inst/tinytest/test_module.R): aftersourceCpp()has loadeddemoModule, load it twice more withModule(..., mustStart = TRUE)and check thatModuleWorldstill has one constructor and onegreet()overload. It sits at the end of the file becauseModule()redefines the module's reference classes.Verification:
1 constructor(s), 1 overload(s) of inc()on every iteration with this branch;show()lists a single constructor and method.Expected '1', got '3'). With it,test_module.R(49/49),test_modref.R,test_expose_class.Randtest_module_client_package.Rpass withRunAllRcppTests=yes RunVerboseRcppTests=yes(R 4.6.1, macOS).Checklist
R CMD checkstill passes all tests (module test files run locally as above)