Skip to content

Commit c4eff7e

Browse files
committed
Use new bucket
1 parent 99ca031 commit c4eff7e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

r/src/arrow_cpp11.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,20 @@ Pointer r6_to_pointer(SEXP self) {
208208
cpp11::stop("Invalid R object for %s, must be an ArrowObject", type_name.c_str());
209209
}
210210

211-
#if R_VERSION >= R_Version(4, 5, 0)
212-
SEXP xp = R_getVarEx(arrow::r::symbols::xp, self, FALSE, R_UnboundValue);
211+
#if R_VERSION >= R_Version(4, 6, 0)
212+
if (!R_existsVarInFrame(self, arrow::r::symbols::xp)) {
213+
cpp11::stop("Invalid: self$`.:xp:.` is NULL");
214+
}
215+
SEXP xp = R_getVar(arrow::r::symbols::xp, self, FALSE);
216+
if (xp == R_NilValue) {
217+
cpp11::stop("Invalid: self$`.:xp:.` is NULL");
218+
}
213219
#else
214220
SEXP xp = Rf_findVarInFrame(self, arrow::r::symbols::xp);
215-
#endif
216221
if (xp == R_UnboundValue || xp == R_NilValue) {
217222
cpp11::stop("Invalid: self$`.:xp:.` is NULL");
218223
}
224+
#endif
219225

220226
void* p = R_ExternalPtrAddr(xp);
221227
if (p == nullptr) {
@@ -227,10 +233,16 @@ Pointer r6_to_pointer(SEXP self) {
227233

228234
template <typename T>
229235
void r6_reset_pointer(SEXP r6) {
230-
#if R_VERSION >= R_Version(4, 5, 0)
231-
SEXP xp = R_getVarEx(arrow::r::symbols::xp, r6, FALSE, R_UnboundValue);
236+
#if R_VERSION >= R_Version(4, 6, 0)
237+
if (!R_existsVarInFrame(r6, arrow::r::symbols::xp)) {
238+
return;
239+
}
240+
SEXP xp = R_getVar(arrow::r::symbols::xp, r6, FALSE);
232241
#else
233242
SEXP xp = Rf_findVarInFrame(r6, arrow::r::symbols::xp);
243+
if (xp == R_UnboundValue) {
244+
return;
245+
}
234246
#endif
235247
void* p = R_ExternalPtrAddr(xp);
236248
if (p != nullptr) {
@@ -388,13 +400,12 @@ SEXP to_r6(const std::shared_ptr<T>& ptr, const char* r6_class_name) {
388400
cpp11::external_pointer<std::shared_ptr<T>> xp(new std::shared_ptr<T>(ptr));
389401
SEXP r6_class = Rf_install(r6_class_name);
390402

391-
// R_existsVarInFrame doesn't exist before R 4.2, so we need to fall back to
392-
// Rf_findVarInFrame3 if it is not defined.
393-
#if R_VERSION >= R_Version(4, 2, 0)
403+
#if R_VERSION >= R_Version(4, 6, 0)
394404
if (!R_existsVarInFrame(arrow::r::ns::arrow, r6_class)) {
395405
cpp11::stop("No arrow R6 class named '%s'", r6_class_name);
396406
}
397407
#else
408+
// Rf_findVarInFrame3 and R_UnboundValue are non-API as of R 4.6
398409
if (Rf_findVarInFrame3(arrow::r::ns::arrow, r6_class, FALSE) == R_UnboundValue) {
399410
cpp11::stop("No arrow R6 class named '%s'", r6_class_name);
400411
}

r/src/symbols.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ SEXP precious(SEXP x) {
4646
// returns the namespace environment for package `name`
4747
SEXP precious_namespace(std::string name) {
4848
SEXP s_name = PROTECT(cpp11::writable::strings({name}));
49-
SEXP ns = R_FindNamespace(s_name);
49+
// Use getNamespace() instead of non-API R_FindNamespace
50+
SEXP call = PROTECT(Rf_lang2(Rf_install("getNamespace"), s_name));
51+
SEXP ns = Rf_eval(call, R_BaseEnv);
5052
R_PreserveObject(ns);
51-
UNPROTECT(1);
53+
UNPROTECT(2);
5254

5355
return ns;
5456
}

0 commit comments

Comments
 (0)