Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

And Bruce is effectively building BruceIX -- Alan Cox


devel / comp.lang.ada / strange cursor in nested containers

SubjectAuthor
* strange cursor in nested containersMario Blunk
+- Re: strange cursor in nested containersSimon Wright
`* Re: strange cursor in nested containersEgil H H
 +- Re: strange cursor in nested containersEgil H H
 `* Re: strange cursor in nested containersSimon Wright
  `* Re: strange cursor in nested containersMario Blunk
   `* Re: strange cursor in nested containersRandy Brukardt
    `* Re: strange cursor in nested containersMario Blunk
     `* Re: strange cursor in nested containersJeffrey R.Carter
      `* Re: strange cursor in nested containersMario Blunk
       `* Re: strange cursor in nested containersRandy Brukardt
        `* Re: strange cursor in nested containersJeffrey R.Carter
         `- Re: strange cursor in nested containersDmitry A. Kazakov

1
strange cursor in nested containers

<a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:6214:b33:b0:5ef:63e8:e64e with SMTP id w19-20020a0562140b3300b005ef63e8e64emr2150094qvj.7.1681888187531;
Wed, 19 Apr 2023 00:09:47 -0700 (PDT)
X-Received: by 2002:a25:cbd5:0:b0:b95:630:197b with SMTP id
b204-20020a25cbd5000000b00b950630197bmr3064575ybg.10.1681888187292; Wed, 19
Apr 2023 00:09:47 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 19 Apr 2023 00:09:46 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.122.5; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.122.5
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
Subject: strange cursor in nested containers
From: mario.blunk.gplus@gmail.com (Mario Blunk)
Injection-Date: Wed, 19 Apr 2023 07:09:47 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Mario Blunk - Wed, 19 Apr 2023 07:09 UTC

Hello out there,
I've put together a demo to reproduce a strange behavior of a cursor.

https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb

Description:
Inside the procedure "get_line" the cursor "result" is assigned only once (on match). Since there is no further match, in the course of the procedure, I assume that "result" is never changed. So the expected output should be:

net: A
L1 S: 2.00000E+00 E: 3.00000E+00
L2 S: 2.00000E+00 E: 3.00000E+00
net: B
L2 S: 2.00000E+00 E: 3.00000E+00
L3 S: 2.00000E+00 E: 3.00000E+00

but the actual output is:

net: A
L1 S: 2.00000E+00 E: 3.00000E+00
L2 S: 2.00000E+00 E: 3.00000E+00
net: B
L2 S: 1.20000E+01 E: 1.30000E+01
L3 S: 7.47956E-39 E: 0.00000E+00 -- changes randomly

Thanks for your help.

Re: strange cursor in nested containers

<lyttxbc3mz.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: simon@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: strange cursor in nested containers
Date: Wed, 19 Apr 2023 16:07:00 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <lyttxbc3mz.fsf@pushface.org>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="40e9c7e81895f811b59dc5c65377c5ce";
logging-data="107378"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rWU677ltPiDnS9nSYQhlkPmNcTlsD9Pg="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin)
Cancel-Lock: sha1:Y0Dr5fCRr7N9Qi2azng//+/uFf8=
sha1:4vvgL6cLWmLfzn0kVJ+fbYWaMHo=
 by: Simon Wright - Wed, 19 Apr 2023 15:07 UTC

Mario Blunk <mario.blunk.gplus@gmail.com> writes:

> I've put together a demo to reproduce a strange behavior of a cursor.
>
> https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb
>
> Description:
> Inside the procedure "get_line" the cursor "result" is assigned only
> once (on match). Since there is no further match, in the course of the
> procedure, I assume that "result" is never changed. So the expected
> output should be:
>
> net: A
> L1 S: 2.00000E+00 E: 3.00000E+00
> L2 S: 2.00000E+00 E: 3.00000E+00
> net: B
> L2 S: 2.00000E+00 E: 3.00000E+00
> L3 S: 2.00000E+00 E: 3.00000E+00
>
> but the actual output is:
>
> net: A
> L1 S: 2.00000E+00 E: 3.00000E+00
> L2 S: 2.00000E+00 E: 3.00000E+00
> net: B
> L2 S: 1.20000E+01 E: 1.30000E+01
> L3 S: 7.47956E-39 E: 0.00000E+00 -- changes randomly

