comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Re: Ada Alternatives to Unrestricted_Access
Date: Sun, 11 Mar 2018 12:53:42 -0700 (PDT)
Date: 2018-03-11T12:53:42-07:00	[thread overview]
Message-ID: <cbefecf5-5178-43c6-8544-51b9b64f56bc@googlegroups.com> (raw)
In-Reply-To: <p83riu$a6a$1@dont-email.me>

On Sunday, March 11, 2018 at 2:12:48 PM UTC-4, Jeffrey R. Carter wrote:
> On 03/11/2018 06:33 PM, Jere wrote:
> > 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.
> 
> So you want to bypass one kind of check in order to have another? Is it possible 
> to tamper with a constant container?
> 
From a naive view where the client doesn't know the implementation of the
container, a client would expect to be able to do:

procedure Debug_Print(C : Container) is
begin
   for E of C loop
      Ada.Text_IO.Put_Line(Element'Image(E));
   end loop;
end Debug_Print;

Which is not possible with Default_Iterator that has mode "in out"
You get the earlier mentioned compiler error.  Note that here, no 
tamper check is needed and we are merely accessing a constant view 
of the container in a constant fashion (forgive the wrong terminology,
I don't know the right terminology here).

However, additionally, one might want to protect the client from this
situation:

procedure Nefarious(C : in out Container) is
begin
   for E of C loop
      if E = Some_Value then
         <do some stuff>
         C.Delete(E);  -- tamper check!
   end loop;
end Nefarious;

Here, someone is trying to delete an element during
iteration, which should be saved by tamper checks.

For reference, the Ada standard containers fulfill both of those 
scenarios.  The original dev team of this code base appears to
be mimicking the same methodology.

As a note, I'm not particularly thrilled about bypassing any checks.
The existing code already does it, and the request is to limit changes
to avoid large code overhauls.

> I presume this code was written for an earlier version of the language, and now 
> you want to bolt on this neat new feature of Ada 12. It seems its design and 
> implementation are not compatible with user-defined iteration. 

It's all pre-existing code.  I don't want to add anything.  The 
iteration was already there.  The owner asked to see if I could 
get rid of some GNAT specific extensions easily.
One was the use of Unrestricted_Access, which led me to the original
question.  They didn't want a major overhaul of the code.


  reply	other threads:[~2018-03-11 19:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 20:11 Ada Alternatives to Unrestricted_Access Jere
2018-03-07 20:38 ` Dmitry A. Kazakov
2018-03-07 22:29   ` Jere
2018-03-08  8:27     ` Dmitry A. Kazakov
2018-03-09  0:43       ` Jere
2018-03-09  0:52         ` Jere
2018-03-09  8:28           ` Dmitry A. Kazakov
2018-03-11  0:31             ` Jere
2018-03-08  3:18 ` gautier_niouzes
2018-03-09  0:41   ` Jere
2018-03-08 17:51 ` Jeffrey R. Carter
2018-03-09  0:36   ` Jere
2018-03-09 16:46     ` Jeffrey R. Carter
2018-03-11  0:38       ` Jere
2018-03-11  9:57         ` Jeffrey R. Carter
2018-03-11 10:44           ` Dmitry A. Kazakov
2018-03-11 14:31           ` Jere
2018-03-11 15:49             ` Jeffrey R. Carter
2018-03-11 17:33               ` Jere
2018-03-11 18:12                 ` Jeffrey R. Carter
2018-03-11 19:53                   ` Jere [this message]
2018-03-12 16:28                     ` Jeffrey R. Carter
2018-03-11 18:27                 ` Niklas Holsti
2018-03-11 20:07                   ` Jere
2018-03-12 23:35                     ` Randy Brukardt
2018-03-12 23:30         ` Randy Brukardt
2018-03-13  7:46           ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox