From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,65b902127ca8a604 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news4.google.com!feeder.news-service.com!de-l.enfer-du-nord.net!usenet-fr.net!proxad.net!feeder1-2.proxad.net!212.27.60.64.MISMATCH!cleanfeed3-b.proxad.net!nnrp9-1.free.fr!not-for-mail Date: Thu, 25 Jun 2009 21:02:38 +0200 From: Damien Carbonne User-Agent: Thunderbird 2.0.0.22 (X11/20090605) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Issue with GNAT GPL 2009 and GtkAda References: <4A414EBB.8060204@free.fr> <1avd65rn49abv$.krcxo2gdzb16$.dlg@40tude.net> In-Reply-To: <1avd65rn49abv$.krcxo2gdzb16$.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <4a43c9ce$0$420$426a74cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 25 Jun 2009 21:02:39 MEST NNTP-Posting-Host: 82.247.219.63 X-Trace: 1245956559 news-1.free.fr 420 82.247.219.63:41895 X-Complaints-To: abuse@proxad.net Xref: g2news2.google.com comp.lang.ada:6618 Date: 2009-06-25T21:02:39+02:00 List-Id: 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. >