This is a puzzler.

To simplify matters (for me, anyway) I changed your doubly linked list
to a vector. Now, instead of junk, I get an access violation.

'result' isn't changed, but a Cursor contains a pointer to the container
and an index; using gdb to look at the container via the unchanged
pointer, it's been overwritten with garbage. However, looping with this
(after the Nets.Iterate call, i.e. after Result has been damaged)

for N of Nets loop
for TL of N.Lines loop
Put_Line (To_String (TL));
end loop;
end loop;

works just fine.

My head hurts.

Re: strange cursor in nested containers

<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1a90:b0:3e9:b2ec:573f with SMTP id s16-20020a05622a1a9000b003e9b2ec573fmr10499qtc.12.1681967734979;
Wed, 19 Apr 2023 22:15:34 -0700 (PDT)
X-Received: by 2002:a25:d604:0:b0:b96:7eae:9946 with SMTP id
n4-20020a25d604000000b00b967eae9946mr247900ybg.11.1681967734698; Wed, 19 Apr
2023 22:15:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 19 Apr 2023 22:15:34 -0700 (PDT)
In-Reply-To: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=81.167.0.45; posting-account=uulyKwoAAAA86DO0ODu--rZtbje8Sytn
NNTP-Posting-Host: 81.167.0.45
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
Subject: Re: strange cursor in nested containers
From: ehh.public@gmail.com (Egil H H)
Injection-Date: Thu, 20 Apr 2023 05:15:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Egil H H - Thu, 20 Apr 2023 05:15 UTC

On Wednesday, April 19, 2023 at 9:09:48 AM UTC+2, Mario Blunk wrote:
> Hello out there,
> I've put together a demo to reproduce a strange behavior of a cursor.
>
> https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb
>

Each call to `element(n)` returns a _copy_ of the element, which in this case includes the enitre doubly linked list
(and since `net` is a renames of `element(n), you would have gotten multiple copies if you had called `net` multiple times inside query net)

Using a reference instead should fix this problem:
net : type_net renames nets.reference (key(n));

or (Ada 2012):
net : type_net renames nets(n);

--
~egilhh

Re: strange cursor in nested containers

<f3d6ce49-c573-4743-919b-443252b3113an@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:12d3:b0:74c:ed4d:7916 with SMTP id e19-20020a05620a12d300b0074ced4d7916mr55793qkl.12.1681968825212;
Wed, 19 Apr 2023 22:33:45 -0700 (PDT)
X-Received: by 2002:a25:cf8e:0:b0:b8f:6a10:7654 with SMTP id
f136-20020a25cf8e000000b00b8f6a107654mr217604ybg.5.1681968824949; Wed, 19 Apr
2023 22:33:44 -0700 (PDT)
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: Wed, 19 Apr 2023 22:33:44 -0700 (PDT)
In-Reply-To: <6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=81.167.0.45; posting-account=uulyKwoAAAA86DO0ODu--rZtbje8Sytn
NNTP-Posting-Host: 81.167.0.45
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com> <6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f3d6ce49-c573-4743-919b-443252b3113an@googlegroups.com>
Subject: Re: strange cursor in nested containers
From: ehh.public@gmail.com (Egil H H)
Injection-Date: Thu, 20 Apr 2023 05:33:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1893
 by: Egil H H - Thu, 20 Apr 2023 05:33 UTC

On Thursday, April 20, 2023 at 7:15:36 AM UTC+2, Egil H H wrote:
> On Wednesday, April 19, 2023 at 9:09:48 AM UTC+2, Mario Blunk wrote:
>
> Using a reference instead should fix this problem:
> net : type_net renames nets.reference (key(n));
>
> or (Ada 2012):
> net : type_net renames nets(n);
>

oops, both my solutions are Ada 2012 :)

If Ada 2005 is a requirement (based on your explicit usage of `iterate`), I guess you would need an extra set of callbacks and call `update_element` in order to get a reference to the element containing the correct instance of the doubly linked list

--
~egilhh

Re: strange cursor in nested containers

<lyttxak3ag.fsf@pushface.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: simon@pushface.org (Simon Wright)
Newsgroups: comp.lang.ada
Subject: Re: strange cursor in nested containers
Date: Thu, 20 Apr 2023 15:59:35 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <lyttxak3ag.fsf@pushface.org>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="9fefc01f5d17daffe51cd7c6729b1277";
logging-data="688487"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181aGWKO0DQ7708hf0C7FIJXrqdXxarwZA="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (darwin)
Cancel-Lock: sha1:gL2qlm4mocVEC/nm7RzQM8L3WLM=
sha1:QJPbpeAiZUmUOYhNmZ+397eucmo=
 by: Simon Wright - Thu, 20 Apr 2023 14:59 UTC

Egil H H <ehh.public@gmail.com> writes:

> Each call to `element(n)` returns a _copy_ of the element, which in
> this case includes the enitre doubly linked list

This is indeed the problem, thanks!

I hadn't considered the effect of renaming a function call; the cursor
constructed inside query_net refers to the locally renamed copy of
type_net, which will be destroyed on exit from query_net.

> (and since `net` is a
> renames of `element(n), you would have gotten multiple copies if you
> had called `net` multiple times inside query net)

