Skip to content

Commit a276b00

Browse files
register functions
1 parent d11bb36 commit a276b00

File tree

8 files changed

+65
-75
lines changed

8 files changed

+65
-75
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::internal::get_Rcpp_namespace() ;
310+
return Rcpp::get_Rcpp_namespace() ;
311311
}
312312

313313
/**

inst/include/Rcpp/Module.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ namespace Rcpp{
9494

9595
namespace Rcpp{
9696

97-
Rcpp::Module* getCurrentScope() ;
98-
void setCurrentScope( Rcpp::Module* ) ;
99-
10097
template <typename Class>
10198
class CppMethod {
10299
public:

inst/include/Rcpp/cache.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

inst/include/Rcpp/routines.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ namespace Rcpp{
3232
unsigned long exitRNGScope() ;
3333
}
3434
SEXP get_Rcpp_namespace() ;
35-
int* get_cache( int n ) ;
3635
SEXP rcpp_get_stack_trace() ;
3736
SEXP rcpp_set_stack_trace(SEXP) ;
3837
}
3938

39+
int* get_cache( int n ) ;
4040
SEXP stack_trace( const char *file, int line) ;
4141
SEXP get_string_elt(SEXP s, int i);
4242
const char* char_get_string_elt(SEXP s, int i) ;
@@ -92,26 +92,20 @@ namespace Rcpp {
9292
static Fun fun = GET_CALLABLE("enterRNGScope") ;
9393
return fun() ;
9494
}
95-
}
9695

97-
inline unsigned long exitRNGScope(){
98-
typedef unsigned long (*Fun)(void) ;
99-
static Fun fun = GET_CALLABLE("exitRNGScope") ;
100-
return fun() ;
96+
inline unsigned long exitRNGScope(){
97+
typedef unsigned long (*Fun)(void) ;
98+
static Fun fun = GET_CALLABLE("exitRNGScope") ;
99+
return fun() ;
100+
}
101101
}
102-
102+
103103
inline SEXP get_Rcpp_namespace() {
104104
typedef SEXP (*Fun)(void) ;
105105
static Fun fun = GET_CALLABLE("get_Rcpp_namespace") ;
106106
return fun();
107107
}
108108

109-
inline int* get_cache( int n ){
110-
typedef int* (*Fun)(int) ;
111-
static Fun fun = GET_CALLABLE("get_cache") ;
112-
return fun(n) ;
113-
}
114-
115109
}
116110

117111
inline SEXP stack_trace( const char *file, int line){
@@ -192,6 +186,12 @@ inline void setCurrentScope( Rcpp::Module* mod ){
192186
fun(mod) ;
193187
}
194188

189+
inline int* get_cache( int n ){
190+
typedef int* (*Fun)(int) ;
191+
static Fun fun = GET_CALLABLE("get_cache") ;
192+
return fun(n) ;
193+
}
194+
195195
#endif
196196

197197

inst/include/RcppCommon.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ namespace Rcpp{
170170

171171
#include <Rcpp/sugar/sugar_forward.h>
172172

173-
#include <Rcpp/cache.h>
174-
175173
#include <Rcpp/iostream/Rstreambuf.h>
176174
#include <Rcpp/longlong.h>
177175

src/Module.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,3 @@ void setCurrentScope( Rcpp::Module* scope ){
229229
Rcpp::current_scope = scope ;
230230
}
231231

232-
extern "C" void R_init_Rcpp( DllInfo* info){
233-
Rcpp::current_scope = 0 ;
234-
235-
// init the cache
236-
init_Rcpp_cache() ;
237-
238-
// init routines
239-
init_Rcpp_routines(info) ;
240-
}
241-

src/Rcpp_init.cpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222
#define COMPILING_RCPP
2323

24-
#include <R.h>
25-
#include <Rinternals.h>
24+
#include <Rcpp.h>
2625
#include "internal.h"
2726

2827
// borrowed from Matrix
@@ -82,7 +81,51 @@ void init_Rcpp_routines(DllInfo *info){
8281
extEntries /*.External*/
8382
);
8483
}
85-
84+
85+
void registerFunctions(){
86+
using namespace Rcpp ;
87+
using namespace Rcpp::internal ;
88+
89+
#define RCPP_REGISTER(__FUN__) R_RegisterCCallable( "Rcpp", #__FUN__ , (DL_FUNC)__FUN__ );
90+
RCPP_REGISTER(rcpp_get_stack_trace)
91+
RCPP_REGISTER(rcpp_set_stack_trace)
92+
RCPP_REGISTER(Rcpp_eval)
93+
RCPP_REGISTER(type2name)
94+
RCPP_REGISTER(demangle)
95+
RCPP_REGISTER(enterRNGScope)
96+
RCPP_REGISTER(exitRNGScope)
97+
RCPP_REGISTER(get_Rcpp_namespace)
98+
RCPP_REGISTER(get_cache)
99+
RCPP_REGISTER(stack_trace)
100+
RCPP_REGISTER(get_string_elt)
101+
RCPP_REGISTER(char_get_string_elt)
102+
RCPP_REGISTER(set_string_elt)
103+
RCPP_REGISTER(char_set_string_elt)
104+
RCPP_REGISTER(get_string_ptr)
105+
RCPP_REGISTER(get_vector_elt)
106+
RCPP_REGISTER(set_vector_elt)
107+
RCPP_REGISTER(get_vector_ptr)
108+
RCPP_REGISTER(char_nocheck)
109+
RCPP_REGISTER(dataptr)
110+
RCPP_REGISTER(getCurrentScope)
111+
RCPP_REGISTER(setCurrentScope)
112+
#undef RCPP_REGISTER
113+
}
114+
115+
86116
extern "C" void R_unload_Rcpp(DllInfo *info) {
87117
/* Release resources. */
88118
}
119+
120+
extern "C" void R_init_Rcpp( DllInfo* info){
121+
setCurrentScope(0) ;
122+
123+
registerFunctions() ;
124+
125+
// init the cache
126+
init_Rcpp_cache() ;
127+
128+
// init routines
129+
init_Rcpp_routines(info) ;
130+
}
131+

src/barrier.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <Rinternals.h>
2626
#include <Rcpp/barrier.h>
2727
#include "internal.h"
28-
#include <Rcpp/cache.h>
2928
#include <algorithm>
3029
#include <Rcpp/protection/Shield.h>
3130

@@ -88,11 +87,11 @@ SEXP get_rcpp_cache() {
8887
}
8988

9089
namespace Rcpp {
91-
namespace internal {
92-
SEXP get_Rcpp_namespace(){
93-
return VECTOR_ELT( get_rcpp_cache() , 0 ) ;
94-
}
95-
}
90+
91+
// [[Rcpp::register]]
92+
SEXP get_Rcpp_namespace(){
93+
return VECTOR_ELT( get_rcpp_cache() , 0 ) ;
94+
}
9695

9796
// [[Rcpp::register]]
9897
SEXP rcpp_get_stack_trace(){

0 commit comments

Comments
 (0)