Re: [Rd] getNativeSymbolInfo fails with Fortran symbol.

From: Thomas Petzoldt <Thomas.Petzoldt_at_TU-Dresden.de>
Date: Wed, 16 Apr 2008 10:15:29 +0200

Prof Brian Ripley wrote:

> It's a bug -- unlike is.loaded, getNativeSymbolInfo seems unaware of 
> Fortran names unless registered.
> 
> Will be fixed in 2.7.0.
> 
> On Wed, 9 Apr 2008, Setzer.Woodrow_at_epamail.epa.gov wrote:
> 

>>
>> In the following code routine 'initaquaphy' is defined in Fortran,
>> and dynamically loaded into R.:
>>
>> test.f:
>>
>>
>> subroutine initaquaphy(odeparms)
>>
>> external odeparms
>> double precision pars(19)
>> common /myparms/pars
>>
>> call odeparms(19, pars)
>>
>> return
>> end
>>
>> $ R CMD SHLIB Aquaphy.f
>> gfortran -fpic -g -O2 -c test.f -o test.o
>> gcc -std=gnu99 -shared -L/usr/local/lib -o test.so test.o -lgfortran -lm
>>
>>
>> and linked into the package dll (or so). Help for is.loaded() and
>> getNativeSymbolInfo() say not to use symbol.For() to convert
>> to Fortran-specific symbols. However, on Linux, getNativeSymbolInfo
>> is unable to find 'initaquaphy' in 'test.so', but does find
>> 'initaquaphy_'. Note that is.loaded() works as advertised. Furthermore,
>> this code works in Windows, R-2.6.2patched44759.
>>
>> triggerbug.R:
>>
>> system("R CMD SHLIB test.f")
>> dyn.load(paste("test",.Platform$dynlib.ext,sep=""))
>> is.loaded("initaquaphy", PACKAGE="test")
>> getNativeSymbolInfo("initaquaphy_", PACKAGE="test")
>> getNativeSymbolInfo("initaquaphy", PACKAGE="test")
>> cat("All Done")
>>
>> Resulting in:
>>
>>> source("triggerbug.R", echo=TRUE, print.eval=TRUE)
>>> system("R CMD SHLIB test.f")
>> gfortran -fpic -g -O2 -c test.f -o test.o
>> gcc -std=gnu99 -shared -L/usr/local/lib -o test.so test.o -lgfortran -lm
>>
>>> dyn.load(paste("test",.Platform$dynlib.ext,sep=""))
>>> is.loaded("initaquaphy", PACKAGE="test")
>> [1] TRUE
>>
>>> getNativeSymbolInfo("initaquaphy_", PACKAGE="test")
>> $name
>> [1] "initaquaphy_"
>>
>> $address
>> <pointer: 0x1c03f0>
>> attr(,"class")
>> [1] "NativeSymbol"
>>
>> $package
>> DLL name: test
>> Filename: /home/setzer/tasks/Programming_Projects/test.so
>> Dynamic lookup: TRUE
>>
>> attr(,"class")
>> [1] "NativeSymbolInfo"
>>
>>> getNativeSymbolInfo("initaquaphy", PACKAGE="test")
>> Error in FUN("initaquaphy"[[1L]], ...) :
>> no such symbol initaquaphy in package test
>> Have I misunderstood the help page, or is this a bug?
>>
>> --please do not edit the information below--
>>
>> Version:
>> platform = i686-pc-linux-gnu
>> arch = i686
>> os = linux-gnu
>> system = i686, linux-gnu
>> status = beta
>> major = 2
>> minor = 7.0
>> year = 2008
>> month = 04
>> day = 07
>> svn rev = 45159
>> language = R
>> version.string = R version 2.7.0 beta (2008-04-07 r45159)
>>
>> Locale:
>> LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C
>>
>> Search Path:
>> .GlobalEnv, package:deSolve, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads,
>> package:base
>>
>> R. Woodrow Setzer, Ph. D.
>> National Center for Computational Toxicology
>> http://www.epa.gov/comptox
>> US Environmental Protection Agency
>> Mail Drop B205-01/US EPA/RTP, NC 27711
>> Ph: (919) 541-0128 Fax: (919) 541-1194
>>
>> ______________________________________________
>> R-devel_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>

Many thanks to Prof. Brian Ripley

for fixing the above mentioned issue for recent versions of R. Unfortunately, the problem seems to persist on Linux x86/64.

The example is almost the same as above:

 > getNativeSymbolInfo("iniaqua", PACKAGE = "deSolve")$address Error in FUN("iniaqua"[[1L]], ...) :

   no such symbol iniaqua in package deSolve  > getNativeSymbolInfo("iniaqua_", PACKAGE = "deSolve")$address <pointer: 0x2b5cd3aa3960>
attr(,"class")
[1] "NativeSymbol"

Thomas Petzoldt

platform "x86_64-unknown-linux-gnu"
arch "x86_64"
os "linux-gnu"
system "x86_64, linux-gnu"
status "Under development (unstable)"
major "2"
minor "8.0"
year "2008"
month "04"
day "15"
`svn rev` "45347"
version.string "R version 2.8.0 Under development (unstable) (2008-04-15 r45347)"

g++ (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)

-- 
Thomas Petzoldt
Technische Universitaet Dresden
Institut fuer Hydrobiologie        thomas.petzoldt_at_tu-dresden.de
01062 Dresden                      http://tu-dresden.de/hydrobiologie/
GERMANY

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 16 Apr 2008 - 08:21:17 GMT

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 Sat 19 Apr 2008 - 19:31:11 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