Re: [Rd] Parameter changes and segfault when calling C code through .Call

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Thu 04 Jan 2007 - 21:31:01 GMT

"Michael Braun" <braunm@MIT.EDU> writes:
> Suppose I want to compute the log density of a multivariate normal
> distribution using C code and the gsl library. My R program is:

>
> dyn.load("mvnorm-logpdf.so")
>
> x<-c(0,0,0,0,0,0)
> mu<-c(0,0,0,0,0,0)
> sig<-diag(6)
> print(sig)
> w<-.Call("R_mvnorm_logpdf",as.double(x),as.double(mu),sig, as.integer(6))
> print(sig) # sig has changed after .Call

Arguments sent via the .Call interface are not copied. In almost all cases, they should be treated as read-only data.

You can copy a given SEXP using duplicate. Something along these lines (untested):

   SEXP sigma_copy;
   PROTECT(sigma_copy = duplicate(sigmax));

But it seems pretty clear that sigmaView is holding a pointer to sigmaAr which in turn points to the data in sigmax.

+ seth



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Jan 05 08:40:31 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 04 Jan 2007 - 22:31:01 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.