comp.lang.ada
 help / color / mirror / Atom feed
* Q. on Automatic Package Finalization
@ 1996-09-28  0:00 Robert Dewar
  1996-10-04  0:00 ` Norman H. Cohen
  0 siblings, 1 reply; 12+ messages in thread
From: Robert Dewar @ 1996-09-28  0:00 UTC (permalink / raw)




rman said that we (Ada 9X) considered

">   begin
>      ...
>   exception
>      ...
>   at end
>      < sequence of frame finalization statements >
>   end"


Interestingly, internally GNAT implements at end, but does not allow it
to be mixed with an exception handler, and at end, unlike an exception
handler, covers the associated declarations.

It would be trivial (but a bit naughty) to make this available as a language
extension :-)





^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Q. on Automatic Package Finalization
@ 1996-09-28  0:00 Robert Dewar
  1996-10-04  0:00 ` Norman H. Cohen
  0 siblings, 1 reply; 12+ messages in thread
From: Robert Dewar @ 1996-09-28  0:00 UTC (permalink / raw)



iRegarding Norm's notes on finalization of packages.

Really the annoying thing is the restriction on controlled typs to the
outer level. This really is not something that the compilre requires. We
may provide some facility in GNAT to get around this restriction ...






^ permalink raw reply	[flat|nested] 12+ messages in thread
* Q. on Automatic Package Finalization
@ 1996-09-22  0:00 david scott gibson
  1996-09-23  0:00 ` Robert Dewar
  0 siblings, 1 reply; 12+ messages in thread
From: david scott gibson @ 1996-09-22  0:00 UTC (permalink / raw)



Hi.  Does anyone know of a good way to achieve automatic package
finalization in Ada95?  I'd like to create a generic package which
automatically cleans up its package instance state (possibly including
allocated memory, temporary files, etc.) when the package scope ends.
The code below (which compiles under GNAT 3.05) is one attempt to
achieve this using controlled types.  It requires that the
representation of state for package P instances be incorporated into
an instance (pkg_var) of a controlled type (PC.T) declared
in a library-level package (PC).  This is not a very satisfactory
solution even if it would work.  Does anyone have some better
ideas for handling automatic package finalization?

Dave
--
dgibson@cis.ohio-state.edu

----------------------------------------
-- pc.ads

with Ada.Finalization;

package PC is               -- library level since controlled

    type T is new Ada.Finalization.Controlled with 
        record
            rep: Integer;   -- representation for pkg P's variables
        end record;         -- non-privtate for P direct access
                       
    procedure Finalize(     
            x: in out T
        );

end PC;

----------------------------------------
-- pc.adb

with Ada.Text_IO;

package body PC is

    procedure Finalize_Package (x: in out T) is
    begin
        Ada.Text_IO.Put_Line("Finalizing package P");
        x.rep := 0;
    end Finalize_Package;

    procedure Finalize(
                x: in out T
            ) is
    begin
        Finalize_Package(x);
    end Finalize;

end PC;

----------------------------------------
-- p.ads

with PC;

generic

package P is

    type T is private;

    procedure Initialize_Package (x: in out PC.T);

private

    type T is 
        record
            rep: PC.T;
        end record;

end P;

----------------------------------------
-- p.adb

with Ada.Text_IO;

package body P is

    pkg_var: PC.T; 

    procedure Initialize_Package (x: in out PC.T) is
    begin
        Ada.Text_IO.Put_Line("Initializing package P");
        x.rep := 1;
    end;

begin
   Initialize_Package(pkg_var);
end P;

----------------------------------------
-- ptest.adb

with P;

procedure PTest is                -- output:

    package PI1 is new P;         -- Initializing package P

begin

    declare
        package PI2 is new P;     -- Initializing package P
    begin
        null;
    end;                          -- Finalizing package P

end PTest;                        -- Finalizing package P




^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1996-10-06  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-28  0:00 Q. on Automatic Package Finalization Robert Dewar
1996-10-04  0:00 ` Norman H. Cohen
1996-10-04  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1996-09-28  0:00 Robert Dewar
1996-10-04  0:00 ` Norman H. Cohen
1996-10-06  0:00   ` Robert Dewar
1996-09-22  0:00 david scott gibson
1996-09-23  0:00 ` Robert Dewar
1996-09-24  0:00   ` Norman H. Cohen
1996-09-24  0:00     ` Tucker Taft
1996-09-25  0:00   ` Norman H. Cohen
1996-09-25  0:00   ` Jens Jakob Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox