From ripley at stats.ox.ac.uk  Wed Oct 26 17:32:17 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed, 26 Oct 2005 16:32:17 +0100 (BST)
Subject: [Rd] pb with dyn.load - fortran code now attached
In-Reply-To: <Pine.OSF.4.58.0510260951360.171503@wotan.mdacc.tmc.edu>
References: <200510261514.40235.gilles.guillot@inapg.inra.fr>
	<Pine.OSF.4.58.0510260951360.171503@wotan.mdacc.tmc.edu>
Message-ID: <Pine.LNX.4.61.0510261626050.5413@gannet.stats>

On Wed, 26 Oct 2005, Paul Roebuck wrote:

> On Wed, 26 Oct 2005, Gilles GUILLOT wrote:
>
>> QUESTION 1:
>> [guillot at laplace guillot]$ R
>> R : Copyright 2005, The R Foundation for Statistical Computing
>> Version 2.2.0  (2005-10-06 r35749)
>> ISBN 3-900051-07-0
>>
>> >system("R CMD SHLIB ~/tmp/test1.f")
>> g77   -fPIC  -g -O2 -c /home/guillot/tmp/test1.f -o /home/guillot/tmp/test1.o
>> gcc -shared -L/usr/local/lib
>> -o /home/guillot/tmp/test1.so /home/guillot/tmp/test1.o  -lg2c -lm -lgcc_s
>>> system("R CMD SHLIB ~/tmp/test2.f")
>> g77   -fPIC  -g -O2 -c /home/guillot/tmp/test2.f -o /home/guillot/tmp/test2.o
>> gcc -shared -L/usr/local/lib
>> -o /home/guillot/tmp/test2.so /home/guillot/tmp/test2.o  -lg2c -lm -lgcc_s
>>>
>>> is.loaded("sub")
>> [1] FALSE
>>> is.loaded("sub_")
>> [1] FALSE
>>>
>> ## OK
>>> dyn.load("~/tmp/test1.so")
>>> is.loaded("sub")
>> [1] FALSE
>>> is.loaded("sub_")
>> [1] TRUE
>>>
>> ## it seems it does not comply with the 'value' section of the help
>> ## of function is.loaded:
>> ## "it needs the
>> ##    name you would give to '.C' or '.Fortran' and *not* that remapped
>> ##    by 'symbol.C' and 'symbol.For'."
>> ##
>> ## am i missing something ?
>>> q()
>
> The is.loaded method needs the argument to look exactly
> like the associated output from 'nm' (i.e., symbol name).
>
> $ nm ~/tmp/test1.so | grep sub
>
> Thus, you are manually asking for the following
>
>> is.loaded(symbol.For("sub"))
>
> The call to .Fortran use the (lowercase) name of the subroutine
> as it would appear in the Fortran source code.
>
> .Fortran("sub", ...)

Not at all the whole story.  First (unfortunately), the case mapping is 
OS-dependent and even compiler-dependent.  Second, look at stats.so which 
has

00030cf0 T supsmu_

yet

> is.loaded("supsmu_")
[1] FALSE
> is.loaded("supsmu")
[1] TRUE

That is a Fortran entry point, and it complies with the description 
quoted.

What is.loaded() needs depends on how the symbol would be found 
and so it is not much use.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] pb with dyn.load - fortran code now attached
Prof Brian Ripley