From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Limited_Controlled types as 'out' arguments
Date: Wed, 30 Jul 2003 16:24:55 +0200
Date: 2003-07-30T16:24:55+02:00 [thread overview]
Message-ID: <f8kfivgf1c7hbe7o0ln983d1r1v0eq4cmu@4ax.com> (raw)
In-Reply-To: slrnbifemd.o6.lutz@taranis.iks-jena.de
On Wed, 30 Jul 2003 12:32:17 +0000 (UTC), Lutz Donnerhacke
<lutz@iks-jena.de> wrote:
>* Dmitry A Kazakov wrote:
>> On Wed, 30 Jul 2003 11:31:03 +0000 (UTC), Lutz Donnerhacke
>>> procedure Copy(to : out Test; from : Test);
>>>
>>>Clearly, the variable 0 and 3 are never finalized. How implement I this
>>>correctly (without refering to the rosen trick).
>>
>> 1. Why do you think that it is incorrect? Copy does not destruct the
>> target, so why should it call Finalize?
>
>In my implementation, the type Test contains an array_access, I have to
>deallocate, before assigning a new value. I can not deallocate this access
>variable, because the procedure Free (unchecked_deallocate) requires an
>'in out' Parameter. But I only have an 'out' paramter. So I can't read it,
>before the first write.
You can in Ada 95.
>In short: The former contents (despite discriminates) of an 'out' parameter
>are not available inside the procedure. So the former contents are not
>finalizable inside this procedure.
>
>> procedure Copy (To : in out Test'Class; From : Test'Class) is
>> begin
>> Destruct (To);
>> Construct (To, From);
>> end Copy;
>
>Fine, but try this with the prototype:
> procedure Copy (To : out Test'Class; From : Test'Class);
This compiles with GNAT:
-----------------------
with Ada.Finalization;
package A is
type Int_Ptr is access Integer;
type Test is new Ada.Finalization.Limited_Controlled with record
Ptr : Int_Ptr;
end record;
procedure Destruct (To : in out Test);
procedure Construct (To : in out Test; From : Test);
procedure Copy (To : out Test'Class; From : Test'Class);
end A;
---------------------
with Ada.Finalization;
with Ada.Unchecked_Deallocation;
package body A is
procedure Free is
new Ada.Unchecked_Deallocation (Integer, Int_Ptr);
procedure Destruct (To : in out Test) is
begin
Free (To.Ptr);
end Destruct;
procedure Construct (To : in out Test; From : Test) is
begin
To.Ptr := From.Ptr;
end Construct;
procedure Copy (To : out Test'Class; From : Test'Class) is
begin
Destruct (To);
Construct (To, From);
end Copy;
end A;
>> Beware, true multiple dispatch is not supported in Ada. So if you want
>> to copy objects of different types you have to simulate MD.
>
>Wrong answer. Not every problem is MI related.
MD /= MI. Multiple dispatch is when there are many controlling
arguments of different tags. Assignment / copy is a case. You have
source and target, and sometimes you want assign:
X : Local_String;
Y : Remote_String;
Copy (Y, X); -- Constraint_Error
---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de
next prev parent reply other threads:[~2003-07-30 14:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-30 11:31 Limited_Controlled types as 'out' arguments Lutz Donnerhacke
2003-07-30 12:22 ` Dmitry A. Kazakov
2003-07-30 12:32 ` Lutz Donnerhacke
2003-07-30 14:24 ` Dmitry A. Kazakov [this message]
2003-07-30 14:25 ` Lutz Donnerhacke
2003-07-30 14:48 ` Dmitry A. Kazakov
2003-07-30 15:15 ` Lutz Donnerhacke
2003-07-31 10:26 ` Dmitry A. Kazakov
2003-07-31 10:54 ` Lutz Donnerhacke
2003-07-31 11:50 ` Dmitry A. Kazakov
2003-07-31 12:19 ` Lutz Donnerhacke
2003-07-31 13:15 ` Dmitry A. Kazakov
2003-07-31 17:51 ` Randy Brukardt
2003-07-30 15:01 ` Vinzent Hoefler
2003-07-30 15:16 ` Lutz Donnerhacke
2003-07-30 15:52 ` Lutz Donnerhacke
2003-07-30 19:30 ` Randy Brukardt
2003-07-31 7:43 ` Lutz Donnerhacke
2003-07-30 12:31 ` Matthew Heaney
2003-07-30 12:57 ` Lutz Donnerhacke
2003-07-30 13:47 ` Martin Dowie
2003-07-30 17:06 ` Matthew Heaney
2003-07-30 12:37 ` Martin Dowie
2003-07-30 12:59 ` Lutz Donnerhacke
2003-07-30 13:41 ` Martin Dowie
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox