Skip to content

Commit 432e315

Browse files
abandon alternative protection stack code
1 parent e210131 commit 432e315

File tree

3 files changed

+2
-130
lines changed

3 files changed

+2
-130
lines changed

inst/include/Rcpp/macros/debug.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929

3030
const char* short_file_name(const char* file) ;
3131

32-
namespace Rcpp{
33-
void Rcpp_Stack_Debug() ;
34-
}
35-
3632
#if RCPP_DEBUG_LEVEL > 0
3733
#define RCPP_DEBUG( MSG ) Rprintf( "%40s:%4d %s\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
3834
#define RCPP_DEBUG_1( fmt, MSG ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, MSG ) ;

src/api.cpp

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -32,82 +32,17 @@
3232
namespace Rcpp {
3333

3434
// {{{ SexpStack
35-
static SEXP RCPP_PROTECTION_STACK = R_NilValue ;
36-
static SEXP* RCPP_PROTECTION_STACK_PTR = 0 ;
37-
static bool RCPP_PROTECTION_STACK_READY = false ;
38-
39-
#define GET_TOP() TRUELENGTH(RCPP_PROTECTION_STACK)
40-
#define SET_TOP(TOP) SET_TRUELENGTH(RCPP_PROTECTION_STACK, TOP)
41-
42-
inline void init_ProtectionStack(){
43-
if(!RCPP_PROTECTION_STACK_READY){
44-
RCPP_PROTECTION_STACK = get_Rcpp_protection_stack() ;
45-
RCPP_PROTECTION_STACK_PTR = get_vector_ptr(RCPP_PROTECTION_STACK) ;
46-
RCPP_PROTECTION_STACK_READY = true ;
47-
}
48-
}
4935

5036
SEXP Rcpp_PreserveObject(SEXP x){
51-
#if RCPP_USE_NEW_PRESERVE_RELEASE
52-
if( x != R_NilValue ){
53-
init_ProtectionStack();
54-
int top = GET_TOP() ;
55-
RCPP_DEBUG_2( "Rcpp_PreserveObject( <%p>), top = %d", x, top )
56-
top++ ;
57-
// RCPP_PROTECTION_STACK_PTR[top] = x ;
58-
set_vector_elt( RCPP_PROTECTION_STACK, top, x ) ;
59-
SET_TOP(top) ;
60-
}
61-
#if RCPP_DEBUG_LEVEL > 1
62-
Rcpp_Stack_Debug() ;
63-
#endif
64-
#else
6537
if( x != R_NilValue ) {
6638
R_PreserveObject(x);
6739
}
68-
#endif
6940
return x ;
7041
}
7142
void Rcpp_ReleaseObject(SEXP x){
72-
#if RCPP_USE_NEW_PRESERVE_RELEASE
73-
if( x != R_NilValue ){
74-
init_ProtectionStack();
75-
76-
int top = GET_TOP();
77-
RCPP_DEBUG_2( "Rcpp_ReleaseObject( <%p>), top = %d )", x, top )
78-
79-
if( x == RCPP_PROTECTION_STACK_PTR[top] ) {
80-
RCPP_PROTECTION_STACK_PTR[top] = R_NilValue ;
81-
top-- ;
82-
SET_TOP(top) ;
83-
} else {
84-
int i = top ;
85-
for( ; i>=0; i--){
86-
if( x == RCPP_PROTECTION_STACK_PTR[i] ){
87-
// swap position i and top
88-
// perhaps should bubble down instead
89-
90-
RCPP_PROTECTION_STACK_PTR[i] = RCPP_PROTECTION_STACK_PTR[top] ;
91-
RCPP_PROTECTION_STACK_PTR[top] = R_NilValue ;
92-
top-- ;
93-
94-
SET_TOP(top) ;
95-
break ;
96-
}
97-
}
98-
#if RCPP_DEBUG_LEVEL > 0
99-
if( i < 0 ) RCPP_DEBUG_2( "!!!! STACK ERROR, did not find SEXP <%p> (i=%d)", x, i ) ;
100-
#endif
101-
}
102-
#if RCPP_DEBUG_LEVEL > 1
103-
Rcpp_Stack_Debug() ;
104-
#endif
105-
}
106-
#else
10743
if (x != R_NilValue) {
10844
R_ReleaseObject(x);
10945
}
110-
#endif
11146
}
11247

11348
SEXP Rcpp_ReplaceObject(SEXP x, SEXP y){
@@ -116,26 +51,6 @@ namespace Rcpp {
11651
} else if( y == R_NilValue ){
11752
Rcpp_ReleaseObject( x ) ;
11853
} else {
119-
#if RCPP_USE_NEW_PRESERVE_RELEASE
120-
init_ProtectionStack();
121-
122-
int top = GET_TOP();
123-
RCPP_DEBUG_3( "Rcpp_ReplaceObject( <%p> , <%p> ), top = %d )", x, y, top )
124-
int i = top ;
125-
for( ; i>= 0; i--){
126-
if( x == RCPP_PROTECTION_STACK_PTR[i] ){
127-
set_vector_elt( RCPP_PROTECTION_STACK, i, y) ;
128-
break ;
129-
}
130-
}
131-
#if RCPP_DEBUG_LEVEL > 0
132-
if( i < 0 ) RCPP_DEBUG_1( "STACK ERROR, did not find SEXP <%p>", x ) ;
133-
#endif
134-
135-
#if RCPP_DEBUG_LEVEL > 1
136-
Rcpp_Stack_Debug() ;
137-
#endif
138-
#else
13954
// if we are setting to the same SEXP as we already have, do nothing
14055
if (x != y) {
14156

@@ -145,27 +60,10 @@ namespace Rcpp {
14560
// the new SEXP is not NULL, so preserve it
14661
Rcpp_PreserveObject(y);
14762

148-
//update();
14963
}
150-
#endif
15164
}
15265
return y ;
15366
}
154-
155-
void Rcpp_Stack_Debug(){
156-
init_ProtectionStack();
157-
int top = GET_TOP() ;
158-
if( top == -1 ){
159-
Rprintf( "Rcpp_Stack_Debug [<<%p>>] : empty stack\n", RCPP_PROTECTION_STACK ) ;
160-
} else {
161-
int n = top + 1 ;
162-
Rprintf( "Rcpp_Stack_Debug, %d objects on stack [<<%p>>]\n", n, RCPP_PROTECTION_STACK ) ;
163-
for( int i=0; i<n;i++){
164-
SEXP ptr = RCPP_PROTECTION_STACK_PTR[i] ;
165-
Rprintf( "[%4d] TYPE = %s, pointer = <%p>\n", i, sexp_to_name(TYPEOF(ptr)), ptr ) ;
166-
}
167-
}
168-
}
16967
// }}}
17068

17169

src/barrier.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// barrier.cpp: Rcpp R/C++ interface class library -- write barrier
44
//
5-
// Copyright (C) 2010 - 2012 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -54,19 +54,9 @@ const char* char_nocheck( SEXP x ){ return CHAR(x); }
5454

5555
static bool Rcpp_cache_know = false ;
5656
static SEXP Rcpp_cache = R_NilValue ;
57-
static SEXP Rcpp_protection_stack = R_NilValue ;
5857

5958
#define RCPP_HASH_CACHE_INDEX 4
60-
#define RCPP_PROTECTION_STACK_INDEX 5
61-
#define RCPP_CACHE_SIZE 6
62-
63-
#ifndef RCPP_PROTECT_STACK_INITIAL_SIZE
64-
#define RCPP_PROTECT_STACK_INITIAL_SIZE 16384
65-
#endif
66-
67-
#ifndef RCPP_PROTECT_STACK_INCREMENT
68-
#define RCPP_PROTECT_STACK_INCREMENT 4096
69-
#endif
59+
#define RCPP_CACHE_SIZE 5
7060

7161
#ifndef RCPP_HASH_CACHE_INITIAL_SIZE
7262
#define RCPP_HASH_CACHE_INITIAL_SIZE 1024
@@ -81,19 +71,11 @@ SEXP get_rcpp_cache() {
8171

8272
Rcpp_cache = Rf_findVarInFrame( RCPP, Rf_install(".rcpp_cache") ) ;
8373
Rcpp_cache_know = true ;
84-
Rcpp_protection_stack = VECTOR_ELT(Rcpp_cache, RCPP_PROTECTION_STACK_INDEX) ;
8574
UNPROTECT(1) ;
8675
}
8776
return Rcpp_cache ;
8877
}
8978

90-
SEXP get_Rcpp_protection_stack(){
91-
if( ! Rcpp_cache_know ){
92-
get_rcpp_cache() ;
93-
}
94-
return Rcpp_protection_stack ;
95-
}
96-
9779
namespace Rcpp {
9880
namespace internal {
9981
SEXP get_Rcpp_namespace(){
@@ -132,10 +114,6 @@ SEXP init_Rcpp_cache(){
132114
set_current_error( cache, R_NilValue ) ; // current error
133115
SET_VECTOR_ELT( cache, 3, R_NilValue ) ; // stack trace
134116
SET_VECTOR_ELT( cache, RCPP_HASH_CACHE_INDEX, Rf_allocVector(INTSXP, RCPP_HASH_CACHE_INITIAL_SIZE) ) ;
135-
SEXP stack = PROTECT(Rf_allocVector(VECSXP, RCPP_PROTECT_STACK_INITIAL_SIZE)) ;
136-
// we use true length to store "top"
137-
SET_TRUELENGTH(stack, -1 ) ;
138-
SET_VECTOR_ELT( cache, RCPP_PROTECTION_STACK_INDEX, stack ) ;
139117
Rf_defineVar( Rf_install(".rcpp_cache"), cache, RCPP );
140118

141119
UNPROTECT(3) ;

0 commit comments

Comments
 (0)