-
Notifications
You must be signed in to change notification settings - Fork 15
Add the Dataptr* methods to ALTREP representation #286
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
Conversation
…nside `mclapply()`)
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.
Thanks!
It's tricky to test this, but I believe that the_list[[0]] <- the_list[[1]]
will trigger SetElt
. For strings sort()
and unique()
will trigger Dataptr()
but I think those will just error here. Perhaps a stub Rcpp function whose only job is to call DATAPTR_RO(input)
would be a way to make sure this works from our test suite.
src/s2-altrep.cpp
Outdated
} | ||
|
||
static void* s2_altrep_Dataptr(SEXP obj, Rboolean writable) { | ||
if (writable) return 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.
I am not sure that you can return NULL here. I don't think it's harmful to skip this check, though, since we allocate all of the lists that we wrap in this ALTREP class.
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.
It sounds like a defect in R spec to me. Technically, DATAPTR is non-api (so I can't use it here), and returning writeable pointers for ALTREP lists is not supported at the API level. Since we seem to be entering the realm of undefined behavior, I think that returning NULL is fine. I also dislike casing away const pointer, but I don't really see a way around it in the current API.
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.
This is definitely a defect/inconsistency in R. Instead of returning NULL (which might trigger a segfault in current or future code), I think Rf_error()
is a better choice.
I've added some simple tests. |
src/s2-altrep.cpp
Outdated
} | ||
|
||
static void* s2_altrep_Dataptr(SEXP obj, Rboolean writable) { | ||
if (writable) return 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.
This is definitely a defect/inconsistency in R. Instead of returning NULL (which might trigger a segfault in current or future code), I think Rf_error()
is a better choice.
tests/testthat/test-s2-geography.R
Outdated
return (double) ((uintptr_t) DATAPTR_RO(obj)); | ||
}") | ||
|
||
expect_no_error(get_dataptr(as_s2_geography("POINT (0 0)"))) |
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.
expect_no_error(get_dataptr(as_s2_geography("POINT (0 0)"))) | |
expect_true(get_dataptr(as_s2_geography("POINT (0 0)")) != 0) |
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've changed the test function result to boolean directly as this is more portable
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.
Thank you!
When processing large amounts on data using the
parallel
package, the session occasionally errors out complaining about missing Dataptr method. It is not easily reproducible, and happens during the collection phase. This patch adds the missing methods.