| 202 | |
| 203 | template <typename Pointer> |
| 204 | Pointer r6_to_pointer(SEXP self) { |
| 205 | if (!Rf_inherits(self, "ArrowObject")) { |
| 206 | std::string type_name = arrow::util::nameof< |
| 207 | cpp11::decay_t<typename std::remove_pointer<Pointer>::type>>(); |
| 208 | cpp11::stop("Invalid R object for %s, must be an ArrowObject", type_name.c_str()); |
| 209 | } |
| 210 | |
| 211 | // R_UnboundValue and Rf_findVarInFrame are non-API as of R 4.6 |
| 212 | #if R_VERSION >= R_Version(4, 6, 0) |
| 213 | SEXP xp = R_NilValue; |
| 214 | if (R_existsVarInFrame(self, arrow::r::symbols::xp)) { |
| 215 | xp = R_getVar(arrow::r::symbols::xp, self, FALSE); |
| 216 | } |
| 217 | if (xp == R_NilValue) { |
| 218 | cpp11::stop("Invalid: self$`.:xp:.` is NULL"); |
| 219 | } |
| 220 | #elif R_VERSION >= R_Version(4, 5, 0) |
| 221 | SEXP xp = R_getVarEx(arrow::r::symbols::xp, self, FALSE, R_UnboundValue); |
| 222 | if (xp == R_UnboundValue || xp == R_NilValue) { |
| 223 | cpp11::stop("Invalid: self$`.:xp:.` is NULL"); |
| 224 | } |
| 225 | #else |
| 226 | SEXP xp = Rf_findVarInFrame(self, arrow::r::symbols::xp); |
| 227 | if (xp == R_UnboundValue || xp == R_NilValue) { |
| 228 | cpp11::stop("Invalid: self$`.:xp:.` is NULL"); |
| 229 | } |
| 230 | #endif |
| 231 | |
| 232 | void* p = R_ExternalPtrAddr(xp); |
| 233 | if (p == nullptr) { |
| 234 | SEXP klass = Rf_getAttrib(self, R_ClassSymbol); |
| 235 | cpp11::stop("Invalid <%s>, external pointer to null", CHAR(STRING_ELT(klass, 0))); |
| 236 | } |
| 237 | return reinterpret_cast<Pointer>(p); |
| 238 | } |
| 239 | |
| 240 | template <typename T> |
| 241 | void r6_reset_pointer(SEXP r6) { |