Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-06-02 JJ Allaire <jj@rstudio.com>

* 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 <jj@rstudio.com>

* src/attributes.cpp: Fix registration for exports with name attribute.
Expand Down
10 changes: 5 additions & 5 deletions R/Rcpp.package.skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,13 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
file.copy(file, src)
message(" >> copied ", file, " to src directory" )
}
compileAttributes(root)
}

if (example_code) {
if (isTRUE(attributes)) {
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)
Expand Down Expand Up @@ -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 ")
}

Copy link
Member

@eddelbuettel eddelbuettel Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am short of coffee but if (attributes) { relies on attributes==TRUE. We could have a case of modules=TRUE (as in #704) and also attributes=FALSE, no? Needless complication?

invisible(NULL)
}

Expand Down
1 change: 1 addition & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
}
Expand Down
20 changes: 18 additions & 2 deletions src/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,11 @@ namespace attributes {
// for generating C++ interfaces
std::vector<Attribute> cppExports_;

// for generating native routine registration
// for generating Rcpp::export native routine registration
std::vector<Attribute> nativeRoutines_;

// for generating module native routine registration
std::vector<std::string> modules_;
};

// Class which manages generating PackageName_RcppExports.h header file
Expand Down Expand Up @@ -1888,6 +1891,9 @@ namespace attributes {
}
} // #nocov end

// record modules
const std::vector<std::string>& modules = attributes.modules();
modules_.insert(modules_.end(), modules.begin(), modules.end());

// verbose if requested
if (verbose) { // #nocov start
Expand Down Expand Up @@ -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<std::string> routineNames;
Expand All @@ -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<modules_.size(); i++) {
routineNames.push_back(kRcppModuleBoot + modules_[i]);
routineArgs.push_back(0);
}
if (hasCppInterface()) {
routineNames.push_back(registerCCallableExportedName());
routineArgs.push_back(0);
Expand All @@ -1976,6 +1987,11 @@ namespace attributes {
std::vector<std::string> declarations = extraRoutines["declarations"];
std::vector<std::string> callEntries = extraRoutines["call_entries"];

// add declarations for modules
for (std::size_t i=0;i<modules_.size(); i++) {
declarations.push_back("RcppExport SEXP " + kRcppModuleBoot + modules_[i] + "();");
}

// generate declarations
if (declarations.size() > 0) {
ostr() << std::endl;
Expand Down