Skip to content

Commit

Permalink
Replace dot (".") with underscore ("_") in package names when generat…
Browse files Browse the repository at this point in the history
…ing native routine registrations (fixes #721)
  • Loading branch information
jjallaire committed Jun 29, 2017
1 parent 7d1973c commit c505d2f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-06-29 JJ Allaire <jj@rstudio.com>

* src/attributes.cpp: Replace dot (".") with underscore ("_") in package
names when generating native routine registrations.

2017-06-17 Krill Müller <krlmlr@mailbox.org>

* inst/include/Rcpp/Dimension.h: Explicit cast to int
Expand Down
2 changes: 2 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
addressing \ghit{704}).
\item Add Shield around parameters in Rcpp::interfaces (JJ in \ghpr{713}
addressing \ghit{712}).
\item Replace dot (".") with underscore ("_") in package names when generating
native routine registrations (fixes \ghit{721}).
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,11 @@ namespace attributes {
bool parseDependencies)
: sourceFile_(sourceFile), hasPackageInit_(false)
{

// transform packageName to valid C++ symbol
std::string packageNameCpp = packageName;
std::replace(packageNameCpp.begin(), packageNameCpp.end(), '.', '_');

// First read the entire file into a std::stringstream so we can check
// it for attributes (we don't want to do any of our more expensive
// processing steps if there are no attributes to parse)
Expand All @@ -1151,7 +1156,7 @@ namespace attributes {
// Check for attribute signature
if (contents.find("[[Rcpp::") != std::string::npos ||
contents.find("RCPP_MODULE") != std::string::npos ||
contents.find("R_init_" + packageName) != std::string::npos) {
contents.find("R_init_" + packageNameCpp) != std::string::npos) {

// Now read into a list of strings (which we can pass to regexec)
// First read into a std::deque (which will handle lots of append
Expand Down Expand Up @@ -1230,7 +1235,7 @@ namespace attributes {
// Scan for package init function
hasPackageInit_ = false;
commentState.reset();
std::string pkgInit = "R_init_" + packageName;
std::string pkgInit = "R_init_" + packageNameCpp;
Rcpp::List initMatches = regexMatches(lines_, "^[^/]+" + pkgInit + ".*DllInfo.*$");
for (int i = 0; i<initMatches.size(); i++) {

Expand Down Expand Up @@ -1968,7 +1973,7 @@ namespace attributes {
std::vector<std::size_t> routineArgs;
for (std::size_t i=0;i<nativeRoutines_.size(); i++) {
const Attribute& attr = nativeRoutines_[i];
routineNames.push_back(package() + "_" + attr.function().name());
routineNames.push_back(packageCpp() + "_" + attr.function().name());
routineArgs.push_back(attr.function().arguments().size());
}
std::string kRcppModuleBoot = "_rcpp_module_boot_";
Expand Down Expand Up @@ -2016,7 +2021,7 @@ namespace attributes {

ostr() << std::endl;

ostr() << "RcppExport void R_init_" << package() << "(DllInfo *dll) {" << std::endl;
ostr() << "RcppExport void R_init_" << packageCpp() << "(DllInfo *dll) {" << std::endl;
ostr() << " R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);" << std::endl;
ostr() << " R_useDynamicSymbols(dll, FALSE);" << std::endl;
ostr() << "}" << std::endl;
Expand Down

0 comments on commit c505d2f

Please sign in to comment.