Re: [Vala] warning: copying delegates is discouraged



On Wed, Jun 08, 2011 at 03:20:58PM -0700, Jim Nelson wrote:
Running valac from master, I'm seeing this warning pop up a lot:

warning: copying delegates is discouraged

Can someone explain the rationale for this?  (I'm guessing it has to do with
references.)

Are there any blessed workarounds (other than not copying delegates)?

The solution is tied to the specific case. The problem in general is:
Func f1; ...
Func f2 = f1;

Both delegates are owned, but when doing f2 = f1 you're "copying" the
delegate but it's not a real copy because the destroy notify is lost. So you
either want:
unowned Func f2 = f1;
or:
Func f2 = () => { f1 (); };

For properties either:
unowned Func f { get; set; }
or:
Func f { owned get; owned set; } <- this is bugged have to fix it,
workaround using private fields

-- 
http://www.debian.org - The Universal Operating System



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