futureverse / marshal

[PROTOTYPE] R package: marshal - Framework to Marshal Objects to be Used in Another R Processes
https://marshal.futureverse.org/
Other
15 stars 1 forks source link

marshal: Rcpp::sourceCpp() #4

Open HenrikBengtsson opened 2 years ago

HenrikBengtsson commented 2 years ago

From https://future.futureverse.org/articles/future-4-non-exportable-objects.html#package-rcpp:

Rcpp::sourceCpp(code = "
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
int my_length(NumericVector x) {
    return x.size();
}
")

This produces:

my_length()

which holds an external reference pointer.

Can such an object be marshalled?

HenrikBengtsson commented 1 year ago

Most likely not possible without Rcpp adding support for this. The generated my_length() function has no references whatsoever to the source code, or to Rcpp for that matter;

> my_length
function (x) 
.Call(<pointer: 0x7f3f12609550>, x)

> str(my_length)
function (x) 

> as.list(body(my_length))
[[1]]
.Call

[[2]]
<pointer: 0x7f3f12609550>
attr(,"class")
[1] "NativeSymbol"

[[3]]
x

> ptr <- body(my_length)[[2]]
> ptr
<pointer: 0x7f3f12609550>
attr(,"class")
[1] "NativeSymbol"
> str(ptr)
Class 'NativeSymbol' <externalptr>