comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Issue with GNAT GPL 2009 and GtkAda
Date: Fri, 26 Jun 2009 05:31:01 -0400
Date: 2009-06-26T05:31:01-04:00	[thread overview]
Message-ID: <u1vp7l4tm.fsf@stephe-leake.org> (raw)
In-Reply-To: 4a43c9ce$0$420$426a74cc@news.free.fr

Damien Carbonne <damien.carbonne@free.fr> writes:

> Thanks to both of you for your answers.
>
> I managed to create a much simpler example (that does not depend on
> GtkAda) that exhibits the same kind of problem. It also shows that
> depending on the way the Foreach is called, the exception is raised or
> not. Disappointing.

The problem is clear here.

"D : in out Derived" is allowed to create a copy of the actual
parameter. Thus the 'Access in Foreach could be on a stack copy of D,
which will disappear eventually, leaving a dangling pointer in BB. So
the accessibility error is correct.

If you replace "in out" in Process with "access":

   procedure Process (L : access Listener) is abstract;

it works fine (with GNAT 6.2.1 on Windows).


Your original program had the same issue; I just missed it.

> I find usage of 'Access quite annoying, because I never really know
> when there is an exception whether it is becauise my code is incorrect
> or because the compiler is incorrect.

It is frustrating. 

It would be nice if the runtime error had some more info; in this case
"taking 'Access of a stack copy due to 'in out'" would be nice :).

Part of the problem is the implicit conversion from object to access
in Process:

   procedure Process (D : in out Derived) is
   begin
      Ada.Text_IO.Put_Line ("Process");
      D.Foreach (2);
   end Process;

The call to Foreach is effectively:

    Foreach (D'access, 2);

If you had written it that way, it would have been clearer what was
happening.

The moral here: if the body of the program needs an access value, pass
in an access value!

My code almost never uses 'Access, because it's better to create the
object via an allocator in the first place, and pass around access
values instead.

Thanks for this puzzle; it has helped me realize exactly why I do
this!

> The last simple example I wrote seems to indicate that GNAT has a
> bug, but I'm not an Ada expert ! If you also consider that there is
> a GNAT bug, I'll submit a bug to AdaCore.

I now think this is not a compiler bug.

-- 
-- Stephe



  reply	other threads:[~2009-06-26  9:31 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-23 21:52 Issue with GNAT GPL 2009 and GtkAda Damien Carbonne
2009-06-24  7:40 ` Dmitry A. Kazakov
2009-06-24 10:15 ` Stephen Leake
2009-06-25  9:06   ` Stephen Leake
2009-06-25  9:39     ` Dmitry A. Kazakov
2009-06-25 19:02       ` Damien Carbonne
2009-06-26  9:31         ` Stephen Leake [this message]
2009-06-26 11:18           ` Niklas Holsti
2009-06-26 16:29             ` Damien Carbonne
2009-06-26 17:28               ` Dmitry A. Kazakov
2009-06-26 19:27                 ` Damien Carbonne
2009-06-26 19:50                   ` Dmitry A. Kazakov
2009-06-26 21:51             ` Randy Brukardt
2009-06-27 11:11               ` Stephen Leake
2009-06-27 17:04                 ` Robert A Duff
2009-06-30 11:11                   ` Stephen Leake
2009-06-30 18:10                     ` Robert A Duff
2009-06-29 22:11                 ` Randy Brukardt
2009-06-30 11:13                   ` Stephen Leake
2009-06-30 15:26                     ` Adam Beneschan
2009-06-30 15:59               ` Adam Beneschan
2009-06-30 23:11                 ` Randy Brukardt
2009-06-27  9:56             ` Stephen Leake
2009-06-26 21:03           ` Damien Carbonne
2009-06-27 11:21             ` Stephen Leake
2009-06-27 12:25               ` Damien Carbonne
2009-06-27 12:35                 ` Damien Carbonne
2009-06-29 22:15                   ` Randy Brukardt
2009-07-01 19:22                     ` Damien Carbonne
2009-06-30  0:48             ` Adam Beneschan
2009-06-30 11:18               ` Stephen Leake
2009-06-25 20:49       ` Randy Brukardt
2009-06-26  7:20         ` Dmitry A. Kazakov
2009-06-26  8:17           ` Georg Bauhaus
2009-06-26  8:52             ` Dmitry A. Kazakov
2009-06-26 21:38               ` Randy Brukardt
2009-06-27  7:47                 ` Dmitry A. Kazakov
2009-06-29 21:59                   ` Randy Brukardt
2009-06-30  8:31                     ` Dmitry A. Kazakov
2009-06-26 21:31           ` Randy Brukardt
2009-06-27  7:53             ` Dmitry A. Kazakov
2009-06-26  8:39       ` Alex R. Mosteo
2009-06-26  9:07         ` Dmitry A. Kazakov
2009-06-27  9:53           ` Stephen Leake
2009-06-26 21:40         ` Randy Brukardt
2009-06-29 10:04           ` Alex R. Mosteo
2009-06-26  9:02       ` Stephen Leake
2009-06-26  9:14         ` Dmitry A. Kazakov
replies disabled

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