Skip to content

Commit 936c19b

Browse files
committed
add template specializations to avoid DATAPTR use
1 parent 5207973 commit 936c19b

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2024-06-11 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/internal/r_vector.h: Use template specializations to
4+
avoid DATAPTR usage
5+
16
2024-06-02 Dirk Eddelbuettel <[email protected]>
27

38
* inst/include/Rcpp/internal/export.h: More R_xlen_t switching

inst/NEWS.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
\itemize{
1010
\item Set R_NO_REMAP if not already defined (Dirk in \ghpr{1296})
1111
\item Add variadic templates to be used instead of generated code
12-
(Andrew Johnson in \ghpr{1303}
12+
(Andrew Johnson in \ghpr{1303})
1313
\item Count variables were switches to \code{size_t} to avoid warnings
1414
about conversion-narrowing (Dirk in \ghpr{1307})
15+
\item Rcpp now avoids the usage of the (non-API) DATAPTR function when
16+
accessing the contents of Rcpp Vector objects where possible.
1517
}
1618
\item Changes in Rcpp Deployment:
1719
\itemize{

inst/include/Rcpp/internal/r_vector.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ typename Rcpp::traits::storage_type<RTYPE>::type* r_vector_start(SEXP x) {
3232
return reinterpret_cast<pointer>(dataptr(x));
3333
}
3434

35+
// add specializations to avoid use of dataptr
36+
#define RCPP_VECTOR_START_IMPL(__RTYPE__, __ACCESSOR__) \
37+
template <> \
38+
inline typename Rcpp::traits::storage_type<__RTYPE__>::type* r_vector_start<__RTYPE__>(SEXP x) { \
39+
return __ACCESSOR__(x); \
40+
}
41+
42+
RCPP_VECTOR_START_IMPL(LGLSXP, LOGICAL);
43+
RCPP_VECTOR_START_IMPL(INTSXP, INTEGER);
44+
RCPP_VECTOR_START_IMPL(RAWSXP, RAW);
45+
RCPP_VECTOR_START_IMPL(CPLXSXP, COMPLEX);
46+
RCPP_VECTOR_START_IMPL(REALSXP, REAL);
47+
48+
#undef RCPP_VECTOR_START_IMPL
49+
3550
/**
3651
* The value 0 statically casted to the appropriate type for
3752
* the given SEXP type

0 commit comments

Comments
 (0)