Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Is knowledge knowable? If not, how do we know that?


devel / comp.lang.ada / Re: On absurdity of collections 7.6.1 (11.1/3)

SubjectAuthor
* On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
+* Re: On absurdity of collections 7.6.1 (11.1/3)Simon Wright
|`* Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
| +* Re: On absurdity of collections 7.6.1 (11.1/3)Simon Wright
| |`* Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
| | +* Re: On absurdity of collections 7.6.1 (11.1/3)Simon Wright
| | |`- Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
| | `* Re: On absurdity of collections 7.6.1 (11.1/3)Randy Brukardt
| |  `- Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
| `* Re: On absurdity of collections 7.6.1 (11.1/3)Randy Brukardt
|  `- Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
`* Re: On absurdity of collections 7.6.1 (11.1/3)G.B.
 `* Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov
  `* Re: On absurdity of collections 7.6.1 (11.1/3)Randy Brukardt
   `- Re: On absurdity of collections 7.6.1 (11.1/3)Dmitry A. Kazakov

1
On absurdity of collections 7.6.1 (11.1/3)

<sj1ah7$7kr$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: On absurdity of collections 7.6.1 (11.1/3)
Date: Wed, 29 Sep 2021 11:09:58 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj1ah7$7kr$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="7835"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Mozilla-News-Host: news://news.aioe.org:119
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Wed, 29 Sep 2021 09:09 UTC

For Ada programmers who wonder what it is, here is a practical example.
Given the package specification:

package P is
type Item (Length : Positive) is
new Ada.Finalization.Limited_Controlled with
record
Text : String (1..Length);
end record;
overriding procedure Finalize (X : in out Item);

type Item_Ptr is access all Item;
function New_Item
( Pool : in out Root_Storage_Pool'Class;
Text : String
) return Item_Ptr;
procedure Free is new Ada.Unchecked_Deallocation (Item, Item_Ptr);
end P;

and the program using it like this:

Ptr : Item_Ptr := New_Item (Some_Pool, "A");

...

Free (Ptr);

Write the package body.

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<lybl4bbq19.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!RKN7TKnHC01q0gdg6EhkbQ.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Wed, 29 Sep 2021 12:05:22 +0100
Organization: Aioe.org NNTP Server
Message-ID: <lybl4bbq19.fsf@pushface.org>
References: <sj1ah7$7kr$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="58257"; posting-host="RKN7TKnHC01q0gdg6EhkbQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:roAeLG6i9rHNat+9H1KAsPmoRws=
 by: Simon Wright - Wed, 29 Sep 2021 11:05 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> type Item_Ptr is access all Item;
> function New_Item
> ( Pool : in out Root_Storage_Pool'Class;
> Text : String
> ) return Item_Ptr;

What I don't see is how you can implement this, never mind any other
problems.

13.11(17) says

"If Storage_Pool is not specified for a type defined by an
access_to_object_definition, then the implementation chooses a
standard storage pool for it in an implementation-defined manner."

I see that 3.10(8) says

"Access-to-object types are further subdivided into pool-specific
access types [...] and general access types, whose values can
designate the elements of any storage pool [...]"

which implies that there *is* a mechanism.

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj1i6g$7hv$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Wed, 29 Sep 2021 13:20:48 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj1i6g$7hv$1@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="7743"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Wed, 29 Sep 2021 11:20 UTC

On 2021-09-29 13:05, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> type Item_Ptr is access all Item;
>> function New_Item
>> ( Pool : in out Root_Storage_Pool'Class;
>> Text : String
>> ) return Item_Ptr;
>
> What I don't see is how you can implement this, never mind any other
> problems.

A naive, but wrong due to 7.6.1 (11.1/3) nonsense, implementation would be:

function New_Item
( Pool : in out Root_Storage_Pool'Class;
Text : String
) return Item_Ptr is
type Ptr is access Item;
for Ptr'Storage_Pool use Pool;
Object : Ptr := new Item (Text'Length);
begin
Object.Text := Text;
return Object.all'Unchecked_Access;
end New_Item;

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<ly35pnawpp.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!RKN7TKnHC01q0gdg6EhkbQ.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Wed, 29 Sep 2021 22:38:42 +0100
Organization: Aioe.org NNTP Server
Message-ID: <ly35pnawpp.fsf@pushface.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
<sj1i6g$7hv$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="22873"; posting-host="RKN7TKnHC01q0gdg6EhkbQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:4zp3R9CKCK0Ko/Dh7gh6618qLJc=
 by: Simon Wright - Wed, 29 Sep 2021 21:38 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2021-09-29 13:05, Simon Wright wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>
>>> type Item_Ptr is access all Item;
>>> function New_Item
>>> ( Pool : in out Root_Storage_Pool'Class;
>>> Text : String
>>> ) return Item_Ptr;
>> What I don't see is how you can implement this, never mind any other
>> problems.
>
> A naive, but wrong due to 7.6.1 (11.1/3) nonsense, implementation would be:
>
> function New_Item
> ( Pool : in out Root_Storage_Pool'Class;
> Text : String
> ) return Item_Ptr is
> type Ptr is access Item;
> for Ptr'Storage_Pool use Pool;
> Object : Ptr := new Item (Text'Length);
> begin
> Object.Text := Text;
> return Object.all'Unchecked_Access;
> end New_Item;

OK, that code compiles.

What you'd need to happen when the returned Item_Ptr is freed would be
for the mechanism of the actual pool to be invoked. But Item_Ptr was
declared without any pool specified, so uses the default, and when the
returned Item_Ptr is freed it uses the default pool's mechanism.

But of course what actually happens with this code is that the returned
Item_Ptr is left dangling; my test

with P;
with System.Pool_Local; -- GNAT special
with Ada.Text_IO; use Ada.Text_IO;
procedure Test is
use P;
Pool : System.Pool_Local.Unbounded_Reclaim_Pool;
Ptr : Item_Ptr := New_Item (Pool, "hello");
begin
Put_Line (Ptr.Text);
Free (Ptr);
end Test;

manages flukily to print "hello" before crashing at the Free (Ptr).

I don't see how what you want can be achieved without every access type
containing a reference to the pool the object was allocated from.

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj3020$u5$1@franka.jacob-sparre.dk>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!paganini.bofh.team!newsfeed.xs3.de!callisto.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Wed, 29 Sep 2021 19:23:28 -0500
Organization: JSA Research & Innovation
Lines: 50
Message-ID: <sj3020$u5$1@franka.jacob-sparre.dk>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org> <sj1i6g$7hv$1@gioia.aioe.org>
Injection-Date: Thu, 30 Sep 2021 00:23:29 -0000 (UTC)
Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226";
logging-data="965"; mail-complaints-to="news@jacob-sparre.dk"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
 by: Randy Brukardt - Thu, 30 Sep 2021 00:23 UTC

It's surely wrong, because you have to deallocate from the same pool as you
allocated. And you have no way to save such a thing. There is no capability
in Ada to use multiple pools with one access type.

At best, you could directly call Allocate and Deallocate for this purpose,
but it is impossible to use anything built-in.

You could use the subpool mechanism (assuming you want a limited number of
kinds of pools) to do this (each subpool could use a different allocation
mechanism). But that would mean a giant pool type containing all of the
implementations -- which seems suboptimal. Note that the subpool mechanism
ensures that finalization happens when a subpool is destroyed.

Randy.

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:sj1i6g$7hv$1@gioia.aioe.org...
> On 2021-09-29 13:05, Simon Wright wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>
>>> type Item_Ptr is access all Item;
>>> function New_Item
>>> ( Pool : in out Root_Storage_Pool'Class;
>>> Text : String
>>> ) return Item_Ptr;
>>
>> What I don't see is how you can implement this, never mind any other
>> problems.
>
> A naive, but wrong due to 7.6.1 (11.1/3) nonsense, implementation would
> be:
>
> function New_Item
> ( Pool : in out Root_Storage_Pool'Class;
> Text : String
> ) return Item_Ptr is
> type Ptr is access Item;
> for Ptr'Storage_Pool use Pool;
> Object : Ptr := new Item (Text'Length);
> begin
> Object.Text := Text;
> return Object.all'Unchecked_Access;
> end New_Item;
>
> --
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj3r5v$pla$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 10:06:21 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj3r5v$pla$1@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
<sj1i6g$7hv$1@gioia.aioe.org> <sj3020$u5$1@franka.jacob-sparre.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="26282"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 30 Sep 2021 08:06 UTC

On 2021-09-30 02:23, Randy Brukardt wrote:
> It's surely wrong, because you have to deallocate from the same pool as you
> allocated. And you have no way to save such a thing. There is no capability
> in Ada to use multiple pools with one access type.

You mean Unchecked_Dellocation? Maybe, then it is another language bug.
However, the object collection schema is irrelevant for a while. The
first problem is that Finalize is called twice.

> At best, you could directly call Allocate and Deallocate for this purpose,
> but it is impossible to use anything built-in.

Actually it is possible using a fake pool:

type Fake_Pool is new Root_Storage_Pool with record
Pool : access Root_Storage_Pool'Class;
end record;

Allocate goes like this:

procedure Allocate
( Pool : in out Fake_Pool;
Storage_Address : out System.Address;
Size : Storage_Count;
Alignment : Storage_Count
) is
begin
Pool.Pool.Allocate (Storage_Address, Size, Alignment);
end Allocate;

Then:

Fake : Fake_Pool;
type Ptr is access Item;
for Ptr'Storage_Pool use Fake; -- "collection" lives here

function New_Item
( Pool : in out Root_Storage_Pool'Class;
Text : String
) return Item_Ptr is
Object : Ptr;
begin
Fake.Pool := Pool'Unchecked_Access; -- Add mutex here
Object := new Item (Text'Length);
Object.Text := Text;
return Object.all'Unchecked_Access;
end New_Item;

Now the object is intact.

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj3r7l$pla$2@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 10:07:17 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj3r7l$pla$2@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
<sj1i6g$7hv$1@gioia.aioe.org> <ly35pnawpp.fsf@pushface.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="26282"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Thu, 30 Sep 2021 08:07 UTC

On 2021-09-29 23:38, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> On 2021-09-29 13:05, Simon Wright wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>>
>>>> type Item_Ptr is access all Item;
>>>> function New_Item
>>>> ( Pool : in out Root_Storage_Pool'Class;
>>>> Text : String
>>>> ) return Item_Ptr;
>>> What I don't see is how you can implement this, never mind any other
>>> problems.
>>
>> A naive, but wrong due to 7.6.1 (11.1/3) nonsense, implementation would be:
>>
>> function New_Item
>> ( Pool : in out Root_Storage_Pool'Class;
>> Text : String
>> ) return Item_Ptr is
>> type Ptr is access Item;
>> for Ptr'Storage_Pool use Pool;
>> Object : Ptr := new Item (Text'Length);
>> begin
>> Object.Text := Text;
>> return Object.all'Unchecked_Access;
>> end New_Item;
>
> OK, that code compiles.
>
> What you'd need to happen when the returned Item_Ptr is freed would be
> for the mechanism of the actual pool to be invoked. But Item_Ptr was
> declared without any pool specified, so uses the default, and when the
> returned Item_Ptr is freed it uses the default pool's mechanism.

That would be another language bug, if true, because 13.11.2 is silent
about that. But the first bug is that New_Item is not implementable,
well it actually is, but in a very clumsy way (see my answer to Randy).

> But of course what actually happens with this code is that the returned
> Item_Ptr is left dangling; my test
>
> with P;
> with System.Pool_Local; -- GNAT special
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Test is
> use P;
> Pool : System.Pool_Local.Unbounded_Reclaim_Pool;
> Ptr : Item_Ptr := New_Item (Pool, "hello");
> begin
> Put_Line (Ptr.Text);
> Free (Ptr);
> end Test;
>
> manages flukily to print "hello" before crashing at the Free (Ptr).

It should print it twice, because Finalize must be called twice. Once
inside New_Item, then in Free.

> I don't see how what you want can be achieved without every access type
> containing a reference to the pool the object was allocated from.

Yes, every general access type that permits instantiation of
Unchecked_Dellocation must indicate the target object's pool, directly,
e.g. per fat pointer, or indirectly by some other schema. I see nothing
in RM that allows a different implementation. But it is could be a bug
by omission and I am not a language lawyer anyway.

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<lyy27ea2bv.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!RKN7TKnHC01q0gdg6EhkbQ.user.46.165.242.75.POSTED!not-for-mail
From: sim...@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 09:35:00 +0100
Organization: Aioe.org NNTP Server
Message-ID: <lyy27ea2bv.fsf@pushface.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
<sj1i6g$7hv$1@gioia.aioe.org> <ly35pnawpp.fsf@pushface.org>
<sj3r7l$pla$2@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="47414"; posting-host="RKN7TKnHC01q0gdg6EhkbQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (darwin)
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:D4fCAMAwQncWUiL3k1+TEoXbODk=
 by: Simon Wright - Thu, 30 Sep 2021 08:35 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> It should print it twice, because Finalize must be called twice. Once
> inside New_Item, then in Free.

That's in your implementation of Finalize, which you haven't shown us

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj3tm7$1um3$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 10:49:11 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj3tm7$1um3$1@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
<sj1i6g$7hv$1@gioia.aioe.org> <ly35pnawpp.fsf@pushface.org>
<sj3r7l$pla$2@gioia.aioe.org> <lyy27ea2bv.fsf@pushface.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="64195"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 30 Sep 2021 08:49 UTC

On 2021-09-30 10:35, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> It should print it twice, because Finalize must be called twice. Once
>> inside New_Item, then in Free.
>
> That's in your implementation of Finalize, which you haven't shown us

procedure Finalize (X : in out Item) is
begin
Put_Line (X.Text & " is dead");
end Finalize;

P.S. You can use the standard pool:

Ptr : Item_Ptr;
type String_Ptr is access String;
begin
Ptr := New_Item (String_Ptr'Storage_Pool, "A");
Free (Ptr);

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj4vb7$heh$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bauh...@notmyhomepage.invalid (G.B.)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 20:23:34 +0200
Organization: A noiseless patient Spider
Lines: 3
Message-ID: <sj4vb7$heh$1@dont-email.me>
References: <sj1ah7$7kr$1@gioia.aioe.org>
Reply-To: nonlegitur@notmyhomepage.de
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 30 Sep 2021 18:23:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4a1af860c01e7ec777a62240066092c4";
logging-data="17873"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hqJT7suCrImQfOIW3L2Zqe0HiNqEl6Es="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0)
Gecko/20100101 Thunderbird/78.14.0
Cancel-Lock: sha1:ytvCsGkKzC+P6tNokHRrHHIvrfI=
In-Reply-To: <sj1ah7$7kr$1@gioia.aioe.org>
Content-Language: en-US
 by: G.B. - Thu, 30 Sep 2021 18:23 UTC

On 29.09.21 11:09, Dmitry A. Kazakov wrote:
> For Ada programmers who wonder what it is,
What's the reasoning behind run-time selection of storage pools?

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj5127$1bbu$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 20:52:55 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj5127$1bbu$1@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <sj4vb7$heh$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="44414"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 30 Sep 2021 18:52 UTC

On 2021-09-30 20:23, G.B. wrote:
> On 29.09.21 11:09, Dmitry A. Kazakov wrote:
>> For Ada programmers who wonder what it is,
> What's the reasoning behind run-time selection of storage pools?

It happens quite frequently. Here is an example without controlled
objects, just an illustration of a dynamically selected storage pool.

Consider a JSON parser. It is be an Ada object with a buffer inside
which size is a discriminant. On top of the buffer sits an arena pool.
The parts of the parsed JSON object are allocated in the arena. After
parsing the result can be used until the next parsing that will sweep
the arena, no Unchecked_Deallocate.

In this case the collection rule will have no effect since JSON objects
do not require controlled components (or tasks, yet another thing killed
by the collection).

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj5oph$qss$1@franka.jacob-sparre.dk>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 20:37:52 -0500
Organization: JSA Research & Innovation
Lines: 29
Message-ID: <sj5oph$qss$1@franka.jacob-sparre.dk>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org> <sj1i6g$7hv$1@gioia.aioe.org> <ly35pnawpp.fsf@pushface.org> <sj3r7l$pla$2@gioia.aioe.org>
Injection-Date: Fri, 1 Oct 2021 01:37:53 -0000 (UTC)
Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226";
logging-data="27548"; mail-complaints-to="news@jacob-sparre.dk"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
 by: Randy Brukardt - Fri, 1 Oct 2021 01:37 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:sj3r7l$pla$2@gioia.aioe.org...
....
> Yes, every general access type that permits instantiation of
> Unchecked_Dellocation must indicate the target object's pool, directly,
> e.g. per fat pointer, or indirectly by some other schema. I see nothing in
> RM that allows a different implementation. But it is could be a bug by
> omission and I am not a language lawyer anyway.

Each access type has only one pool, and all allocations and deallocations
for that access type use that pool. You can see at RM 13.11(13) that you can
retrieve the storage pool of T, that wouldn't be possible if it could have
multiple pools. Allocation for T uses T'Storage_Pool (RM 13.11(16)), and
deallocation for T also uses T'Storage_Pool (13.11.2(9/3) - I see this
wording isn't as clear as it could be, but "the storage_pool" here is the
one for the type T. It is clear, however, from 13.11.2(16/3) that it is
erroneous to deallocate an object for some other pool than the pool of the
access type passed to the instance of Unchecked_Deallocation.

Surely no one would expect the pool to be associated with the object -- it
would be impossible to interface to C or most other languages that way. Note
that GNAT insists that all access types are C-compatible.

As I've said repeatedly, if you want the behavior of multiple pools with a
single access type, you have to use the subpool mechanism somehow.

Randy.

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj5oui$qt7$1@franka.jacob-sparre.dk>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail
From: ran...@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Thu, 30 Sep 2021 20:40:33 -0500
Organization: JSA Research & Innovation
Lines: 30
Message-ID: <sj5oui$qt7$1@franka.jacob-sparre.dk>
References: <sj1ah7$7kr$1@gioia.aioe.org> <sj4vb7$heh$1@dont-email.me> <sj5127$1bbu$1@gioia.aioe.org>
Injection-Date: Fri, 1 Oct 2021 01:40:34 -0000 (UTC)
Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226";
logging-data="27559"; mail-complaints-to="news@jacob-sparre.dk"
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
 by: Randy Brukardt - Fri, 1 Oct 2021 01:40 UTC

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:sj5127$1bbu$1@gioia.aioe.org...
> On 2021-09-30 20:23, G.B. wrote:
>> On 29.09.21 11:09, Dmitry A. Kazakov wrote:
>>> For Ada programmers who wonder what it is,
>> What's the reasoning behind run-time selection of storage pools?
>
> It happens quite frequently. Here is an example without controlled
> objects, just an illustration of a dynamically selected storage pool.
>
> Consider a JSON parser. It is be an Ada object with a buffer inside which
> size is a discriminant. On top of the buffer sits an arena pool. The parts
> of the parsed JSON object are allocated in the arena. After parsing the
> result can be used until the next parsing that will sweep the arena, no
> Unchecked_Deallocate.
>
> In this case the collection rule will have no effect since JSON objects do
> not require controlled components (or tasks, yet another thing killed by
> the collection).

To implement an arena pool, you need to use the subpool mechanism (which
does properly handle finalization when you "sweep the pool" as you put it).
Each "arena" is a separate subpool, and you can dump the entire subpool with
Unchecked_Deallocate_Subpool.

It helps to use the tool designed for the job. ;-)

Randy.

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj6f1g$tlp$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Fri, 1 Oct 2021 09:57:35 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj6f1g$tlp$1@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <lybl4bbq19.fsf@pushface.org>
<sj1i6g$7hv$1@gioia.aioe.org> <ly35pnawpp.fsf@pushface.org>
<sj3r7l$pla$2@gioia.aioe.org> <sj5oph$qss$1@franka.jacob-sparre.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="30393"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Fri, 1 Oct 2021 07:57 UTC

On 2021-10-01 03:37, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:sj3r7l$pla$2@gioia.aioe.org...
> ...
>> Yes, every general access type that permits instantiation of
>> Unchecked_Dellocation must indicate the target object's pool, directly,
>> e.g. per fat pointer, or indirectly by some other schema. I see nothing in
>> RM that allows a different implementation. But it is could be a bug by
>> omission and I am not a language lawyer anyway.
>
> Each access type has only one pool, and all allocations and deallocations
> for that access type use that pool. You can see at RM 13.11(13) that you can
> retrieve the storage pool of T, that wouldn't be possible if it could have
> multiple pools. Allocation for T uses T'Storage_Pool (RM 13.11(16)), and
> deallocation for T also uses T'Storage_Pool (13.11.2(9/3) - I see this
> wording isn't as clear as it could be, but "the storage_pool" here is the
> one for the type T. It is clear, however, from 13.11.2(16/3) that it is
> erroneous to deallocate an object for some other pool than the pool of the
> access type passed to the instance of Unchecked_Deallocation.

At least instantiations of Unchecked_Deallocation should be illegal with
general access.

> Surely no one would expect the pool to be associated with the object -- it
> would be impossible to interface to C or most other languages that way. Note
> that GNAT insists that all access types are C-compatible.

Normally you cannot allocate C objects intended to be freed from C using
Ada allocator. This is a common mistake of binding designers which
promptly crashes the program.

But I see no problem here, especially because the access type must have
C convention anyway.

> As I've said repeatedly, if you want the behavior of multiple pools with a
> single access type, you have to use the subpool mechanism somehow.

Honestly I still try to find a useful case for subpools. It is nothing
that could not be easily implemented using existing pools or might help
fighting off collections etc.

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

Re: On absurdity of collections 7.6.1 (11.1/3)

<sj6f1q$tlp$2@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!aioe.org!x6YkKUCkj2qHLwbKnVEeag.user.46.165.242.91.POSTED!not-for-mail
From: mail...@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: On absurdity of collections 7.6.1 (11.1/3)
Date: Fri, 1 Oct 2021 09:57:46 +0200
Organization: Aioe.org NNTP Server
Message-ID: <sj6f1q$tlp$2@gioia.aioe.org>
References: <sj1ah7$7kr$1@gioia.aioe.org> <sj4vb7$heh$1@dont-email.me>
<sj5127$1bbu$1@gioia.aioe.org> <sj5oui$qt7$1@franka.jacob-sparre.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="30393"; posting-host="x6YkKUCkj2qHLwbKnVEeag.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Fri, 1 Oct 2021 07:57 UTC

On 2021-10-01 03:40, Randy Brukardt wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
> news:sj5127$1bbu$1@gioia.aioe.org...
>> On 2021-09-30 20:23, G.B. wrote:
>>> On 29.09.21 11:09, Dmitry A. Kazakov wrote:
>>>> For Ada programmers who wonder what it is,
>>> What's the reasoning behind run-time selection of storage pools?
>>
>> It happens quite frequently. Here is an example without controlled
>> objects, just an illustration of a dynamically selected storage pool.
>>
>> Consider a JSON parser. It is be an Ada object with a buffer inside which
>> size is a discriminant. On top of the buffer sits an arena pool. The parts
>> of the parsed JSON object are allocated in the arena. After parsing the
>> result can be used until the next parsing that will sweep the arena, no
>> Unchecked_Deallocate.
>>
>> In this case the collection rule will have no effect since JSON objects do
>> not require controlled components (or tasks, yet another thing killed by
>> the collection).
>
> To implement an arena pool, you need to use the subpool mechanism (which
> does properly handle finalization when you "sweep the pool" as you put it).
> Each "arena" is a separate subpool, and you can dump the entire subpool with
> Unchecked_Deallocate_Subpool.

Not in this case, where all pool is arena. Allocate takes memory from
the object's buffer.

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


devel / comp.lang.ada / Re: On absurdity of collections 7.6.1 (11.1/3)

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor