romainfrancois commented on a change in pull request #7819: URL: https://github.com/apache/arrow/pull/7819#discussion_r471349293
########## File path: r/src/arrow_cpp11.h ########## @@ -0,0 +1,243 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <limits> +#include <memory> +#include <utility> +#include <vector> +#undef Free + +namespace cpp11 { + +template <typename T> +SEXP as_sexp(const std::shared_ptr<T>& ptr); + +template <typename T> +SEXP as_sexp(const std::vector<std::shared_ptr<T>>& vec); + +template <typename E, typename std::enable_if<std::is_enum<E>::value>::type* = nullptr> +SEXP as_sexp(E e); + +} // namespace cpp11 + +#include <cpp11.hpp> + +namespace arrow { +namespace r { +struct symbols { + static SEXP units; + static SEXP tzone; + static SEXP xp; + static SEXP dot_Internal; + static SEXP inspect; + static SEXP row_names; + static SEXP serialize_arrow_r_metadata; + static SEXP as_list; + static SEXP ptype; + static SEXP byte_width; + static SEXP list_size; +}; + +struct data { + static SEXP classes_POSIXct; + static SEXP classes_metadata_r; + static SEXP classes_vctrs_list_of; + static SEXP classes_tbl_df; + + static SEXP classes_arrow_binary; + static SEXP classes_arrow_large_binary; + static SEXP classes_arrow_fixed_size_binary; + + static SEXP classes_arrow_list; + static SEXP classes_arrow_large_list; + static SEXP classes_arrow_fixed_size_list; + + static SEXP classes_factor; + static SEXP classes_ordered; + + static SEXP names_metadata; + static SEXP empty_raw; +}; + +struct ns { + static SEXP arrow; +}; + +template <typename Pointer> +Pointer r6_to_pointer(SEXP self) { + return reinterpret_cast<Pointer>( + R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp))); +} + +template <typename T, template <class> class SmartPtr> +class ConstRefSmartPtrInput { + public: + using const_reference = const SmartPtr<T>&; + + explicit ConstRefSmartPtrInput(SEXP self) + : ptr(r6_to_pointer<const SmartPtr<T>*>(self)) {} + + inline operator const_reference() { return *ptr; } + + private: + // this class host + const SmartPtr<T>* ptr; +}; Review comment: I believe we need to have an R external pointer to a smart (either shared or unique) pointer, and that we cannot directly have an external pointer to the underlying (e.g. Array) object. ########## File path: r/src/arrow_cpp11.h ########## @@ -0,0 +1,243 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include <limits> +#include <memory> +#include <utility> +#include <vector> +#undef Free + +namespace cpp11 { + +template <typename T> +SEXP as_sexp(const std::shared_ptr<T>& ptr); + +template <typename T> +SEXP as_sexp(const std::vector<std::shared_ptr<T>>& vec); + +template <typename E, typename std::enable_if<std::is_enum<E>::value>::type* = nullptr> +SEXP as_sexp(E e); + +} // namespace cpp11 + +#include <cpp11.hpp> + +namespace arrow { +namespace r { +struct symbols { + static SEXP units; + static SEXP tzone; + static SEXP xp; + static SEXP dot_Internal; + static SEXP inspect; + static SEXP row_names; + static SEXP serialize_arrow_r_metadata; + static SEXP as_list; + static SEXP ptype; + static SEXP byte_width; + static SEXP list_size; +}; + +struct data { + static SEXP classes_POSIXct; + static SEXP classes_metadata_r; + static SEXP classes_vctrs_list_of; + static SEXP classes_tbl_df; + + static SEXP classes_arrow_binary; + static SEXP classes_arrow_large_binary; + static SEXP classes_arrow_fixed_size_binary; + + static SEXP classes_arrow_list; + static SEXP classes_arrow_large_list; + static SEXP classes_arrow_fixed_size_list; + + static SEXP classes_factor; + static SEXP classes_ordered; + + static SEXP names_metadata; + static SEXP empty_raw; +}; + +struct ns { + static SEXP arrow; +}; + +template <typename Pointer> +Pointer r6_to_pointer(SEXP self) { + return reinterpret_cast<Pointer>( + R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp))); +} + +template <typename T, template <class> class SmartPtr> +class ConstRefSmartPtrInput { + public: + using const_reference = const SmartPtr<T>&; + + explicit ConstRefSmartPtrInput(SEXP self) + : ptr(r6_to_pointer<const SmartPtr<T>*>(self)) {} + + inline operator const_reference() { return *ptr; } + + private: + // this class host + const SmartPtr<T>* ptr; +}; Review comment: Thanks. ---------------------------------------------------------------- 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: [email protected]
