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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7350da5176edec2c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-25 19:14:04 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!newspeer1-gui.server.ntli.net!ntli.net!newsfep2-win.server.ntli.net.POSTED!53ab2750!not-for-mail From: "chris.danx" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1b) Gecko/20020721 X-Accept-Language: en-gb, en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: In a pickle. References: <3D3F0E27.9080303@worldnet.att.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 25 Jul 2002 16:49:06 +0100 NNTP-Posting-Host: 80.5.140.234 X-Complaints-To: abuse@ntlworld.com X-Trace: newsfep2-win.server.ntli.net 1027612182 80.5.140.234 (Thu, 25 Jul 2002 16:49:42 BST) NNTP-Posting-Date: Thu, 25 Jul 2002 16:49:42 BST Organization: ntl Cablemodem News Service Xref: archiver1.google.com comp.lang.ada:27413 Date: 2002-07-25T16:49:06+01:00 List-Id: Jim Rogers wrote: > chris.danx wrote: > >> Hi, >> >> Is there a resolution to the following problem that allows convienant >> assignment of iterators? An iterator points to a node in a list, like >> this >> >> -- Bi-Directional Iterator definition for positions within >> -- objects of List_Type. >> -- >> type Iterator_Type is new Ada.Finalization.Controlled >> with record >> List : List_Base_Access; >> Position : Node_Access; >> end record; >> >> While more than one iterator points to a node it cannot be >> deallocated, with >> the number of iterators pointing to the node, recorded in the node >> itself. >> The problem is assignment! If we do >> >> Iterator := Next (Iterator); >> >> The iterator is assigned to the next position, but the count of iterators >> isn't decremented so the node always thinks an iterator is on it. >> >> I've just noticed something in Cohen that may help but am not sure if my >> interpretation is correct. >> >> At the top of page 573 he says "The target variable in an assignment >> statement is finalized just before a new value is about to be copied >> to that >> variable". >> >> Does this mean that in the above assignment Iterator is finalized >> after Next >> (Iterator) is evaluated but before the assignment takes place? That >> would >> mean that a suitably coded finalize would do the job, correct? > > > > That is my understanding of how assignment works. > > Jim Rogers ARGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!!!!!!!!!!! Managing all the finalisation calls is a nightmare! raised PROGRAM_ERROR : aqua-lists-linear-unbounded-doubly.adb:56 caused by finalization of an iterator in a call in a subprogram. I reckon I know how to fix it, but it will require each iterator modifing subprogram setting a flag, while basic query ops clear it. Finalization will check the flag and if it's cleared do nothing, otherwise adjust the iterator. Think that's ugly? Anyone think of a better way?