This appears to say that this renaming of a function call results in
something like a macro, but I think that

R : T renames Func;

is more like

R : constant T := Func;

ARM 8.5(3) says

"The elaboration of a renaming_declaration evaluates the name that
follows the reserved word renames and thereby determines the view and
entity denoted by this name (the renamed view and renamed entity). A
name that denotes the renaming_declaration denotes (a new view of)
the renamed entity."

Re: strange cursor in nested containers

<ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a37:c246:0:b0:745:6afc:9bb2 with SMTP id j6-20020a37c246000000b007456afc9bb2mr255397qkm.14.1682004489175;
Thu, 20 Apr 2023 08:28:09 -0700 (PDT)
X-Received: by 2002:a81:ed06:0:b0:54e:edf3:b48f with SMTP id
k6-20020a81ed06000000b0054eedf3b48fmr1018622ywm.5.1682004488895; Thu, 20 Apr
2023 08:28:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.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: Thu, 20 Apr 2023 08:28:08 -0700 (PDT)
In-Reply-To: <lyttxak3ag.fsf@pushface.org>
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.122.5; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.122.5
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com> <lyttxak3ag.fsf@pushface.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com>
Subject: Re: strange cursor in nested containers
From: mario.blunk.gplus@gmail.com (Mario Blunk)
Injection-Date: Thu, 20 Apr 2023 15:28:09 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1785
 by: Mario Blunk - Thu, 20 Apr 2023 15:28 UTC

Thanks for your replies. Now it is becoming clear to me:

1. The statement net : type_net renames element (n) gives a copy of element (n).
2. After the assignment to "result" (line 55), "result" points to an element inside the local copy "net".
3. Once "net" is overwritten in the next call of query_net, "result" still refers to a "net" that does not exist anymore. Likewise, once procedure query_net is left, "result" still points to a list that does not exist anymore.. Thatswhy I get garbage in line 68 and 77.
Correct ?

Re: strange cursor in nested containers

