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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.190.66 with SMTP id o63mr3243306iof.65.1520789593747; Sun, 11 Mar 2018 10:33:13 -0700 (PDT) X-Received: by 10.157.4.22 with SMTP id 22mr301784otc.2.1520789593544; Sun, 11 Mar 2018 10:33:13 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!r195no1000974itc.0!news-out.google.com!a25ni2528itj.0!nntp.google.com!r195no1000971itc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 11 Mar 2018 10:33:13 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.71.218.250; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 173.71.218.250 References: <4ab69a18-5766-446c-85c2-14e094199c95@googlegroups.com> <6792fcd7-a25a-417c-b45a-1a17b0168234@googlegroups.com> <5c448ce7-5646-45c5-b221-3d9c884c4d52@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Ada Alternatives to Unrestricted_Access From: Jere Injection-Date: Sun, 11 Mar 2018 17:33:13 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 3945 X-Received-Body-CRC: 1418241573 Xref: reader02.eternal-september.org comp.lang.ada:50929 Date: 2018-03-11T10:33:13-07:00 List-Id: On Sunday, March 11, 2018 at 11:49:28 AM UTC-4, Jeffrey R. Carter wrote: > On 03/11/2018 03:31 PM, Jere wrote: > >> > > It's iterator related. In order to iterate through a container in all > > contexts, the Default_Iterator function needs a parameter of mode "in". > > In order to leverage the anti tamper functionality, the iterator needs > > a non constant access to the container to be supplied when building > > the iterator inside the Default_Iterator function (so it can modify > > the tamper state of the container). The GNAT body for the Vectors > > package has an example (I think it is a-convec.adb, just search for > > "function iterate" and look for the one that returns an iterator). > > I doubt the intention of user-defined iteration was to require people to bypass > the language checks, so I conclude that it's intended for the container > parameter of the Default_Iterator function to have mode "in out". The definition > of Default_Iterator doesn't restrict the parameter mode of the container > parameter in any way, so "in out" should be accepted. > > Presumably the Iterator functions for the standard containers have mode "in" for > the containers because their bodies don't need to be portable and can use > compiler-specific tricks, similar to the Generator parameter of the > random-number functions from an earlier version of the language. > > Or else user-defined iteration seems broken. The problem I run into with this provided code base, is that it often iterates over a constant view of the container. In those cases, Default_Iterator cannot have a mode of "in out" as you just get the error "variable container expected" If you refer back to my original question, I mentioned that I tried doing this and got a slew of errors (like the one mentioned above). I don't have permission to completely rewrite things. That's why I was trying to tackle it from the Unrestricted_Access calls. Changing those to Access_To_Address_Conversions implementations worked. I just wasn't sure it was kosher in portable Ada was all (hence my original question). It's kind of an odd place to be. You want the tamper checks to ensure container safety/correctness, which potentially requires Default_Iterator to have mode "in out" but you also don't want to restrict the Container to only be used in mutable situations. If you want to use a container in non mutable situations, you need Default_Iterator to have mode "in". Without tamper checks, everything can be mode "in" and happy.