You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jonkeane (via GitHub)" <gi...@apache.org> on 2025/03/27 03:09:08 UTC

[PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

jonkeane opened a new pull request, #45951:
URL: https://github.com/apache/arrow/pull/45951

   This gets rid of `OBJECT`, thought it looks like `DATAPTR` is going to be more complicated. `DATAPTR_RO` isn't always a drop-in replacement 


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2781219657

   After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 34a984c842db42b409a1359e6e2cf167a2365a48.
   
   There were no benchmark performance regressions. 🎉
   
   The [full Conbench report](https://github.com/apache/arrow/runs/40048102535) has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2020338733


##########
r/src/altrep.cpp:
##########
@@ -1267,24 +1304,27 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
-    for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+    R_xlen_t len = Rf_xlength(x);
+
+    for (R_xlen_t i = 0; i < len; i++) {
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   `DATAPTR` and `STRING_ELT` work a bit different for altrep so it seems reasonable to me to assume we were implicitly materializing before and no longer are with `STRING_ELT`. It seems like this is an assumption of the test that no longer holds and the expectation could be removed.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2021535712


##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1293,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
     for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   When I remove this code, I get test failures about element access methods for characters:
   
   ```
   ══ Failed ══════════════════════════════════════════════════════════════════════
   ── 1. Failure (test-altrep.R:248:3): element access methods for character ALTREP
   test_arrow_altrep_copy_by_dataptr(altrep) (`actual`) not identical to `original` (`expected`).
   
   `actual` is NULL
   `expected` is a character vector (NA, '1', '2', '3', '4', ...)
   
   ── 2. Failure (test-altrep.R:255:3): element access methods for character ALTREP
   test_arrow_altrep_copy_by_dataptr(altrep) (`actual`) not identical to `original` (`expected`).
   
   `actual` is NULL
   `expected` is a character vector (NA, '1', '2', '3', '4', ...)
   
   ── 3. Failure (test-altrep.R:270:3): element access methods for character ALTREP
   test_arrow_altrep_copy_by_dataptr(altrep) (`actual`) not identical to `original` (`expected`).
   
   `actual` is NULL
   `expected` is a character vector (NA, '1', '2', '3', '4', ...)
   
   ── 4. Failure (test-altrep.R:277:3): element access methods for character ALTREP
   test_arrow_altrep_copy_by_dataptr(altrep) (`actual`) not identical to `original` (`expected`).
   
   `actual` is NULL
   `expected` is a character vector (NA, '1', '2', '3', '4', ...)
   ```



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "nealrichardson (via GitHub)" <gi...@apache.org>.
nealrichardson commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2764729754

   I don't understand this code well enough to have much to say. I did look at the part of WRE that the CRAN check points to, and it suggests using `DATAPTR_RO` instead of `DATAPTR`: https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Moving-into-C-API-compliance
   
   Is that not an option for us? 


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2019795742


##########
r/src/altrep.cpp:
##########
@@ -1267,24 +1304,27 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
-    for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+    R_xlen_t len = Rf_xlength(x);
+
+    for (R_xlen_t i = 0; i < len; i++) {
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   As a follow-on for myself that line 1319 is duplicative and should be removed (but I don't want to outdate ^^^ just yet)



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "h-vetinari (via GitHub)" <gi...@apache.org>.
h-vetinari commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2841310873

   I believe this PR is the likely reason for the following failure I'm seeing in https://github.com/conda-forge/r-arrow-feedstock/pull/101:
   
   ```
   In file included from r_to_arrow.cpp:18:
   .\./arrow_types.h:193:14: error: called object type 'arrow::r::RVectorType' is not a function or function pointer
     193 |       return COMPLEX(vec);
         |              ^~~~~~~
   .\./arrow_types.h:176:50: note: in instantiation of member function 'arrow::r::RBuffer<cpp11::r_vector<int>>::getDataPointer' requested here
     176 |       : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
         |                                                  ^
   C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\include\xutility:506:58: note: in instantiation of member function 'arrow::r::RBuffer<cpp11::r_vector<int>>::RBuffer' requested here
     506 |         ::new (static_cast<void*>(_STD addressof(_Obj))) _Ty(_STD forward<_Types>(_Args)...);
         |                                                          ^
   C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\include\memory:2092:18: note: in instantiation of function template specialization 'std::_Construct_in_place<arrow::r::RBuffer<cpp11::r_vector<int>>, cpp11::r_vector<int> &>' requested here
    2092 |             _STD _Construct_in_place(_Storage._Value, _STD forward<_Types>(_Args)...);
         |                  ^
   C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.43.34808\include\memory:2903:26: note: in instantiation of function template specialization 'std::_Ref_count_obj2<arrow::r::RBuffer<cpp11::r_vector<int>>>::_Ref_count_obj2<cpp11::r_vector<int> &>' requested here
    2903 |     const auto _Rx = new _Ref_count_obj2<_Ty>(_STD forward<_Types>(_Args)...);
         |                          ^
   r_to_arrow.cpp:1240:53: note: in instantiation of function template specialization 'std::make_shared<arrow::r::RBuffer<cpp11::r_vector<int>>, cpp11::r_vector<int> &>' requested here
    1240 |                                                std::make_shared<RBuffer<RVector>>(vec)};
         |                                                     ^
   r_to_arrow.cpp:1283:12: note: in instantiation of function template specialization 'arrow::r::MakeSimpleArray<13, cpp11::r_vector<int>, arrow::Int32Type>' requested here
    1283 |     return MakeSimpleArray<INTSXP, cpp11::integers, Int32Type>(x);
         |            ^
   ```
   
   This smells like macro leakage from the UCRT headers (e.g. if there's something called `COMPLEX` there already), which is always an issue on windows... C.f. `NOMINMAX`, `WIN32_LEAN_AND_MEAN` etc.
   
   We're using a clang on windows (adapted for the needs of R packages), together with the standard windows runtimes. CC @xhochy


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2780788987

   @github-actions crossbow submit -g r


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2029950592


##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1293,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
     for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   Thanks for checking that! I don't recall any tests that checked the whether something was materialized more than once but it was quite a long time ago 🙂 



##########
r/src/altrep.cpp:
##########
@@ -531,7 +552,7 @@ struct AltrepFactor : public AltrepVectorBase<AltrepFactor> {
       SEXP copy = PROTECT(Rf_allocVector(INTSXP, size));
 
       // copy the data from the array, through Get_region
-      Get_region(alt, 0, size, reinterpret_cast<int*>(DATAPTR(copy)));
+      Get_region(alt, 0, size, reinterpret_cast<int*>(INTEGER(copy)));

Review Comment:
   ```suggestion
         Get_region(alt, 0, size, INTEGER(copy));
   ```



##########
r/tests/testthat/test-altrep.R:
##########
@@ -244,11 +244,12 @@ test_that("element access methods for character ALTREP", {
   expect_identical(test_arrow_altrep_copy_by_element(altrep), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # DATAPTR() should always materialize for strings
+  # DATAPTR() does not materialize

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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "amoeba (via GitHub)" <gi...@apache.org>.
amoeba commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2020318572


##########
r/src/arrow_types.h:
##########
@@ -173,14 +173,39 @@ template <typename RVector>
 class RBuffer : public MutableBuffer {
  public:
   explicit RBuffer(RVector vec)
-      : MutableBuffer(reinterpret_cast<uint8_t*>(DATAPTR(vec)),
+      : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
                       vec.size() * sizeof(typename RVector::value_type),
                       arrow::CPUDevice::memory_manager(gc_memory_pool())),
         vec_(vec) {}
 
  private:
   // vec_ holds the memory
   RVector vec_;
+
+  static void* getDataPointer(RVector& vec) {
+    if (TYPEOF(vec) == LGLSXP) {
+      return LOGICAL(vec);
+    } else if (TYPEOF(vec) == INTSXP) {
+      return INTEGER(vec);
+    } else if (TYPEOF(vec) == REALSXP) {
+      return REAL(vec);
+    } else if (TYPEOF(vec) == CPLXSXP) {
+      return COMPLEX(vec);
+    } else if (TYPEOF(vec) == STRSXP) {
+      cpp11::writable::strings out(Rf_xlength(vec));
+      R_xlen_t len = Rf_xlength(vec);
+
+      for (R_xlen_t i = 0; i < len; i++) {
+        SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(vec, i));
+        out[i] = str_elt;
+      }
+
+      return out;

Review Comment:
   Just doing `return STRING_ELT(vec, 0)` actually makes sense to me since it looks like we just need a pointer to the same address as what we'd get with DATAPTR. Seems like that's what `STRING_ELT(vec, 0)` should accomplish. It does seem like a strange way to do it but it also seems like what we're doing here is already breaking the rules CRAN wants us to play by. If it works, I'm +1.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2021527879


##########
r/src/arrow_types.h:
##########
@@ -173,14 +173,33 @@ template <typename RVector>
 class RBuffer : public MutableBuffer {
  public:
   explicit RBuffer(RVector vec)
-      : MutableBuffer(reinterpret_cast<uint8_t*>(DATAPTR(vec)),
+      : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
                       vec.size() * sizeof(typename RVector::value_type),
                       arrow::CPUDevice::memory_manager(gc_memory_pool())),
         vec_(vec) {}
 
  private:
   // vec_ holds the memory
   RVector vec_;
+
+  static void* getDataPointer(RVector& vec) {
+    if (TYPEOF(vec) == LGLSXP) {
+      return LOGICAL(vec);
+    } else if (TYPEOF(vec) == INTSXP) {
+      return INTEGER(vec);
+    } else if (TYPEOF(vec) == REALSXP) {
+      return REAL(vec);
+    } else if (TYPEOF(vec) == CPLXSXP) {
+      return COMPLEX(vec);
+    } else if (TYPEOF(vec) == STRSXP) {
+      // Technically this returns the address to the first element of the string vector

Review Comment:
   _nods_ yeah, I agree this is weird! Did you see this comment (and especially the code block that was there, I've added below in case github folding hides it) https://github.com/apache/arrow/pull/45951#discussion_r2019797949 would this code be better here?
   
   ```
       } else if (TYPEOF(vec) == STRSXP) {
         cpp11::writable::strings out(Rf_xlength(vec));
         R_xlen_t len = Rf_xlength(vec);
   
         for (R_xlen_t i = 0; i < len; i++) {
           SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(vec, i));
           out[i] = str_elt;
         }
   
         return out;
       }
   ``` 



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2029875903


##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1285,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));

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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2019797949


##########
r/src/arrow_types.h:
##########
@@ -173,14 +173,39 @@ template <typename RVector>
 class RBuffer : public MutableBuffer {
  public:
   explicit RBuffer(RVector vec)
-      : MutableBuffer(reinterpret_cast<uint8_t*>(DATAPTR(vec)),
+      : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
                       vec.size() * sizeof(typename RVector::value_type),
                       arrow::CPUDevice::memory_manager(gc_memory_pool())),
         vec_(vec) {}
 
  private:
   // vec_ holds the memory
   RVector vec_;
+
+  static void* getDataPointer(RVector& vec) {
+    if (TYPEOF(vec) == LGLSXP) {
+      return LOGICAL(vec);
+    } else if (TYPEOF(vec) == INTSXP) {
+      return INTEGER(vec);
+    } else if (TYPEOF(vec) == REALSXP) {
+      return REAL(vec);
+    } else if (TYPEOF(vec) == CPLXSXP) {
+      return COMPLEX(vec);
+    } else if (TYPEOF(vec) == STRSXP) {
+      cpp11::writable::strings out(Rf_xlength(vec));
+      R_xlen_t len = Rf_xlength(vec);
+
+      for (R_xlen_t i = 0; i < len; i++) {
+        SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(vec, i));
+        out[i] = str_elt;
+      }
+
+      return out;

Review Comment:
   I believe this chunk is necessary to return the array of strings here. But oddly(??) when I tried this block as simply `return STRING_ELT(vec, 0);` (which would return just the first element IIUC), all tests passed. So maybe I misunderstand what's happening in the MutableBuffer there and we actually only need an object of the right type? Or we don't have test coverage that ensures that the full vector is there?



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2020940864


##########
r/src/arrow_types.h:
##########
@@ -173,14 +173,39 @@ template <typename RVector>
 class RBuffer : public MutableBuffer {
  public:
   explicit RBuffer(RVector vec)
-      : MutableBuffer(reinterpret_cast<uint8_t*>(DATAPTR(vec)),
+      : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
                       vec.size() * sizeof(typename RVector::value_type),
                       arrow::CPUDevice::memory_manager(gc_memory_pool())),
         vec_(vec) {}
 
  private:
   // vec_ holds the memory
   RVector vec_;
+
+  static void* getDataPointer(RVector& vec) {
+    if (TYPEOF(vec) == LGLSXP) {
+      return LOGICAL(vec);
+    } else if (TYPEOF(vec) == INTSXP) {
+      return INTEGER(vec);
+    } else if (TYPEOF(vec) == REALSXP) {
+      return REAL(vec);
+    } else if (TYPEOF(vec) == CPLXSXP) {
+      return COMPLEX(vec);
+    } else if (TYPEOF(vec) == STRSXP) {
+      cpp11::writable::strings out(Rf_xlength(vec));
+      R_xlen_t len = Rf_xlength(vec);
+
+      for (R_xlen_t i = 0; i < len; i++) {
+        SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(vec, i));
+        out[i] = str_elt;
+      }
+
+      return out;

Review Comment:
   Ok, I've also commented this to be explicit for the next person



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2020945049


##########
r/tests/testthat/test-altrep.R:
##########
@@ -170,7 +170,7 @@ test_that("element access methods for int32 ALTREP with nulls", {
   expect_identical(test_arrow_altrep_copy_by_region(altrep, 123), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # because there are no nulls, DATAPTR() does not materialize
+  # because there are nulls, DATAPTR() does materialize

Review Comment:
   This comment change and the one below are not _behavior_ changes with this PR, but I think the comments were simply wrong (either old or copy pasted). I've tried to correct them to be accurate descriptions of what's going on (but see "does not materialize" and then two lines later `expect_true(test_arrow_altrep_is_materialized(altrep))` is at odds with each other



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2766277845

   @github-actions crossbow submit -g r


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2780790376

   Revision: a4b457dd112eeeb760aff5525923f4a51df9c378
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-97a8d02cea](https://github.com/ursacomputing/crossbow/branches/all?query=actions-97a8d02cea)
   
   |Task|Status|
   |----|------|
   |r-binary-packages|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-r-binary-packages)](https://github.com/ursacomputing/crossbow/actions/runs/14283011616/job/40034749446)|
   |r-recheck-most|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-r-recheck-most)](https://github.com/ursacomputing/crossbow/actions/runs/14283011321/job/40034749201)|
   |test-r-arrow-backwards-compatibility|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-arrow-backwards-compatibility)](https://github.com/ursacomputing/crossbow/actions/runs/14283011367/job/40034749203)|
   |test-r-clang-sanitizer|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-clang-sanitizer)](https://github.com/ursacomputing/crossbow/actions/runs/14283011083/job/40034748317)|
   |test-r-depsource-bundled|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-depsource-bundled)](https://github.com/ursacomputing/crossbow/runs/40034749649)|
   |test-r-depsource-system|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-depsource-system)](https://github.com/ursacomputing/crossbow/actions/runs/14283011080/job/40034748313)|
   |test-r-dev-duckdb|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-dev-duckdb)](https://github.com/ursacomputing/crossbow/actions/runs/14283010991/job/40034748075)|
   |test-r-devdocs|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-devdocs)](https://github.com/ursacomputing/crossbow/actions/runs/14283011163/job/40034748749)|
   |test-r-extra-packages|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-extra-packages)](https://github.com/ursacomputing/crossbow/actions/runs/14283010970/job/40034748068)|
   |test-r-gcc-11|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-gcc-11)](https://github.com/ursacomputing/crossbow/actions/runs/14283011279/job/40034748928)|
   |test-r-gcc-12|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-gcc-12)](https://github.com/ursacomputing/crossbow/actions/runs/14283011243/job/40034748621)|
   |test-r-install-local|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-install-local)](https://github.com/ursacomputing/crossbow/actions/runs/14283011547/job/40034749551)|
   |test-r-install-local-minsizerel|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-install-local-minsizerel)](https://github.com/ursacomputing/crossbow/actions/runs/14283011033/job/40034748287)|
   |test-r-linux-as-cran|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-linux-as-cran)](https://github.com/ursacomputing/crossbow/actions/runs/14283011171/job/40034749414)|
   |test-r-linux-rchk|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-linux-rchk)](https://github.com/ursacomputing/crossbow/actions/runs/14283011339/job/40034749097)|
   |test-r-linux-sanitizer|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-linux-sanitizer)](https://github.com/ursacomputing/crossbow/actions/runs/14283011311/job/40034748978)|
   |test-r-linux-valgrind|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-linux-valgrind)](https://github.com/ursacomputing/crossbow/actions/runs/14283011431/job/40034749345)|
   |test-r-macos-as-cran|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-macos-as-cran)](https://github.com/ursacomputing/crossbow/actions/runs/14283011030/job/40034748115)|
   |test-r-minimal-build|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-minimal-build)](https://github.com/ursacomputing/crossbow/runs/40034750161)|
   |test-r-offline-maximal|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-offline-maximal)](https://github.com/ursacomputing/crossbow/actions/runs/14283011252/job/40034748766)|
   |test-r-offline-minimal|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-offline-minimal)](https://github.com/ursacomputing/crossbow/runs/40034749808)|
   |test-r-rhub-debian-gcc-devel-lto-latest|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-rhub-debian-gcc-devel-lto-latest)](https://github.com/ursacomputing/crossbow/runs/40034749852)|
   |test-r-rhub-debian-gcc-release-custom-ccache|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-rhub-debian-gcc-release-custom-ccache)](https://github.com/ursacomputing/crossbow/runs/40034749820)|
   |test-r-rhub-ubuntu-release-latest|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-rhub-ubuntu-release-latest)](https://github.com/ursacomputing/crossbow/runs/40034749406)|
   |test-r-rocker-r-ver-latest|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-rocker-r-ver-latest)](https://github.com/ursacomputing/crossbow/runs/40034749875)|
   |test-r-rstudio-r-base-4.1-opensuse155|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-rstudio-r-base-4.1-opensuse155)](https://github.com/ursacomputing/crossbow/runs/40034749810)|
   |test-r-rstudio-r-base-4.2-focal|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-97a8d02cea-azure-test-r-rstudio-r-base-4.2-focal)](https://github.com/ursacomputing/crossbow/runs/40034749580)|
   |test-r-ubuntu-22.04|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-ubuntu-22.04)](https://github.com/ursacomputing/crossbow/actions/runs/14283011138/job/40034748386)|
   |test-r-versions|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-97a8d02cea-github-test-r-versions)](https://github.com/ursacomputing/crossbow/actions/runs/14283011256/job/40034749148)|


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2029878648


##########
r/tests/testthat/test-altrep.R:
##########
@@ -244,11 +244,12 @@ test_that("element access methods for character ALTREP", {
   expect_identical(test_arrow_altrep_copy_by_element(altrep), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # DATAPTR() should always materialize for strings
+  # DATAPTR() does not materialize

Review Comment:
   Ah ok, I'm updating these to use `match()` to confirm that internally calling `DATAPTR()` (since we can't do that ourselves directly anymore) does materialize the vector.



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2029875356


##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1293,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
     for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   Ah, got it. Yeah if it's not helping us I agree removing it is the way to go. I tried the reprexes with `unique()` on my branch here as well as on released arrow and the results are comparable so I think we're ok. 
   
   I'm curious though — were there other tests we had that would have caught the multiple materialization issue? Or were these the ones that did that?
   
   Released arrow:
   ```
   > library(arrow)
   > df1 <- tibble::tibble(x=as.character(floor(runif(1000000) * 20)))
   > write_parquet(df1,"./test.parquet")
   > df2 <- read_parquet("./test.parquet")
   > system.time(unique(df1$x))
      user  system elapsed 
     0.014   0.000   0.015 
   > system.time(unique(df2$x))
      user  system elapsed 
     0.113   0.001   0.114 
   ```
   
   This branch:
   ```
   > library(arrow)
   > df1 <- tibble::tibble(x=as.character(floor(runif(1000000) * 20)))
   > write_parquet(df1,"./test.parquet")
   df2 <- read_parquet("./test.parquet")
   system.time(unique(df1$x))
   system.time(unique(df2$x))
   > df2 <- read_parquet("./test.parquet")
   > system.time(unique(df1$x))
      user  system elapsed 
     0.014   0.001   0.014 
   > system.time(unique(df2$x))
      user  system elapsed 
     0.106   0.001   0.107 
   ```



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2781110153

   @assignUser would it be possible to pull this into 20? We will need to patch it in our CRAN release regardless, but it would be nice to have it on the actual release.


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2780863373

   Failres: `test-r-rstudio-r-base-4.1-opensuse155` and `test-r-offline-maximal` are unrelated / being fixed elsewhere.


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2023917967


##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1285,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));

Review Comment:
   ```suggestion
       int* ptr = INTEGER(x);
   ```
   
   (and below as well)



##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1293,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
     for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   Yes, you'd have to remove the test that depends on it, too. This test was added in a follow up to https://github.com/apache/arrow/pull/13415 which fixed a case of multiple materializations when R's internals called DATAPTR(). As written, this test no longer calls DATAPTR() for a character vector, so it may be less confusing to remove it.
   
   In R  some things that might call DATAPTR are `altrep_vctr[1] = "something else"`, `unique()`, and `match(altrep_vctr, c("one", "two", "three"))` (one could check with the debugger or a print to see if it's actually getting called).



##########
r/tests/testthat/test-altrep.R:
##########
@@ -244,11 +244,12 @@ test_that("element access methods for character ALTREP", {
   expect_identical(test_arrow_altrep_copy_by_element(altrep), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # DATAPTR() should always materialize for strings
+  # DATAPTR() does not materialize

Review Comment:
   Yes, this was the crux of https://github.com/apache/arrow/pull/13415 (we were materializing the entire array multiple times when R's internals called DATAPTR()).



##########
r/src/altrep.cpp:
##########
@@ -220,7 +220,11 @@ struct AltrepVectorPrimitive : public AltrepVectorBase<AltrepVectorPrimitive<sex
       SEXP copy = PROTECT(Rf_allocVector(sexp_type, size));
 
       // copy the data from the array, through Get_region
-      Get_region(alt, 0, size, reinterpret_cast<c_type*>(DATAPTR(copy)));
+      if constexpr (std::is_same_v<c_type, double>) {
+        Get_region(alt, 0, size, REAL(copy));
+      } else {

Review Comment:
   Here and one other place would benefit from the `if constexpr (std::is_same_v<c_type, int>)` suggestion as well



##########
r/src/arrow_types.h:
##########
@@ -173,14 +173,33 @@ template <typename RVector>
 class RBuffer : public MutableBuffer {
  public:
   explicit RBuffer(RVector vec)
-      : MutableBuffer(reinterpret_cast<uint8_t*>(DATAPTR(vec)),
+      : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
                       vec.size() * sizeof(typename RVector::value_type),
                       arrow::CPUDevice::memory_manager(gc_memory_pool())),
         vec_(vec) {}
 
  private:
   // vec_ holds the memory
   RVector vec_;
+
+  static void* getDataPointer(RVector& vec) {
+    if (TYPEOF(vec) == LGLSXP) {
+      return LOGICAL(vec);
+    } else if (TYPEOF(vec) == INTSXP) {
+      return INTEGER(vec);
+    } else if (TYPEOF(vec) == REALSXP) {
+      return REAL(vec);
+    } else if (TYPEOF(vec) == CPLXSXP) {
+      return COMPLEX(vec);
+    } else if (TYPEOF(vec) == STRSXP) {
+      // Technically this returns the address to the first element of the string vector

Review Comment:
   I think erroring is a better option here (I believe exposing the bytes of a STRSXP's data buffer would be a programming error on our end).



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2766286153

   Revision: ec5161be763e506780e0eb01867a21106e2eabe9
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-50121181c0](https://github.com/ursacomputing/crossbow/branches/all?query=actions-50121181c0)
   
   |Task|Status|
   |----|------|
   |r-binary-packages|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-r-binary-packages)](https://github.com/ursacomputing/crossbow/actions/runs/14173068634/job/39701199382)|
   |r-recheck-most|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-r-recheck-most)](https://github.com/ursacomputing/crossbow/actions/runs/14173068740/job/39701202266)|
   |test-r-arrow-backwards-compatibility|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-arrow-backwards-compatibility)](https://github.com/ursacomputing/crossbow/actions/runs/14173069047/job/39701200871)|
   |test-r-clang-sanitizer|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-clang-sanitizer)](https://github.com/ursacomputing/crossbow/actions/runs/14173068747/job/39701201464)|
   |test-r-depsource-bundled|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-depsource-bundled)](https://github.com/ursacomputing/crossbow/runs/39701203276)|
   |test-r-depsource-system|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-depsource-system)](https://github.com/ursacomputing/crossbow/actions/runs/14173067443/job/39701195094)|
   |test-r-dev-duckdb|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-dev-duckdb)](https://github.com/ursacomputing/crossbow/actions/runs/14173068981/job/39701200498)|
   |test-r-devdocs|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-devdocs)](https://github.com/ursacomputing/crossbow/actions/runs/14173067743/job/39701197333)|
   |test-r-extra-packages|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-extra-packages)](https://github.com/ursacomputing/crossbow/actions/runs/14173067877/job/39701196673)|
   |test-r-gcc-11|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-gcc-11)](https://github.com/ursacomputing/crossbow/actions/runs/14173067369/job/39701194914)|
   |test-r-gcc-12|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-gcc-12)](https://github.com/ursacomputing/crossbow/actions/runs/14173068764/job/39701199351)|
   |test-r-install-local|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-install-local)](https://github.com/ursacomputing/crossbow/actions/runs/14173067887/job/39701197448)|
   |test-r-install-local-minsizerel|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-install-local-minsizerel)](https://github.com/ursacomputing/crossbow/actions/runs/14173067367/job/39701195928)|
   |test-r-linux-as-cran|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-linux-as-cran)](https://github.com/ursacomputing/crossbow/actions/runs/14173068686/job/39701204723)|
   |test-r-linux-rchk|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-linux-rchk)](https://github.com/ursacomputing/crossbow/actions/runs/14173068015/job/39701197313)|
   |test-r-linux-sanitizer|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-linux-sanitizer)](https://github.com/ursacomputing/crossbow/actions/runs/14173067532/job/39701195726)|
   |test-r-linux-valgrind|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-linux-valgrind)](https://github.com/ursacomputing/crossbow/actions/runs/14173068363/job/39701198062)|
   |test-r-macos-as-cran|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-macos-as-cran)](https://github.com/ursacomputing/crossbow/actions/runs/14173068485/job/39701198132)|
   |test-r-minimal-build|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-minimal-build)](https://github.com/ursacomputing/crossbow/runs/39701201747)|
   |test-r-offline-maximal|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-offline-maximal)](https://github.com/ursacomputing/crossbow/actions/runs/14173067447/job/39701195592)|
   |test-r-offline-minimal|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-offline-minimal)](https://github.com/ursacomputing/crossbow/runs/39701202185)|
   |test-r-rhub-debian-gcc-devel-lto-latest|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-rhub-debian-gcc-devel-lto-latest)](https://github.com/ursacomputing/crossbow/runs/39701203073)|
   |test-r-rhub-debian-gcc-release-custom-ccache|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-rhub-debian-gcc-release-custom-ccache)](https://github.com/ursacomputing/crossbow/runs/39701202207)|
   |test-r-rhub-ubuntu-release-latest|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-rhub-ubuntu-release-latest)](https://github.com/ursacomputing/crossbow/runs/39701199842)|
   |test-r-rocker-r-ver-latest|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-rocker-r-ver-latest)](https://github.com/ursacomputing/crossbow/runs/39701203336)|
   |test-r-rstudio-r-base-4.1-opensuse155|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-rstudio-r-base-4.1-opensuse155)](https://github.com/ursacomputing/crossbow/runs/39701200881)|
   |test-r-rstudio-r-base-4.2-focal|[![Azure](https://dev.azure.com/ursacomputing/crossbow/_apis/build/status/ursacomputing.crossbow?branchName=actions-50121181c0-azure-test-r-rstudio-r-base-4.2-focal)](https://github.com/ursacomputing/crossbow/runs/39701204532)|
   |test-r-ubuntu-22.04|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-ubuntu-22.04)](https://github.com/ursacomputing/crossbow/actions/runs/14173068893/job/39701200243)|
   |test-r-versions|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-50121181c0-github-test-r-versions)](https://github.com/ursacomputing/crossbow/actions/runs/14173068458/job/39701203586)|


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2021519977


##########
r/src/altrep.cpp:
##########
@@ -892,7 +904,19 @@ struct AltrepVectorString : public AltrepVectorBase<AltrepVectorString<Type>> {
     return s;
   }
 
-  static void* Dataptr(SEXP alt, Rboolean writeable) { return DATAPTR(Materialize(alt)); }
+  static void* Dataptr(SEXP alt, Rboolean writeable) {
+    // DATAPTR(Materialize(alt)) is disallowed by CRAN, so we need to createt the array of
+    // string and place the SEXPs in it ourselves with STRING_ELT()
+    SEXP materialized = Materialize(alt);
+
+    R_xlen_t len = XLENGTH(materialized);
+    void** str_array = (void**)R_alloc(len, sizeof(void*));
+    for (R_xlen_t i = 0; i < len; i++) {
+      str_array[i] = (void*)STRING_ELT(materialized, i);
+    }
+
+    return str_array;

Review Comment:
   Yup! that works. 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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2021509972


##########
r/tests/testthat/test-altrep.R:
##########
@@ -244,11 +244,12 @@ test_that("element access methods for character ALTREP", {
   expect_identical(test_arrow_altrep_copy_by_element(altrep), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # DATAPTR() should always materialize for strings
+  # DATAPTR() does not materialize

Review Comment:
   I should probably change these comments, we aren't calling `DATAPTR()` (ourselves) anymore. Do you think the changed code _should_ materialize? 



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2021496177


##########
r/src/altrep.cpp:
##########
@@ -220,7 +220,11 @@ struct AltrepVectorPrimitive : public AltrepVectorBase<AltrepVectorPrimitive<sex
       SEXP copy = PROTECT(Rf_allocVector(sexp_type, size));
 
       // copy the data from the array, through Get_region
-      Get_region(alt, 0, size, reinterpret_cast<c_type*>(DATAPTR(copy)));
+      if constexpr (std::is_same_v<c_type, double>) {
+        Get_region(alt, 0, size, reinterpret_cast<double*>(REAL(copy)));

Review Comment:
   Ah, yes! Thanks (and same for the following branch too, which I got)



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2019675135


##########
r/src/altrep.cpp:
##########
@@ -1267,24 +1304,27 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
-    for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+    R_xlen_t len = Rf_xlength(x);
+
+    for (R_xlen_t i = 0; i < len; i++) {
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   Something about this isn't quite right, because the test here (and other assertions that strings are materialized) fail:
   
   https://github.com/apache/arrow/blob/3c63f37d4211e7a8d42c8388a12888e63fe377e3/r/tests/testthat/test-altrep.R#L249
   
   But I haven't yet figured out if this is a real problem with this code change, or maybe it's an assumption in the tests that no longer holds?
   
   @nealrichardson @paleolimbot y'all might have thoughts ?



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2764733813

   > suggests using DATAPTR_RO instead of DATAPTR: https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Moving-into-C-API-compliance
   > 
   > Is that not an option for us?
   
   It is an option in one place and I did use it there, but not all: I would get segfaults/illegal access in the places that I didn't use it. If I'm reading the code correctly, those are places where we are actually mutating in place


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "paleolimbot (via GitHub)" <gi...@apache.org>.
paleolimbot commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2021335064


##########
r/src/altrep.cpp:
##########
@@ -269,13 +273,21 @@ struct AltrepVectorPrimitive : public AltrepVectorBase<AltrepVectorPrimitive<sex
     }
 
     // Otherwise we have to materialize and hand the pointer to data2
-    return DATAPTR(Materialize(alt));
+    if constexpr (std::is_same_v<c_type, double>) {
+      return REAL(Materialize(alt));
+    } else {
+      return INTEGER(Materialize(alt));
+    }

Review Comment:
   ```suggestion
       } else if constexpr (std::is_same_v<c_type, int>) {
         return INTEGER(Materialize(alt));
       } else {
         static_assert(false, "ALTREP not implemented for c_type");
       }
   ```
   
   ...maybe safer in case we ever add altraw support?



##########
r/src/altrep.cpp:
##########
@@ -220,7 +220,11 @@ struct AltrepVectorPrimitive : public AltrepVectorBase<AltrepVectorPrimitive<sex
       SEXP copy = PROTECT(Rf_allocVector(sexp_type, size));
 
       // copy the data from the array, through Get_region
-      Get_region(alt, 0, size, reinterpret_cast<c_type*>(DATAPTR(copy)));
+      if constexpr (std::is_same_v<c_type, double>) {
+        Get_region(alt, 0, size, reinterpret_cast<double*>(REAL(copy)));

Review Comment:
   ```suggestion
           Get_region(alt, 0, size, REAL(copy));
   ```
   
   (I think this should work)



##########
r/tests/testthat/test-altrep.R:
##########
@@ -170,7 +170,7 @@ test_that("element access methods for int32 ALTREP with nulls", {
   expect_identical(test_arrow_altrep_copy_by_region(altrep, 123), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # because there are no nulls, DATAPTR() does not materialize
+  # because there are nulls, DATAPTR() does materialize

Review Comment:
   You're correct here that my earlier comment was simply wrong 🙂 



##########
r/tests/testthat/test-altrep.R:
##########
@@ -265,11 +266,12 @@ test_that("element access methods for character ALTREP from large_utf8()", {
   expect_identical(test_arrow_altrep_copy_by_element(altrep), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # DATAPTR() should always materialize for strings
+  # DATAPTR() sdoes not materialize

Review Comment:
   Again, I'm almost positive that DATAPTR() should still materialize (but check with somebody who has kept up on the internals here!)



##########
r/src/altrep.cpp:
##########
@@ -892,7 +904,19 @@ struct AltrepVectorString : public AltrepVectorBase<AltrepVectorString<Type>> {
     return s;
   }
 
-  static void* Dataptr(SEXP alt, Rboolean writeable) { return DATAPTR(Materialize(alt)); }
+  static void* Dataptr(SEXP alt, Rboolean writeable) {
+    // DATAPTR(Materialize(alt)) is disallowed by CRAN, so we need to createt the array of
+    // string and place the SEXPs in it ourselves with STRING_ELT()
+    SEXP materialized = Materialize(alt);
+
+    R_xlen_t len = XLENGTH(materialized);
+    void** str_array = (void**)R_alloc(len, sizeof(void*));
+    for (R_xlen_t i = 0; i < len; i++) {
+      str_array[i] = (void*)STRING_ELT(materialized, i);
+    }
+
+    return str_array;

Review Comment:
   ```suggestion
       return const_cast<void*>(DATAPTR_RO(Materialize(alt)));
   ```
   
   (Not sure if this works but it's worth a shot!)



##########
r/src/arrow_types.h:
##########
@@ -173,14 +173,33 @@ template <typename RVector>
 class RBuffer : public MutableBuffer {
  public:
   explicit RBuffer(RVector vec)
-      : MutableBuffer(reinterpret_cast<uint8_t*>(DATAPTR(vec)),
+      : MutableBuffer(reinterpret_cast<uint8_t*>(getDataPointer(vec)),
                       vec.size() * sizeof(typename RVector::value_type),
                       arrow::CPUDevice::memory_manager(gc_memory_pool())),
         vec_(vec) {}
 
  private:
   // vec_ holds the memory
   RVector vec_;
+
+  static void* getDataPointer(RVector& vec) {
+    if (TYPEOF(vec) == LGLSXP) {
+      return LOGICAL(vec);
+    } else if (TYPEOF(vec) == INTSXP) {
+      return INTEGER(vec);
+    } else if (TYPEOF(vec) == REALSXP) {
+      return REAL(vec);
+    } else if (TYPEOF(vec) == CPLXSXP) {
+      return COMPLEX(vec);
+    } else if (TYPEOF(vec) == STRSXP) {
+      // Technically this returns the address to the first element of the string vector

Review Comment:
   This should almost certainly error if I'm reading this properly (I don't think we should ever be exposing the internal `SEXP**` to Arrow and I don't think we ever do?)



##########
r/tests/testthat/test-altrep.R:
##########
@@ -244,11 +244,12 @@ test_that("element access methods for character ALTREP", {
   expect_identical(test_arrow_altrep_copy_by_element(altrep), original)
   expect_false(test_arrow_altrep_is_materialized(altrep))
 
-  # DATAPTR() should always materialize for strings
+  # DATAPTR() does not materialize

Review Comment:
   I believe that a call to DATAPTR() should still materialize?



##########
r/src/altrep.cpp:
##########
@@ -1267,23 +1293,23 @@ sexp test_arrow_altrep_copy_by_dataptr(sexp x) {
 
   if (TYPEOF(x) == INTSXP) {
     cpp11::writable::integers out(Rf_xlength(x));
-    int* ptr = reinterpret_cast<int*>(DATAPTR(x));
+    int* ptr = reinterpret_cast<int*>(INTEGER(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == REALSXP) {
     cpp11::writable::doubles out(Rf_xlength(x));
-    double* ptr = reinterpret_cast<double*>(DATAPTR(x));
+    double* ptr = reinterpret_cast<double*>(REAL(x));
     for (R_xlen_t i = 0; i < n; i++) {
       out[i] = ptr[i];
     }
     return out;
   } else if (TYPEOF(x) == STRSXP) {
     cpp11::writable::strings out(Rf_xlength(x));
-    SEXP* ptr = reinterpret_cast<SEXP*>(DATAPTR(x));
     for (R_xlen_t i = 0; i < n; i++) {
-      out[i] = ptr[i];
+      SEXP str_elt = reinterpret_cast<SEXP>(STRING_ELT(x, i));
+      out[i] = str_elt;

Review Comment:
   I think you can remove this branch since it quite literally peeks into the internals they're trying to make opaque and it's just test code. A more real-world application would be to find where r-source does this and make sure that method works on our ALTREP. I think, but don't know, that `SET_STRING_ELT()` and `match()` will call DATAPTR().



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2766676654

   Failures:
   
   * `test-r-linux-as-cran` https://github.com/apache/arrow/issues/45714 (it's a cleanup issue, I'm not sure why that one has it but others don't, but the check is clean)
   * `test-r-offline-maximal` https://github.com/apache/arrow/issues/45716
   * `r-recheck-most` I think this is ok because the error is in the old results?


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "assignUser (via GitHub)" <gi...@apache.org>.
assignUser commented on PR #45951:
URL: https://github.com/apache/arrow/pull/45951#issuecomment-2781113038

   Of course!


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane merged PR #45951:
URL: https://github.com/apache/arrow/pull/45951


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-45949: [R] Fix CRAN warnings for 19.0.1 about compiled code [arrow]

Posted by "jonkeane (via GitHub)" <gi...@apache.org>.
jonkeane commented on code in PR #45951:
URL: https://github.com/apache/arrow/pull/45951#discussion_r2029958390


##########
r/src/altrep.cpp:
##########
@@ -531,7 +552,7 @@ struct AltrepFactor : public AltrepVectorBase<AltrepFactor> {
       SEXP copy = PROTECT(Rf_allocVector(INTSXP, size));
 
       // copy the data from the array, through Get_region
-      Get_region(alt, 0, size, reinterpret_cast<int*>(DATAPTR(copy)));
+      Get_region(alt, 0, size, reinterpret_cast<int*>(INTEGER(copy)));

Review Comment:
   Ah yes, thanks for that reminder, I found a few others too



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org