-
Notifications
You must be signed in to change notification settings - Fork 4.2k
ARROW-10071: [R] segfault with ArrowObject from previous session, or saved #8246
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40af861
ArrowObject back by null external pointers fail gracefully instead of…
romainfrancois e77d98a
refinements
romainfrancois 87c26f7
add nameof utility to replace typeid().name()
bkietz 06e4ac6
de-constexpr
bkietz 0086446
remove <iostream> include
bkietz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // 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 <string> | ||
|
|
||
| namespace arrow { | ||
| namespace util { | ||
| namespace detail { | ||
|
|
||
| #ifdef _MSC_VER | ||
| #define ARROW_PRETTY_FUNCTION __FUNCSIG__ | ||
| #else | ||
| #define ARROW_PRETTY_FUNCTION __PRETTY_FUNCTION__ | ||
| #endif | ||
|
|
||
| template <typename T> | ||
| const char* raw() { | ||
| return ARROW_PRETTY_FUNCTION; | ||
| } | ||
|
|
||
| template <typename T> | ||
| size_t raw_sizeof() { | ||
| return sizeof(ARROW_PRETTY_FUNCTION); | ||
| } | ||
|
|
||
| #undef ARROW_PRETTY_FUNCTION | ||
|
|
||
| constexpr bool starts_with(char const* haystack, char const* needle) { | ||
| return needle[0] == '\0' || | ||
| (haystack[0] == needle[0] && starts_with(haystack + 1, needle + 1)); | ||
| } | ||
|
|
||
| constexpr size_t search(char const* haystack, char const* needle) { | ||
| return haystack[0] == '\0' || starts_with(haystack, needle) | ||
| ? 0 | ||
| : search(haystack + 1, needle) + 1; | ||
| } | ||
|
|
||
| const size_t typename_prefix = search(raw<void>(), "void"); | ||
|
|
||
| template <typename T> | ||
| size_t struct_class_prefix() { | ||
| #ifdef _MSC_VER | ||
| return starts_with(raw<T>() + typename_prefix, "struct ") | ||
| ? 7 | ||
| : starts_with(raw<T>() + typename_prefix, "class ") ? 6 : 0; | ||
| #else | ||
| return 0; | ||
| #endif | ||
| } | ||
|
|
||
| template <typename T> | ||
| size_t typename_length() { | ||
| // raw_sizeof<T>() - raw_sizeof<void>() == (length of T's name) - strlen("void") | ||
| // (length of T's name) == raw_sizeof<T>() - raw_sizeof<void>() + strlen("void") | ||
| return raw_sizeof<T>() - raw_sizeof<void>() + 4; | ||
| } | ||
|
|
||
| template <typename T> | ||
| const char* typename_begin() { | ||
| return raw<T>() + struct_class_prefix<T>() + typename_prefix; | ||
| } | ||
|
|
||
| } // namespace detail | ||
|
|
||
| template <typename T> | ||
| std::string nameof() { | ||
| return {detail::typename_begin<T>(), detail::typename_length<T>()}; | ||
| } | ||
|
|
||
| } // namespace util | ||
| } // namespace arrow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If we're checking for nullptr here, can we remove the
shared_ptr_is_nullcheck inside theshared_ptr()constructor? Then we can just$new()to create the R6 objects.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.
We can't really do that because of the implicit
else NULLcase: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:
For example in this tests:
having the extra layer with the R function
shared_ptr(T, .)maybe callingT$new(.)gives the NULL.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.
Another way would be to have the ability to directly create the R6 objects internally, either by having more code in
but we would need some sort of dispatch from
Tto the R6 object.Or we would need to change the interface of many functions:
perhaps to:
but I don't think it's worth it
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.
Ah ok, I missed that that check translated some responses into
NULL--though I don't think that's something we do widely, and maybe it would be better to make that more explicit in order to simplify the rest of the cases.Regarding directly returning R6 objects from the cpp code, my thought had been more like the first idea of modifying
as_sexpto mapTto R6 classes. Our convention is that R6 class names are generally the bare C++ class name (assuming namespaces), i.e.arrow::dataset::DatasetisDatasetR6 class, with some exceptions. So we could record a map of those exceptions (e.g. "arrow::csv::TableReader" maps to "CsvTableReader") in cpp. If I were writing this in R, it could look something like this:cc @bkietz
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.
I'd prefer to specify a complete mapping T to R6 class names, rather than only listing special cases. This would be a pretty straightforward trait structure in c++