comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Amount of copying on returned constant objects
Date: Mon, 18 Jun 2007 15:25:33 -0500
Date: 2007-06-18T15:25:33-05:00	[thread overview]
Message-ID: <f56pjg$nlr$1@jacob-sparre.dk> (raw)
In-Reply-To: 4676C27D.2050608@obry.net


"Pascal Obry" <pascal@obry.net> wrote in message
news:4676C27D.2050608@obry.net...
> Or in a more Ada 2005 way:
>
>    function Element
>      (Key : Key_Type) return access constant Element_Type;

The problem with this is that this access can be saved, and any operation on
the original container could make it become dangling (and thus any further
use be erroneous). That is *very* unsafe and virtually impossible to detect.

There were a substantial number of people (a group that includes me) that
want the containers to be safer than using raw access types (because they
can do checks that would be too tedious to do in hand-written code). That's
why the containers access-in-place routines use access-to-subprograms,
because they can have tampering checks that prevent the dangling access
problem (you get Program_Error if you try to do something that could make
the element inaccessible). That makes them much safer than returning a raw
pointer.

We actually spent quite a bit of effort on trying to find a way to secure
access values returned this way. But it isn't quite possible: even if you
make them uncopyable; they still can be held onto long enough to potentially
cause trouble with a renames.

What really would help would be a way for the container to know when the
access was destroyed, but there isn't any obvious way to do that in Ada.

Dmitry might (will?) tell us that a user-defined ".all" operation would do
the trick, but it's not obvious how to define that operation so that the
".all" definition itself would not expose the original problem.

                            Randy.





  parent reply	other threads:[~2007-06-18 20:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-15 16:19 Amount of copying on returned constant objects Alex R. Mosteo
2007-06-15 16:32 ` Ludovic Brenta
2007-06-18 17:26   ` Alex R. Mosteo
2007-06-19 10:22     ` Alex R. Mosteo
2007-06-15 22:03 ` Georg Bauhaus
2007-06-18 17:23   ` Alex R. Mosteo
2007-06-18 17:35     ` Pascal Obry
2007-06-18 18:04       ` Alex R. Mosteo
2007-06-18 20:25       ` Randy Brukardt [this message]
2007-06-19  8:26         ` Dmitry A. Kazakov
2007-06-19 10:24         ` Alex R. Mosteo
2007-06-19 21:33           ` Randy Brukardt
2007-06-20  1:31             ` Markus E Leypold
2007-06-20  6:25               ` Georg Bauhaus
2007-06-20 13:00                 ` Markus E Leypold
2007-06-20  7:34             ` Dmitry A. Kazakov
2007-06-18 18:34     ` Georg Bauhaus
2007-06-16  6:48 ` Dmitry A. Kazakov
2007-06-18 17:14   ` Alex R. Mosteo
replies disabled

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