Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

When we write programs that "learn", it turns out we do and they don't.


devel / comp.lang.ada / Unchecked_Deallocation with tagged class type.

SubjectAuthor
* Unchecked_Deallocation with tagged class type.Blady
`* Re: Unchecked_Deallocation with tagged class type.Dmitry A. Kazakov
 `* Re: Unchecked_Deallocation with tagged class type.Blady
  `* Re: Unchecked_Deallocation with tagged class type.Dmitry A. Kazakov
   `* Re: Unchecked_Deallocation with tagged class type.Blady
    `* Re: Unchecked_Deallocation with tagged class type.AdaMagica
     `- Re: Unchecked_Deallocation with tagged class type.AdaMagica

1
Unchecked_Deallocation with tagged class type.

<uj0npn$1d156$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10255&group=comp.lang.ada#10255

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.p11@orange.fr (Blady)
Newsgroups: comp.lang.ada
Subject: Unchecked_Deallocation with tagged class type.
Date: Tue, 14 Nov 2023 22:11:18 +0100
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <uj0npn$1d156$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Nov 2023 21:11:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b0db478629f69b88ade2660b342a1b18";
logging-data="1475750"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RhRXeBDhVlSxoz4s83/+a"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8VIXoXOEj0f9HFmeibIX0GZiPao=
Content-Language: fr, en-US
 by: Blady - Tue, 14 Nov 2023 21:11 UTC

Hello,

The following code present a Finalize procedure with a parameter of
access tagged class type in order to deallocate the memory of the given
parameter from the root tagged type TTA and his children.
The same for TTB which is inherited from TTA. But this Finalize call
Finalize of TTA.
It may be not the best idea.
But let's see:

with Ada.Unchecked_Deallocation;
procedure test_20231113_free_tag is

type TTA is tagged record
AA : Integer;
end record;
type ATTA is access all TTA;
type CATTA is access all TTA'Class;
procedure Finalize (O : in out CATTA) is
procedure Free is new Ada.Unchecked_Deallocation (TTA, ATTA);
begin
Free (ATTA (O));
end Finalize;

type TTB is new TTA with record
BB : Integer;
end record;
type ATTB is access all TTB;
type CATTB is access all TTB'Class;
procedure Finalize (O : in out CATTB) is
begin
Finalize (CATTA (O));
end Finalize;

OA : CATTA := new TTA;
OB : CATTB := new TTB;

begin
Finalize (OA);
Finalize (OB);
end test_20231113_free_tag;

The procedure Free is the instanciation of Unchecked_Deallocation with
the tagged type TTA.
Thus the call "Finalize (OA);" deallocate the memory of object OA of
type access class TTA.

But what does "Finalize (OB);"?
What is the memory deallocate of object OB of type TTB?

Thanks, Pascal.

Re: Unchecked_Deallocation with tagged class type.

<uj0t5j$1dp63$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10256&group=comp.lang.ada#10256

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Unchecked_Deallocation with tagged class type.
Date: Tue, 14 Nov 2023 23:42:59 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <uj0t5j$1dp63$1@dont-email.me>
References: <uj0npn$1d156$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 14 Nov 2023 22:42:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="194c7c3c86974836b515613134ba380a";
logging-data="1500355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+soVppmemtbY17W6uSu+mcxt4yFtjS6A8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LSfFRDZ7oL5LZimezTmPN5GOt+k=
In-Reply-To: <uj0npn$1d156$1@dont-email.me>
Content-Language: en-US
 by: Dmitry A. Kazakov - Tue, 14 Nov 2023 22:42 UTC

On 2023-11-14 22:11, Blady wrote:

