comp.lang.ada
 help / color / mirror / Atom feed
From: Jere <jhb.chat@gmail.com>
Subject: Ada Alternatives to Unrestricted_Access
Date: Wed, 7 Mar 2018 12:11:01 -0800 (PST)
Date: 2018-03-07T12:11:01-08:00	[thread overview]
Message-ID: <d4363829-f718-48cf-a01d-6986563e632d@googlegroups.com> (raw)

I'm currently updating a generic package that takes a container type
as an input and creates an iterative type around it.  I found quite a
few instances of GNAT's Unrestricted_Access which appear to be
necessary because of the Iterate function's container parameter of
being mode "in" and the iterator needing a non constant access to it
to supply tamper check semantics.  I tried changing the mode to
"in out" but that caused a slew of errors where Iterate was used 
inside other operations that had the Container supplied via "in"
mode parameters.  Changing those other operations doesn't make
sense (and causes other errors later), but I don't like relying
on GNAT's implementation defined attribute if I can help it.

I was able to use System.Address_To_Access_Conversions to 
achieve both compiler happiness and expected runtime execution, but
I am worried this is not legal as it is skirting kind of close
to Address overlays.  In this case the types are identical aside
from one (the Iterate "in" mode parameter) being constant and the
other (the iterators "Container_Access" component) being variable.
However, I am not fully convinced it is (relatively) safe or portable yet.

The gist of the differences being:

   Container_Access => C'Unrestricted_Access

is converted to:

   Container_Access => A2A.To_Pointer(C'Address)

where:
   
   package A2A is new System.Address_To_Access_Conversions(Container);

and the parameter mode of C is defined as:

   function Iterate
            (C : in Container)
             return Iterator_Interfaces.Forward_Iterator'Class;

and the generic formal for Container

   type Container is tagged private;

I'm working with an existing code base, so complete overhaul is 
not a great option.

If it isn't a good idea, are there alternatives?  Since the Container
implementation is unknown in the generic, I wasn't able to get a version
of the Rosen technique to work as an alternative (same constant vs
variable access problem).


             reply	other threads:[~2018-03-07 20:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 20:11 Jere [this message]
2018-03-07 20:38 ` Ada Alternatives to Unrestricted_Access 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
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