[Issue 9601] Make regular D objects on closures

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 27 09:22:00 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9601



--- Comment #6 from Denis Shelomovskij <verylonglogin.reg at gmail.com> 2013-02-27 20:21:58 MSK ---
(In reply to comment #4)
> (In reply to comment #0)
> > The idea is to make created delegate data pointer referring to a valid D object
> > just like for class member function.
> 
> Since creation delegate data pointer points to valid memory forgetting about
> tricks to deliberatly break it. Problem may come when i.e. class destructor
> references such object which was collected already by GC. But pointer should be
> reset to null. This actually is a problem of class destructor synchronizing.
> Are you targeting at this problem?

No. I'm targeting the problem when delegate's outer scope is destroyed and the
problem of determining that the delegate will live "forever" (no "destroyable"
outer scope). See example suggested in my previous post.

> > It will allow passing closure delegate to functions where such objects are
> > expected and controlling/watching delegate lifetime.
> 
> How do you suggest to pass information within delegate about data lifetime? Or
> what mechanism (in addition to GC) would ensure that?

This is trivial. When creating a closure allocate a special D class instead,
that's all. I.e. add a few hidden D object fields before closure data. We will
have something like member function delegate then.

> > Once it will be implemented the only "raw" delegates would be struct member
> > function delegates? which are used rarely and can easily be avoided.
> 
> If such delegate references this struct pointer it may lead to trouble.
> Otherwise what is specific to struct delegates?

Yes, struct pointer delegates will still be troubles unless D struct will
contain regular D object hidden fields defining it being a "struct object". I
see no good solution for this problem now. But as I have never meet with such
difficulties I don't think it is near as high priority issue as closure
delegates.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list