> The following code present a Finalize procedure with a parameter of
> access tagged class type in order to deallocate the memory of the given
> parameter from the root tagged type TTA and his children.
> The same for TTB which is inherited from TTA. But this Finalize call
> Finalize of TTA.
> It may be not the best idea.
> But let's see:
>
> with Ada.Unchecked_Deallocation;
> procedure test_20231113_free_tag is
>
>    type TTA is tagged record
>       AA : Integer;
>    end record;
>    type ATTA is access all TTA;
>    type CATTA is access all TTA'Class;
>    procedure Finalize (O : in out CATTA) is
>       procedure Free is new Ada.Unchecked_Deallocation (TTA, ATTA);
>    begin
>       Free (ATTA (O));
>    end Finalize;
>
>    type TTB is new TTA with record
>       BB : Integer;
>    end record;
>    type ATTB is access all TTB;
>    type CATTB is access all TTB'Class;
>    procedure Finalize (O : in out CATTB) is
>    begin
>       Finalize (CATTA (O));
>    end Finalize;
>
>    OA : CATTA := new TTA;
>    OB : CATTB := new TTB;
>
> begin
>    Finalize (OA);
>    Finalize (OB);
> end test_20231113_free_tag;
>
> The procedure Free is the instanciation of Unchecked_Deallocation with
> the tagged type TTA.
> Thus the call "Finalize (OA);" deallocate the memory of object OA of
> type access class TTA.
>
> But what does "Finalize (OB);"?

Crashes your program. It is a bug. You should instantiate
Unchecked_Deallocation with class-wide type if you pass a class-wide
pointer.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Unchecked_Deallocation with tagged class type.

<uj39gv$1srlq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10257&group=comp.lang.ada#10257

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.p11@orange.fr (Blady)
Newsgroups: comp.lang.ada
Subject: Re: Unchecked_Deallocation with tagged class type.
Date: Wed, 15 Nov 2023 21:26:06 +0100
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <uj39gv$1srlq$1@dont-email.me>
References: <uj0npn$1d156$1@dont-email.me> <uj0t5j$1dp63$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 15 Nov 2023 20:26:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="87d02a79d9ca46faad794c46f152fcbf";
logging-data="1994426"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PptjP2y0a/H+TRPrrYStQ"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:wxX1ASf+PScMkX/h+4DnxNkW37U=
In-Reply-To: <uj0t5j$1dp63$1@dont-email.me>
Content-Language: fr, en-US
 by: Blady - Wed, 15 Nov 2023 20:26 UTC

Le 14/11/2023 à 23:42, Dmitry A. Kazakov a écrit :
>> But what does "Finalize (OB);"?
>
> Crashes your program. It is a bug. You should instantiate
> Unchecked_Deallocation with class-wide type if you pass a class-wide
> pointer.

Thanks, I haven't considered this possibility.
Note: the previous program built with GNAT FSF 13.2.0 ran without exception.

I've changed:
with Ada.Unchecked_Deallocation;
procedure test_20231113_free_class is

