Skip to content

Commit f1fdc92

Browse files
authored
Merge pull request #725 from RcppCore/feature/native-routine-export-prefix
Generate C++ native routines with underscore prefix
2 parents 44905f3 + e0f95a5 commit f1fdc92

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2017-06-02 JJ Allaire <[email protected]>
2+
3+
* src/attributes.cpp: Generate C++ native routines with underscore
4+
prefix to avoid export when standard exportPattern is used in NAMESPACE
5+
16
2017-06-29 JJ Allaire <[email protected]>
27

38
* src/attributes.cpp: Replace dot (".") with underscore ("_") in package

inst/NEWS.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
\itemize{
1010
\item The \code{tinyformat.h} header now ends in a newline (\ghit{701}).
1111
\item Fixed rare protection error that occurred when fetching stack traces
12-
during the construction of an Rcpp exception (Kirill Müller;
12+
during the construction of an Rcpp exception (Kirill Müller;
1313
\ghit{706}).
1414
\item Compilation is now also possibly on Haiku-OS (Yo Gong in \ghpr{708}
1515
addressing \ghit{707}).
@@ -31,6 +31,8 @@
3131
addressing \ghit{712}).
3232
\item Replace dot (".") with underscore ("_") in package names when generating
3333
native routine registrations (fixes \ghit{721}).
34+
\item Generate C++ native routines with underscore ("_") prefix to avoid
35+
exporting when standard exportPattern is used in NAMESPACE
3436
}
3537
}
3638
}

src/attributes.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ namespace attributes {
578578
const std::string& targetFile() const { return targetFile_; }
579579
const std::string& package() const { return package_; }
580580
const std::string& packageCpp() const { return packageCpp_; }
581+
const std::string packageCppPrefix() const { return "_" + packageCpp(); }
581582

582583
// Abstract interface for code generation
583584
virtual void writeBegin() = 0;
@@ -611,10 +612,10 @@ namespace attributes {
611612
return "RcppExport_validate";
612613
}
613614
std::string exportValidationFunctionRegisteredName() {
614-
return packageCpp() + "_" + exportValidationFunction();
615+
return packageCppPrefix() + "_" + exportValidationFunction();
615616
}
616617
std::string registerCCallableExportedName() { // #nocov
617-
return packageCpp() + "_RcppExport_registerCCallable"; // #nocov
618+
return packageCppPrefix() + "_RcppExport_registerCCallable"; // #nocov
618619
}
619620

620621
// Commit the stream -- is a no-op if the existing code is identical
@@ -1822,7 +1823,7 @@ namespace attributes {
18221823
// write header/preamble
18231824
std::ostringstream headerStream;
18241825
headerStream << commentPrefix_ << " Generated by using "
1825-
<< "Rcpp::compileAttributes()"
1826+
<< "Rcpp::compileAttributes()"
18261827
<< " -> do not edit by hand" << std::endl;
18271828
headerStream << commentPrefix_ << " Generator token: "
18281829
<< generatorToken() << std::endl << std::endl;
@@ -1872,7 +1873,7 @@ namespace attributes {
18721873
attributes,
18731874
true,
18741875
attributes.hasInterface(kInterfaceCpp),
1875-
packageCpp());
1876+
packageCppPrefix());
18761877

18771878
// track cppExports, signatures, and native routines (we use these
18781879
// at the end to generate the ValidateSignature and RegisterCCallable
@@ -1973,7 +1974,7 @@ namespace attributes {
19731974
std::vector<std::size_t> routineArgs;
19741975
for (std::size_t i=0;i<nativeRoutines_.size(); i++) {
19751976
const Attribute& attr = nativeRoutines_[i];
1976-
routineNames.push_back(packageCpp() + "_" + attr.function().name());
1977+
routineNames.push_back(packageCppPrefix() + "_" + attr.function().name());
19771978
routineArgs.push_back(attr.function().arguments().size());
19781979
}
19791980
std::string kRcppModuleBoot = "_rcpp_module_boot_";
@@ -2035,8 +2036,8 @@ namespace attributes {
20352036
std::ostringstream ostr;
20362037
std::string indentStr(indent, ' ');
20372038
ostr << indentStr << "R_RegisterCCallable(\"" << package() << "\", "
2038-
<< "\"" << packageCpp() << "_" << exportedName << "\", "
2039-
<< "(DL_FUNC)" << packageCpp() << "_" << name << ");";
2039+
<< "\"" << packageCppPrefix() << "_" << exportedName << "\", "
2040+
<< "(DL_FUNC)" << packageCppPrefix() << "_" << name << ");";
20402041
return ostr.str(); // #nocov end
20412042
}
20422043

@@ -2166,7 +2167,7 @@ namespace attributes {
21662167
<< std::endl;
21672168
ostr() << " " << ptrName << " = "
21682169
<< "(" << fnType << ")"
2169-
<< getCCallable(packageCpp() + "_" + function.name()) << ";"
2170+
<< getCCallable(packageCppPrefix() + "_" + function.name()) << ";"
21702171
<< std::endl;
21712172
ostr() << " }" << std::endl;
21722173
ostr() << " RObject rcpp_result_gen;" << std::endl;
@@ -2377,9 +2378,13 @@ namespace attributes {
23772378
ostr() << ".Call(";
23782379
if (!registration_)
23792380
ostr() << "'";
2380-
ostr() << packageCpp() << "_" << function.name();
2381+
else
2382+
ostr() << "`";
2383+
ostr() << packageCppPrefix() << "_" << function.name();
23812384
if (!registration_)
23822385
ostr() << "', " << "PACKAGE = '" << package() << "'";
2386+
else
2387+
ostr() << "`";
23832388

23842389
// add arguments
23852390
const std::vector<Argument>& arguments = function.arguments();
@@ -2973,8 +2978,8 @@ namespace {
29732978
public:
29742979
SourceCppDynlib() {}
29752980

2976-
SourceCppDynlib(const std::string& cacheDir,
2977-
const std::string& cppSourcePath,
2981+
SourceCppDynlib(const std::string& cacheDir,
2982+
const std::string& cppSourcePath,
29782983
Rcpp::List platform)
29792984
: cppSourcePath_(cppSourcePath)
29802985

@@ -3336,7 +3341,7 @@ namespace {
33363341
Rcpp::Function dynlibLookupFunc = rcppEnv[".sourceCppDynlibLookup"];
33373342
Rcpp::List dynlibList = dynlibLookupFunc(cacheDir, file, code);
33383343
if (dynlibList.length() > 0)
3339-
return SourceCppDynlib(dynlibList);
3344+
return SourceCppDynlib(dynlibList);
33403345
else
33413346
return SourceCppDynlib();
33423347
}

0 commit comments

Comments
 (0)