Skip to content
This repository was archived by the owner on Nov 11, 2018. It is now read-only.

Commit db740a7

Browse files
cleanups
1 parent c7da957 commit db740a7

3 files changed

Lines changed: 39 additions & 43 deletions

File tree

src/api.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,9 @@ namespace Rcpp {
8787
/* call the tryCatch call */
8888
SEXP res = PROTECT(::Rf_eval( call, RCPP ) );
8989

90-
/* was there an error ? */
91-
int error = INTEGER( rcpp_get_error_occured())[0] ;
92-
9390
UNPROTECT(3) ;
9491

95-
if( error ) {
92+
if( error_occured() ) {
9693
SEXP current_error = PROTECT( rcpp_get_current_error() ) ;
9794
SEXP conditionMessageCall = PROTECT(::Rf_lang2(conditionMessageSym, current_error)) ;
9895
SEXP condition_message = PROTECT(::Rf_eval(conditionMessageCall, R_GlobalEnv)) ;

src/barrier.cpp

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ static SEXP Rcpp_cache = R_NilValue ;
6262
#define RCPP_HASH_CACHE_INITIAL_SIZE 1024
6363
#endif
6464

65-
SEXP reset_current_error__(SEXP) ;
66-
6765
namespace Rcpp {
6866
namespace internal {
6967
SEXP get_Rcpp_namespace(){
@@ -86,14 +84,35 @@ SEXP get_rcpp_cache() {
8684
return Rcpp_cache ;
8785
}
8886

87+
SEXP set_error_occured(SEXP cache, SEXP e){
88+
SET_VECTOR_ELT( cache, 1, e ) ;
89+
return R_NilValue ;
90+
}
91+
92+
SEXP set_current_error(SEXP cache, SEXP e){
93+
SET_VECTOR_ELT( cache, 2, e ) ;
94+
return R_NilValue ;
95+
}
96+
97+
SEXP rcpp_set_stack_trace(SEXP e){
98+
SET_VECTOR_ELT( get_rcpp_cache(), 3, e ) ;
99+
return R_NilValue ;
100+
}
101+
102+
SEXP rcpp_get_stack_trace(){
103+
return VECTOR_ELT( get_rcpp_cache(), 3 ) ;
104+
}
105+
89106
SEXP init_Rcpp_cache(){
90107
SEXP getNamespaceSym = Rf_install("getNamespace"); // cannot be gc()'ed once in symbol table
91108
SEXP RCPP = PROTECT( Rf_eval(Rf_lang2( getNamespaceSym, Rf_mkString("Rcpp") ), R_GlobalEnv) ) ;
92109
SEXP cache = PROTECT( Rf_allocVector( VECSXP, RCPP_CACHE_SIZE ) );
93110

94111
// the Rcpp namespace
95112
SET_VECTOR_ELT( cache, 0, RCPP ) ;
96-
reset_current_error__(cache) ;
113+
set_error_occured( cache, Rf_ScalarLogical(FALSE) ) ; // error occured
114+
set_current_error( cache, R_NilValue ) ; // current error
115+
SET_VECTOR_ELT( cache, 3, R_NilValue ) ; // stack trace
97116
SET_VECTOR_ELT( cache, RCPP_HASH_CACHE_INDEX, Rf_allocVector(INTSXP, RCPP_HASH_CACHE_INITIAL_SIZE) ) ;
98117

99118
Rf_defineVar( Rf_install(".rcpp_cache"), cache, RCPP );
@@ -102,60 +121,42 @@ SEXP init_Rcpp_cache(){
102121
return cache ;
103122
}
104123

105-
SEXP reset_current_error__(SEXP cache){
124+
SEXP reset_current_error(){
125+
SEXP cache = get_rcpp_cache() ;
106126

107-
SET_VECTOR_ELT( cache, 1, Rf_ScalarLogical(FALSE) ) ;
127+
// error occured
128+
set_error_occured( cache, Rf_ScalarLogical(FALSE) ) ;
108129

109130
// current error
110-
SET_VECTOR_ELT( cache, 2, R_NilValue ) ;
131+
set_current_error( cache, R_NilValue ) ;
111132

112133
// stack trace
113134
SET_VECTOR_ELT( cache, 3, R_NilValue ) ;
114135

115136
return R_NilValue ;
116137
}
117-
SEXP reset_current_error(){ return reset_current_error__( get_rcpp_cache() ) ; }
118138

119-
SEXP rcpp_error_recorder(SEXP e, SEXP cache){
139+
int error_occured(){
140+
SEXP err = VECTOR_ELT( get_rcpp_cache(), 1 ) ;
141+
return LOGICAL(err)[0] ;
142+
}
143+
144+
SEXP rcpp_error_recorder(SEXP e){
145+
SEXP cache = get_rcpp_cache() ;
146+
120147
// error occured
121-
SET_VECTOR_ELT( cache, 1, Rf_ScalarLogical(TRUE) ) ;
148+
set_error_occured( cache, Rf_ScalarLogical(TRUE) ) ;
122149

123150
// current error
124-
rcpp_set_current_error(e ) ;
151+
set_current_error(cache, e ) ;
125152

126153
return R_NilValue ;
127-
128154
}
129-
SEXP rcpp_error_recorder(SEXP e){ return rcpp_error_recorder(e, get_rcpp_cache() ) ;}
130-
131-
SEXP rcpp_set_current_error(SEXP e, SEXP cache){
132-
SET_VECTOR_ELT( cache, 2, e ) ;
133-
return R_NilValue ;
134-
}
135-
SEXP rcpp_set_current_error(SEXP e){ return rcpp_set_current_error(e, get_rcpp_cache() ) ; }
136155

137156
SEXP rcpp_get_current_error(){
138157
return VECTOR_ELT( get_rcpp_cache(), 2 ) ;
139158
}
140159

141-
SEXP rcpp_set_error_occured(SEXP e){
142-
SET_VECTOR_ELT( get_rcpp_cache(), 1, e ) ;
143-
return R_NilValue ;
144-
}
145-
146-
SEXP rcpp_get_error_occured(){
147-
return VECTOR_ELT( get_rcpp_cache(), 1 ) ;
148-
}
149-
150-
SEXP rcpp_set_stack_trace(SEXP e){
151-
SET_VECTOR_ELT( get_rcpp_cache(), 3, e ) ;
152-
return R_NilValue ;
153-
}
154-
155-
SEXP rcpp_get_stack_trace(){
156-
return VECTOR_ELT( get_rcpp_cache(), 3 ) ;
157-
}
158-
159160
int* get_cache( int m){
160161
SEXP cache = get_rcpp_cache() ;
161162
SEXP hash_cache = VECTOR_ELT( cache, RCPP_HASH_CACHE_INDEX) ;

src/internal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,8 @@ extern "C" {
6363

6464
CALLFUN_0(reset_current_error);
6565
CALLFUN_1(rcpp_error_recorder);
66-
CALLFUN_1(rcpp_set_current_error);
6766
CALLFUN_0(rcpp_get_current_error);
68-
CALLFUN_1(rcpp_set_error_occured);
69-
CALLFUN_0(rcpp_get_error_occured);
67+
int error_occured() ;
7068
CALLFUN_1(rcpp_set_stack_trace);
7169
CALLFUN_0(rcpp_get_stack_trace);
7270

0 commit comments

Comments
 (0)