Loss of local variables when unloading shared library

HI,

When loading a library, then defining a variable, and then unloading a shared library - it seems the definition of the variable is lost, as if the environment is reset. Here is an example on Red Hat Enterprise 3 Linux using ROOT 4.02.00

root [0] gSystem->Load(“libPhysics.so”)
(int)0
root [1] int loop=25
root [2] loop
(int)25
root [3] gSystem->Unload(“libPhysics.so”)
root [4] loop
Error: Symbol loop is not defined in current scope FILE:(tmpfile) LINE:1
*** Interpreter error recovered ***
root [5]

I am assuming this would not be expected behavior.

Thanks,
Heather

Hi,

ROOT does not reset Cint when unloading libraries, as you can see in this example: root [0] int a=5 root [1] gSystem->Load("libPhysics") (int)0 root [2] int b=10 root [3] a (int)5 root [4] b (int)10 root [5] gSystem->Unload("libPhysics") root [6] b Error: Symbol b is not defined in current scope *** Interpreter error recovered *** root [7] a (int)5 root [8]
Only variables defined after loading the library will be removed, as they might reference the library, e.g. via virtual function tables. These references would be rendered invalid by unloading the library. Checking which variables (directly or indirectly) reference the library’s symbols is a lot of overhead.

Axel.

Hi,

Ok - I understand… one more question… is the same true of libraries loaded?

So if I load library X and then library Y… and then unload library X… library Y will be automatically unloaded in case Y depends on X?

I’ve seen this behavior too…

Thanks,
Heather

Hi Heather,
yes, any lib Y loaded after the lib X that is unloaded will be unloaded, too - for the exact same reason. Again, checking what symbols lib Y depends on (i.e. whether it depends on symbols of X) would be a hack to avoid it, but it’s not really guaranteed to find all indirect dependencies, and may thus fail. Unloading Y when unloading X is the only clean way out.

Axel.