-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-43349: [R] Fix altrep string columns from readr #43351
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
Changes from all commits
2a7eee6
2a0da1e
206e94d
a22cb2e
2a57460
990e2cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,7 +138,13 @@ inline R_xlen_t r_string_size(SEXP s) { | |
| } // namespace unsafe | ||
|
|
||
| inline SEXP utf8_strings(SEXP x) { | ||
| return cpp11::unwind_protect([x] { | ||
| return cpp11::unwind_protect([&] { | ||
| // ensure that x is not actually altrep first this also ensures that | ||
| // x is not altrep even after it is materialized | ||
| bool was_altrep = ALTREP(x); | ||
| if (was_altrep) { | ||
| x = PROTECT(Rf_duplicate(x)); | ||
| } | ||
| R_xlen_t n = XLENGTH(x); | ||
|
|
||
| // if `x` is an altrep of some sort, this will | ||
|
|
@@ -152,6 +158,9 @@ inline SEXP utf8_strings(SEXP x) { | |
| SET_STRING_ELT(x, i, Rf_mkCharCE(Rf_translateCharUTF8(s), CE_UTF8)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we want to check whether
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like this from above? SEXP new_s = Rf_translateCharUTF8(s); Yeah, that's probably good. It'll also make this slightly more inline with what was there before (checking that not utf8)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried this, but after getting it to work with a bit of type faffing, doing the translate first we get errors with our utf string tests again. |
||
| } | ||
| } | ||
| if (was_altrep) { | ||
| UNPROTECT(1); | ||
| } | ||
| return x; | ||
| }); | ||
| } | ||
|
|
||
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.
Add a comment about why we have to duplicate?
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.
Yeah, I'll expand what I have there