Skip to content

Commit ac41f8f

Browse files
unregister Rcpp_eval and register rcpp_get_current_error, reset_current_error and error_occured
1 parent f073064 commit ac41f8f

File tree

10 files changed

+89
-57
lines changed

10 files changed

+89
-57
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 0.10.6.2
3+
Version: 0.10.6.3
44
Date: 2013-11-14
55
Authors@R: c(
6-
person("Dirk", "Eddelbuettel", role = c("aut", "cre"), email = "edd@debian.org" ),
7-
person("Romain", "Francois", role = "aut", email = "romain@r-enthusiasts.com"),
6+
person("Dirk", "Eddelbuettel", role = "aut", email = "edd@debian.org" ),
7+
person("Romain", "Francois", role = c("aut", "cre"), email = "romain@r-enthusiasts.com"),
88
person("JJ", "Allaire", role = "ctb", email = "jj.allaire@gmail.com"),
99
person("John", "Chambers", role = "ctb", email = "jmc@r-project.org"),
1010
person("Douglas", "Bates", role = "ctb", email = "bates@stat.wisc.edu")

inst/include/Rcpp/DataFrame.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ namespace Rcpp{
4747
set_sexp(other) ;
4848
}
4949

50-
template <typename Proxy>
51-
DataFrame_Impl( const GenericProxy<Proxy>& proxy ){
52-
set_sexp( proxy.get() ) ;
53-
}
54-
5550
template <typename T>
5651
DataFrame_Impl( const T& obj ) ;
5752

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (C) 2013 Romain Francois
2+
//
3+
// This file is part of Rcpp.
4+
//
5+
// Rcpp is free software: you can redistribute it and/or modify it
6+
// under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 2 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Rcpp is distributed in the hope that it will be useful, but
11+
// WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#ifndef Rcpp_api_meat_Rcpp_eval_h
19+
#define Rcpp_api_meat_Rcpp_eval_h
20+
21+
namespace Rcpp{
22+
23+
inline SEXP Rcpp_eval(SEXP expr_, SEXP env) {
24+
Shield<SEXP> expr( expr_) ;
25+
26+
reset_current_error() ;
27+
28+
Environment RCPP = Environment::Rcpp_namespace();
29+
SEXP tryCatchSym = ::Rf_install("tryCatch");
30+
SEXP evalqSym = ::Rf_install("evalq");
31+
SEXP conditionMessageSym = ::Rf_install("conditionMessage");
32+
SEXP errorRecorderSym = ::Rf_install(".rcpp_error_recorder");
33+
SEXP errorSym = ::Rf_install("error");
34+
35+
Shield<SEXP> call( Rf_lang3(
36+
tryCatchSym,
37+
Rf_lang3( evalqSym, expr, env ),
38+
errorRecorderSym
39+
) ) ;
40+
SET_TAG( CDDR(call), errorSym ) ;
41+
/* call the tryCatch call */
42+
Shield<SEXP> res(::Rf_eval( call, RCPP ) );
43+
44+
if( error_occured() ) {
45+
Shield<SEXP> current_error ( rcpp_get_current_error() ) ;
46+
Shield<SEXP> conditionMessageCall (::Rf_lang2(conditionMessageSym, current_error)) ;
47+
Shield<SEXP> condition_message (::Rf_eval(conditionMessageCall, R_GlobalEnv)) ;
48+
std::string message(CHAR(::Rf_asChar(condition_message)));
49+
throw eval_error(message) ;
50+
}
51+
52+
return res ;
53+
}
54+
55+
}
56+
57+
#endif

inst/include/Rcpp/api/meat/meat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#ifndef Rcpp_api_meat_meat_h
2323
#define Rcpp_api_meat_meat_h
2424

25+
#include <Rcpp/api/meat/Rcpp_eval.h>
2526
#include <Rcpp/api/meat/Dimension.h>
2627

2728
#include <Rcpp/api/meat/TagProxy.h>

inst/include/Rcpp/routines.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// the idea is that this file should be generated automatically by Rcpp::register
2424

2525
namespace Rcpp{
26-
SEXP Rcpp_eval(SEXP expr, SEXP env = R_GlobalEnv) ;
2726
const char* type2name(SEXP x) ;
2827

2928
namespace internal{
@@ -54,18 +53,15 @@ const char* char_nocheck( SEXP x) ;
5453
void* dataptr(SEXP x) ;
5554
Rcpp::Module* getCurrentScope() ;
5655
void setCurrentScope( Rcpp::Module* mod ) ;
57-
56+
SEXP reset_current_error() ;
57+
int error_occured() ;
58+
SEXP rcpp_get_current_error() ;
59+
5860
#else
5961
namespace Rcpp {
6062

6163
#define GET_CALLABLE(__FUN__) (Fun) R_GetCCallable( "Rcpp", __FUN__ )
6264

63-
inline SEXP Rcpp_eval(SEXP expr, SEXP env = R_GlobalEnv){
64-
typedef SEXP (*Fun)(SEXP,SEXP) ;
65-
static Fun fun = GET_CALLABLE("Rcpp_eval") ;
66-
return fun(expr, env) ;
67-
}
68-
6965
inline const char* type2name(SEXP x){
7066
typedef const char* (*Fun)(SEXP) ;
7167
static Fun fun = GET_CALLABLE("type2name") ;
@@ -221,6 +217,22 @@ inline int* get_cache( int n ){
221217
return fun(n) ;
222218
}
223219

220+
inline SEXP reset_current_error(){
221+
typedef SEXP (*Fun)(void) ;
222+
static Fun fun = GET_CALLABLE("reset_current_error") ;
223+
return fun() ;
224+
}
225+
226+
inline int error_occured(){
227+
typedef int (*Fun)(void) ;
228+
static Fun fun = GET_CALLABLE("error_occured") ;
229+
return fun() ;
230+
}
231+
inline SEXP rcpp_get_current_error(){
232+
typedef SEXP (*Fun)(void) ;
233+
static Fun fun = GET_CALLABLE("rcpp_get_current_error") ;
234+
return fun() ;
235+
}
224236
#endif
225237

226238

inst/include/RcppCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace Rcpp{
8181
#include <Rcpp/sugar/undoRmath.h>
8282

8383
namespace Rcpp{
84+
85+
SEXP Rcpp_eval(SEXP expr_, SEXP env = R_GlobalEnv ) ;
8486
class Module ;
8587

8688
namespace traits{

src/Rcpp_init.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ void registerFunctions(){
8989
#define RCPP_REGISTER(__FUN__) R_RegisterCCallable( "Rcpp", #__FUN__ , (DL_FUNC)__FUN__ );
9090
RCPP_REGISTER(rcpp_get_stack_trace)
9191
RCPP_REGISTER(rcpp_set_stack_trace)
92-
RCPP_REGISTER(Rcpp_eval)
9392
RCPP_REGISTER(type2name)
9493
RCPP_REGISTER(demangle)
9594
RCPP_REGISTER(enterRNGScope)
@@ -113,6 +112,9 @@ void registerFunctions(){
113112
RCPP_REGISTER(short_file_name)
114113
RCPP_REGISTER(mktime00)
115114
RCPP_REGISTER(gmtime_)
115+
RCPP_REGISTER(reset_current_error)
116+
RCPP_REGISTER(error_occured)
117+
RCPP_REGISTER(rcpp_get_current_error)
116118
#undef RCPP_REGISTER
117119
}
118120

src/api.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -82,42 +82,6 @@ namespace Rcpp {
8282

8383
}
8484

85-
// [[Rcpp::register]]
86-
SEXP Rcpp_eval(SEXP expr_, SEXP env) {
87-
Shield<SEXP> expr( expr_) ;
88-
89-
reset_current_error() ;
90-
91-
Environment RCPP = Environment::Rcpp_namespace();
92-
static SEXP tryCatchSym = NULL, evalqSym, conditionMessageSym, errorRecorderSym, errorSym ;
93-
if (!tryCatchSym) {
94-
tryCatchSym = ::Rf_install("tryCatch");
95-
evalqSym = ::Rf_install("evalq");
96-
conditionMessageSym = ::Rf_install("conditionMessage");
97-
errorRecorderSym = ::Rf_install(".rcpp_error_recorder");
98-
errorSym = ::Rf_install("error");
99-
}
100-
101-
Shield<SEXP> call( Rf_lang3(
102-
tryCatchSym,
103-
Rf_lang3( evalqSym, expr, env ),
104-
errorRecorderSym
105-
) ) ;
106-
SET_TAG( CDDR(call), errorSym ) ;
107-
/* call the tryCatch call */
108-
Shield<SEXP> res(::Rf_eval( call, RCPP ) );
109-
110-
if( error_occured() ) {
111-
Shield<SEXP> current_error ( rcpp_get_current_error() ) ;
112-
Shield<SEXP> conditionMessageCall (::Rf_lang2(conditionMessageSym, current_error)) ;
113-
Shield<SEXP> condition_message (::Rf_eval(conditionMessageCall, R_GlobalEnv)) ;
114-
std::string message(CHAR(::Rf_asChar(condition_message)));
115-
throw eval_error(message) ;
116-
}
117-
118-
return res ;
119-
}
120-
12185
// [[Rcpp::register]]
12286
const char * type2name(SEXP x) {
12387
switch (TYPEOF(x)) {

src/barrier.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ SEXP init_Rcpp_cache(){
132132
return cache ;
133133
}
134134

135+
// [[Rcpp::register]]
135136
SEXP reset_current_error(){
136137
SEXP cache = get_rcpp_cache() ;
137138

@@ -147,6 +148,7 @@ SEXP reset_current_error(){
147148
return R_NilValue ;
148149
}
149150

151+
// [[Rcpp::register]]
150152
int error_occured(){
151153
SEXP err = VECTOR_ELT( get_rcpp_cache(), 1 ) ;
152154
return LOGICAL(err)[0] ;
@@ -164,6 +166,7 @@ SEXP rcpp_error_recorder(SEXP e){
164166
return R_NilValue ;
165167
}
166168

169+
// [[Rcpp::register]]
167170
SEXP rcpp_get_current_error(){
168171
return VECTOR_ELT( get_rcpp_cache(), 2 ) ;
169172
}

src/internal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ CALLFUN_2(CppObject__finalize);
114114
CALLFUN_0(get_rcpp_cache);
115115
CALLFUN_0(init_Rcpp_cache);
116116

117-
CALLFUN_0(reset_current_error);
118117
CALLFUN_1(rcpp_error_recorder);
119-
CALLFUN_0(rcpp_get_current_error);
120-
int error_occured() ;
121-
122118
CALLFUN_3(CppField__get);
123119
CALLFUN_4(CppField__set);
124120

0 commit comments

Comments
 (0)