Should destructors be able to tell who called them?

2010-08-10 Thread Steven Schveighoffer
One of the common problems of destructors is that they cannot assume any of their GC-allocated resources are valid when inside the destrutor. The spec says: The garbage collector is not guaranteed to run the destructor for all unreferenced objects. Furthermore, the order in which the garbage

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Michel Fortin
On 2010-08-10 14:25:48 -0400, "Steven Schveighoffer" said: ~this(bool deterministic) { if(deterministic) file.close(); } or like this: ~this() { } Scope classes (if allowed to exist) or calls to clear will set deterministic to true. The GC will set it to false. This would make dest

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Sean Kelly
Steven Schveighoffer Wrote: > One of the common problems of destructors is that they cannot assume any > of their GC-allocated resources are valid when inside the destrutor. Just a note. It's already possible to do this in D2 using an interface. Here's a thread about it: http://www.digitalm

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Mafi
Am 10.08.2010 20:25, schrieb Steven Schveighoffer: One of the common problems of destructors is that they cannot assume any of their GC-allocated resources are valid when inside the destrutor. The spec says: The garbage collector is not guaranteed to run the destructor for all unreferenced obje

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Steven Schveighoffer
On Tue, 10 Aug 2010 14:56:54 -0400, Mafi wrote: Am 10.08.2010 20:25, schrieb Steven Schveighoffer: One of the common problems of destructors is that they cannot assume any of their GC-allocated resources are valid when inside the destrutor. The spec says: The garbage collector is not guarant

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Steven Schveighoffer
On Tue, 10 Aug 2010 14:51:56 -0400, Sean Kelly wrote: Steven Schveighoffer Wrote: One of the common problems of destructors is that they cannot assume any of their GC-allocated resources are valid when inside the destrutor. Just a note. It's already possible to do this in D2 using an i

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Lutger
Steven Schveighoffer wrote: ... > This would make destructors a lot more useful. Thoughts? > > -Steve My first thought was that they are actually two separate functions distinguished by a boolean, then Michel also mentioned the SafeD argument. atm I think it is better to let go of the destru

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Steven Schveighoffer
On Tue, 10 Aug 2010 14:38:13 -0400, Michel Fortin wrote: On 2010-08-10 14:25:48 -0400, "Steven Schveighoffer" said: ~this(bool deterministic) { if(deterministic) file.close(); } or like this: ~this() { } Scope classes (if allowed to exist) or calls to clear will set determinist

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Steven Schveighoffer
On Tue, 10 Aug 2010 15:08:30 -0400, Lutger wrote: Steven Schveighoffer wrote: ... This would make destructors a lot more useful. Thoughts? -Steve My first thought was that they are actually two separate functions distinguished by a boolean, then Michel also mentioned the SafeD argumen

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Yao G.
Thanks for this Sean. Although I concur with Steve that it looks weird, at least is usable. Yao G. On Tue, 10 Aug 2010 13:51:56 -0500, Sean Kelly wrote: Steven Schveighoffer Wrote: One of the common problems of destructors is that they cannot assume any of their GC-allocated resources

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Lutger
Steven Schveighoffer wrote: > On Tue, 10 Aug 2010 15:08:30 -0400, Lutger > wrote: > >> Steven Schveighoffer wrote: >> ... >>> This would make destructors a lot more useful. Thoughts? >>> >>> -Steve >> >> My first thought was that they are actually two separate functions >> distinguished >> by a

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Sean Kelly
That hook was really added for other purposes anyway. I mostly wanted to note that it's possible to try this out now without any language changes. Yao G. Wrote: > Thanks for this Sean. Although I concur with Steve that it looks weird, at > least is usable. > > Yao G. > > > On Tue, 10 Aug 2

Re: Should destructors be able to tell who called them?

2010-08-10 Thread Steven Schveighoffer
On Tue, 10 Aug 2010 16:03:42 -0400, Lutger wrote: Steven Schveighoffer wrote: On Tue, 10 Aug 2010 15:08:30 -0400, Lutger wrote: Steven Schveighoffer wrote: ... This would make destructors a lot more useful. Thoughts? -Steve My first thought was that they are actually two separate