Skip to content

Commit 7f56d2e

Browse files
authored
Merge pull request #1133 from Enchufa2/feature/rcpp_precious_2
second pass at 'precious_{preserve,remove}' (addresses #382, #1081)
2 parents c260499 + 2c2eb89 commit 7f56d2e

File tree

12 files changed

+349
-103
lines changed

12 files changed

+349
-103
lines changed

ChangeLog

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1+
2021-01-17 Iñaki Ucar <[email protected]>
2+
3+
* inst/include/Rcpp/String.h: Use Rcpp_{Preserve,Release}Object
4+
throughout which connects to Rcpp_precious_* routines
5+
* inst/include/Rcpp/exceptions.h: Use Rcpp_ReleaseObject
6+
* inst/include/Rcpp/routines.h: Several corrections and refinements
7+
* inst/include/Rcpp/storage/PreserveStorage.h: Ditto
8+
* inst/include/Rcpp/traits/named_object.h: Ditto
9+
* inst/include/Rcpp/unwuindProtect.h: Ditto
10+
* inst/include/RcppCommon.h: Ditto
11+
* src/barrier.cpp: Ditto
12+
113
2021-01-17 Dirk Eddelbuettel <[email protected]>
214

315
* DESCRIPTION (Version, Date): Roll minor version
416
* inst/include/Rcpp/config.h: Idem
517

18+
[ these were originally committed 17 May 2020 and have been rebased ]
19+
* src/barrier.cpp: Implement Rcpp_precious_{init,teardown,preserve,remove}
20+
* src/rcpp_init.c: Register cpp_precious_{init,teardown,preserve,remove}
21+
and call from R_{init,unload}_Rcpp
22+
* inst/include/Rcpp/routines.h: Declare Rcpp_precious_{init,teardown,
23+
preserve,remove}
24+
* inst/include/Rcpp/exceptions.h: Use Rcpp_precious_remove
25+
* inst/include/Rcpp/traits/named_object.h: Use
26+
Rcpp_precious_{preserve,remove}
27+
* inst/include/Rcpp/unwuindProtect.h: Use Rcpp_precious_preserve
28+
* inst/include/RcppCommon.h: Use Rcpp_precious_{preserve,remove}
29+
630
2021-01-16 Dirk Eddelbuettel <[email protected]>
731

32+
* DESCRIPTION (Version, Date): Roll minor version
33+
* inst/include/Rcpp/config.h: Idem
34+
835
* tests/tinytest.R: Test for CODECOV when deciding to run extensive
936
tests or just a subset, and set CI=true to enable run full set
1037

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: Rcpp
22
Title: Seamless R and C++ Integration
3-
Version: 1.0.6.1
3+
Version: 1.0.6.2
44
Date: 2021-01-17
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Douglas Bates and John Chambers

inst/include/Rcpp/String.h

Lines changed: 173 additions & 48 deletions
Large diffs are not rendered by default.

inst/include/Rcpp/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#define RCPP_VERSION_STRING "1.0.6"
3131

3232
// the current source snapshot
33-
#define RCPP_DEV_VERSION RcppDevVersion(1,0,6,1)
34-
#define RCPP_DEV_VERSION_STRING "1.0.6.1"
33+
#define RCPP_DEV_VERSION RcppDevVersion(1,0,6,2)
34+
#define RCPP_DEV_VERSION_STRING "1.0.6.2"
3535

3636
#endif

inst/include/Rcpp/exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// exceptions.h: Rcpp R/C++ interface class library -- exceptions
33
//
44
// Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2021 - 2020 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
56
//
67
// This file is part of Rcpp.
78
//

inst/include/Rcpp/routines.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
1+
2+
// routines.h: Rcpp R/C++ interface class library -- callable function setup
23
//
3-
// Copyright (C) 2013 Romain Francois
4-
// Copyright (C) 2015 Dirk Eddelbuettel
4+
// Copyright (C) 2013 - 2014 Romain Francois
5+
// Copyright (C) 2015 - 2020 Romain Francois and Dirk Eddelbuettel
6+
// Copyright (C) 2021 Romain Francois, Dirk Eddelbuettel and Iñaki Ucar
57
//
68
// This file is part of Rcpp.
79
//
@@ -38,6 +40,11 @@ namespace Rcpp{
3840
}
3941
double mktime00(struct tm &);
4042
struct tm * gmtime_(const time_t * const);
43+
44+
void Rcpp_precious_init();
45+
void Rcpp_precious_teardown();
46+
SEXP Rcpp_precious_preserve(SEXP object);
47+
void Rcpp_precious_remove(SEXP token);
4148
}
4249