<u209li$37hob$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: strange cursor in nested containers
Date: Sat, 22 Apr 2023 04:33:37 -0500
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <u209li$37hob$1@dont-email.me>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com> <6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com> <lyttxak3ag.fsf@pushface.org> <ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com>
Injection-Date: Sat, 22 Apr 2023 09:33:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ad3be9722f67937aaedae639877f02d3";
logging-data="3393291"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PaYahm4MSuaHQsB2TUhtjvUEtFP3F5j8="
Cancel-Lock: sha1:jd9nnSwcBndjfYDzCbSAXpp/Zwk=
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-RFC2646: Format=Flowed; Original
X-Priority: 3
 by: Randy Brukardt - Sat, 22 Apr 2023 09:33 UTC

I agree. If you used a debugging container that checked for dangling
cursors, you probably would have gotten an exception from any use of the
cursor to the dead copy. Not sure that would have been any clearer as to the
cause, but it would be a suggestion. (Not sure if GNAT still has debugging
containers, they did at one point, but a lot of work has been done on them
since.)

Randy.

"Mario Blunk" <mario.blunk.gplus@gmail.com> wrote in message
news:ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com...
Thanks for your replies. Now it is becoming clear to me:

1. The statement net : type_net renames element (n) gives a copy of element
(n).
2. After the assignment to "result" (line 55), "result" points to an element
inside the local copy "net".
3. Once "net" is overwritten in the next call of query_net, "result" still
refers to a "net" that does not exist anymore. Likewise, once procedure
query_net is left, "result" still points to a list that does not exist
anymore. Thatswhy I get garbage in line 68 and 77.
Correct ?

Re: strange cursor in nested containers

<f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:1b8b:b0:3ef:8159:5ec4 with SMTP id bp11-20020a05622a1b8b00b003ef81595ec4mr49504qtb.9.1682183047476;
Sat, 22 Apr 2023 10:04:07 -0700 (PDT)
X-Received: by 2002:a81:b667:0:b0:534:d71f:14e6 with SMTP id
h39-20020a81b667000000b00534d71f14e6mr3084399ywk.9.1682183047199; Sat, 22 Apr
2023 10:04:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.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: Sat, 22 Apr 2023 10:04:06 -0700 (PDT)
In-Reply-To: <u209li$37hob$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.122.5; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.122.5
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com> <lyttxak3ag.fsf@pushface.org>
<ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com> <u209li$37hob$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com>
Subject: Re: strange cursor in nested containers
From: mario.blunk.gplus@gmail.com (Mario Blunk)
Injection-Date: Sat, 22 Apr 2023 17:04:07 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1554
 by: Mario Blunk - Sat, 22 Apr 2023 17:04 UTC

I wonder why at runtime no exception is raised.
How could I solve the problem ? Not using "rename" ? Using an aliased access type as John Barnes suggests in Ada2005 on page 275 ?

Re: strange cursor in nested containers

<u2199a$3cm0v$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: strange cursor in nested containers
Date: Sat, 22 Apr 2023 20:33:14 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <u2199a$3cm0v$1@dont-email.me>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
<lyttxak3ag.fsf@pushface.org>
<ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com>
<u209li$37hob$1@dont-email.me>
<f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 22 Apr 2023 18:33:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="850f35eea88dfa029483915c2ca22df4";
logging-data="3561503"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+IhKxgQ1PyzA8c0G4pKo7kmOMAi+YGn4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0
Cancel-Lock: sha1:sYtkKSWWM4hLjo2ysQD8vvD3P5c=
In-Reply-To: <f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Sat, 22 Apr 2023 18:33 UTC

On 2023-04-22 19:04, Mario Blunk wrote:
> I wonder why at runtime no exception is raised.
> How could I solve the problem ? Not using "rename" ? Using an aliased access type as John Barnes suggests in Ada2005 on page 275 ?

You have to avoid calling Element. Since you have a cursor, you can call
Query_Element, which should pass the actual element to the procedure you supply.

--
Jeff Carter
"He didn't get that nose from playing ping-pong."
Never Give a Sucker an Even Break
110

Re: strange cursor in nested containers

