Skip to content

Commit 44905f3

Browse files
authored
Merge pull request #722 from RcppCore/bugfix/dot-package-name-registration
Replace dot (".") with underscore ("_") in package names when generating native routine registrations (fixes #721)
2 parents 7d1973c + c505d2f commit 44905f3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2017-06-29 JJ Allaire <[email protected]>
2+
3+
* src/attributes.cpp: Replace dot (".") with underscore ("_") in package
4+
names when generating native routine registrations.
5+
16
2017-06-17 Krill Müller <[email protected]>
27

38
* inst/include/Rcpp/Dimension.h: Explicit cast to int

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
addressing \ghit{704}).
3030
\item Add Shield around parameters in Rcpp::interfaces (JJ in \ghpr{713}
3131
addressing \ghit{712}).
32+
\item Replace dot (".") with underscore ("_") in package names when generating
33+
native routine registrations (fixes \ghit{721}).
3234
}
3335
}
3436
}

src/attributes.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,11 @@ namespace attributes {
11411141
bool parseDependencies)
11421142
: sourceFile_(sourceFile), hasPackageInit_(false)
11431143
{
1144+
1145+
// transform packageName to valid C++ symbol
1146+
std::string packageNameCpp = packageName;
1147+
std::replace(packageNameCpp.begin(), packageNameCpp.end(), '.', '_');
1148+
11441149
// First read the entire file into a std::stringstream so we can check
11451150
// it for attributes (we don't want to do any of our more expensive
11461151
// processing steps if there are no attributes to parse)
@@ -1151,7 +1156,7 @@ namespace attributes {
11511156
// Check for attribute signature
11521157
if (contents.find("[[Rcpp::") != std::string::npos ||
11531158
contents.find("RCPP_MODULE") != std::string::npos ||
1154-
contents.find("R_init_" + packageName) != std::string::npos) {
1159+
contents.find("R_init_" + packageNameCpp) != std::string::npos) {
11551160

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

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

20172022
ostr() << std::endl;
20182023

2019-
ostr() << "RcppExport void R_init_" << package() << "(DllInfo *dll) {" << std::endl;
2024+
ostr() << "RcppExport void R_init_" << packageCpp() << "(DllInfo *dll) {" << std::endl;
20202025
ostr() << " R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);" << std::endl;
20212026
ostr() << " R_useDynamicSymbols(dll, FALSE);" << std::endl;
20222027
ostr() << "}" << std::endl;

0 commit comments

Comments
 (0)