type TTA is tagged record
AA : Integer;
end record;
type ATTA is access all TTA;
type CATTA is access all TTA'Class;
procedure Finalize (O : in out CATTA) is
procedure Free is new Ada.Unchecked_Deallocation (TTA'Class, CATTA);
begin
Free (O);
end Finalize;

type TTB is new TTA with record
BB : Integer;
end record;
type ATTB is access all TTB;
type CATTB is access all TTB'Class;
procedure Finalize (O : in out CATTB) is
begin
Finalize (CATTA (O));
end Finalize;

OA : CATTA := new TTA;
OB : CATTB := new TTB;

begin
Finalize (OA);
Finalize (OB);
end test_20231113_free_class;

It runs without exception.
One question remains about "Finalize (OB);":
Which memory size is deallocated TTA'Size or TTB'Size?

Thanks, Pascal.

Re: Unchecked_Deallocation with tagged class type.

<uj3chf$1tbp8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10258&group=comp.lang.ada#10258

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: Unchecked_Deallocation with tagged class type.
Date: Wed, 15 Nov 2023 22:17:37 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <uj3chf$1tbp8$1@dont-email.me>
References: <uj0npn$1d156$1@dont-email.me> <uj0t5j$1dp63$1@dont-email.me>
<uj39gv$1srlq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 15 Nov 2023 21:17:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2243a23eed6a547f86f030f62c3aa490";
logging-data="2010920"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mgDPWYycxblO2TJBeb8rnnGO8cRWBTpU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5AKq9WdBYrTTKnQ03o6SG2S3YQA=
Content-Language: en-US
In-Reply-To: <uj39gv$1srlq$1@dont-email.me>
 by: Dmitry A. Kazakov - Wed, 15 Nov 2023 21:17 UTC

On 2023-11-15 21:26, Blady wrote:
> Le 14/11/2023 à 23:42, Dmitry A. Kazakov a écrit :
>>> But what does "Finalize (OB);"?
>>
>> Crashes your program. It is a bug. You should instantiate
>> Unchecked_Deallocation with class-wide type if you pass a class-wide
>> pointer.
>
> Thanks, I haven't considered this possibility.
> Note: the previous program built with GNAT FSF 13.2.0 ran without
> exception.
>
> I've changed:
> with Ada.Unchecked_Deallocation;
> procedure test_20231113_free_class is
>
>    type TTA is tagged record
>       AA : Integer;
>    end record;
>    type ATTA is access all TTA;
>    type CATTA is access all TTA'Class;
>    procedure Finalize (O : in out CATTA) is
>       procedure Free is new Ada.Unchecked_Deallocation (TTA'Class, CATTA);
>    begin
>       Free (O);
>    end Finalize;
>
>    type TTB is new TTA with record
>       BB : Integer;
>    end record;
>    type ATTB is access all TTB;
>    type CATTB is access all TTB'Class;
>    procedure Finalize (O : in out CATTB) is
>    begin
>       Finalize (CATTA (O));
>    end Finalize;
>
>    OA : CATTA := new TTA;
>    OB : CATTB := new TTB;
>
> begin
>    Finalize (OA);
>    Finalize (OB);
> end test_20231113_free_class;
>
> It runs without exception.
> One question remains about "Finalize (OB);":
> Which memory size is deallocated TTA'Size or TTB'Size?

It is a wrong question. The implementation of the pool may ignore size
using the block size instead. Furthermore T'Size is not necessarily the
size actually allocated.

Regarding Unchecked_Deallocation instantiated with a pointer to a
class-wide object, consider it dispatching on the target object tag.
Thus you can deallocate any object using any instance of
Unchecked_Deallocation for any class-wide parent of, interfaces included.

So Finalize (OB) is OK.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Unchecked_Deallocation with tagged class type.

<uj5u2s$2dq6m$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10259&group=comp.lang.ada#10259

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: p.p11@orange.fr (Blady)
Newsgroups: comp.lang.ada
Subject: Re: Unchecked_Deallocation with tagged class type.
Date: Thu, 16 Nov 2023 21:29:15 +0100
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <uj5u2s$2dq6m$1@dont-email.me>
References: <uj0npn$1d156$1@dont-email.me> <uj0t5j$1dp63$1@dont-email.me>
<uj39gv$1srlq$1@dont-email.me> <uj3chf$1tbp8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Nov 2023 20:29:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5ad3de8a0a64d0677585a386be4ce5b";
logging-data="2549974"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XDLm12Vs5qsgYpteKMB99"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zffcTTE34W+rnCSC2sQkMh4rNyY=
Content-Language: fr, en-US
In-Reply-To: <uj3chf$1tbp8$1@dont-email.me>
 by: Blady - Thu, 16 Nov 2023 20:29 UTC

Le 15/11/2023 à 22:17, Dmitry A. Kazakov a écrit :
> On 2023-11-15 21:26, Blady wrote:
>> Le 14/11/2023 à 23:42, Dmitry A. Kazakov a écrit :
>>>> But what does "Finalize (OB);"?
<...>
> Regarding Unchecked_Deallocation instantiated with a pointer to a
> class-wide object, consider it dispatching on the target object tag.
> Thus you can deallocate any object using any instance of
> Unchecked_Deallocation for any class-wide parent of, interfaces included.
>
> So Finalize (OB) is OK.
>

Thanks, yes, the instanciation of Unchecked_Deallocation seemed to
indicate that but I was not able to confirm it from the Ada RM.
A mention in Ada RM 13.11.2 Unchecked Storage Deallocation of that
particular possibility would be valuable.

Regards, Pascal.

PS: after a quick search, I found also a smart answer with a full
example from Simon:
https://stackoverflow.com/questions/64951954/how-can-i-do-an-unchecked-deallocation-of-abstract-classes-in-ada

Re: Unchecked_Deallocation with tagged class type.

<1286cc2e-2fc8-4de4-9598-a6a53e21ce6bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10267&group=comp.lang.ada#10267

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:6214:118a:b0:66d:fb7:c53a with SMTP id t10-20020a056214118a00b0066d0fb7c53amr246347qvv.7.1700226743614;
Fri, 17 Nov 2023 05:12:23 -0800 (PST)
X-Received: by 2002:a63:1a42:0:b0:5bd:d409:16ef with SMTP id
a2-20020a631a42000000b005bdd40916efmr1054872pgm.10.1700226743147; Fri, 17 Nov
2023 05:12:23 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 17 Nov 2023 05:12:22 -0800 (PST)
In-Reply-To: <uj5u2s$2dq6m$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=3.67.78.197; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.67.78.197
References: <uj0npn$1d156$1@dont-email.me> <uj0t5j$1dp63$1@dont-email.me>
<uj39gv$1srlq$1@dont-email.me> <uj3chf$1tbp8$1@dont-email.me> <uj5u2s$2dq6m$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1286cc2e-2fc8-4de4-9598-a6a53e21ce6bn@googlegroups.com>
Subject: Re: Unchecked_Deallocation with tagged class type.
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Fri, 17 Nov 2023 13:12:23 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1764
 by: AdaMagica - Fri, 17 Nov 2023 13:12 UTC

Blady schrieb am Donnerstag, 16. November 2023 um 21:29:20 UTC+1:
> Thanks, yes, the instanciation of Unchecked_Deallocation seemed to
> indicate that but I was not able to confirm it from the Ada RM.
> A mention in Ada RM 13.11.2 Unchecked Storage Deallocation of that
> particular possibility would be valuable.

type Object(<>) is limited private;

The box here denotes unknown discriminants, i.e. indefinite types - these include task types;
limited is "assume the worst" => i.e. any type may be used as actual type for this formal type.

Re: Unchecked_Deallocation with tagged class type.

<cd769c06-962c-40a8-9cf3-e4fadcfddf33n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=10268&group=comp.lang.ada#10268

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:45cd:0:b0:40f:e0dd:8050 with SMTP id e13-20020ac845cd000000b0040fe0dd8050mr112220qto.5.1700226822728;
Fri, 17 Nov 2023 05:13:42 -0800 (PST)
X-Received: by 2002:a17:902:6b8a:b0:1cc:3c52:1b13 with SMTP id
p10-20020a1709026b8a00b001cc3c521b13mr2831768plk.11.1700226822284; Fri, 17
Nov 2023 05:13:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.network!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 17 Nov 2023 05:13:41 -0800 (PST)
In-Reply-To: <1286cc2e-2fc8-4de4-9598-a6a53e21ce6bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=3.67.78.197; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.67.78.197
References: <uj0npn$1d156$1@dont-email.me> <uj0t5j$1dp63$1@dont-email.me>
<uj39gv$1srlq$1@dont-email.me> <uj3chf$1tbp8$1@dont-email.me>
<uj5u2s$2dq6m$1@dont-email.me> <1286cc2e-2fc8-4de4-9598-a6a53e21ce6bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cd769c06-962c-40a8-9cf3-e4fadcfddf33n@googlegroups.com>
Subject: Re: Unchecked_Deallocation with tagged class type.
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Fri, 17 Nov 2023 13:13:42 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1970
 by: AdaMagica - Fri, 17 Nov 2023 13:13 UTC

AdaMagica schrieb am Freitag, 17. November 2023 um 14:12:25 UTC+1:
> Blady schrieb am Donnerstag, 16. November 2023 um 21:29:20 UTC+1:
> > Thanks, yes, the instanciation of Unchecked_Deallocation seemed to
> > indicate that but I was not able to confirm it from the Ada RM.
> > A mention in Ada RM 13.11.2 Unchecked Storage Deallocation of that
> > particular possibility would be valuable.
> type Object(<>) is limited private;
>
> The box here denotes unknown discriminants, i.e. indefinite types - these include task types;
nonsense - I mean class types
> limited is "assume the worst" => i.e. any type may be used as actual type for this formal type.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor