Re: [Rd] external pointers

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Wed, 28 Dec 2011 10:09:05 -0500

Patrick,

On Dec 28, 2011, at 12:07 AM, Patrick Leyshock wrote:

> I have an external pointer object that I'd like to pass from my R code to
> some C code. Per Section 5.13 of "Writing R Extensions", I've noted that
> "external pointers should only be used as part of an object with normal
> semantics, for example an attribute or an element of a list." So I've
> written up a workable C function as such:
>
> SEXP my_c_function(SEXP param) {
> SEXP temp = getAttrib(param, install("ptr_attribute"));
> void * ptr = R_ExternalPtrAddr(temp);
> ... // do useful things with ptr
> }
>
> I can pass my_c_function() an object with "normal" semantics (such as an
> integer vector), where the external pointer object is a parameter named
> "ptr_attribute". The function extracts the pointer object from param; i.e.
> this function does what I want it to do.
>
> My question is: is there a way to do this using the .C() interface, rather
> than .Call()?

No. Why would you want to do that? .C is slower and mostly for backwards-compatibility. You can't pass anything complex with .C and the docs recommend .Call for this. The whole point of .C was to bypass R API but in your case you need it to get the pointer.

> Using call_R seems a possibility - has anyone had luck
> going this route?
>

call_R has nothing to do with this, it is sort of the equivalent of using the restricted set of objects to evaluate R function (so you still can't pass your pointer). As the docs say there is no point in using it in modern code.

Cheers,
Simon

> Any suggestions appreciated.
>
> Thanks, Patrick
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 28 Dec 2011 - 15:11:20 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 28 Dec 2011 - 16:20:21 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.

list of date sections of archive