diff --git a/ChangeLog b/ChangeLog index 2b1261d9c..88d7cd29f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-07-07 Kevin Ushey + + * inst/include/Rcpp/internal/SEXP_Iterator.h: Avoid using VECTOR_PTR + * inst/include/Rcpp/vector/Subsetter.h: Avoid using STRING_PTR + * inst/include/RcppCommon.h: Include compatibility defines + * src/barrier.cpp: Avoid using {STRING/VECTOR}_PTR + * inst/include/Rcpp/r/compat.h: Include compatibility defines + 2024-06-22 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll micro version diff --git a/inst/include/Rcpp/internal/SEXP_Iterator.h b/inst/include/Rcpp/internal/SEXP_Iterator.h index 62e604d23..fbb8e2ad4 100644 --- a/inst/include/Rcpp/internal/SEXP_Iterator.h +++ b/inst/include/Rcpp/internal/SEXP_Iterator.h @@ -37,7 +37,7 @@ class SEXP_Iterator { SEXP_Iterator( ): ptr(){} ; SEXP_Iterator( const SEXP_Iterator& other) : ptr(other.ptr){} ; - SEXP_Iterator( const VECTOR& vec ) : ptr( get_vector_ptr(vec) ){} ; + SEXP_Iterator( const VECTOR& vec ) : ptr( RCPP_VECTOR_PTR(vec) ){} ; SEXP_Iterator& operator=(const SEXP_Iterator& other){ ptr = other.ptr ; return *this ;} diff --git a/inst/include/Rcpp/r/compat.h b/inst/include/Rcpp/r/compat.h new file mode 100644 index 000000000..218f3d7bc --- /dev/null +++ b/inst/include/Rcpp/r/compat.h @@ -0,0 +1,39 @@ + +// +// compat.h: Rcpp R/C++ interface class library -- compatibility defines +// +// Copyright (C) 2024 Dirk Eddelbuettel, Kevin Ushey +// +// This file is part of Rcpp. +// +// Rcpp is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 2 of the License, or +// (at your option) any later version. +// +// Rcpp is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Rcpp. If not, see . + +#ifndef RCPP_R_COMPAT_H +#define RCPP_R_COMPAT_H + +#include + +#if R_VERSION >= R_Version(4, 4, 2) +# define RCPP_STRING_PTR STRING_PTR_RO +#else +# define RCPP_STRING_PTR STRING_PTR +#endif + +#if R_VERSION >= R_Version(4, 4, 2) +# define RCPP_VECTOR_PTR VECTOR_PTR_RO +#else +# define RCPP_VECTOR_PTR VECTOR_PTR +#endif + +#endif /* RCPP_R_COMPAT_H */ diff --git a/inst/include/Rcpp/vector/Subsetter.h b/inst/include/Rcpp/vector/Subsetter.h index 339d2000d..085179171 100644 --- a/inst/include/Rcpp/vector/Subsetter.h +++ b/inst/include/Rcpp/vector/Subsetter.h @@ -174,10 +174,10 @@ class SubsetProxy { indices.reserve(rhs_n); SEXP names = Rf_getAttrib(lhs, R_NamesSymbol); if (Rf_isNull(names)) stop("names is null"); - SEXP* namesPtr = STRING_PTR(names); - SEXP* rhsPtr = STRING_PTR(rhs); + const SEXP* namesPtr = RCPP_STRING_PTR(names); + const SEXP* rhsPtr = RCPP_STRING_PTR(rhs); for (R_xlen_t i = 0; i < rhs_n; ++i) { - SEXP* match = std::find(namesPtr, namesPtr + lhs_n, *(rhsPtr + i)); + const SEXP* match = std::find(namesPtr, namesPtr + lhs_n, *(rhsPtr + i)); if (match == namesPtr + lhs_n) stop("not found"); indices.push_back(match - namesPtr); diff --git a/inst/include/RcppCommon.h b/inst/include/RcppCommon.h index a2760ec7a..5cbe895b5 100644 --- a/inst/include/RcppCommon.h +++ b/inst/include/RcppCommon.h @@ -28,6 +28,7 @@ // #define RCPP_DEBUG_MODULE_LEVEL 1 #include +#include /** * \brief Rcpp API diff --git a/src/api.cpp b/src/api.cpp index 7d3d729ba..aaf29ef6d 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -112,7 +112,7 @@ namespace Rcpp { case BCODESXP: return "BCODESXP"; case EXTPTRSXP: return "EXTPTRSXP"; case WEAKREFSXP: return "WEAKREFSXP"; -#if R_Version >= R_Version(4,4,0) // replaces S4SXP in R 4.4.0 +#if R_VERSION >= R_Version(4,4,0) // replaces S4SXP in R 4.4.0 case OBJSXP: return Rf_isS4(x) ? "S4SXP" : "OBJSXP"; // cf src/main/inspect.c #else case S4SXP: return "S4SXP"; diff --git a/src/barrier.cpp b/src/barrier.cpp index 374870ef2..c4e417920 100644 --- a/src/barrier.cpp +++ b/src/barrier.cpp @@ -22,11 +22,15 @@ #define COMPILING_RCPP #define USE_RINTERNALS + +#include #include + #include -#include "internal.h" -#include #include +#include + +#include "internal.h" // [[Rcpp::register]] SEXP get_string_elt(SEXP x, R_xlen_t i) { // #nocov start @@ -50,7 +54,8 @@ void char_set_string_elt(SEXP x, R_xlen_t i, const char* value) { // [[Rcpp::register]] SEXP* get_string_ptr(SEXP x) { - return STRING_PTR(x); + // TODO: should we deprecate this? + return const_cast(RCPP_STRING_PTR(x)); } // [[Rcpp::register]] @@ -65,7 +70,8 @@ void set_vector_elt(SEXP x, R_xlen_t i, SEXP value) { // [[Rcpp::register]] SEXP* get_vector_ptr(SEXP x) { - return VECTOR_PTR(x); // #nocov end + // TODO: should we deprecate this? + return const_cast(RCPP_VECTOR_PTR(x)); // #nocov end } // [[Rcpp::register]]