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: 103376,c4cb2c432feebd9d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.germany.com!news.ecp.fr!news1.int-evry.fr!u-psud.fr!not-for-mail From: Philippe Tarroux Newsgroups: comp.lang.ada Subject: Finalization Date: Tue, 21 Nov 2006 10:02:35 +0100 Organization: University Paris-Sud, France. Message-ID: References: <0ugu4e.4i7.ln@hunter.axlog.fr> <%P_cg.155733$eR6.26337@bgtnsc04-news.ops.worldnet.att.net> <6H9dg.10258$S7.9150@news-server.bigpond.net.au> <1hfv5wb.1x4ab1tbdzk7eN%nospam@see.signature> <2006052509454116807-gsande@worldnetattnet> NNTP-Posting-Host: osiris.limsi.fr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: upsn250.cri.u-psud.fr 1164099813 32221 129.175.157.197 (21 Nov 2006 09:03:33 GMT) X-Complaints-To: newsmaster@u-psud.fr NNTP-Posting-Date: Tue, 21 Nov 2006 09:03:33 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; fr-FR; rv:1.7.8) Gecko/20050511 X-Accept-Language: fr, en In-Reply-To: Xref: g2news2.google.com comp.lang.ada:7594 Date: 2006-11-21T10:02:35+01:00 List-Id: I have a problem trying to use controlled types. My purpose was to use finalize to deallocate a big data structure each time a reuse. I wrote a simpler program that exhibits the problem too. here is the code followed by a comment on what I observed: with Ada.Unchecked_Deallocation, Ada.Finalization; package Final is type Vector is array (Positive range <>) of Float; type Vector_Ptr is access Vector; procedure Free is new Ada.Unchecked_Deallocation (Vector, Vector_Ptr); type Obj is new Ada.Finalization.Controlled with record X : Vector_Ptr := null; end record; overriding procedure Finalize (O : in out Obj); procedure Process (O : in out Obj); function Process return Obj; end Final; with Ada.Text_Io; package body Final is package Text_Io renames Ada.Text_Io; procedure Finalize (O : in out Obj) is begin Text_Io.Put ("Finalize: "); Text_Io.New_Line; Free (O.X); end Finalize; procedure Process (O : in out Obj) is begin Text_Io.Put ("In process procedure"); Text_Io.New_Line; Finalize(O); O.X := new Vector (1 .. 100); end Process; function Process return Obj is O : Obj; begin Text_Io.Put ("In process function"); Text_Io.New_Line; O.Process; return O; end Process; end Final; with Ada.Text_Io, Final; procedure main is O : Final.Obj; begin for I in 1 .. 100 loop Ada.Text_Io.put(Integer'Image(I)); Ada.Text_Io.New_Line; O := Final.Process; -- O.Process; end loop; Ada.Text_Io.Put("Fin"); Ada.Text_Io.New_Line; end Main; and the resulting execution trace: 1 In process function In process procedure Finalize: Finalize: Finalize: Finalize: 2 and so on...until: 7 In process function In process procedure Finalize: Finalize: Finalize: Finalize: 8 In process function In process procedure Finalize: process exited with status 128 When I use the function call the program stops with an unexpected error that seems to be different from one compiler to another (I tried gnat gcc 3.4.6 on Windows and the Debian gnat version on Linux). The message depends also on the type of structure to be freed (vector or vector'class). Even when the program raises PROGRAM_ERROR I am unable to trap the exception. I tried to follow what happens under gdb and observed that an unexpected signal cencerning the heap is received by the program. When i use the procedure call (commented out in the main program), all is correct but I suspect that the memory is not deallocated at each call in the main loop since there i s only one call to Finalize at the end of the program. Does somebody has any idea of what happens? Do you think there is a faulty construct in my code? Thanks for your help Philippe Tarroux