Re: [Vala] Memory safety



do you think that  in a code like:



void func() {

 uint64[] output = new uint64[1];  // return callback

 GLib.Timeout.add( 1000,
                            () => {
                                     output[0]=1;
                                     return false;
                                  }
                );
}


I have to check if output is still valid?

regards


2014-05-15 10:22 GMT+02:00 Luca Bruno <lethalman88 gmail com>:

On 15/05/2014 10:18, Florian Weimer wrote:

Hi,

am I correct in assuming that Vala is supposed to inherit the lack of
memory safety from C?  Or put differently: If there is Vala code that does
not guard callers from memory safety violations but it could do so, this is
not a problem because callers are generally expected to fulfill such
(implicit) preconditions.

 Vala inherits the problem of C, yes. You could certainly do some evil
casts like in C. Vala however is certainly safer than C in many aspects, in
other aspects however you have to know what you are doing and how Vala
compiles down to C in certain cases.
For example:
1. func1(): create a local array
2. Call async func2(array) without waiting the function to finish
3. Return from func1
4. func2 runs with a dangling pointer to the array

Vala is not free of rough edges, it makes your life easier. But since a
Vala array is a standard C array, it can't be referenced counted and that's
why you get the above (unwanted from a newbie perspective) behavior.

Best regards

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



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