\Header{getNativeSymbolInfo}{Obtain a description of a native (C/Fortran) symbol}
\keyword{interface}{getNativeSymbolInfo}
\begin{Description}\relax
This finds and returns as comprehensive a description of a
dynamically loaded or \dQuote{exported} built-in native
symbol. It returns information about the
name of the symbol, the library in which it is located
and, if available, the number of arguments it expects
and by which interface it should be called (i.e
\code{\Link{.Call}},   \code{\Link{.C}},
\code{\Link{.Fortran}},  or \code{\Link{.External}}).
Additionally, it returns the address of the symbol and this
can be passed to other C routines which can invoke.
Specifically, this provides a way to explicitly share
symbols between different dynamically loaded package libraries.
Also, it provides a way to query where symbols were resolved,
and aids diagnosing strange behavior associated with dynamic
resolution.
\end{Description}
\begin{Usage}
\begin{verbatim}
getNativeSymbolInfo(name, PACKAGE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{name}] the name of the native symbol as used in a call
to \code{\Link{is.loaded}}, etc.
\item[\code{PACKAGE}] an optional argument that specifies to which
dynamically loaded library we restrict the search for this symbol.
If this is \code{"base"}, we search in the R executable itself.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This uses the same mechanism for resolving symbols as is used
in all the native interfaces (\code{\Link{.Call}}, etc.).
If the symbol has been explicitly registered by the shared library
in which it is contained, information about the number of arguments
and the interface by which it should be called will be returned.
Otherwise, a generic native symbol object is returned.
\end{Details}
\begin{Value}
If the symbol is not found, an error is raised.
Otherwise, the value is a list containing the following elements:
\begin{ldescription}
\item[\code{name}] the name of the symbol, as given by the
\code{name} argument.
\item[\code{address}] the native memory address of the symbol which can
be used to invoke the routine, and also
compare with other symbol address. This is an external pointer
object and of class \code{NativeSymbol}.
\item[\code{package}] a list containing 3 elements:
\describe{
\item[name] the short form of the library name which can be used
as the value of the \code{PACKAGE} argument in
the different native interface functions.
\item[path] the fully qualified name of the shared library file.
\item[dynamicLookup] a logical value indicating whether dynamic
resolution is used when looking for symbols in this library,
or only registered routines can be located.
}    

\item[\code{numParameters}] the number of arguments that should be passed
in a call to this routine.
\end{ldescription}

Additionally, the list will have an additional class,
being \code{CRoutine},   \code{CallRoutine},
\code{FortranRoutine} or \code{ExternalRoutine}
corresponding to the R interface by which it should be invoked.
\end{Value}
\begin{Note}\relax
One motivation for accessing this reflectance information
is to be able to pass native routines to 
C routines as \dQuote{function pointers} in C.
This allows us to treat native routines and R functions
in a similar manner, such as when passing an R function
to C code that makes callbacks to that function
at different points in its computation
(e.g., \code{\Link{nls}}).
Additionally, we can resolve the symbol just once and
avoid resolving it repeatedly or using the internal
cache.
In the future, one may be able to treat \code{NativeSymbol}
objects as directly callback objects.
\end{Note}
\begin{Author}\relax
Duncan Temple Lang
\end{Author}
\begin{References}\relax
For information about registering native routines,
see \dQuote{In Search of {C/C++} \& {FORTRAN} Routines},
R News, volume 1, number 3, 2001, p20--23
(\url{http://CRAN.R-project.org/doc/Rnews/}).
\end{References}
\begin{SeeAlso}\relax
\code{\Link{is.loaded}},
\code{\Link{.C}},
\code{\Link{.Fortran}},
\code{\Link{.External}},
\code{\Link{.Call}},
\code{\Link{dyn.load}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
library(stats) # normally loaded
getNativeSymbolInfo("dansari")

getNativeSymbolInfo(symbol.For("hcass2"))
\end{ExampleCode}
\end{Examples}

