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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b031c56dc601135 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Problem with access parameter Date: Tue, 25 May 2004 17:32:51 +0200 Message-ID: References: <5d6fdb61.0405250252.3a1f1f68@posting.google.com> <82347202.0405250600.2a911b52@posting.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de HUf6PrqgFSK4Vo3RPi5l8ghgWwxI04/95ZfTym5hYT2aEimdo= X-Newsreader: Forte Agent 1.8/32.548 Xref: controlnews3.google.com comp.lang.ada:818 Date: 2004-05-25T17:32:51+02:00 List-Id: On 25 May 2004 07:00:48 -0700, jimmaureenrogers@worldnet.att.net (Jim Rogers) wrote: >402450@cepsz.unizar.es (Jano) wrote in message news:<5d6fdb61.0405250252.3a1f1f68@posting.google.com>... >> I'm trying to finalize data inside a protected type, using the >> approach pasted at the end. I'm not sure if I get this bizarre error >> because of a Gnat 3.15p bug or because what I'm trying is illegal: >> >> agpl-counter-multi.ads:59:04: expected an access type with designated >> type "Object" defined at line 59 >> agpl-counter-multi.ads:59:04: found an access type with designated >> type derived from "Object" defined at line 59 >> agpl-counter-multi.ads:59:04: ==> in call to "_Init_Proc" at line 73 >> >> The package code is: (trimmed) >> >> package Agpl.Counter.Multi is >> >> type Object; >> type Object_Access is access all Object; >> >> type Destructor_Type (Parent : access Object) is limited private; > >The discriminant type is not the same as Object_Access. It is an >anonymous type. If you want to use Object_Access as the discriminant type >then specify this clearly. It is pretty legal for record types. For example: type Object; type Destructor_Type (Parent : access Object) is limited private; type Object is limited record Destructor : Destructor_Type (Object'Access); end record; private type Destructor_Type (Parent : access Object) is new Ada.Finalization.Limited_Controlled with null record; procedure Finalize (This : in out Destructor_Type); I am not sure, but it seems to be allowed for record types only 3.8(12). >> ---------------------------------------------------------------- >> -- Object -- >> ---------------------------------------------------------------- >> protected type Object is >> -- Things >> private >> procedure Destroy; >> Destructor : Destructor_Type (Object'Access); > >Object is the name of a type. You cannot take the access value of a type, >only of an instance. See above. >It looks like you are trying to create something equivalent to a C++ or Java >"this" reference. What are you trying to achieve? It looks that he wants a destructor for a protected object. A rightful wish, or? Because protected types are not and cannot be derived from Limited_Controlled, he tries to inject a controlled member pointing to the protected parent. When parent gets finalized, the member's Finalize is called with access to parent's as the discriminant. >> Values : Counter_Map.Container_Type; >> end Object; >> >> private >> >> type Destructor_Type (Parent : access Object) is new >> Finalization.Limited_Controlled with null record; >> >> procedure Finalize (This : in out Destructor_Type); >> -- Here call to This.Parent.Destroy; > >You are trying to destroy a protected object from within itself. >Such an operation can cause a large number of problems. What happens to >tasks waiting in an entry queue for the protected object? Are they >released from the queue? I do not believe the Ada Reference Manual >specifies the results of such an operation. That's no problem, because Finalize will be called upon parent's finalization. At that point the parent is out of scope of anybody who might use it. (if no dangling pointers used) ----------------------------- Well, it seems that the trick won't work. So one should pack the protected object into a limited controlled type and make proxies to its entries and subprograms. -- Regards, Dmitry Kazakov www.dmitry-kazakov.de