comp.lang.ada
 help / color / mirror / Atom feed
* I do not understand this error...
@ 2016-02-06 22:55 John Smith
  2016-02-06 23:47 ` Jeffrey R. Carter
  0 siblings, 1 reply; 15+ messages in thread
From: John Smith @ 2016-02-06 22:55 UTC (permalink / raw)


Here is my code:
http://pastebin.com/JeR2VcXr
http://pastebin.com/PU65NmYB

It's a very simple gtk example that I copied just to mess with.  When I run 
"gprbuild", this is the error that I see:
$ gprbuild
using project file gtk_test.gpr
gcc -c -g gtk_test.adb
gtk_test.adb:16:04: instantiation error at gtk-handlers.ads:1039
gtk_test.adb:16:04: subprogram must not be deeper than access type
gtk_test.adb:17:04: instantiation error at gtk-handlers.ads:437
gtk_test.adb:17:04: subprogram must not be deeper than access type
gprbuild: *** compilation phase failed

Why?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-06 22:55 I do not understand this error John Smith
@ 2016-02-06 23:47 ` Jeffrey R. Carter
  2016-02-07  0:34   ` John Smith
  0 siblings, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2016-02-06 23:47 UTC (permalink / raw)


On 02/06/2016 03:55 PM, John Smith wrote:
> 
> gtk_test.adb:16:04: instantiation error at gtk-handlers.ads:1039
> gtk_test.adb:16:04: subprogram must not be deeper than access type
> gtk_test.adb:17:04: instantiation error at gtk-handlers.ads:437
> gtk_test.adb:17:04: subprogram must not be deeper than access type

This an accessibility check. It means that it's possible for an
access-to-subprogram value to be copied into a variable which has longer life
than the subprogram. This is not allowed by the language.

-- 
Jeff Carter
"Help! Help! I'm being repressed!"
Monty Python & the Holy Grail
67


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-06 23:47 ` Jeffrey R. Carter
@ 2016-02-07  0:34   ` John Smith
  2016-02-07  4:36     ` Jeffrey R. Carter
  2016-02-07  8:23     ` Dmitry A. Kazakov
  0 siblings, 2 replies; 15+ messages in thread
From: John Smith @ 2016-02-07  0:34 UTC (permalink / raw)


The the following example is wrong:
http://rosettacode.org/wiki/Hello_world/Graphical#Ada

If so, then how would you fix this?

On Saturday, February 6, 2016 at 6:47:49 PM UTC-5, Jeffrey R. Carter wrote:
> On 02/06/2016 03:55 PM, John Smith wrote:
> > 
> > gtk_test.adb:16:04: instantiation error at gtk-handlers.ads:1039
> > gtk_test.adb:16:04: subprogram must not be deeper than access type
> > gtk_test.adb:17:04: instantiation error at gtk-handlers.ads:437
> > gtk_test.adb:17:04: subprogram must not be deeper than access type
> 
> This an accessibility check. It means that it's possible for an
> access-to-subprogram value to be copied into a variable which has longer life
> than the subprogram. This is not allowed by the language.
> 
> -- 
> Jeff Carter
> "Help! Help! I'm being repressed!"
> Monty Python & the Holy Grail
> 67

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-07  0:34   ` John Smith
@ 2016-02-07  4:36     ` Jeffrey R. Carter
  2016-02-08  3:51       ` John Smith
  2016-02-07  8:23     ` Dmitry A. Kazakov
  1 sibling, 1 reply; 15+ messages in thread
From: Jeffrey R. Carter @ 2016-02-07  4:36 UTC (permalink / raw)


On 02/06/2016 05:34 PM, John Smith wrote:
> The the following example is wrong:
> http://rosettacode.org/wiki/Hello_world/Graphical#Ada

Perhaps. I've always used callbacks in library-level pkgs with GtkAda, so I
don't know if using a callback declared at a deeper level might be legal in some
cases. There are also questions about the versions of GtkAda and the compiler
used to compile this.

> If so, then how would you fix this?

I would declare the callbacks in a library-level pkg.

-- 
Jeff Carter
"[I]f we should ever separate, my little plum,
I want to give you one little bit of fatherly advice. ... Never
give a sucker an even break."
Poppy
97

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-07  0:34   ` John Smith
  2016-02-07  4:36     ` Jeffrey R. Carter
@ 2016-02-07  8:23     ` Dmitry A. Kazakov
  2016-02-07 22:11       ` John Smith
  1 sibling, 1 reply; 15+ messages in thread
From: Dmitry A. Kazakov @ 2016-02-07  8:23 UTC (permalink / raw)


On 2016-02-07 01:34, John Smith wrote:
> The the following example is wrong:
> http://rosettacode.org/wiki/Hello_world/Graphical#Ada
>
> If so, then how would you fix this?
>
> On Saturday, February 6, 2016 at 6:47:49 PM UTC-5, Jeffrey R. Carter wrote:
>> On 02/06/2016 03:55 PM, John Smith wrote:
>>>
>>> gtk_test.adb:16:04: instantiation error at gtk-handlers.ads:1039
>>> gtk_test.adb:16:04: subprogram must not be deeper than access type
>>> gtk_test.adb:17:04: instantiation error at gtk-handlers.ads:437
>>> gtk_test.adb:17:04: subprogram must not be deeper than access type
>>
>> This an accessibility check. It means that it's possible for an
>> access-to-subprogram value to be copied into a variable which has longer life
>> than the subprogram. This is not allowed by the language.

Generic packages from Gtk.Handlers cannot be instantiated in the main 
procedure, due to accessibility check, as Jeffrey wrote.

To resolve this move instantiations Handlers and Return_Handles into a 
separate [library level] package and use this package in the main procedure.

In GtkAda contributions there are pre-instantiated handlers to deal with 
gtk program exit. A working example will look like:
--------------------------------------------
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;

with Gtk.Main;
with Gtk.Missed;

procedure gtk_test is
    Window : Gtk_Window;
    Label  : Gtk_Label;
  begin
    Gtk.Main.Init;
    Gtk.Window.Gtk_New (Window);
    Window.On_Delete_Event (Gtk.Missed.Delete_Event_Handler'Access);
    Window.On_Destroy (Gtk.Missed.Destroy_Handler'Access);
    Gtk_New (Label, "Goodbye, World!");
    Window.Add (Label);
    Window.Show_All;
    Gtk.Main.Main;
end gtk_test;
-----------------------------------------------
http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-07  8:23     ` Dmitry A. Kazakov
@ 2016-02-07 22:11       ` John Smith
  2016-02-07 23:26         ` John Smith
  0 siblings, 1 reply; 15+ messages in thread
