comp.lang.ada
 help / color / mirror / Atom feed
* Bad cursor, good cursor
@ 2017-03-27 16:56 Marius Amado-Alves
  2017-03-27 18:12 ` G.B.
  0 siblings, 1 reply; 4+ messages in thread
From: Marius Amado-Alves @ 2017-03-27 16:56 UTC (permalink / raw)


Ada 2012 compiled with latest(?) free GNAT (20160515-19)

This breaks with a "bad cursor" error for Subthing_Maps.Element at line 7. But how can that be, if the cursor has just been vetted at line 6 as not No_Element, and there were no changes to the container meanwhile, not even navigation?

1   C := Thing.Find (Thing_ID);
2   if C = Thing_Maps.No_Element then
3      Thing.Insert (Thing_ID, Subthing_Maps.Empty_Map, C, Ok);
4   end if;
5   I := Subthing_Maps.Find (Thing_Maps.Element (C), Subthing_ID);
6   if I = Subthing_Maps.No_Element
7   or else Subthing_Maps.Element (I) = Preterred then
8      Thing.Update_Element (C, Add_Subthing'Access);
9   end if;

(Thing is a map of Subthing_Maps. C, I are cursors of these containers, respectively. The keys are Unbounded_String. The maps are Ordered_Maps.)

What might I be missing, language-wise? Or might it be a GNAT bug? Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bad cursor, good cursor
  2017-03-27 16:56 Bad cursor, good cursor Marius Amado-Alves
@ 2017-03-27 18:12 ` G.B.
  2017-03-27 18:35   ` Marius Amado-Alves
  0 siblings, 1 reply; 4+ messages in thread
From: G.B. @ 2017-03-27 18:12 UTC (permalink / raw)


On 27/03/2017 18:56, Marius Amado-Alves wrote:
> Ada 2012 compiled with latest(?) free GNAT (20160515-19)
>
> This breaks with a "bad cursor" error for Subthing_Maps.Element at line 7. But how can that be, if the cursor has just been vetted at line 6 as not No_Element, and there were no changes to the container meanwhile, not even navigation?
>
> 1   C := Thing.Find (Thing_ID);
> 2   if C = Thing_Maps.No_Element then
> 3      Thing.Insert (Thing_ID, Subthing_Maps.Empty_Map, C, Ok);
> 4   end if;
> 5   I := Subthing_Maps.Find (Thing_Maps.Element (C), Subthing_ID);
> 6   if I = Subthing_Maps.No_Element
> 7   or else Subthing_Maps.Element (I) = Preterred then
> 8      Thing.Update_Element (C, Add_Subthing'Access);
> 9   end if;

Are Thing_Maps and Thing different?  Thing.Insert involves C,
which is then passed to Thing_Maps.Element.
Just an observation, even though it isn't obviously connected
with  I.

Is there overlap in some form or other, of things involved?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bad cursor, good cursor
  2017-03-27 18:12 ` G.B.
@ 2017-03-27 18:35   ` Marius Amado-Alves
  2017-03-27 22:26     ` Randy Brukardt
  0 siblings, 1 reply; 4+ messages in thread
From: Marius Amado-Alves @ 2017-03-27 18:35 UTC (permalink / raw)


Thanks. Thing_Maps is the package (instance of Ordered_Maps), Thing a container (Map). Similarly for Subthing.

Dont know about "overlapping", but there is a nesting of sorts as elements of Thing are themselves Maps.

I seem to remember having problems in the past with nested containers i.e. containers of containers... The Ada idioms for this are a bit convoluted... but should work, no?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Bad cursor, good cursor
  2017-03-27 18:35   ` Marius Amado-Alves
@ 2017-03-27 22:26     ` Randy Brukardt
  0 siblings, 0 replies; 4+ messages in thread
From: Randy Brukardt @ 2017-03-27 22:26 UTC (permalink / raw)


"Marius Amado-Alves" <amado.alves@gmail.com> wrote in message 
news:db7bb891-5640-40bb-9c1d-d0970cb6555e@googlegroups.com...
> Thanks. Thing_Maps is the package (instance of Ordered_Maps), Thing a 
> container (Map). Similarly for Subthing.
>
> Dont know about "overlapping", but there is a nesting of sorts as elements 
> of Thing are themselves Maps.
>
> I seem to remember having problems in the past with nested containers i.e. 
> containers of containers...
> The Ada idioms for this are a bit convoluted... but should work, no?

Should work, yes. :-)

Your original problem looks like a bug in the containers implementation to 
me, as it doesn't make any sense (as you say, it should either be null or a 
good cursor, and nothing has happened that should be able to change it).

                                     Randy.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-27 22:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-27 16:56 Bad cursor, good cursor Marius Amado-Alves
2017-03-27 18:12 ` G.B.
2017-03-27 18:35   ` Marius Amado-Alves
2017-03-27 22:26     ` Randy Brukardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox