Skip to content

Commit 8b57069

Browse files
committed
Throw an error on s2_altrep_Dataptr(writable = true), improve tests
1 parent 4d273ef commit 8b57069

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/s2-altrep.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ static void s2_altrep_SetElt(SEXP obj, R_xlen_t i, SEXP v) {
2828
}
2929

3030
static void* s2_altrep_Dataptr(SEXP obj, Rboolean writable) {
31-
if (writable) return NULL;
31+
if (writable) Rf_error("unable to produce writable DATAPTR for list data");
32+
3233
SEXP data = R_altrep_data1(obj);
3334
return (void*) DATAPTR_RO(data);
3435
}

tests/testthat/test-s2-geography.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ test_that("s2_geography vectors support elementwise assignment", {
284284
})
285285

286286
test_that("DATAPTR can be obtained for s2_geography", {
287-
Rcpp::cppFunction("double get_dataptr(SEXP obj) {
288-
return (double) ((uintptr_t) DATAPTR_RO(obj));
287+
Rcpp::cppFunction("bool get_dataptr(SEXP obj) {
288+
return DATAPTR_RO(obj) != NULL;
289289
}")
290290

291-
expect_no_error(get_dataptr(as_s2_geography("POINT (0 0)")))
291+
expect_true(get_dataptr(as_s2_geography("POINT (0 0)")))
292292
})

0 commit comments

Comments
 (0)