Skip to content

Commit d092c1e

Browse files
committed
Merge pull request #267 from RcppCore/bugfix/visibility-hidden
set attribute_hidden in routines.h (closes #264)
2 parents 10ab73a + 3d86412 commit d092c1e

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2015-02-25 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/routines.h: Use the 'attribute_hidden' define from
4+
the R header R_ext/Visibility.h to protect symbols (cf #264)
5+
6+
* inst/include/RcppCommon.h: Also include R_ext/Visibility.h
7+
18
2015-02-24 JJ Allaire <[email protected]>
29

310
* src/attributes.cpp: Guard against includes referencing themselves

inst/include/Rcpp/routines.h

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,125 +110,129 @@ namespace Rcpp {
110110

111111
}
112112

113-
inline SEXP rcpp_get_stack_trace(){
113+
// The 'attribute_hidden' used here is a simple precessor defined from
114+
// ${R_HOME}/include/R_ext/Visibility.h -- it is empty when not supported
115+
// by the compiler and otherwise '__attribute__ ((visibility ("hidden")))'
116+
117+
inline attribute_hidden SEXP rcpp_get_stack_trace(){
114118
typedef SEXP (*Fun)(void) ;
115119
static Fun fun = GET_CALLABLE("rcpp_get_stack_trace") ;
116120
return fun() ;
117121
}
118122

119-
inline SEXP rcpp_set_stack_trace(SEXP e){
123+
inline attribute_hidden SEXP rcpp_set_stack_trace(SEXP e){
120124
typedef SEXP (*Fun)(SEXP) ;
121125
static Fun fun = GET_CALLABLE("rcpp_set_stack_trace") ;
122126
return fun(e) ;
123127
}
124128

125-
inline std::string demangle( const std::string& name){
129+
inline attribute_hidden std::string demangle( const std::string& name){
126130
typedef std::string (*Fun)( const std::string& ) ;
127131
static Fun fun = GET_CALLABLE("demangle") ;
128132
return fun(name) ;
129133
}
130134

131-
inline const char* short_file_name(const char* file) {
135+
inline attribute_hidden const char* short_file_name(const char* file) {
132136
typedef const char* (*Fun)(const char*) ;
133137
static Fun fun = GET_CALLABLE("short_file_name") ;
134138
return fun(file) ;
135139
}
136-
inline SEXP stack_trace( const char *file, int line){
140+
inline attribute_hidden SEXP stack_trace( const char *file, int line){
137141
typedef SEXP (*Fun)(const char*, int) ;
138142
static Fun fun = GET_CALLABLE("stack_trace") ;
139143
return fun(file, line) ;
140144
}
141145

142-
inline SEXP get_string_elt(SEXP s, int i){
146+
inline attribute_hidden SEXP get_string_elt(SEXP s, int i){
143147
typedef SEXP (*Fun)(SEXP, int) ;
144148
static Fun fun = GET_CALLABLE("get_string_elt") ;
145149
return fun(s, i) ;
146150
}
147151

148-
inline const char* char_get_string_elt(SEXP s, int i){
152+
inline attribute_hidden const char* char_get_string_elt(SEXP s, int i){
149153
typedef const char* (*Fun)(SEXP, int) ;
150154
static Fun fun = GET_CALLABLE("char_get_string_elt") ;
151155
return fun(s, i);
152156
}
153157

154-
inline void set_string_elt(SEXP s, int i, SEXP v){
158+
inline attribute_hidden void set_string_elt(SEXP s, int i, SEXP v){
155159
typedef void (*Fun)(SEXP,int,SEXP) ;
156160
static Fun fun = GET_CALLABLE("set_string_elt") ;
157161
fun(s, i, v) ;
158162
}
159163

160-
inline void char_set_string_elt(SEXP s, int i, const char* v){
164+
inline attribute_hidden void char_set_string_elt(SEXP s, int i, const char* v){
161165
typedef void (*Fun)(SEXP,int, const char*) ;
162166
static Fun fun = GET_CALLABLE("char_set_string_elt") ;
163167
fun(s, i, v ) ;
164168
}
165169

166-
inline SEXP* get_string_ptr(SEXP s){
170+
inline attribute_hidden SEXP* get_string_ptr(SEXP s){
167171
typedef SEXP* (*Fun)(SEXP) ;
168172
static Fun fun = GET_CALLABLE("get_string_ptr") ;
169173
return fun(s) ;
170174
}
171175

172-
inline SEXP get_vector_elt(SEXP v, int i){
176+
inline attribute_hidden SEXP get_vector_elt(SEXP v, int i){
173177
typedef SEXP (*Fun)(SEXP, int );
174178
static Fun fun = GET_CALLABLE("get_vector_elt") ;
175179
return fun(v, i) ;
176180
}
177181

178-
inline void set_vector_elt(SEXP v, int i, SEXP x){
182+
inline attribute_hidden void set_vector_elt(SEXP v, int i, SEXP x){
179183
typedef void (*Fun)(SEXP, int, SEXP) ;
180184
static Fun fun = GET_CALLABLE("set_vector_elt") ;
181185
fun(v, i, x) ;
182186
}
183187

184-
inline SEXP* get_vector_ptr(SEXP v){
188+
inline attribute_hidden SEXP* get_vector_ptr(SEXP v){
185189
typedef SEXP* (*Fun)(SEXP) ;
186190
static Fun fun = GET_CALLABLE("get_vector_ptr") ;
187191
return fun(v) ;
188192
}
189193

190-
inline const char* char_nocheck( SEXP x){
194+
inline attribute_hidden const char* char_nocheck( SEXP x){
191195
typedef const char* (*Fun)(SEXP) ;
192196
static Fun fun = GET_CALLABLE("char_nocheck") ;
193197
return fun(x) ;
194198
}
195199

196-
inline void* dataptr(SEXP x){
200+
inline attribute_hidden void* dataptr(SEXP x){
197201
typedef void* (*Fun)(SEXP) ;
198202
static Fun fun = GET_CALLABLE("dataptr") ;
199203
return fun(x) ;
200204
}
201205

202-
inline Rcpp::Module* getCurrentScope(){
206+
inline attribute_hidden Rcpp::Module* getCurrentScope(){
203207
typedef Rcpp::Module* (*Fun)(void) ;
204208
static Fun fun = GET_CALLABLE("getCurrentScope") ;
205209
return fun();
206210
}
207211

208-
inline void setCurrentScope( Rcpp::Module* mod ){
212+
inline attribute_hidden void setCurrentScope( Rcpp::Module* mod ){
209213
typedef void (*Fun)(Rcpp::Module*) ;
210214
static Fun fun = GET_CALLABLE("setCurrentScope") ;
211215
fun(mod) ;
212216
}
213217

214-
inline int* get_cache( int n ){
218+
inline attribute_hidden int* get_cache( int n ){
215219
typedef int* (*Fun)(int) ;
216220
static Fun fun = GET_CALLABLE("get_cache") ;
217221
return fun(n) ;
218222
}
219223

220-
inline SEXP reset_current_error(){
224+
inline attribute_hidden SEXP reset_current_error(){
221225
typedef SEXP (*Fun)(void) ;
222226
static Fun fun = GET_CALLABLE("reset_current_error") ;
223227
return fun() ;
224228
}
225229

226-
inline int error_occured(){
230+
inline attribute_hidden int error_occured(){
227231
typedef int (*Fun)(void) ;
228232
static Fun fun = GET_CALLABLE("error_occured") ;
229233
return fun() ;
230234
}
231-
inline SEXP rcpp_get_current_error(){
235+
inline attribute_hidden SEXP rcpp_get_current_error(){
232236
typedef SEXP (*Fun)(void) ;
233237
static Fun fun = GET_CALLABLE("rcpp_get_current_error") ;
234238
return fun() ;

inst/include/RcppCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace Rcpp{
7070
#include <typeinfo>
7171
#include <Rcpp/sprintf.h>
7272
#include <R_ext/Callbacks.h>
73+
#include <R_ext/Visibility.h>
7374
#include <Rcpp/utils/tinyformat.h>
7475

7576
#include <Rmath.h>

0 commit comments

Comments
 (0)