diff --git a/ChangeLog b/ChangeLog index 0facccb5c..edb7fa262 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-06-02 JJ Allaire + + * src/attributes.cpp: Automatically register init functions for RcppModules + * R/Rcpp.package.skeleton.R: compileAttributes only after all code is generated + 2017-06-01 JJ Allaire * src/attributes.cpp: Fix registration for exports with name attribute. diff --git a/R/Rcpp.package.skeleton.R b/R/Rcpp.package.skeleton.R index fe73edc4c..f0f2e697c 100644 --- a/R/Rcpp.package.skeleton.R +++ b/R/Rcpp.package.skeleton.R @@ -138,7 +138,6 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), file.copy(file, src) message(" >> copied ", file, " to src directory" ) } - compileAttributes(root) } if (example_code) { @@ -146,10 +145,6 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), file.copy(file.path( skeleton, "rcpp_hello_world_attributes.cpp"), file.path( src, "rcpp_hello_world.cpp")) message(" >> added example src file using Rcpp attributes") - compileAttributes(root) - message(" >> compiled Rcpp attributes") - message(" >> do NOT modify by hand either RcppExports.cpp or ", - "RcppExports.R") } else { header <- readLines(file.path(skeleton, "rcpp_hello_world.h")) header <- gsub("@PKG@", name, header, fixed = TRUE) @@ -218,6 +213,11 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), rm("rcpp_hello_world", envir = env) } + if (attributes) { + compileAttributes(root) + message(" >> compiled Rcpp attributes ") + } + invisible(NULL) } diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 74d0b210f..78af9e999 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -17,6 +17,7 @@ or newer (Elias Pipping in \ghpr{698}). \item Fix native registration for exports with name attribute (\ghpr{703} addressing \ghit{702}). + \item Automatically register init functions for RcppModules. } } } diff --git a/src/attributes.cpp b/src/attributes.cpp index cda172709..3eeccdf93 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -675,8 +675,11 @@ namespace attributes { // for generating C++ interfaces std::vector cppExports_; - // for generating native routine registration + // for generating Rcpp::export native routine registration std::vector nativeRoutines_; + + // for generating module native routine registration + std::vector modules_; }; // Class which manages generating PackageName_RcppExports.h header file @@ -1888,6 +1891,9 @@ namespace attributes { } } // #nocov end + // record modules + const std::vector& modules = attributes.modules(); + modules_.insert(modules_.end(), modules.begin(), modules.end()); // verbose if requested if (verbose) { // #nocov start @@ -1955,7 +1961,7 @@ namespace attributes { } // write native routines - if (!hasPackageInit && !nativeRoutines_.empty()) { + if (!hasPackageInit && (!nativeRoutines_.empty() || !modules_.empty())) { // build list of routines we will register std::vector routineNames; @@ -1965,6 +1971,11 @@ namespace attributes { routineNames.push_back(package() + "_" + attr.function().name()); routineArgs.push_back(attr.function().arguments().size()); } + std::string kRcppModuleBoot = "_rcpp_module_boot_"; + for (std::size_t i=0;i declarations = extraRoutines["declarations"]; std::vector callEntries = extraRoutines["call_entries"]; + // add declarations for modules + for (std::size_t i=0;i 0) { ostr() << std::endl;