Skip to content

Commit dfb530d

Browse files
avoid using SET_TYPEOF (#1315)
* avoid using SET_TYPEOF * try using r_cast * add coerce helper * update ChangeLog * try a shallow duplicate * CONS macro not available? * revert un-needed changes * Rebased and updated --------- Co-authored-by: Dirk Eddelbuettel <[email protected]>
1 parent c1699a0 commit dfb530d

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
* inst/include/Rcpp/Environment.h: Drop support for UserDefinedDatabase
2222
[ merged 2024-07-22 after release of Rcpp 1.0.13 ]
2323

24+
* inst/include/Rcpp/Language.h: Avoid using SET_TYPEOF
25+
* inst/include/Rcpp/Pairlist.h: Idem
26+
* inst/include/Rcpp/r_cast.h: Idem
27+
2428
2024-06-22 Dirk Eddelbuettel <[email protected]>
2529

2630
* DESCRIPTION (Version, Date): Roll micro version

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.13.0.1
3+
Version: 1.0.13.0.2
44
Date: 2024-07-22
55
Author: Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou,
66
Nathan Russell, Inaki Ucar, Douglas Bates and John Chambers

inst/include/Rcpp/Language.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ namespace Rcpp{
162162
return internal::Rcpp_eval_impl( Storage::get__(), env);
163163
}
164164

165-
void update( SEXP x){
166-
SET_TYPEOF( x, LANGSXP );
165+
void update(SEXP x) {
166+
if (TYPEOF(x) != LANGSXP) {
167+
Storage::set__(r_cast<LANGSXP>(x));
168+
}
167169
SET_TAG( x, R_NilValue );
168170
}
169171

inst/include/Rcpp/Pairlist.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ namespace Rcpp{
5050
#else
5151
#include <Rcpp/generated/Pairlist__ctors.h>
5252
#endif
53-
void update(SEXP x){
54-
SET_TYPEOF( x, LISTSXP ) ;
53+
void update(SEXP x) {
54+
if (TYPEOF(x) != LISTSXP) {
55+
Storage::set__(r_cast<LISTSXP>(x));
56+
}
5557
}
5658
} ;
5759

inst/include/Rcpp/r_cast.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,9 @@ namespace Rcpp {
143143
}
144144
template<>
145145
inline SEXP r_true_cast<LISTSXP>(SEXP x) {
146-
switch( TYPEOF(x) ){
147-
case LANGSXP:
148-
{
149-
Shield<SEXP> y( Rf_duplicate( x ));
150-
SET_TYPEOF(y,LISTSXP);
151-
return y;
152-
}
153-
default:
146+
if (TYPEOF(x) == LANGSXP) {
147+
return Rf_cons(CAR(x), CDR(x));
148+
} else {
154149
return convert_using_rfunction(x, "as.pairlist" );
155150
}
156151
}

0 commit comments

Comments
 (0)