From: John Smith @ 2016-02-07 22:11 UTC (permalink / raw)


Hello Dmitry,

What is Gtk.Missed?  That does not seem to exist according to the docs:
http://docs.adacore.com/gtkada-docs/gtkada_rm/gtkada_rm/

On Sunday, February 7, 2016 at 3:23:59 AM UTC-5, Dmitry A. Kazakov wrote:
> On 2016-02-07 01:34, John Smith wrote:
> > The the following example is wrong:
> > http://rosettacode.org/wiki/Hello_world/Graphical#Ada
> >
> > If so, then how would you fix this?
> >
> > On Saturday, February 6, 2016 at 6:47:49 PM UTC-5, Jeffrey R. Carter wrote:
> >> On 02/06/2016 03:55 PM, John Smith wrote:
> >>>
> >>> gtk_test.adb:16:04: instantiation error at gtk-handlers.ads:1039
> >>> gtk_test.adb:16:04: subprogram must not be deeper than access type
> >>> gtk_test.adb:17:04: instantiation error at gtk-handlers.ads:437
> >>> gtk_test.adb:17:04: subprogram must not be deeper than access type
> >>
> >> This an accessibility check. It means that it's possible for an
> >> access-to-subprogram value to be copied into a variable which has longer life
> >> than the subprogram. This is not allowed by the language.
> 
> Generic packages from Gtk.Handlers cannot be instantiated in the main 
> procedure, due to accessibility check, as Jeffrey wrote.
> 
> To resolve this move instantiations Handlers and Return_Handles into a 
> separate [library level] package and use this package in the main procedure.
> 
> In GtkAda contributions there are pre-instantiated handlers to deal with 
> gtk program exit. A working example will look like:
> --------------------------------------------
> with Gtk.Label;   use Gtk.Label;
> with Gtk.Window;  use Gtk.Window;
> 
> with Gtk.Main;
> with Gtk.Missed;
> 
> procedure gtk_test is
>     Window : Gtk_Window;
>     Label  : Gtk_Label;
>   begin
>     Gtk.Main.Init;
>     Gtk.Window.Gtk_New (Window);
>     Window.On_Delete_Event (Gtk.Missed.Delete_Event_Handler'Access);
>     Window.On_Destroy (Gtk.Missed.Destroy_Handler'Access);
>     Gtk_New (Label, "Goodbye, World!");
>     Window.Add (Label);
>     Window.Show_All;
>     Gtk.Main.Main;
> end gtk_test;
> -----------------------------------------------
> http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-07 22:11       ` John Smith
@ 2016-02-07 23:26         ` John Smith
  0 siblings, 0 replies; 15+ messages in thread
From: John Smith @ 2016-02-07 23:26 UTC (permalink / raw)


Aaah, Missed is something that you created.  I'll have a look later.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-07  4:36     ` Jeffrey R. Carter
@ 2016-02-08  3:51       ` John Smith
  2016-02-08  4:41         ` Jeffrey R. Carter
  0 siblings, 1 reply; 15+ messages in thread
From: John Smith @ 2016-02-08  3:51 UTC (permalink / raw)


On Saturday, February 6, 2016 at 11:36:25 PM UTC-5, Jeffrey R. Carter wrote:
> On 02/06/2016 05:34 PM, John Smith wrote:
> > The the following example is wrong:
> > http://rosettacode.org/wiki/Hello_world/Graphical#Ada
> 
> Perhaps. I've always used callbacks in library-level pkgs with GtkAda, so I
> don't know if using a callback declared at a deeper level might be legal in some
> cases. There are also questions about the versions of GtkAda and the compiler
> used to compile this.
> 
> > If so, then how would you fix this?
> 
> I would declare the callbacks in a library-level pkg.
> 

Stupid question.  What do you mean by a library-level package?  Is this just a regular package that has these callbacks declared and I just include it in my application?

My version of Gnatmake is 5.3.0, if that helps.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-08  3:51       ` John Smith
@ 2016-02-08  4:41         ` Jeffrey R. Carter
  2016-02-08 23:33           ` Robert A Duff
  2016-02-08 23:39           ` John Smith
  0 siblings, 2 replies; 15+ messages in thread
From: Jeffrey R. Carter @ 2016-02-08  4:41 UTC (permalink / raw)


On 02/07/2016 08:51 PM, John Smith wrote:
> 
> Stupid question.  What do you mean by a library-level package?  Is this just
> a regular package that has these callbacks declared and I just include it in
> my application?

"Library-level" means not nested in anything else.

[Technically, nested directly in Standard, since all compilation units are
considered nested directly in Standard. Standard is usually not mentioned
explicitly, though, so this may be confusing to a beginner.]

-- 
Jeff Carter
"I'm a lumberjack and I'm OK."
Monty Python's Flying Circus
54

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-08  4:41         ` Jeffrey R. Carter
@ 2016-02-08 23:33           ` Robert A Duff
  2016-02-09  5:25             ` Jeffrey R. Carter
  2016-02-09  9:43             ` G.B.
  2016-02-08 23:39           ` John Smith
  1 sibling, 2 replies; 15+ messages in thread
From: Robert A Duff @ 2016-02-08 23:33 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:

> On 02/07/2016 08:51 PM, John Smith wrote:
>> 
>> Stupid question.  What do you mean by a library-level package?  Is this just
>> a regular package that has these callbacks declared and I just include it in
>> my application?
>
> "Library-level" means not nested in anything else.

It means not nested in any procedure, function, or task.
In can be nested in arbitrarily many packages, and still be
library level.

> [Technically, nested directly in Standard, since all compilation units are
> considered nested directly in Standard. Standard is usually not mentioned
> explicitly, though, so this may be confusing to a beginner.]

I'm not sure what you mean by "directly" there, but if you say
"package A.B is...", B is inside of A, and A is inside of Standard.
And all of Standard, A, and B are library level.

- Bob

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-08  4:41         ` Jeffrey R. Carter
  2016-02-08 23:33           ` Robert A Duff
@ 2016-02-08 23:39           ` John Smith
  2016-02-09  5:25             ` Jeffrey R. Carter
  1 sibling, 1 reply; 15+ messages in thread
From: John Smith @ 2016-02-08 23:39 UTC (permalink / raw)


On Sunday, February 7, 2016 at 11:41:51 PM UTC-5, Jeffrey R. Carter wrote:
> On 02/07/2016 08:51 PM, John Smith wrote:
> > 
> > Stupid question.  What do you mean by a library-level package?  Is this just
> > a regular package that has these callbacks declared and I just include it in
> > my application?
> 
> "Library-level" means not nested in anything else.
> 
> [Technically, nested directly in Standard, since all compilation units are
> considered nested directly in Standard. Standard is usually not mentioned
> explicitly, though, so this may be confusing to a beginner.]
> 
> -- 
> Jeff Carter
> "I'm a lumberjack and I'm OK."
> Monty Python's Flying Circus
> 54

How does that look like?

I tried to "with" the following package:
http://pastebin.com/ghd6kjZP

But I got the following errors:
$ gprbuild
using project file gtk_hello_world.gpr
gcc -c -g -gnatwa gtk_hello_world.adb
gtk_hello_world.adb:22:26: warning: formal parameter "Widget" is not referenced
gtk_hello_world.adb:28:22: warning: formal parameter "Widget" is not referenced
gtk_hello_world.adb:38:03: "Return_Handlers" is not visible
gtk_hello_world.adb:38:03: non-visible declaration at handler_package.ads:11
gtk_hello_world.adb:39:03: "Handlers" is not visible
gtk_hello_world.adb:39:03: non-visible declaration at handler_package.ads:10
gtk_hello_world.adb:39:03: non-visible declaration at gtk-handlers.ads:181
gprbuild: *** compilation phase failed


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-08 23:33           ` Robert A Duff
@ 2016-02-09  5:25             ` Jeffrey R. Carter
  2016-02-09  9:43             ` G.B.
  1 sibling, 0 replies; 15+ messages in thread
From: Jeffrey R. Carter @ 2016-02-09  5:25 UTC (permalink / raw)


On 02/08/2016 04:33 PM, Robert A Duff wrote:
> 
> It means not nested in any procedure, function, or task.
> In can be nested in arbitrarily many packages, and still be
> library level.

Protected object?

> I'm not sure what you mean by "directly" there, but if you say
> "package A.B is...", B is inside of A, and A is inside of Standard.
> And all of Standard, A, and B are library level.

Thanks for the clarification. I wasn't thinking about child pkgs.

-- 
Jeff Carter
"When danger reared its ugly head, he bravely
turned his tail and fled."
Monty Python and the Holy Grail
60


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-08 23:39           ` John Smith
@ 2016-02-09  5:25             ` Jeffrey R. Carter
  0 siblings, 0 replies; 15+ messages in thread
From: Jeffrey R. Carter @ 2016-02-09  5:25 UTC (permalink / raw)


On 02/08/2016 04:39 PM, John Smith wrote:
> 
> I tried to "with" the following package:
> http://pastebin.com/ghd6kjZP
> 
> But I got the following errors:
> gtk_hello_world.adb:38:03: "Return_Handlers" is not visible
> gtk_hello_world.adb:38:03: non-visible declaration at handler_package.ads:11
> gtk_hello_world.adb:39:03: "Handlers" is not visible
> gtk_hello_world.adb:39:03: non-visible declaration at handler_package.ads:10

Handlers and Return_Handlers are inside Handler_Package, and have to be
referenced just like anything else inside a pkg. Just as you say
Gtk.Widget.Gtk_Widget_Record, you should say Handler_Package.Handlers.

But presumably the callbacks are still in your main-program subprogram, which is
not library level, so this won't help you by itself.

Typically I've put everything dealing with GtkAda in the same pkg, except the
call to Gtk.Main.Main. You can look at the Mine Detector game for an example.

https://pragmada.x10hosting.com/mindet.html

-- 
Jeff Carter
"When danger reared its ugly head, he bravely
turned his tail and fled."
Monty Python and the Holy Grail
60


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-08 23:33           ` Robert A Duff
  2016-02-09  5:25             ` Jeffrey R. Carter
@ 2016-02-09  9:43             ` G.B.
  2016-02-09 16:14               ` AdaMagica
  1 sibling, 1 reply; 15+ messages in thread
From: G.B. @ 2016-02-09  9:43 UTC (permalink / raw)


On 09.02.16 00:33, Robert A Duff wrote:
> "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> writes:
>
>> On 02/07/2016 08:51 PM, John Smith wrote:
>>>
>>> Stupid question.  What do you mean by a library-level package?  Is this just
>>> a regular package that has these callbacks declared and I just include it in
>>> my application?
>>
>> "Library-level" means not nested in anything else.
>
> It means not nested in any procedure, function, or task.

Also, not nested in the handled_sequence_of_statements of
a package's body, I think?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: I do not understand this error...
  2016-02-09  9:43             ` G.B.
@ 2016-02-09 16:14               ` AdaMagica
  0 siblings, 0 replies; 15+ messages in thread
From: AdaMagica @ 2016-02-09 16:14 UTC (permalink / raw)


Am Dienstag, 9. Februar 2016 10:43:27 UTC+1 schrieb G.B.:
> >>> Stupid question.  What do you mean by a library-level package?  Is this just
> >>> a regular package that has these callbacks declared and I just include it in
> >>> my application?
> >>
> >> "Library-level" means not nested in anything else.
> >
> > It means not nested in any procedure, function, or task.
> 
> Also, not nested in the handled_sequence_of_statements of
> a package's body, I think?

Yes, of course.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-02-09 16:14 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-06 22:55 I do not understand this error John Smith
2016-02-06 23:47 ` Jeffrey R. Carter
2016-02-07  0:34   ` John Smith
2016-02-07  4:36     ` Jeffrey R. Carter
2016-02-08  3:51       ` John Smith
2016-02-08  4:41         ` Jeffrey R. Carter
2016-02-08 23:33           ` Robert A Duff
2016-02-09  5:25             ` Jeffrey R. Carter
2016-02-09  9:43             ` G.B.
2016-02-09 16:14               ` AdaMagica
2016-02-08 23:39           ` John Smith
2016-02-09  5:25             ` Jeffrey R. Carter
2016-02-07  8:23     ` Dmitry A. Kazakov
2016-02-07 22:11       ` John Smith
2016-02-07 23:26         ` John Smith

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