Skip to content

Commit c27764a

Browse files
committed
give a go
1 parent f53a687 commit c27764a

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

r/src/materialize.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
#include <R.h>
2020
#include <Rinternals.h>
2121

22+
#include "array.h"
2223
#include "nanoarrow.h"
23-
24+
#include "nanoarrow/r.h"
2425
#include "util.h"
2526

2627
// Needed for the list_of materializer
@@ -270,6 +271,33 @@ static void copy_vec_into(SEXP x, SEXP dst, R_xlen_t offset, R_xlen_t len) {
270271
}
271272
}
272273

274+
static int nanoarrow_materialize_nanoarrow_vctr(struct RConverter* converter,
275+
SEXP converter_xptr) {
276+
// This is a case where the callee needs ownership, which we can do via a
277+
// shallow copy.
278+
SEXP converter_shelter = R_ExternalPtrProtected(converter_xptr);
279+
280+
// TODO: Check that this SEXP has a lifecycle that is going to work with this
281+
SEXP array_xptr = VECTOR_ELT(converter_shelter, 2);
282+
283+
SEXP array_out_xptr = PROTECT(nanoarrow_array_owning_xptr());
284+
struct ArrowArray* out_array = nanoarrow_output_array_from_xptr(array_xptr);
285+
array_export(array_xptr, out_array);
286+
287+
// Append the chunk to the pairlist
288+
SEXP chunks_tail_sym = PROTECT(Rf_install("chunks_tail"));
289+
SEXP chunks_tail = PROTECT(Rf_getAttrib(converter->dst.vec_sexp, chunks_tail_sym));
290+
291+
SEXP next_sexp = PROTECT(Rf_cons(array_out_xptr, R_NilValue));
292+
SETCDR(chunks_tail, next_sexp);
293+
UNPROTECT(1);
294+
295+
Rf_setAttrib(converter->dst.vec_sexp, chunks_tail_sym, next_sexp);
296+
UNPROTECT(3);
297+
298+
return NANOARROW_OK;
299+
}
300+
273301
static int nanoarrow_materialize_other(struct RConverter* converter,
274302
SEXP converter_xptr) {
275303
// Ensure that we have a ptype SEXP to send in the call back to R

0 commit comments

Comments
 (0)