From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: accessibility check failed
Date: Mon, 30 Nov 2015 17:22:47 -0600
Date: 2015-11-30T17:22:47-06:00 [thread overview]
Message-ID: <n3ilo8$hvg$1@loke.gir.dk> (raw)
In-Reply-To: 29d3244c-1769-4cb7-8af3-e1b20eb2e1e2@googlegroups.com
"Serge Robyns" <serge.robyns@gmail.com> wrote in message
news:29d3244c-1769-4cb7-8af3-e1b20eb2e1e2@googlegroups.com...
...
>In my case I'm trying to build an interface to hide implementation details.
>The
>code provided is using containers as a store but should also be able to use
>any
>kind of (R)DBMS for all or part of the data. And hence this is where the
>beauty of OO comes but does indeed require to use access type to "keep"
>track of things.
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.
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.)
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).
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.
Randy.
next prev parent reply other threads:[~2015-11-30 23:22 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 [this message]
2015-12-01 9:38 ` Serge Robyns
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