Le 15 mai 2014 à 09:03, Stefano Calza a écrit :
> Hi everybody,
>
> I am trying to use big.matrix from Rcpp basically to write some (integer)
> data to a matrix.
>
> I keep getting segmentation fault due to 'memory not mapped'.
> Debugging with gdb I found out that the critical point is
>
> MatrixAccessor ma(*pBigMat);
>
> The function is declared as something like (I just followed the Gallery Rcpp
> example):
>
> RcppExport SEXP myFun(SEXP X, SEXP Y, SEXP Z, SEXP XX, XPtr
> pBigMat)
>
> Basically it cannot get to the correct pointer.
>
> The really weird thing is that this error happens ONLY using the function
> built within a package
>
> .Call('myFun',X,Y,Z,XX,bigMat@address,package='myPackage')
>
> BUT if I use the very same code, changing just the declaration
>
> // [Rcpp::export]
> IntegerVector myFun(SEXP X, SEXP Y, SEXP Z, SEXP XX, XPtr pBigMat)
>
> and then
>
> sourceCpp('mycode.cpp')
>
> and
>
> myFun(X,Y,Z,XX,bigMat@address)
>
> it works fine!
>
> So what am I doing wrong here? Is the pointer reset somehow? But why only
> when using .Call version?
>
> Thanks
>
> Stefano
If you use a raw .Call, all your parameters have to be SEXP.
If you want to use other parameter types, such as XPtr, you need to
use attributes (i.e. sourceCpp or compileAttributes) so that it generates .Call
compatible function for you.
Romain
___
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel