comp.lang.ada
 help / color / mirror / Atom feed
From: Damien Carbonne <damien.carbonne@free.fr>
Subject: Re: Issue with GNAT GPL 2009 and GtkAda
Date: Thu, 25 Jun 2009 21:02:38 +0200
Date: 2009-06-25T21:02:39+02:00	[thread overview]
Message-ID: <4a43c9ce$0$420$426a74cc@news.free.fr> (raw)
In-Reply-To: <1avd65rn49abv$.krcxo2gdzb16$.dlg@40tude.net>

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.

Here it is:

--------------------------------------------------------------------------
package Bug is

    -- Base interface
    type Listener is interface;
    type Listener_Ref is access all Listener'Class;
    procedure Process (L : in out Listener) is abstract;

    -- Base class
    type Base is tagged null record;
    type Base_Ref is access all Base'Class;
    procedure Foreach (B : access Base; I : Integer);

    -- Derived class
    type Derived is new Base and Listener with null record;
    type Derived_Ref is access all Derived'Class;
    overriding procedure Process (D : in out Derived);

    procedure Main;

end Bug;
--------------------------------------------------------------------------
with Ada.Text_IO;
package body Bug is

    procedure Foreach (B : access Base; I : Integer) is
       BB : Base_Ref;
    begin
       Ada.Text_IO.Put_Line ("Foreach" & Integer'Image (I));
       BB := B.all'Access; -- Line that fails
    end Foreach;

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

    procedure Main is
       G_Derived : constant Derived_Ref := new Derived;
       G_Listener : constant Listener_Ref := Listener_Ref (G_Derived);
    begin
       Ada.Text_IO.Put_Line ("Main");
       G_Derived.Foreach (1);  -- This one works
       G_Listener.Process; -- This one fails
    end Main;

end Bug;
--------------------------------------------------------------------------
with Bug;
procedure Main is
begin
    Bug.Main;
end Main;
-- Tested with GNAT GPL 2009 on Linux
--
-- Main
-- Foreach 1
-- Process
-- Foreach 2
--
-- raised PROGRAM_ERROR : bug.adb:8 accessibility check failed
--------------------------------------------------------------------------

The workaround is obviously to replace the 'Access with 'Unchecked_Access.
In such case, I don't modify Gtkda iteself but create a special package 
that contains a corrected version of the function. In that case, the 
function is no more a primitive one, but it does not really matter.

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.
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.

Thanks again.

Damien Carbonne



Dmitry A. Kazakov a �crit :
> On Thu, 25 Jun 2009 05:06:08 -0400, Stephen Leake wrote:
> 
>> Another thought: whenever I have trouble with anonymous access types,
>> I replace them with the corresponding named access type, and the
>> problem goes away. That may indicate a conmpiler bug, but I've always
>> had to much to do to find out.
> 
> Yes, but that is not necessarily a compiler bug. It is quite simple to
> create a serious problem to oneself:
> 
> declare
>    Ptr : access T := new T;
> begin
>    ...
>    External_Ptr := Ptr.all'Uchecked_Access; -- Copy the pointer
>    ...
> end;  -- Now External_Ptr is dangling, because the object is freed.
> 



  reply	other threads:[~2009-06-25 19:02 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 [this message]
2009-06-26  9:31         ` Stephen Leake
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