Bug 17184

Summary: getDLLRegisteredRoutines: subscript out of bounds
Product: R Reporter: Matt Dowle <mattjdowle>
Component: Low-levelAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: minor CC: maechler
Priority: P5    
Version: R-devel (trunk)   
Hardware: All   
OS: All   

Description Matt Dowle 2016-11-22 19:34:26 UTC
When two .so objects are loaded with the same name, the warning message constructor in getDLLRegisteredRoutines.character has an out of bounds error.

Using R-release or R-devel on any platform. I assume it occurs with Windows .dll as well but I've only checked with Linux .so.

Pick any package .so you have two of in different paths but the same name. I'll use datatable.so to illustrate as I have that handy but any .so should reproduce.

$ Rdevel
> dyn.load("/home/mdowle/data.table/src/datatable.so")
> length(getDLLRegisteredRoutines("datatable", TRUE))
[1] 4    # correct and ok so far

Now load the same file name in a different place. Does not have to be the same file contents, just the same name.

> dyn.load("/usr/local/lib/R/site-library/data.table/libs/datatable.so")
> getLoadedDLLs()  # shows both loaded ok

> length(getDLLRegisteredRoutines("datatable", TRUE))
Error in dll[["path"]] : subscript out of bounds

In getDLLRegisteredRoutines.character change this line :

 warning(gettextf("multiple DLLs match '%s'. Using '%s'", 
     dll, dll[["path"]]), domain = NA)

to this :

 warning(gettextf("multiple DLLs match '%s'. Using '%s'", 
     names(dll), dlls[[dll]][["path"]]), domain = NA)

Now works correctly :

> length(getDLLRegisteredRoutines("datatable", TRUE))
[1] 4
Warning message:
In getDLLRegisteredRoutines.character("datatable", TRUE) :
  multiple DLLs match 'datatable'. Using '/home/mdowle/data.table/src/datatable.so'
>
Comment 1 Martin Maechler 2016-11-23 09:53:44 UTC
You are right, thank you very much, Matt!

A bug fix hase been committed .. and will be ported to  "R patched", i.e., should be fixed in all future versions of R