Skip to content

Commit d11bb36

Browse files
correct enter/exit RNG code
1 parent f76c473 commit d11bb36

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

inst/include/Rcpp/routines.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ namespace Rcpp{
2626
SEXP Rcpp_eval(SEXP expr, SEXP env = R_GlobalEnv) ;
2727
const char* type2name(SEXP x) ;
2828
std::string demangle( const std::string& name) ;
29-
unsigned long enterRNGScope();
30-
unsigned long exitRNGScope() ;
29+
30+
namespace internal{
31+
unsigned long enterRNGScope();
32+
unsigned long exitRNGScope() ;
33+
}
3134
SEXP get_Rcpp_namespace() ;
3235
int* get_cache( int n ) ;
3336
SEXP rcpp_get_stack_trace() ;
@@ -82,11 +85,13 @@ namespace Rcpp {
8285
static Fun fun = GET_CALLABLE("demangle") ;
8386
return fun(name) ;
8487
}
85-
86-
inline unsigned long enterRNGScope(){
87-
typedef unsigned long (*Fun)(void) ;
88-
static Fun fun = GET_CALLABLE("enterRNGScope") ;
89-
return fun() ;
88+
89+
namespace internal{
90+
inline unsigned long enterRNGScope(){
91+
typedef unsigned long (*Fun)(void) ;
92+
static Fun fun = GET_CALLABLE("enterRNGScope") ;
93+
return fun() ;
94+
}
9095
}
9196

9297
inline unsigned long exitRNGScope(){

inst/include/Rcpp/stats/random/random.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#define Rcpp__stats__random_random_h
2424

2525
namespace Rcpp{
26-
namespace internal {
27-
void enterRNGScope();
28-
void exitRNGScope();
29-
}
3026

3127
class RNGScope{
3228
public:

src/api.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ namespace Rcpp {
6161
}
6262

6363
// [[Rcpp::register]]
64-
void enterRNGScope() {
64+
unsigned long enterRNGScope() {
6565
if (RNGScopeCounter == 0) GetRNGstate();
6666
RNGScopeCounter++;
67+
return RNGScopeCounter ;
6768
}
6869

6970
// [[Rcpp::register]]
70-
void exitRNGScope() {
71+
unsigned long exitRNGScope() {
7172
RNGScopeCounter--;
7273
if (RNGScopeCounter == 0) PutRNGstate();
74+
return RNGScopeCounter ;
7375
}
7476

7577
// [[Rcpp::register]]

0 commit comments

Comments
 (0)