Re: [Vala] Change in 0.23.1 for array ownership and .length parameter



This case trigger me a question I wanted to ask before.
Why transforming ownership is nulling the original variable?

Instead of nulling, maybe just change variable to behave as unowned.

You might say that there is a problem in my solution, like this code:

uint8[] ar = new uint8[10];
if (some_method() != NULL)
    another_method((owned)ar);
...

Since after the "if" case, valac can't determinate if ownership was given(at compile time).

Despite of this, nulling "ar" variable is even worse in my opinion and it's error prone.

The user might use "ar" varible later and it will crush he's application.
If he was lucky enough, he would realize that ar is null.
It's not easy to find that this line causing it.

I suggest solution for the last problem from valac side - treat ar as unowned after the
(owned) operator, even if this operator was in "if" block!

That way, "ar" won't be null, and the user could use it later only as unowned.

And for class/struct fields - I do accept that they must be nulled when transferring ownership.

Waiting for your reply,
Tal

Date: Tue, 7 Jan 2014 02:20:49 -0008
From: jim yorba org
To: vala-list gnome org
Subject: [Vala] Change in 0.23.1 for array ownership and .length parameter

Just wanted to give everyone a head's-up about a change that appeared 
in Vala 0.23.  Previously you could do this in Vala:

uint8[] ar = new uint8[10];
// ... fill ar with interesting bytes ...
process((owned) ar, ar.length);

... where process() takes an array and a length field (sometimes 
because an array might have a "filled" count versus it's allocated 
length).  Before 0.23 the above worked, but now ar.length will be 
zeroed out before it's passed to process():

https://bugzilla.gnome.org/show_bug.cgi?id=721001

I found a few instances of this pattern in our code and thought others 
might want to be alerted about it as well.

-- Jim
_______________________________________________
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]