Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2018-02-26 Kevin Ushey <kevinushey@gmail.com>

* src/api.cpp: Always set / put RNG state when calling Rcpp function


2018-02-25 Dirk Eddelbuettel <edd@debian.org>

* vignettes/Rcpp.bib: Updated
Expand Down
5 changes: 5 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
\section{Changes in Rcpp version 0.12.16 (2018-03-xx)}{
\itemize{
\item Changes in Rcpp API:
\itemize{
\item Rcpp now sets and puts the RNG state upon each entry to an Rcpp
function, ensuring that nested invocations of Rcpp functions manage the
RNG state as expected
}
\itemize{
\item The \code{long long} type can now be used on 64-bit Windows (Kevin
in \ghpr{811})
Expand Down
13 changes: 4 additions & 9 deletions src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,17 @@ using namespace Rcpp;
namespace Rcpp {

namespace internal {
namespace {
unsigned long RNGScopeCounter = 0;
}

// [[Rcpp::register]]
unsigned long enterRNGScope() {
if (RNGScopeCounter == 0) GetRNGstate();
RNGScopeCounter++;
return RNGScopeCounter;
GetRNGstate();
return 0;
}

// [[Rcpp::register]]
unsigned long exitRNGScope() {
RNGScopeCounter--;
if (RNGScopeCounter == 0) PutRNGstate();
return RNGScopeCounter;
PutRNGstate();
return 0;
}

// [[Rcpp::register]]
Expand Down