4350
SEXP rcpp_get_stack_trace();
@@ -127,6 +134,27 @@ namespace Rcpp {
127134
return fun(x);
128135
}
129136

137+
inline attribute_hidden void Rcpp_precious_init() {
138+
typedef void (*Fun)(void);
139+
static Fun fun = GET_CALLABLE("Rcpp_precious_init");
140+
fun();
141+
}
142+
inline attribute_hidden void Rcpp_precious_teardown() {
143+
typedef void (*Fun)(void);
144+
static Fun fun = GET_CALLABLE("Rcpp_precious_teardown");
145+
fun();
146+
}
147+
inline attribute_hidden SEXP Rcpp_precious_preserve(SEXP object) {
148+
typedef SEXP (*Fun)(SEXP);
149+
static Fun fun = GET_CALLABLE("Rcpp_precious_preserve");
150+
return fun(object);
151+
}
152+
inline attribute_hidden void Rcpp_precious_remove(SEXP token) {
153+
typedef void (*Fun)(SEXP);
154+
static Fun fun = GET_CALLABLE("Rcpp_precious_remove");
155+
fun(token);
156+
}
157+
130158
}
131159

132160
// The 'attribute_hidden' used here is a simple precessor defined from

inst/include/Rcpp/storage/PreserveStorage.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
2+
// PreserveStorage.h: Rcpp R/C++ interface class library -- helper class
3+
//
4+
// Copyright (C) 2013 - 2020 Romain Francois
5+
// Copyright (C) 2021 Romain Francois and Iñaki Ucar
6+
//
7+
// This file is part of Rcpp.
8+
//
9+
// Rcpp is free software: you can redistribute it and/or modify it
10+
// under the terms of the GNU General Public License as published by
11+
// the Free Software Foundation, either version 2 of the License, or
12+
// (at your option) any later version.
13+
//
14+
// Rcpp is distributed in the hope that it will be useful, but
15+
// WITHOUT ANY WARRANTY; without even the implied warranty of
16+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
// GNU General Public License for more details.
18+
//
19+
// You should have received a copy of the GNU General Public License
20+
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21+
122
#ifndef Rcpp_PreserveStorage_h
223
#define Rcpp_PreserveStorage_h
324

