www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - IDisposable interface (phobos patch)

A very alpha stage release of my Disposable interface for classes which 
want guaranteed destruction on program termination.  Currently it is 
only for linux.  It installs signal handlers before the app main is 
called to trap seg faults and other nasty things.

The API needs a bit of work, as you have to call 
std.disposable.markForDisposal(Disposable obj) in order to register an 
object with the disposal handler.  Similarly, unmarkForDisposal 
unregisters an object.

Registering an object simply means that it will be put on the dispose 
list to be disposed when the program is terminated.  The disposal 
iteration routine tries to guarantee disposal of all objects.  The one 
thing it cannot protect against, however, is a signal generated from 
within a Dispose() method.

The interface name is Disposable, rather than IDisposable.  I think (at 
the time) I was worried about conflicts there.

With a bit more work I think it could make a valuable contribution to 
Ares or Phobos.

NOTE:  the patch modifies linux.mak, internal/dmain2.d, and 
std/disposable.d (new file).  Unfortunately the modifications to 
linux.mak remove recls, since I had trouble compiling it under GCC 4.0. 
  However, they also add compilation of std/disposable.d to libphobos. 
So, I guess beware.

-- 
Regards,
James Dunne
Feb 22 2006