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,FREEMAIL_FROM, T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,4b758210c0900d03,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!goblin2!goblin.stu.neva.ru!aioe.org!not-for-mail From: =?iso-8859-15?Q?Hibou57_=28Yannick_Duch=EAne=29?= Newsgroups: comp.lang.ada Subject: Protected object which never get finalized Date: Sat, 13 Feb 2010 01:45:40 +0100 Organization: At Home Message-ID: NNTP-Posting-Host: eDalwZYR47oA57zIQILR/g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 User-Agent: Opera Mail/10.10 (Win32) Xref: g2news1.google.com comp.lang.ada:9185 Date: 2010-02-13T01:45:40+01:00 List-Id: Hi, I may be not lucky : after the case of an object of a protected type being finalized too much soon, here is now that I have to do with an object of a protected type which never gets finalized (think I was to use this latter as a work around after long try failure with the former, I'm really not lucky at all). Inquisitive peoples with interests in the case, may have a look at the following test : two protected types are defined, with exact equivalent definition. One is defined in a package, the other is defined in the local scope. An instance of the first (the one defined in the package), never get finalized. An instance of the second type (declared in the local scope), goes through its normal life. But perhaps there's something I did not understood with Ada.Text_IO; with Ada.Finalization; procedure Test is -- This test program exposes a protected -- object which is initialized, but never -- get finalized (object of type A_Type). -- Don't care starting here if you just want to -- have a quick look, jump to the comment -- "Important things starts here" later below. package Spies is type Instance_Type (Client_Name : access String) is limited private; private type Instance_Type (Client_Name : access String) is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize (Instance : in out Instance_Type); overriding procedure Finalize (Instance : in out Instance_Type); end Spies; package body Spies is overriding procedure Initialize (Instance : in out Instance_Type) is Me : Instance_Type renames Instance; begin Ada.Text_IO.Put_Line ("Spy : I am coping with Initialization of " & Me.Client_Name.all & "."); end; overriding procedure Finalize (Instance : in out Instance_Type) is Me : Instance_Type renames Instance; begin Ada.Text_IO.Put_Line ("Spy : I am coping with Finalization of " & Me.Client_Name.all & "."); end; end Spies; -- Important things starts here package P is type A_Type is limited private; private protected type A_Type is private Spy : Spies.Instance_Type (Client_Name => new String'("P.A_Type")); end; end P; package body P is protected body A_Type is end; end P; protected type B_Type is private Spy : Spies.Instance_Type (Client_Name => new String'("B_Type")); end; protected body B_Type is end; begin declare Tested_Object : P.A_Type; begin Ada.Text_IO.Put_Line ("Inside block testing A_Type"); -- Tested_Object is initialized, but never -- get finalized, while [ARM 7.6.1(8)] requires -- finalization for protected types. Or am I wrong ? end; Ada.Text_IO.New_Line; declare Tested_Object : B_Type; begin Ada.Text_IO.Put_Line ("Inside block testing B_Type"); -- This one, with a strictly equivalent declaration, which -- is just not declared inside a package, get finalized -- as expected. end; end Test;