<9a1c3ba5-d5ae-41d3-9eab-2b8cd941bc66n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:598a:0:b0:3de:b5fa:dbad with SMTP id e10-20020ac8598a000000b003deb5fadbadmr5612340qte.5.1682407838417;
Tue, 25 Apr 2023 00:30:38 -0700 (PDT)
X-Received: by 2002:a25:7396:0:b0:b95:31a3:9d89 with SMTP id
o144-20020a257396000000b00b9531a39d89mr5870878ybc.2.1682407838220; Tue, 25
Apr 2023 00:30:38 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.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: Tue, 25 Apr 2023 00:30:37 -0700 (PDT)
In-Reply-To: <u2199a$3cm0v$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=87.143.122.5; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40
NNTP-Posting-Host: 87.143.122.5
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com> <lyttxak3ag.fsf@pushface.org>
<ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com> <u209li$37hob$1@dont-email.me>
<f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com> <u2199a$3cm0v$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9a1c3ba5-d5ae-41d3-9eab-2b8cd941bc66n@googlegroups.com>
Subject: Re: strange cursor in nested containers
From: mario.blunk.gplus@gmail.com (Mario Blunk)
Injection-Date: Tue, 25 Apr 2023 07:30:38 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2230
 by: Mario Blunk - Tue, 25 Apr 2023 07:30 UTC

> > How could I solve the problem ? Not using "rename" ? Using an aliased access type as John Barnes suggests in Ada2005 on page 275 ?
> You have to avoid calling Element. Since you have a cursor, you can call
> Query_Element, which should pass the actual element to the procedure you supply.

Right, that solves the problem. For those interested please find a comparison here:

1. The demo with a dangling (dangerous) cursor:
https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb

And the demo with the issue solved properly:
https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_2.adb

Still the question remains, why such a dangling cursor is not detected at runtime.

Re: strange cursor in nested containers

<u3cg9c$5ppl$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: randy@rrsoftware.com (Randy Brukardt)
Newsgroups: comp.lang.ada
Subject: Re: strange cursor in nested containers
Date: Mon, 8 May 2023 22:56:30 -0500
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <u3cg9c$5ppl$1@dont-email.me>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com> <6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com> <lyttxak3ag.fsf@pushface.org> <ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com> <u209li$37hob$1@dont-email.me> <f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com> <u2199a$3cm0v$1@dont-email.me> <9a1c3ba5-d5ae-41d3-9eab-2b8cd941bc66n@googlegroups.com>
Injection-Date: Tue, 9 May 2023 03:56:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="36aee6c93b48d52a7a489ecbf0a77bfa";
logging-data="190261"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JSAqt4rW68GgU6mIiQNwwXw1i2Aa8vhw="
Cancel-Lock: sha1:yXdipKPa8+VNFpTK1w9ERBgGNHs=
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246
X-RFC2646: Format=Flowed; Original
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5931
X-Priority: 3
 by: Randy Brukardt - Tue, 9 May 2023 03:56 UTC

It's not required to detect such cursors because it is expensive to do so
perfectly (essentially, each cursor has to be controlled and one has to keep
a list of them associated with the container). There are imperfect solutions
which are likely to be "good enough" in practice, but they still have a
(small) cost which may be an issue for some uses. Thus, most implementers
don't use them. I know the original GNAT containers had a debugging version
that included such checks, but I don't know if they still exist or how one
would enable them if they do.

Randy.

"Mario Blunk" <mario.blunk.gplus@gmail.com> wrote in message
news:9a1c3ba5-d5ae-41d3-9eab-2b8cd941bc66n@googlegroups.com...
>> > How could I solve the problem ? Not using "rename" ? Using an aliased
>> > access type as John Barnes suggests in Ada2005 on page 275 ?
>> You have to avoid calling Element. Since you have a cursor, you can call
>> Query_Element, which should pass the actual element to the procedure you
>> supply.
>
> Right, that solves the problem. For those interested please find a
> comparison here:
>
> 1. The demo with a dangling (dangerous) cursor:
> https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_1.adb
>
> And the demo with the issue solved properly:
> https://github.com/Blunk-electronic/ada_training/blob/master/src/containers/demo/nested/nest_2.adb
>
> Still the question remains, why such a dangling cursor is not detected at
> runtime.

