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!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!elnk-atl-nf1!newsfeed.earthlink.net!stamper.news.atl.earthlink.net!newsread1.news.atl.earthlink.net.POSTED!14bb18d8!not-for-mail Sender: mheaney@MHEANEYX200 Newsgroups: comp.lang.ada Subject: Re: GCC 4.0 Ada.Containers Cursor danger. References: <1120474891.635131.216700@g44g2000cwa.googlegroups.com> <1120575076.876798.108220@g44g2000cwa.googlegroups.com> <1120583470.429264.325450@g43g2000cwa.googlegroups.com> <42cb8d21$0$22761$9b4e6d93@newsread2.arcor-online.net> <1120740766.343393.168420@g14g2000cwa.googlegroups.com> <1120789712.389559.11090@g49g2000cwa.googlegroups.com> From: Matthew Heaney Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 09 Jul 2005 14:20:50 GMT NNTP-Posting-Host: 24.149.57.125 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.atl.earthlink.net 1120918850 24.149.57.125 (Sat, 09 Jul 2005 07:20:50 PDT) NNTP-Posting-Date: Sat, 09 Jul 2005 07:20:50 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: g2news1.google.com comp.lang.ada:11974 Date: 2005-07-09T14:20:50+00:00 List-Id: "Dmitriy Anisimkov" writes: > Me, not. 99.9 would be enought. If you sure thar cursors would be > checked in the coming Ada 200X, i'm quiet. I'm working on the lists right now, so I modified your original example as follows: procedure Test_Dangling is package Integer_Lists is new Ada.Containers.Doubly_Linked_Lists (Integer); use Integer_Lists; L : List; C, C2 : Cursor; begin L.Append (1); L.Insert (No_Element, 2, C); L.Append (3); C2 := L.Find (2); L.Delete (C2); Replace_Element (C, By => -2); -- dangling reference end; I added some logic to detect dangling cursors, and when I run the program above I get this output: raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : bad cursor in Replace_Element The extra check is inside a pragma Assert, so you can choose to enable it or not. To make this work, I set the Next and Prev pointers of the internal storage node to point to the node itself, just before the node is deallocated. In the GCC implementation, a linked list node never points to itself, so I know that if a node pointer of a node has the node as its value, then something must be wrong. For the indefinite list, the element is designated by a pointer, which can never be null. When a node is deallocated, I set the element pointer to null (that's sort of true anyway, since I must also deallocate the element), and then check for a null element pointer during cursor manipulation. -Matt