Re: GCC 4.0 Ada.Containers Cursor danger.
- From: "Matthew Heaney" <mheaney@xxxxxxx>
- Date: 5 Jul 2005 07:51:17 -0700
Dmitriy Anisimkov wrote:
> begin
> Table.Insert (Container, "one", 11111, Cursor, Success);
> pragma Assert (Success);
> Table.Insert (Container, "two", 22222, Cursor, Success);
> pragma Assert (Success);
> Table.Insert (Container, "three", 33333, Cursor, Success);
> pragma Assert (Success);
You don't need conditional insertion here. Just use the 3-param
Insert:
Container.Insert ("one", 1);
Container.Insert ("two", 2);
Container.Insert ("three", 3);
> Table.Insert (Container, "two", 2222, Cursor, Success);
> pragma Assert (not Success);
>
> -- Delete element "two" independently.
>
> Cursor2 := Table.Find (Container, "two");
> Table.Delete (Container, Cursor2);
>
> -- The erroreneous line below do nothing and do not raise any
> exception.
>
> Table.Replace_Element (Cursor, -22222);
Well of course this is erroneous, since the element designated by
Cursor was deleted in the previous statement!
> ------------------------------------------------------------
> The code above have to raise at least runtime error at
> Table.Replace_Element (Cursor, -22222); but it do nothing and do not
> raise any exception.
It certainly does not have to raise a runtime error. It can do
anything it likes, since the behavior is undefined.
> valgrind showing the memory corruption
That's good, since what you did corrupts the memory.
> ADT do not have a cursors at all. All get/put operations from container
> is just per key. All iterations via the containers are with simple
> generic procedures.
This is like saying, Tall buildings shouldn't have windows, since if
there's a window, you might jump out of the window and hurt yourself.
The solution is simple: don't jump out of windows...
> I'm not sure that it is possible to implement runtime error detection
> in such cursor situation.
It's software, we can doing anything we want. So of course you can
detect dangling cursors -- but not without a runtime penalty (in both
time and space).
> I think that ADT is much more on the Ada way then proposed
> Ada.Containers with cursors.
If you don't like cursors, then don't use 'em. Certainly with a map,
you never need to use cursors.
.
- Follow-Ups:
- Re: GCC 4.0 Ada.Containers Cursor danger.
- From: Dmitriy Anisimkov
- Re: GCC 4.0 Ada.Containers Cursor danger.
- References:
- GCC 4.0 Ada.Containers Cursor danger.
- From: Dmitriy Anisimkov
- GCC 4.0 Ada.Containers Cursor danger.
- Prev by Date: Re: Free e-book discussing the C Standard
- Next by Date: Re: GCC 4.0 Ada.Containers Cursor danger.
- Previous by thread: Re: GCC 4.0 Ada.Containers Cursor danger.
- Next by thread: Re: GCC 4.0 Ada.Containers Cursor danger.
- Index(es):