Skip to content

Commit fc65e7e

Browse files
attempt to put functions back in the namespace they were in previous versions. related to #63
1 parent 6485dc0 commit fc65e7e

File tree

10 files changed

+146
-142
lines changed

10 files changed

+146
-142
lines changed

inst/include/Rcpp/Environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace Rcpp{
307307
* @return the Rcpp namespace
308308
*/
309309
static Environment_Impl Rcpp_namespace(){
310-
return Rcpp::get_Rcpp_namespace() ;
310+
return Rcpp::internal::get_Rcpp_namespace() ;
311311
}
312312

313313
/**

inst/include/Rcpp/exceptions.h

Lines changed: 74 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -123,82 +123,84 @@ namespace Rcpp{
123123
#undef RCPP_EXCEPTION_CLASS
124124
#undef RCPP_SIMPLE_EXCEPTION_CLASS
125125

126-
inline SEXP get_last_call(){
127-
SEXP sys_calls_symbol = Rf_install( "sys.calls" ) ;
128-
Shield<SEXP> sys_calls_expr( Rf_lang1(sys_calls_symbol) );
129-
Shield<SEXP> calls( Rf_eval( sys_calls_expr, R_GlobalEnv ) );
130-
SEXP res = calls ;
131-
while( !Rf_isNull(CDR(res)) ) res = CDR(res);
132-
return CAR(res) ;
133-
}
134-
135-
inline SEXP get_exception_classes( const std::string& ex_class) {
136-
Shield<SEXP> res( Rf_allocVector( STRSXP, 4 ) );
137-
SET_STRING_ELT( res, 0, Rf_mkChar( ex_class.c_str() ) ) ;
138-
SET_STRING_ELT( res, 1, Rf_mkChar( "C++Error" ) ) ;
139-
SET_STRING_ELT( res, 2, Rf_mkChar( "error" ) ) ;
140-
SET_STRING_ELT( res, 3, Rf_mkChar( "condition" ) ) ;
141-
return res;
142-
}
143126

144-
inline SEXP make_condition(const std::string& ex_msg, SEXP call, SEXP cppstack, SEXP classes){
145-
Shield<SEXP> res( Rf_allocVector( VECSXP, 3 ) ) ;
146-
147-
SET_VECTOR_ELT( res, 0, Rf_mkString( ex_msg.c_str() ) ) ;
148-
SET_VECTOR_ELT( res, 1, call ) ;
149-
SET_VECTOR_ELT( res, 2, cppstack ) ;
150-
151-
Shield<SEXP> names( Rf_allocVector( STRSXP, 3 ) );
152-
SET_STRING_ELT( names, 0, Rf_mkChar( "message" ) ) ;
153-
SET_STRING_ELT( names, 1, Rf_mkChar( "call" ) ) ;
154-
SET_STRING_ELT( names, 2, Rf_mkChar( "cppstack" ) ) ;
155-
Rf_setAttrib( res, R_NamesSymbol, names ) ;
156-
Rf_setAttrib( res, R_ClassSymbol, classes ) ;
157-
return res ;
158-
}
159-
160-
inline SEXP exception_to_r_condition( const std::exception& ex){
161-
std::string ex_class = demangle( typeid(ex).name() ) ;
162-
std::string ex_msg = ex.what() ;
163-
164-
Shield<SEXP> cppstack( rcpp_get_stack_trace() );
165-
Shield<SEXP> call( get_last_call() );
166-
Shield<SEXP> classes( get_exception_classes(ex_class) );
167-
Shield<SEXP> condition( make_condition( ex_msg, call, cppstack, classes) );
168-
rcpp_set_stack_trace( R_NilValue ) ;
169-
return condition ;
170-
}
171-
172-
inline void forward_exception_to_r( const std::exception& ex){
173-
SEXP stop_sym = Rf_install( "stop" ) ;
174-
Shield<SEXP> condition( exception_to_r_condition(ex) );
175-
Shield<SEXP> expr( Rf_lang2( stop_sym , condition ) ) ;
176-
Rf_eval( expr, R_GlobalEnv ) ;
177-
}
178-
179-
inline SEXP string_to_try_error( const std::string& str){
180-
using namespace Rcpp;
181-
182-
Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install("simpleError"), Rf_mkString(str.c_str())) );
183-
Shield<SEXP> simpleError( Rf_eval(simpleErrorExpr, R_GlobalEnv) );
184-
Shield<SEXP> tryError( Rf_mkString( str.c_str() ) );
185-
Rf_setAttrib( tryError, R_ClassSymbol, Rf_mkString("try-error") ) ;
186-
Rf_setAttrib( tryError, Rf_install( "condition") , simpleError ) ;
187-
188-
return tryError;
189-
}
127+
} // namespace Rcpp
128+
129+
inline SEXP get_last_call(){
130+
SEXP sys_calls_symbol = Rf_install( "sys.calls" ) ;
131+
Rcpp::Shield<SEXP> sys_calls_expr( Rf_lang1(sys_calls_symbol) );
132+
Rcpp::Shield<SEXP> calls( Rf_eval( sys_calls_expr, R_GlobalEnv ) );
133+
SEXP res = calls ;
134+
while( !Rf_isNull(CDR(res)) ) res = CDR(res);
135+
return CAR(res) ;
136+
}
137+
138+
inline SEXP get_exception_classes( const std::string& ex_class) {
139+
Rcpp::Shield<SEXP> res( Rf_allocVector( STRSXP, 4 ) );
140+
SET_STRING_ELT( res, 0, Rf_mkChar( ex_class.c_str() ) ) ;
141+
SET_STRING_ELT( res, 1, Rf_mkChar( "C++Error" ) ) ;
142+
SET_STRING_ELT( res, 2, Rf_mkChar( "error" ) ) ;
143+
SET_STRING_ELT( res, 3, Rf_mkChar( "condition" ) ) ;
144+
return res;
145+
}
146+
147+
inline SEXP make_condition(const std::string& ex_msg, SEXP call, SEXP cppstack, SEXP classes){
148+
Rcpp::Shield<SEXP> res( Rf_allocVector( VECSXP, 3 ) ) ;
149+
150+
SET_VECTOR_ELT( res, 0, Rf_mkString( ex_msg.c_str() ) ) ;
151+
SET_VECTOR_ELT( res, 1, call ) ;
152+
SET_VECTOR_ELT( res, 2, cppstack ) ;
153+
154+
Rcpp::Shield<SEXP> names( Rf_allocVector( STRSXP, 3 ) );
155+
SET_STRING_ELT( names, 0, Rf_mkChar( "message" ) ) ;
156+
SET_STRING_ELT( names, 1, Rf_mkChar( "call" ) ) ;
157+
SET_STRING_ELT( names, 2, Rf_mkChar( "cppstack" ) ) ;
158+
Rf_setAttrib( res, R_NamesSymbol, names ) ;
159+
Rf_setAttrib( res, R_ClassSymbol, classes ) ;
160+
return res ;
161+
}
162+
163+
inline SEXP exception_to_r_condition( const std::exception& ex){
164+
std::string ex_class = demangle( typeid(ex).name() ) ;
165+
std::string ex_msg = ex.what() ;
166+
167+
Rcpp::Shield<SEXP> cppstack( rcpp_get_stack_trace() );
168+
Rcpp::Shield<SEXP> call( get_last_call() );
169+
Rcpp::Shield<SEXP> classes( get_exception_classes(ex_class) );
170+
Rcpp::Shield<SEXP> condition( make_condition( ex_msg, call, cppstack, classes) );
171+
rcpp_set_stack_trace( R_NilValue ) ;
172+
return condition ;
173+
}
174+
175+
inline SEXP string_to_try_error( const std::string& str){
176+
using namespace Rcpp;
190177

191-
inline SEXP exception_to_try_error( const std::exception& ex){
192-
return string_to_try_error(ex.what());
193-
}
178+
Rcpp::Shield<SEXP> simpleErrorExpr( Rf_lang2(::Rf_install("simpleError"), Rf_mkString(str.c_str())) );
179+
Rcpp::Shield<SEXP> simpleError( Rf_eval(simpleErrorExpr, R_GlobalEnv) );
180+
Rcpp::Shield<SEXP> tryError( Rf_mkString( str.c_str() ) );
181+
Rf_setAttrib( tryError, R_ClassSymbol, Rf_mkString("try-error") ) ;
182+
Rf_setAttrib( tryError, Rf_install( "condition") , simpleError ) ;
194183

195-
std::string demangle( const std::string& name) ;
196-
#define DEMANGLE(__TYPE__) demangle( typeid(__TYPE__).name() ).c_str()
184+
return tryError;
185+
}
186+
187+
inline SEXP exception_to_try_error( const std::exception& ex){
188+
return string_to_try_error(ex.what());
189+
}
190+
191+
std::string demangle( const std::string& name) ;
192+
#define DEMANGLE(__TYPE__) demangle( typeid(__TYPE__).name() ).c_str()
197193

198-
inline void stop(const std::string& message) {
199-
throw Rcpp::exception(message.c_str());
200-
}
194+
inline void stop(const std::string& message) {
195+
throw Rcpp::exception(message.c_str());
196+
}
197+
198+
inline void forward_exception_to_r( const std::exception& ex){
199+
SEXP stop_sym = Rf_install( "stop" ) ;
200+
Rcpp::Shield<SEXP> condition( exception_to_r_condition(ex) );
201+
Rcpp::Shield<SEXP> expr( Rf_lang2( stop_sym , condition ) ) ;
202+
Rf_eval( expr, R_GlobalEnv ) ;
203+
}
201204

202-
} // namespace Rcpp
203205

204206
#endif

inst/include/Rcpp/macros/macros.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
#endif
3232

3333
#ifndef VOID_END_RCPP
34-
#define VOID_END_RCPP } catch( std::exception& __ex__ ){ Rcpp::forward_exception_to_r( __ex__ ) ; } catch(...){ ::Rf_error( "c++ exception (unknown reason)" ) ; }
34+
#define VOID_END_RCPP } catch( std::exception& __ex__ ){ forward_exception_to_r( __ex__ ) ; } catch(...){ ::Rf_error( "c++ exception (unknown reason)" ) ; }
3535
#endif
3636

3737
#ifndef END_RCPP
3838
#define END_RCPP VOID_END_RCPP return R_NilValue;
3939
#endif
4040

4141
#ifndef END_RCPP_RETURN_ERROR
42-
#define END_RCPP_RETURN_ERROR } catch( std::exception& __ex__ ){ return Rcpp::exception_to_try_error( __ex__ ) ; } catch(...){ return Rcpp::string_to_try_error( "c++ exception (unknown reason)" ) ; } return R_NilValue;
42+
#define END_RCPP_RETURN_ERROR } catch( std::exception& __ex__ ){ return exception_to_try_error( __ex__ ) ; } catch(...){ return string_to_try_error( "c++ exception (unknown reason)" ) ; } return R_NilValue;
4343
#endif
4444

4545
#define Rcpp_error(MESSAGE) throw Rcpp::exception( MESSAGE, __FILE__, __LINE__ )

inst/include/Rcpp/module/Module_generated_Constructor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// Module_generated_Constructor.h: Rcpp R/C++ interface class library -- Rcpp modules
44
//
5-
// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -34,7 +34,7 @@ template <typename Class>
3434
class Constructor_0 : public Constructor_Base<Class>{
3535
public:
3636
virtual Class* get_new( SEXP* args, int nargs ){
37-
return new Class() ;
37+
return new Class() ;
3838
}
3939
virtual int nargs(){ return 0 ; }
4040
virtual void signature(std::string& s, const std::string& class_name ){

inst/include/Rcpp/routines.h

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@
2525
namespace Rcpp{
2626
SEXP Rcpp_eval(SEXP expr, SEXP env = R_GlobalEnv) ;
2727
const char* type2name(SEXP x) ;
28-
std::string demangle( const std::string& name) ;
2928

3029
namespace internal{
3130
unsigned long enterRNGScope();
3231
unsigned long exitRNGScope() ;
3332
char* get_string_buffer() ;
33+
SEXP get_Rcpp_namespace() ;
3434
}
35-
SEXP get_Rcpp_namespace() ;
36-
SEXP rcpp_get_stack_trace() ;
37-
SEXP rcpp_set_stack_trace(SEXP) ;
3835
double mktime00(struct tm &) ;
3936
struct tm * gmtime_(const time_t * const) ;
4037
}
41-
38+
39+
SEXP rcpp_get_stack_trace() ;
40+
SEXP rcpp_set_stack_trace(SEXP) ;
41+
std::string demangle( const std::string& name) ;
4242
const char* short_file_name(const char* ) ;
4343
int* get_cache( int n ) ;
4444
SEXP stack_trace( const char *file, int line) ;
@@ -60,18 +60,6 @@ namespace Rcpp {
6060

6161
#define GET_CALLABLE(__FUN__) (Fun) R_GetCCallable( "Rcpp", __FUN__ )
6262

63-
inline SEXP rcpp_get_stack_trace(){
64-
typedef SEXP (*Fun)(void) ;
65-
static Fun fun = GET_CALLABLE("rcpp_get_stack_trace") ;
66-
return fun() ;
67-
}
68-
69-
inline SEXP rcpp_set_stack_trace(SEXP e){
70-
typedef SEXP (*Fun)(SEXP) ;
71-
static Fun fun = GET_CALLABLE("rcpp_set_stack_trace") ;
72-
return fun(e) ;
73-
}
74-
7563
inline SEXP Rcpp_eval(SEXP expr, SEXP env = R_GlobalEnv){
7664
typedef SEXP (*Fun)(SEXP,SEXP) ;
7765
static Fun fun = GET_CALLABLE("Rcpp_eval") ;
@@ -84,12 +72,6 @@ namespace Rcpp {
8472
return fun(x) ;
8573
}
8674

87-
inline std::string demangle( const std::string& name){
88-
typedef std::string (*Fun)( const std::string& ) ;
89-
static Fun fun = GET_CALLABLE("demangle") ;
90-
return fun(name) ;
91-
}
92-
9375
namespace internal{
9476
inline unsigned long enterRNGScope(){
9577
typedef unsigned long (*Fun)(void) ;
@@ -108,13 +90,15 @@ namespace Rcpp {
10890
static Fun fun = GET_CALLABLE("get_string_buffer") ;
10991
return fun();
11092
}
93+
94+
inline SEXP get_Rcpp_namespace() {
95+
typedef SEXP (*Fun)(void) ;
96+
static Fun fun = GET_CALLABLE("get_Rcpp_namespace") ;
97+
return fun();
98+
}
99+
111100
}
112101

113-
inline SEXP get_Rcpp_namespace() {
114-
typedef SEXP (*Fun)(void) ;
115-
static Fun fun = GET_CALLABLE("get_Rcpp_namespace") ;
116-
return fun();
117-
}
118102

119103
inline double mktime00(struct tm &tm){
120104
typedef double (*Fun)(struct tm&) ;
@@ -129,6 +113,24 @@ namespace Rcpp {
129113
}
130114

131115
}
116+
117+
inline SEXP rcpp_get_stack_trace(){
118+
typedef SEXP (*Fun)(void) ;
119+
static Fun fun = GET_CALLABLE("rcpp_get_stack_trace") ;
120+
return fun() ;
121+
}
122+
123+
inline SEXP rcpp_set_stack_trace(SEXP e){
124+
typedef SEXP (*Fun)(SEXP) ;
125+
static Fun fun = GET_CALLABLE("rcpp_set_stack_trace") ;
126+
return fun(e) ;
127+
}
128+
129+
inline std::string demangle( const std::string& name){
130+
typedef std::string (*Fun)( const std::string& ) ;
131+
static Fun fun = GET_CALLABLE("demangle") ;
132+
return fun(name) ;
133+
}
132134

133135
inline const char* short_file_name(const char* file) {
134136
typedef const char* (*Fun)(const char*) ;

inst/unitTests/RcppTestA/src/rcpp_hello_world.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SEXP hello_world_ex(){
1212
try{
1313
throw std::range_error( "boom" ) ;
1414
} catch( std::exception& __ex__ ){
15-
Rcpp::forward_exception_to_r( __ex__ ) ;
15+
forward_exception_to_r( __ex__ ) ;
1616
}
1717
return R_NilValue ;
1818
}

src/Module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ SEXP class__newInstance(SEXP args){
146146
// relies on being set in .onLoad()
147147
SEXP rcpp_dummy_pointer = R_NilValue;
148148

149-
#define CHECK_DUMMY_OBJ(p) if(p == rcpp_dummy_pointer) Rcpp::forward_exception_to_r( Rcpp::not_initialized())
149+
#define CHECK_DUMMY_OBJ(p) if(p == rcpp_dummy_pointer) forward_exception_to_r( Rcpp::not_initialized())
150150

151151

152152
SEXP class__dummyInstance(SEXP args) {

src/api.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using namespace Rcpp ;
4646
buffer.begin(),
4747
buffer.begin() + buffer.find_last_of( ' ' ) + 1
4848
) ;
49-
return Rcpp::demangle( buffer) ;
49+
return demangle( buffer) ;
5050
}
5151

5252
#endif
@@ -118,25 +118,6 @@ namespace Rcpp {
118118
return res ;
119119
}
120120

121-
// [[Rcpp::register]]
122-
std::string demangle( const std::string& name ){
123-
#ifdef RCPP_HAS_DEMANGLING
124-
std::string real_class ;
125-
int status =-1 ;
126-
char *dem = 0;
127-
dem = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
128-
if( status == 0 ){
129-
real_class = dem ;
130-
free(dem);
131-
} else {
132-
real_class = name ;
133-
}
134-
return real_class ;
135-
#else
136-
return name ;
137-
#endif
138-
}
139-
140121
// [[Rcpp::register]]
141122
const char * type2name(SEXP x) {
142123
switch (TYPEOF(x)) {
@@ -172,6 +153,25 @@ namespace Rcpp {
172153

173154
} // namespace Rcpp
174155

156+
// [[Rcpp::register]]
157+
std::string demangle( const std::string& name ){
158+
#ifdef RCPP_HAS_DEMANGLING
159+
std::string real_class ;
160+
int status =-1 ;
161+
char *dem = 0;
162+
dem = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
163+
if( status == 0 ){
164+
real_class = dem ;
165+
free(dem);
166+
} else {
167+
real_class = name ;
168+
}
169+
return real_class ;
170+
#else
171+
return name ;
172+
#endif
173+
}
174+
175175
// [[Rcpp::register]]
176176
const char* short_file_name(const char* file){
177177
std::string f(file) ;

0 commit comments

Comments
 (0)