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 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-7-bit Path: g2news2.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Issue with GNAT GPL 2009 and GtkAda References: <4A414EBB.8060204@free.fr> <1avd65rn49abv$.krcxo2gdzb16$.dlg@40tude.net> <4a43c9ce$0$420$426a74cc@news.free.fr> From: Stephen Leake Date: Fri, 26 Jun 2009 05:31:01 -0400 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (windows-nt) Cancel-Lock: sha1:/GP6PBxeKqbDlRdNnmEK6Bs8wLk= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 1063f4a44953be9cadf9d14469 Xref: g2news2.google.com comp.lang.ada:6634 Date: 2009-06-26T05:31:01-04:00 List-Id: Damien Carbonne 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