Re: strange cursor in nested containers

<u3d0mh$70f5$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: strange cursor in nested containers
Date: Tue, 9 May 2023 10:36:33 +0200
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <u3d0mh$70f5$1@dont-email.me>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
<lyttxak3ag.fsf@pushface.org>
<ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com>
<u209li$37hob$1@dont-email.me>
<f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com>
<u2199a$3cm0v$1@dont-email.me>
<9a1c3ba5-d5ae-41d3-9eab-2b8cd941bc66n@googlegroups.com>
<u3cg9c$5ppl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 9 May 2023 08:36:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="458747c8624c999a90f84720d28d0279";
logging-data="229861"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BZELEWrY0XZ87vbnRDY7+zHrUc22Uyyw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.10.0
Cancel-Lock: sha1:FNuofo9wT4ohx9bndWjPgcw/3KE=
Content-Language: en-US
In-Reply-To: <u3cg9c$5ppl$1@dont-email.me>
 by: Jeffrey R.Carter - Tue, 9 May 2023 08:36 UTC

On 2023-05-09 05:56, Randy Brukardt wrote:
> It's not required to detect such cursors because it is expensive to do so
> perfectly (essentially, each cursor has to be controlled and one has to keep
> a list of them associated with the container). There are imperfect solutions
> which are likely to be "good enough" in practice, but they still have a
> (small) cost which may be an issue for some uses. Thus, most implementers
> don't use them. I know the original GNAT containers had a debugging version
> that included such checks, but I don't know if they still exist or how one
> would enable them if they do.

This cost is due to the decision to allow access to elements using only a
cursor. If both the container and the cursor are needed, then the cost is
significantly reduced. This is the approach that was used in the Ada-95 version
of the PragmAda Reusable Components.

--
Jeff Carter
“Bug rates in C++ are running higher even than C ...”
Stephen F. Zeigler
216

Re: strange cursor in nested containers

<u3d1fm$6plm$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!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: strange cursor in nested containers
Date: Tue, 9 May 2023 10:49:58 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <u3d1fm$6plm$1@dont-email.me>
References: <a346f13d-9876-488a-9472-4563de130311n@googlegroups.com>
<6aa39f27-62ca-4486-9fc7-1c713da5b098n@googlegroups.com>
<lyttxak3ag.fsf@pushface.org>
<ed311a62-41ba-493e-a4cc-481402a1cc6bn@googlegroups.com>
<u209li$37hob$1@dont-email.me>
<f72b8843-6022-408d-bf90-56be02010b73n@googlegroups.com>
<u2199a$3cm0v$1@dont-email.me>
<9a1c3ba5-d5ae-41d3-9eab-2b8cd941bc66n@googlegroups.com>
<u3cg9c$5ppl$1@dont-email.me> <u3d0mh$70f5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 9 May 2023 08:49:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9530d295f34e89374f23a9ac8234ce5a";
logging-data="222902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/20KE9sgTByuBRYzIS1SzLNVVJQb/PXE0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.10.1
Cancel-Lock: sha1:eb13zXalSVB6va/IADk9/4mr5M4=
Content-Language: en-US
In-Reply-To: <u3d0mh$70f5$1@dont-email.me>
 by: Dmitry A. Kazakov - Tue, 9 May 2023 08:49 UTC

On 2023-05-09 10:36, Jeffrey R.Carter wrote:

> This cost is due to the decision to allow access to elements using only
> a cursor. If both the container and the cursor are needed, then the cost
> is significantly reduced.

That would be in the index/position team rather than in the
cursor/pointer/address one.

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

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor