-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use read-only variants of {STRING/VECTOR}_PTR #1317
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
// | ||
// 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 <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef RCPP_R_COMPAT_H | ||
#define RCPP_R_COMPAT_H | ||
|
||
#if defined(STRING_PTR_RO) | ||
# define RCPP_STRING_PTR STRING_PTR_RO | ||
#else | ||
# define RCPP_STRING_PTR STRING_PTR | ||
#endif | ||
|
||
#if defined(VECTOR_PTR_RO) | ||
# define RCPP_VECTOR_PTR VECTOR_PTR_RO | ||
#else | ||
# define RCPP_VECTOR_PTR VECTOR_PTR | ||
#endif | ||
|
||
#endif /* RCPP_R_COMPAT_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,15 @@ | |
#define COMPILING_RCPP | ||
|
||
#define USE_RINTERNALS | ||
|
||
#include <algorithm> | ||
#include <Rinternals.h> | ||
|
||
#include <Rcpp/barrier.h> | ||
#include "internal.h" | ||
#include <algorithm> | ||
#include <Rcpp/protection/Shield.h> | ||
#include <Rcpp/r/compat.h> | ||
|
||
#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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May need a full rev.dep run to see if it is being called? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we leave this code as-is for this PR, and then later test their removal in a separate PR, to see what breaks? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a plan! |
||
return const_cast<SEXP*>(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<SEXP*>(RCPP_VECTOR_PTR(x)); // #nocov end | ||
} | ||
|
||
// [[Rcpp::register]] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. I wondered about the need to make this conditonal on existence of the new macro or min R version.