After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 611904 - static variables do not get initialized even after an object was created
static variables do not get initialized even after an object was created
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Dova
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-03-05 14:20 UTC by Ralf Michl
Modified: 2012-08-06 17:59 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Ralf Michl 2010-03-05 14:20:49 UTC
public class A {
    public static string A = "blafasel";
}

does not generate any code in a_type_init() to initialize the static member variable from the (generated) constant struct.
Comment 1 Luca Bruno 2010-03-08 14:15:34 UTC
It's static, Why do you want it in type initialization? Maybe you're looking for public class string A = "something";
Comment 2 Ralf Michl 2010-03-08 15:29:41 UTC
Even a static variable needs to get initialized (= assigned some value) at some point - i guessed that static variables get set during type init - but maybe there is other, some better place to do this.
Obviously some static variables can be directly initialized statically via C structs, but for some types that may not be possible, so ...
Comment 3 Ralf Michl 2010-03-08 15:33:52 UTC
Maybe i should clarify the bug a little more: A.A never gets initialized (and thus always is null).
Comment 4 Jürg Billeter 2010-03-09 16:36:21 UTC
I'd actually like to move initialization of static members to something like module init functions in Dova (instead of type init functions as it's done in the GObject backend). This fixes issues when accessing static members before instantiating the corresponding instance and static members outside classes.
Comment 5 Ralf Michl 2010-03-10 12:15:36 UTC
I am not sure what the advantage of that would be.
On the other hand i see some difficulties if the vala compiler does not have all sources of a module available in a single run - or would that be a requirement then?
Comment 6 Jürg Billeter 2010-03-13 21:55:04 UTC
It's not quite clear yet, however, a module is not necessarily the same as a library or an application. You could have multiple modules in a single library. valac already needs access to all sources that have mutual dependencies as there is nothing like header files.
Comment 7 Ralf Michl 2010-03-16 13:46:26 UTC
Another problem with statics - with the following code ...

public class F {
    public static int i;

    public static int main(string[] args) {
        return F.i;
    }    
}

... the static variable only gets declared as extern (in the C code), thus the linker will not find it.
Removing the 'public' keyword fixes the problem (declares i as static variable in the C code).
Comment 8 geert jordaens 2011-08-04 18:40:56 UTC
Would qualifying the static members and moving them to the global:: namespace be an option?
Comment 9 Luca Bruno 2011-08-04 19:00:08 UTC
(In reply to comment #8)
> Would qualifying the static members and moving them to the global:: namespace
> be an option?

It's the right workaround here, yes.
Comment 10 Jürg Billeter 2012-08-06 17:59:16 UTC
The Dova profile has been removed in Vala 0.17.4. The upcoming successor will be available from verbon.org when it's ready.