Skip to content
Prev 12456 / 398502 Next

registration of C routines

Interesting. I also run into this idea of specifying the name of a
routine rather than an R function. I haven't done much about
implementing anything yet, but here is my plan.  When the user
specifies a "callback", if it is a function object, then we treat it
as a regular R function. If it is a string, then we lookup the
corresponding native symbol and return its address (and type) as an R
object. For example, suppose the user calls
  lsoda(y, times, func = "foo")
then the lsoda() code would call
  NativeSymbol(func)
and get back an object such as
  x <- list(address= numeric(1), pid="R session identifier", numArgs = ?, argTypes = c(argName=type, argName=type))
  class(x) <- c("CRoutine", "NativeSymbolRef")

(The numArgs and argTypes would be available if the routine were registered.)

Now, this object (returned from NativeSymbol()) would get passed to
the C code that implements the lsoda() internals and contains the
address which can be cast to a C routine pointer and the routine
invoked that way.


If we have a collection of constructor functions such as 

  CRoutine(name, PACKAGE="")
  FortranRoutine(name, PACKAGE="")
  CallRoutine(name, PACKAGE="")
  ExternalRoutine(name, PACKAGE="")
and the generic one
  NativeSymbol(name, PACKAGE="")
the user can specify which package to use, etc.
and be precise about which symbol they want.
This avoids any loading order issues, etc.


This approach would require a little bit of code in the base R that
would "reflect" information about the native symbols in one or more
DLLs/Shared libraries. This is very convenient for exactly your
purposes and doing general meta-computing on the system.  But it keeps
users above the C-level internals of R which are potentially subject
to change.

One has to be very careful not to save one of these symbol reference
objects and restore it in a different session. But this is also
another recurring issue that we have to deal with.


Will this approach work for your problem? Is it too complex?

  D.
Setzer.Woodrow at epamail.epa.gov wrote:
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Message-ID: <20010720073607.D12804@jessie.research.bell-labs.com>
In-Reply-To: <OF1AA75EB7.DA61FB67-ON85256A8E.005CABB6@rtp.epa.gov>; from Setzer.Woodrow@epamail.epa.gov on Thu, Jul 19, 2001 at 01:04:07PM -0400