Re: [Vala] Should be warning(maybe error) when method with [ReturnsModifiedPointer] is called from unowned variable



Yes, now I see it. I guess that it might be error specific to
implementation of GLib.SList.

In example that you gave, same behaviour can be seen when removing first
item from other list (given_list). If it is first item, list you were
modifying works fine, but other seems to be broken (it is the same in both
cases, modifying given_list or list).

I won't be able to help you :( (btw, I use Gee for lists/arrays etc).

Jarek

2012/11/6 Tal Hadad <tal_hd hotmail com>


I'm sorry, the example I gave is bad. Forgot the "unowned" word.
Example:

unowned GLib.SList list = given_list;

list.remove(data);

Do you see the problem here?
If "data" is on the FIRST item on the list, it only removes it from
"list", not from the owned variable "given_list".

I run into bug likes that im my program and just wanted to warn
Vala devs.

Do you see the problem now?

Tal

Date: Mon, 5 Nov 2012 17:01:14 +0100
Subject: Re: [Vala] Should be warning(maybe error) when method with
[ReturnsModifiedPointer] is called from unowned variable
From: kotowate gmail com
To: tal_hd hotmail com
CC: vala-list gnome org

I am confused here. What [ReturnsModifiedPointer] has to do with
copying/referencing an object?
With GLib.SList list = given_list; you do not create a copy of an object
but owned reference/pointer. And if you do anything to that reference, you
will modify given_list too.

And in most cases not copying object, but referencing it is desired
behaviour, so I don't see problem here. I would also not desire assuming
that copy should be created whenever I assign object from unowned reference
to owned reference.

I think that everything is ok here, unless I am missing something.
Could you describe the result you expect from the code you provided?
Jarek

2012/11/4 Tal Hadad <tal_hd hotmail com>



There should be warning(maybe error) when method with

[ReturnsModifiedPointer] is called from unowned variable.



Take a look on GLib.SList. The beginner programer(me too) can be

assign an unowned variable to the list, and remove items, but he

don't know it shell update the owned pointer.



Example:



GLib.SList list = given_list;

list.remove(data);



Naive programers can be fooled(like me) that this code are valid,

since Vala print no errors neither warning.



I think we all agree it's NOT ok, but do you see this as error or warning?



Yours

Tal


_______________________________________________

vala-list mailing list

vala-list gnome org

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





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