comp.lang.ada
 help / color / mirror / Atom feed
From: Serge Robyns <serge.robyns@gmail.com>
Subject: Re: accessibility check failed
Date: Tue, 1 Dec 2015 01:38:52 -0800 (PST)
Date: 2015-12-01T01:38:52-08:00	[thread overview]
Message-ID: <925a7e3b-1234-4572-befb-4fa60667f8c3@googlegroups.com> (raw)
In-Reply-To: <n3ilo8$hvg$1@loke.gir.dk>

On Tuesday, 1 December 2015 00:22:50 UTC+1, Randy Brukardt  wrote:
> You rarely need explicit access types in an Ada interface, as "in out T" and 
> "access T" are essentially the same for any tagged type T. Ada always allows 
> taking 'Access (or 'Unchecked_Access) of a tagged type parameter.

Initially I was using in/out and then I wanted to uni-formalize the interface because I need to take the access somewhere.  Now I'm rewriting it as per some previous suggestion without requiring to store the access parameter.

The only thing I do now wished it would be possible is to use multiple inheritance when merging all DOA class implementing their respective interfaces (in plural).


type abstract_interface is new limited interface and I1 and I2 and ....;
-- Below is not Ada
type concrete is new abstract_interface with I1_Impl and I2_Impl and ...;

Now I'm using mixin's but this require to write all overrides to call their respective implementations.
type concrete is new abstract_interface with record
I1 : T_I1_Impl;
I2 : T_I2_Impl;
....
end record;

> Claw ("Class Library for Ada and Windows", see rrsoftware.com) uses almost 
> no access types in its public interface, yet almost everything is 
> referential under the covers. Works fine, and puts all of the pain on the 
> implementor of the library (where it belongs) and not on the clients (like 
> access types do). (The one place where we had to use an access type was in a 
> single function return where return-by-copy didn't have the proper effect. 
> That's pretty rare.)

I'll attempt to build my interface the same way.
However I need to be able to change the returned object and have it reflected in the store.

> To answer your original question, once you use anonymous access types, all 
> accessibility checks become dynamic. That is, the accessibility of the 
> actual object is checked, no matter how many levels it's passed through. 
> Most likely, someone is operating on a local object and made a call on the 
> routine that's failing. Bob Duff calls that a "tripping hazard", and it 
> means that you can never reliably save anonymous access parameters outside 
> of the original subprogram (you can do it in the subprogram with a local 
> anonymous access object -- a hack on top of a hack, IMHO).

Now I do understand better why I found references on the web suggesting using named access types instead of anonymous. 

I've given the ARM section 3.10.2 a read to understand better this whole thing.  All I can say is that it isn't certainly not late evening lecture.  And I my case, I'm using a return and a qualified expression in one statement, for which I found a lot of "rules".

> In Ada 2012, you can "protect" an anonymous access with a precondition using 
> a membership test (but warning: these aren't tested in the ACATS and I don't 
> know if anyone has implemented them correctly). Something like:
> 
>     type Global_Access is access all Object;
> 
>     function Something (Acc : access Object; ...) return ...
>         with Pre => Acc in Global_Access;
> 
> In this case, if the object designated by Acc isn't defined globally, the 
> precondition will fail, so you can safely assign Acc to an object of 
> Global_Access in the body of Something. But, of course, that exposes part of 
> your implementation in the precondition, so it's not clear that's a good 
> thing.

Thanks.

Serge


  reply	other threads:[~2015-12-01  9:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-29 18:03 accessibility check failed Serge Robyns
2015-11-29 18:37 ` Jeffrey R. Carter
2015-11-29 19:00   ` Serge Robyns
2015-11-29 22:32     ` Jeffrey R. Carter
2015-11-29 22:53       ` Serge Robyns
2015-11-30  2:04         ` Jeffrey R. Carter
2015-11-30 23:22         ` Randy Brukardt
2015-12-01  9:38           ` Serge Robyns [this message]
2015-11-29 19:15 ` Dmitry A. Kazakov
2015-11-29 22:40 ` Serge Robyns
2015-12-01 20:17 ` sbelmont700
  -- strict thread matches above, loose matches on Subject: below --
2014-08-11  2:12 Accessibility " hreba
2014-08-11  5:32 ` Jeffrey Carter
2014-08-11 16:45   ` hreba
2014-08-11 16:55     ` Jeffrey Carter
2014-08-12 11:57       ` hreba
2014-08-11 19:56 ` sbelmont700
2014-08-11 20:17   ` Jeffrey Carter
2014-08-11 20:28     ` sbelmont700
2014-08-11 21:14       ` Jeffrey Carter
replies disabled

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