Re: [Vala] Private variable/function/class



2013/7/15 Ulink <ulink gmx at>

Hi,

If I'm declaring a private variable/funtion/class and compile it to a
"package" (.so), it is not shown up in the .h and .vapi, this is ok.

However, all this symbols ARE exported in the .so symbol table!

If one bind more than one .so with e.g. the same PRIVATE variable named
"testVar" it acts like a one single global variable/function, but it
should be private!

I think valac should compile private variables/functions using the C
"static" modifier?


Example .vala file:

private int testVar;
private void TestFunc(string str) {
   print("TestFunc"+str);
}
private class TestClass : GLib.Object {
   private int data;
   public TestClass() {
      this.data = 5;
   }
   public void Method1() {
      print("Method1");
   }
}

Excerpt from .so symbol Table:

00000d3c T TestFunc
0000309c B testVar
00000e38 T testclass_Method1
00000dcf T testclass_construct
00000f60 T testclass_get_type
00000e13 T testclass_new




--
Ulink
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list



Hi Ulink,

I discovered this too when I wrote my library in Vala.
What I did to remedy this was compiling in two steps:

First, compile without linking (valac -c) while also using
valac's --symbols switch to output all public C symbols to a .sym file,
second, use a bash script to generate a linker script from the .sym file
which declares all those symbols global and the rest local,
and third, manually link the object files using the previously generated
linker script to only export the wanted symbols.

You can check out the rather hacky code at the github
repo<https://github.com/Ancurio/libzippler>,
specifically
"gen_linker_script.sh" and "Makefile".

This is in no way ideal, but I just wanted to tell you that it's possible.

Jonas


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]