From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4083771199667fd1 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!198.186.194.250.MISMATCH!news-xxxfer.readnews.com!news-out.readnews.com!transit4.readnews.com!panix!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ensuring resource cleanup Date: Mon, 08 Feb 2010 10:31:20 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <87zl3jertf.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1265643068 25205 192.74.137.71 (8 Feb 2010 15:31:08 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 8 Feb 2010 15:31:08 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:pHxfQSnxKPnDbAso2A6Kslulw0I= Xref: g2news1.google.com comp.lang.ada:8982 Date: 2010-02-08T10:31:20-05:00 List-Id: Florian Weimer writes: > It looks as if I might need to do some Ada maintenance programming > soon. I can use the GNAT from GCC 4.3. > > Are there any new ways to ensure resource cleanup? > > I tried to use Ada.Finalization.Limited_Controlled in the past, but > there were several issues with it: there was some run-time overhead AdaCore is working on a more efficient implementation of finalization. > (because of the tag and because the finalizer is abort-deferred, ... I think if you use the appropriate pragma Restrictions, so the compiler knows there are no aborts, it will avoid the cost of deferring and undeferring aborts (which is quite high on some systems). >...which > seemed to defeat inlining Inlining of what? The Initialize and Finalize calls? It seems feasible to inline them in most cases, but I'm not sure if GNAT is capable of that. Try it. >...and scalar replacement of aggregates), it > was impossible to instantiate generics containing such types below the > library level,... Ada 2005 allows such nesting (with or without generics). ....and having multiple different types inherting from > Limited_Controled in the same package often resulted in multi-dispatch > errors (and using 'Class required exposing the tagged nature of the > type in the interface, with has other drawbacks). Yes, but in my experience these are minor issues. Another way to avoid multi-dispatch is to put the procedure in a nested package. Both workarounds are annoying, I admit. > Explicit cleanup using cleanup subprograms is okay, too, provided that > there is some tool to ensure that they are used properly. This is > despite the rather cumbersome syntax: > > declare > X : Object; > > begin > Init (X); > begin > Make_Use_Of (X); > exception > when others => > Cleanup (X); > raise; > end; > Cleanup (X); > end; > > But I'd really have a tool that ensures that Init and Cleanup calls > are properly paired in this way. You could wrap this is a procedure: procedure With_Cleanup (Action : not null access procedure (...)); so you only have to write the above pattern once (per type that needs cleanup), and you can call it with any Action procedure you like. Note that this is slightly different from using Limited_Controlled, because it does not clean up in case of abort. If you don't use abort, then this is not an issue. > Are there other approaches I don't know about yet? I think that about covers it. - Bob