Re: [Rd] getNativeSymbolInfo("user_unif_rand") returns different results on windows and linux

From: Duncan Temple Lang <duncan_at_wald.ucdavis.edu>
Date: Wed, 17 Aug 2011 11:59:58 -0700

Hi Renaud

  I cannot presently step through the code on Windows to verify the cause of the problem, but looking at the code, I would _presume_ the reason is that symbol lookup is cached on Windows but not on Linux or OS X (at least by default). Thus when we perform the second search for user_unif_rand, we find it in the cache rather than searching all the DLLs.

This happens because we did not specify a value for the PACKAGE parameter.

When we load a new DLL, the cache should probably be cleared or we intelligently update it as necessary for the new DLLs on demand, i.e. for a new search for a symbol we look in the new DLLs and then use the cache. (This involves some book-keeping that could become convoluted.)

If we had specified a value for PACKAGE, e.g.

  getNativeSymbolInfo("user_unif_rand", "rstream")

we would get the version in that package's DLL.

So this gives a workaround that you can use with just R code

  findNativeSymbolInfo =
  function(sym, dlls = rev(getLoadedDLLs())) {

      for(d in dlls) {
         z = getNativeSymbolInfo(sym, d)
         if(!is.null(z))
          return(z)
      }

    NULL
  }

We'll think about whether to change the behaviour on Windows and how to do it without affecting performance excessively.

 Best,
   D.

On 8/17/11 9:12 AM, Renaud Gaujoux wrote:
> Hi,
>
> When loading a package that provides the user-supplied RNG hook user_unif_rand, calling
> getNativeSymbolInfo("user_unif_rand") returns informations about the loaded symbol.
> I am using this to identify which package currently provides the RNG hook.
> The results are the same on windows and linux if only one library provides the hook.
>
> If one loads a second package that provides this hook, then on linux (Ubuntu 10.10), calling again
> getNativeSymbolInfo("user_unif_rand") returns the latest symbol information (which I presume is the correct result).
> On windows (XP and Vista) however the symbol information does not change (same pointer address) and the package data is
> NULL.
> See results for both systems below. I tested this with R 2.12.1, 2.13.0 and 2.13.1 on Windows.
>
> Is this a normal behaviour for dll loaded on Windows?
> Thank you.
>
> Renaud
>
>
> #####################
> # LINUX
> #####################

>> library(rlecuyer)
>> getNativeSymbolInfo("user_unif_rand")

> $name
> [1] "user_unif_rand"
>
> $address
> <pointer: 0x7ff55acffed0>
> attr(,"class")
> [1] "NativeSymbol"
>
> $package
> DLL name: rlecuyer
> Filename: /home/renaud/R/x86_64-pc-linux-gnu-library/2.12/rlecuyer/libs/rlecuyer.so
> Dynamic lookup: TRUE
>
> attr(,"class")
> [1] "NativeSymbolInfo"
>> library(rstream)
>> getNativeSymbolInfo("user_unif_rand")

> $name
> [1] "user_unif_rand"
>
> $address
> <pointer: 0x7ff55aaf58c0>
> attr(,"class")
> [1] "NativeSymbol"
>
> $package
> DLL name: rstream
> Filename: /home/renaud/R/x86_64-pc-linux-gnu-library/2.12/rstream/libs/rstream.so
> Dynamic lookup: TRUE
>
> attr(,"class")
> [1] "NativeSymbolInfo"
>
> #####################
> # WINDOWS
> #####################
>> library(rlecuyer)
>> getNativeSymbolInfo("user_unif_rand")

> $name
> [1] "user_unif_rand"
>
> $address
> <pointer: 0x6bb84fb8>
> attr(,"class")
> [1] "NativeSymbol"
>
> $package
> DLL name: rlecuyer
> Filename: C:/Program
> Files/R/R-2.13.1/library/rlecuyer/libs/i386/rlecuyer.dll
> Dynamic lookup: TRUE
>
> attr(,"class")
> [1] "NativeSymbolInfo"
>> library(rstream)
>> getNativeSymbolInfo("user_unif_rand")

> $name
> [1] "user_unif_rand"
>
> $address
> <pointer: 0x6bb84fb8>
> attr(,"class")
> [1] "NativeSymbol"
>
> $package
> NULL
>
> attr(,"class")
> [1] "NativeSymbolInfo"
>
>
>
>
>
>
>
>
> ###
> UNIVERSITY OF CAPE TOWN
> This e-mail is subject to the UCT ICT policies and e-mai...{{dropped:5}}
>
> ______________________________________________
> 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 17 Aug 2011 - 19:05:02 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 17 Aug 2011 - 19:10:19 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