Skip to content

Commit fc24b2c

Browse files
committed
Merge pull request #248 from RcppCore/feature/rngscope-codegen
Simplify generated attributes code for RNGScope
2 parents 9f85b1f + a1270e9 commit fc24b2c

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2015-02-03 JJ Allaire <jj@rstudio.org>
2+
3+
* src/attributes.cpp: Simplify generated attributes code for
4+
RNGScope (use RObject and it's destructor rather than SEXP
5+
protect/unprotect).
6+
* vignettes/Rcpp-package.Rnw: Update docs on generated code.
7+
18
2015-02-03 JJ Allaire <jj@rstudio.org>
29

310
* inst/include/Rcpp/exceptions.h: Add Rcpp::warning function as

inst/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
\itemize{
2121
\item Include pkg_types.h file in RcppExports.cpp if it's present in
2222
inst/include or src.
23+
\item Simplify generated attributes code for \code{RNGScope} (use
24+
\code{RObject} and it's destructor rather than \code{SEXP}
25+
protect/unprotect).
2326
}
2427
}
2528
}

src/attributes.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,40 +2225,34 @@ namespace attributes {
22252225
ostr << args << ") {" << std::endl;
22262226
ostr << "BEGIN_RCPP" << std::endl;
22272227
if (!function.type().isVoid())
2228-
ostr << " SEXP __sexp_result;" << std::endl;
2229-
ostr << " {" << std::endl;
2228+
ostr << " Rcpp::RObject __result;" << std::endl;
22302229
if (!cppInterface)
2231-
ostr << " Rcpp::RNGScope __rngScope;" << std::endl;
2230+
ostr << " Rcpp::RNGScope __rngScope;" << std::endl;
22322231
for (size_t i = 0; i<arguments.size(); i++) {
22332232
const Argument& argument = arguments[i];
22342233

2235-
ostr << " Rcpp::traits::input_parameter< "
2234+
ostr << " Rcpp::traits::input_parameter< "
22362235
<< argument.type().full_name() << " >::type " << argument.name()
2237-
<< "(" << argument.name() << "SEXP );" << std::endl;
2236+
<< "(" << argument.name() << "SEXP);" << std::endl;
22382237
}
22392238

2240-
ostr << " ";
2239+
ostr << " ";
22412240
if (!function.type().isVoid())
2242-
ostr << function.type() << " __result = ";
2241+
ostr << "__result = Rcpp::wrap(";
22432242
ostr << function.name() << "(";
22442243
for (size_t i = 0; i<arguments.size(); i++) {
22452244
const Argument& argument = arguments[i];
22462245
ostr << argument.name();
22472246
if (i != (arguments.size()-1))
22482247
ostr << ", ";
22492248
}
2249+
if (!function.type().isVoid())
2250+
ostr << ")";
22502251
ostr << ");" << std::endl;
22512252

22522253
if (!function.type().isVoid())
22532254
{
2254-
ostr << " PROTECT(__sexp_result = Rcpp::wrap(__result));"
2255-
<< std::endl;
2256-
}
2257-
ostr << " }" << std::endl;
2258-
if (!function.type().isVoid())
2259-
{
2260-
ostr << " UNPROTECT(1);" << std::endl;
2261-
ostr << " return __sexp_result;" << std::endl;
2255+
ostr << " return __result;" << std::endl;
22622256
}
22632257
else
22642258
{

vignettes/Rcpp-package.Rnw

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,10 @@ using namespace Rcpp;
183183
List rcpp_hello_world();
184184
RcppExport SEXP mypackage_rcpp_hello_world() {
185185
BEGIN_RCPP
186-
SEXP __sexp_result;
187-
{
188-
Rcpp::RNGScope __rngScope;
189-
List __result = rcpp_hello_world();
190-
PROTECT(__sexp_result = Rcpp::wrap(__result));
191-
}
192-
UNPROTECT(1);
193-
return __sexp_result;
186+
Rcpp::RObject __result;
187+
Rcpp::RNGScope __rngScope;
188+
__result = Rcpp::wrap(rcpp_hello_world());
189+
return __result;
194190
END_RCPP
195191
}
196192
@

0 commit comments

Comments
 (0)