From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f2690a5e963b61b6 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g44g2000cwa.googlegroups.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: GCC 4.0 Ada.Containers Cursor danger. Date: 5 Jul 2005 07:51:17 -0700 Organization: http://groups.google.com Message-ID: <1120575076.876798.108220@g44g2000cwa.googlegroups.com> References: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> NNTP-Posting-Host: 66.162.65.162 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1120575082 9683 127.0.0.1 (5 Jul 2005 14:51:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 5 Jul 2005 14:51:22 +0000 (UTC) In-Reply-To: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: g44g2000cwa.googlegroups.com; posting-host=66.162.65.162; posting-account=Zl1UPAwAAADEsUSm1PMMiDjihtBlZUi_ Xref: g2news1.google.com comp.lang.ada:11865 Date: 2005-07-05T07:51:17-07:00 List-Id: 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.