romainfrancois commented on a change in pull request #8246: URL: https://github.com/apache/arrow/pull/8246#discussion_r494154401
########## File path: r/src/arrow_cpp11.h ########## @@ -157,8 +157,15 @@ struct ns { template <typename Pointer> Pointer r6_to_pointer(SEXP self) { - return reinterpret_cast<Pointer>( - R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp))); + void* p = R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp)); + if (p == nullptr) { Review comment: We can't really do that because of the implicit `else NULL` case: ```r shared_ptr <- function(class, xp) { if (!shared_ptr_is_null(xp)) class$new(xp) } ``` There are cases where we want an R NULL when the internal C++ shared pointer holds a C++ null pointer, e.g. when we call: ```c++ std::shared_ptr<Array> RecordBatch::GetColumnByName(const std::string& name) const { auto i = schema_->GetFieldIndex(name); return i == -1 ? NULLPTR : column(i); } ``` For example in this tests: ```r test_that("[[ and $ on RecordBatch", { [...] expect_null(batch$qwerty) [...] }) ``` having the extra layer with the R function `shared_ptr(T, .)` maybe calling `T$new(.)` gives the NULL. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org