comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Allocators and exceptions
Date: Wed, 12 Sep 2007 09:08:18 -0700
Date: 2007-09-12T09:08:18-07:00	[thread overview]
Message-ID: <1189613298.182273.23310@22g2000hsm.googlegroups.com> (raw)
In-Reply-To: <1189599757.106695.147440@57g2000hsv.googlegroups.com>

On Sep 12, 5:22 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
> On 11 Wrz, 23:56, Adam Beneschan <a...@irvine.com> wrote:
>
> > OK, I think I have one.  GNAT compiles and runs it, although I haven't
> > checked the language rules carefully to make sure it's legal.
>
> Without checking the language rules carefully, I think this is a legal
> program demonstrating artificially broken design.
>
> Consider that there is no exception and instead you call
> Unchecked_Deallocation after successfully creating the object.
> The P pointer will be dangling.
>
> So what is your example proving? That we can make dangling pointers in
> Ada? This is already known.

You can create dangling pointers and do all sorts of other bad stuff
by using "Unchecked" features like Unchecked_Deallocation, and other
things like 'Address clauses.  These are documented in the manual, and
it's pointed out that the user needs to know what they're doing or
else the result could be erroneous.  But the language shouldn't be
adding dangerous stuff like that automatically.
Unchecked_Deallocation is called "Unchecked" for a very good reason,
to remind those who use the routine that it could lead to trouble.
But the language can't start doing such unchecked stuff itself
automatically.

Now, I'm aware that I used an Unchecked thing ('Unchecked_Access) in
my example.  So far, I haven't been able to create an example that
doesn't.  But I'd want a *proof* that it's impossible for the
automatic deallocation you're asking for could not create a dangling
pointer in the absence of Unchecked or other dangerous features, and
I'm not yet convinced.  (And your earlier statement that  "the object
simply does not exist" falls several miles short of a proof, and my
example proves that that is wrong anyway, because the object does
exist temporarily.)

But you seem to be suggesting that the language should just do the
"right thing" anyway (i.e. deallocate the object), and if a certain
combination of legal features leads to a disaster like a dangling
pointer, you throw up your hands and blame it on a broken design.
That's the C++ way, not the Ada way.  In Ada, safety is important.  We
try to make sure programs can't cause this sort of problem unless the
user deliberately does something that is known to be dangerous.

By the way, although I think having the language deallocate the object
automatically is a bad idea, I do sympathize with the problem that
it's impossible to get a hold of the access value that was already
allocated so that you can do an Unchecked_Deallocation yourself.  None
of the workarounds seem all that good.  Unfortunately, I can't think
of a good way to add this to the language.

                        -- Adam





  parent reply	other threads:[~2007-09-12 16:08 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-09  7:40 Allocators and exceptions Maciej Sobczak
2007-09-09 12:17 ` anon
2007-09-09 20:31   ` Maciej Sobczak
2007-09-09 22:43     ` Simon Wright
2007-09-10 12:10       ` Maciej Sobczak
2007-09-10 19:08         ` Simon Wright
2007-09-10  2:56     ` anon
2007-09-10 12:42     ` Dmitry A. Kazakov
2007-09-10 21:48       ` Maciej Sobczak
2007-09-11  9:16         ` Dmitry A. Kazakov
2007-09-11  9:19           ` Maciej Sobczak
2007-09-11 12:27             ` Dmitry A. Kazakov
2007-09-11 19:07               ` Maciej Sobczak
2007-09-11 22:56                 ` Georg Bauhaus
2007-09-12 12:36                   ` Maciej Sobczak
2007-09-12 22:19                     ` Randy Brukardt
2007-09-12  9:32                 ` Dmitry A. Kazakov
2007-09-12 12:42                   ` Maciej Sobczak
2007-09-12 15:25                     ` Dmitry A. Kazakov
2007-09-12 12:29             ` Stephen Leake
2007-09-12 12:46               ` Maciej Sobczak
2007-09-12 20:53                 ` Simon Wright
2007-09-12 22:32                   ` Randy Brukardt
2007-09-12 23:43                     ` Simon Wright
2007-09-13  3:42                       ` Randy Brukardt
2007-09-13  3:36                     ` Randy Brukardt
2007-09-13  9:43                     ` Maciej Sobczak
2007-09-12 22:25                 ` Randy Brukardt
2007-09-13 11:51                 ` Stephen Leake
2007-09-12 14:14               ` Markus E L
2007-09-10 10:37 ` Allocators and exceptions => Read Me First anon
2007-09-10 12:16   ` Maciej Sobczak
2007-09-10 22:10     ` Allocators and exceptions => Trying Again anon
2007-09-10 23:15       ` Markus E L
2007-09-10 15:44 ` Allocators and exceptions Adam Beneschan
2007-09-10 21:58   ` Maciej Sobczak
2007-09-10 22:07   ` Jeffrey R. Carter
2007-09-11  9:14   ` Dmitry A. Kazakov
2007-09-11  9:23     ` Maciej Sobczak
2007-09-11  2:36 ` Randy Brukardt
2007-09-11 15:33   ` Adam Beneschan
2007-09-11 19:21     ` Maciej Sobczak
2007-09-11 21:56     ` Adam Beneschan
2007-09-12  0:34       ` Jeffrey R. Carter
2007-09-12 12:13         ` Maciej Sobczak
2007-09-12 16:34           ` Jeffrey R. Carter
2007-09-12 23:50             ` Jeffrey R. Carter
2007-09-12 12:22       ` Maciej Sobczak
2007-09-12 14:11         ` Markus E L
2007-09-12 16:08         ` Adam Beneschan [this message]
2007-09-12 20:35           ` Dmitry A. Kazakov
2007-09-12 21:01             ` Adam Beneschan
2007-09-12 22:45             ` Randy Brukardt
2007-09-13  7:48               ` Dmitry A. Kazakov
2007-09-12  3:08 ` Allocators and exceptions -- Debugging says memory leak! anon
replies disabled

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