Skip to content

Commit

Permalink
Generate C++ native routines with underscore prefix
Browse files Browse the repository at this point in the history
Avoid export from package when standard [[ alpha ]] exportPattern is used in NAMESPACE
  • Loading branch information
jjallaire committed Jul 2, 2017
1 parent 44905f3 commit e0f95a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
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 <[email protected]>

* src/attributes.cpp: Generate C++ native routines with underscore
prefix to avoid export when standard exportPattern is used in NAMESPACE

2017-06-29 JJ Allaire <[email protected]>

* src/attributes.cpp: Replace dot (".") with underscore ("_") in package
Expand Down
4 changes: 3 additions & 1 deletion inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
\itemize{
\item The \code{tinyformat.h} header now ends in a newline (\ghit{701}).
\item Fixed rare protection error that occurred when fetching stack traces
during the construction of an Rcpp exception (Kirill Müller;
during the construction of an Rcpp exception (Kirill Müller;
\ghit{706}).
\item Compilation is now also possibly on Haiku-OS (Yo Gong in \ghpr{708}
addressing \ghit{707}).
Expand All @@ -31,6 +31,8 @@
addressing \ghit{712}).
\item Replace dot (".") with underscore ("_") in package names when generating
native routine registrations (fixes \ghit{721}).
\item Generate C++ native routines with underscore ("_") prefix to avoid
exporting when standard exportPattern is used in NAMESPACE
}
}
}
Expand Down
29 changes: 17 additions & 12 deletions src/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ namespace attributes {
const std::string& targetFile() const { return targetFile_; }
const std::string& package() const { return package_; }
const std::string& packageCpp() const { return packageCpp_; }
const std::string packageCppPrefix() const { return "_" + packageCpp(); }

// Abstract interface for code generation
virtual void writeBegin() = 0;
Expand Down Expand Up @@ -611,10 +612,10 @@ namespace attributes {
return "RcppExport_validate";
}
std::string exportValidationFunctionRegisteredName() {
return packageCpp() + "_" + exportValidationFunction();
return packageCppPrefix() + "_" + exportValidationFunction();
}
std::string registerCCallableExportedName() { // #nocov
return packageCpp() + "_RcppExport_registerCCallable"; // #nocov
return packageCppPrefix() + "_RcppExport_registerCCallable"; // #nocov
}

// Commit the stream -- is a no-op if the existing code is identical
Expand Down Expand Up @@ -1822,7 +1823,7 @@ namespace attributes {
// write header/preamble
std::ostringstream headerStream;
headerStream << commentPrefix_ << " Generated by using "
<< "Rcpp::compileAttributes()"
<< "Rcpp::compileAttributes()"
<< " -> do not edit by hand" << std::endl;
headerStream << commentPrefix_ << " Generator token: "
<< generatorToken() << std::endl << std::endl;
Expand Down Expand Up @@ -1872,7 +1873,7 @@ namespace attributes {
attributes,
true,
attributes.hasInterface(kInterfaceCpp),
packageCpp());
packageCppPrefix());

// track cppExports, signatures, and native routines (we use these
// at the end to generate the ValidateSignature and RegisterCCallable
Expand Down Expand Up @@ -1973,7 +1974,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(packageCpp() + "_" + attr.function().name());
routineNames.push_back(packageCppPrefix() + "_" + attr.function().name());
routineArgs.push_back(attr.function().arguments().size());
}
std::string kRcppModuleBoot = "_rcpp_module_boot_";
Expand Down Expand Up @@ -2035,8 +2036,8 @@ namespace attributes {
std::ostringstream ostr;
std::string indentStr(indent, ' ');
ostr << indentStr << "R_RegisterCCallable(\"" << package() << "\", "
<< "\"" << packageCpp() << "_" << exportedName << "\", "
<< "(DL_FUNC)" << packageCpp() << "_" << name << ");";
<< "\"" << packageCppPrefix() << "_" << exportedName << "\", "
<< "(DL_FUNC)" << packageCppPrefix() << "_" << name << ");";
return ostr.str(); // #nocov end
}

Expand Down Expand Up @@ -2166,7 +2167,7 @@ namespace attributes {
<< std::endl;
ostr() << " " << ptrName << " = "
<< "(" << fnType << ")"
<< getCCallable(packageCpp() + "_" + function.name()) << ";"
<< getCCallable(packageCppPrefix() + "_" + function.name()) << ";"
<< std::endl;
ostr() << " }" << std::endl;
ostr() << " RObject rcpp_result_gen;" << std::endl;
Expand Down Expand Up @@ -2377,9 +2378,13 @@ namespace attributes {
ostr() << ".Call(";
if (!registration_)
ostr() << "'";
ostr() << packageCpp() << "_" << function.name();
else
ostr() << "`";
ostr() << packageCppPrefix() << "_" << function.name();
if (!registration_)
ostr() << "', " << "PACKAGE = '" << package() << "'";
else
ostr() << "`";

// add arguments
const std::vector<Argument>& arguments = function.arguments();
Expand Down Expand Up @@ -2973,8 +2978,8 @@ namespace {
public:
SourceCppDynlib() {}

SourceCppDynlib(const std::string& cacheDir,
const std::string& cppSourcePath,
SourceCppDynlib(const std::string& cacheDir,
const std::string& cppSourcePath,
Rcpp::List platform)
: cppSourcePath_(cppSourcePath)

Expand Down Expand Up @@ -3336,7 +3341,7 @@ namespace {
Rcpp::Function dynlibLookupFunc = rcppEnv[".sourceCppDynlibLookup"];
Rcpp::List dynlibList = dynlibLookupFunc(cacheDir, file, code);
if (dynlibList.length() > 0)
return SourceCppDynlib(dynlibList);
return SourceCppDynlib(dynlibList);
else
return SourceCppDynlib();
}
Expand Down

0 comments on commit e0f95a5

Please sign in to comment.