@@ -7,15 +28,20 @@ namespace Rcpp{
728
class PreserveStorage {
829
public:
930

10-
PreserveStorage() : data(R_NilValue){}
31+
PreserveStorage() : data(R_NilValue), token(R_NilValue){}
1132

1233
~PreserveStorage(){
13-
Rcpp_ReleaseObject(data) ;
34+
Rcpp_ReleaseObject(token) ;
1435
data = R_NilValue;
36+
token = R_NilValue;
1537
}
1638

1739
inline void set__(SEXP x){
18-
data = Rcpp_ReplaceObject(data, x) ;
40+
if (data != x) {
41+
data = x;
42+
Rcpp_ReleaseObject(token);
43+
token = Rcpp_PreserveObject(data);
44+
}
1945

2046
// calls the update method of CLASS
2147
// this is where to react to changes in the underlying SEXP
@@ -28,7 +54,9 @@ namespace Rcpp{
2854

2955
inline SEXP invalidate__(){
3056
SEXP out = data ;
57+
Rcpp_ReleaseObject(token);
3158
data = R_NilValue ;
59+
token = R_NilValue ;
3260
return out ;
3361
}
3462

@@ -48,6 +76,7 @@ namespace Rcpp{
4876

4977
private:
5078
SEXP data ;
79+
SEXP token ;
5180
} ;
5281

5382
}

inst/include/Rcpp/traits/named_object.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */
3-
//
1+
42
// named_object.h: Rcpp R/C++ interface class library -- named SEXP
53
//
6-
// Copyright (C) 2010 - 2017 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2010 - 2020 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2021 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
76
//
87
// This file is part of Rcpp.
98
//
@@ -41,19 +40,22 @@ template <typename T> class named_object {
4140
template <> class named_object<SEXP> {
4241
public: // #nocov start
4342
named_object( const std::string& name_, const SEXP& o_):
44-
name(name_), object(o_) {
45-
R_PreserveObject(object);
43+
name(name_), object(o_), token(R_NilValue) {
44+
token = Rcpp_precious_preserve(object);
4645
}
4746

4847
named_object( const named_object<SEXP>& other ) :
49-
name(other.name), object(other.object) {
50-
R_PreserveObject(object);
48+
name(other.name), object(other.object), token(other.token) {
49+
token = Rcpp_precious_preserve(object);
5150
}
5251
~named_object() {
53-
R_ReleaseObject(object);
52+
Rcpp_precious_remove(token);
53+
5454
} // #nocov end
5555
const std::string& name;
5656
SEXP object;
57+
private:
58+
SEXP token;
5759
};
5860

5961

inst/include/Rcpp/unwindProtect.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
12
// unwind.h: Rcpp R/C++ interface class library -- Unwind Protect
23
//
3-
// Copyright (C) 2018 RStudio
4+
// Copyright (C) 2018 - 2020 RStudio
5+
// Copyright (C) 2021 RStudio, Dirk Eddelbuettel and Iñaki Ucar
46
//
57
// This file is part of Rcpp.
68
//

inst/include/RcppCommon.h

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
1+
22
//
33
// RcppCommon.h: Rcpp R/C++ interface class library -- common include and defines statements
44
//
55
// Copyright (C) 2008 - 2009 Dirk Eddelbuettel
6-
// Copyright (C) 2009 - 2017 Dirk Eddelbuettel and Romain Francois
6+
// Copyright (C) 2009 - 2020 Dirk Eddelbuettel and Romain Francois
7+
// Copyright (C) 2021 Dirk Eddelbuettel, Romain Francois and Iñaki Ucar
78
//
89
// This file is part of Rcpp.
910
//
@@ -77,6 +78,9 @@ namespace Rcpp {
7778
SEXP Rcpp_fast_eval(SEXP expr_, SEXP env);
7879
SEXP Rcpp_eval(SEXP expr_, SEXP env = R_GlobalEnv);
7980

81+
SEXP Rcpp_precious_preserve(SEXP object);
82+
void Rcpp_precious_remove(SEXP token);
83+
8084
namespace internal {
8185
SEXP Rcpp_eval_impl(SEXP expr, SEXP env);
8286
}
@@ -87,28 +91,12 @@ namespace Rcpp {
8791
template <typename T> class named_object;
8892
}
8993

90-
inline SEXP Rcpp_PreserveObject(SEXP x) {
91-
if (x != R_NilValue) {
92-
R_PreserveObject(x);
93-
}
94-
return x;
95-
}
96-
97-
inline void Rcpp_ReleaseObject(SEXP x) {
98-
if (x != R_NilValue) {
99-
R_ReleaseObject(x);
100-
}
94+
inline SEXP Rcpp_PreserveObject(SEXP object) {
95+
return Rcpp_precious_preserve(object);
10196
}
10297

103-
inline SEXP Rcpp_ReplaceObject(SEXP x, SEXP y) {
104-
105-
// if we are setting to the same SEXP as we already have, do nothing
106-
if (x != y) {
107-
Rcpp_ReleaseObject(x);
108-
Rcpp_PreserveObject(y);
109-
}
110-
111-
return y;
98+
inline void Rcpp_ReleaseObject(SEXP token) {
99+
Rcpp_precious_remove(token);
112100
}
113101

114102
}

0 commit comments

Comments
 (0)