[Vala] Behavior on null pointers



Hi,

I played a bit with vala and ran in some very unintuitive behavior
related to null pointers. Consider the following code:

class Thing : GLib.Object {
        public int property {get;set;}
}

class Test : Object {
        static int main(string[] args){
                Thing thing = null;
                thing.property = 42;
                return 0;
        }
}

Executing it results in:

** (process:19834): CRITICAL **: thing_set_property: assertion `self !=
NULL' failed

Apparently the c-version of Thing.set_property makes a call to
g_return_if_fail, which prints the critical message as thing is null.
Shouldn't a programming language, that offers exception handling, throw
some kind of null pointer exception?

Anyway, changing "int property {get;set;}" to "int property;" even
results in a segmentation fault. It might be discouraged to use a public
property without getters or setters, but valac should generate something
saver than :

        Thing* thing;
        thing = NULL;
        thing->property = 42;

in this case, shouldn't it? My valac version is 0.11.3.
I am sorry, if this is the hundredth time someone mentions this here,
please point me to the according discussion, if this is the case.

best regards,
Thomas








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