comp.lang.ada
 help / color / mirror / Atom feed
From: "Greg Bek" <gbek_nospam@removethis.bigpond.net.au>
Subject: Re: Ada / Motif Binding Question
Date: Fri, 26 Apr 2002 02:25:31 GMT
Date: 2002-04-26T02:25:31+00:00	[thread overview]
Message-ID: <vU2y8.51441$o66.157374@news-server.bigpond.net.au> (raw)
In-Reply-To: %Elx8.52627$WV1.16784880@typhoon.ne.ipsvc.net

I recognise Apex code when I see the formatting, so....

At a guess (it's been awhile since I've done this), the storage error is
being raise by the callback because the first thing the Exit_Option
routine does is a stack check at the top of the routine.

At runtime with Apex we usually store the stack limit in a known
register, rather than in memory, because the value is referenced
frequently, so the code runs faster.

But...

In this case the code is being called from a non Ada context, so the
content of the stack limit register is not guaranteed to be correct,
and in fact probably isn't.

It works this way because you haven't given the compiler enough
information about how the routine is being used.  All the compiler
can see is a nested routine, which it thinks can only be called from
the enclosing Ada scope.

To resolve the problem you need to put a pragma Export() on the
routine, which forces the complier to generate conservative code
because the routine can now be called from anywhere.  The procedure
prolog will now load the stack limit register from a know location in
memory (actually out of the task control block).

You may still have a problem as the routine is in a nested local scope.
In which case you need to move it in a separately compiled package,
as routines in package have static scope.

There are many examples that come with the AXI bindings, both
standard X as well as MOTIF.  I recommend plagiarism as a path
to success with GUI programming.

Greg Bek
-------------------------------------------
Greg Bek  mailto:gab@rational.com
Product Manager
Rational Software, Cupertino CA 95014
Ph: +1 408 863 4394   Fax: + 1 408 863 4180
-------------------------------------------



"Tony Yu" <tonyyu99@attbi.com> wrote in message
news:%Elx8.52627$WV1.16784880@typhoon.ne.ipsvc.net...
> Hi,
>     I recently started using the Motif binding with Ada and had great
> difficulty getting the callback functions to work properly.  The following
> is a small program I created:
>
> --------------------------------------------------------------------------
--
> --------------------------
> with X_Support.Xt, X_Support.Lib, X_Support.Xm, X_Support.Xm_Defs,
> Ada.Text_Io;
>
> with X_Support.Form, X_Support.Push_Button;
>
>
>
> procedure My_Test is
>
>     Appshell : X_Support.Xt.Widget := X_Support.Xt.Null_Widget;
>
>     App_Con : X_Support.Xt.Xt_App_Context;
>
>     Form, Exitbutton : X_Support.Xt.Widget;
>
>     Argc : Natural := 0;
>
>     Argv : X_Support.Xt.Argv_Type;
>
>     procedure My_Proc is
>
>         begin
>
>             Ada.Text_Io.Put_Line ("Hello!");
>
>         end My_Proc;
>
>     procedure Exit_Option (W : X_Support.Xt.Widget;
>
>         Client_Data : X_Support.Xt.Xt_Pointer;
>
>         Call_Data : X_Support.Xt.Xt_Pointer) is
>
>         My_String : String (1 .. 625) := (others => ' ');
>
>         procedure C_Exit (Status : Integer);
>
>         pragma Import (C, C_Exit, External_Name => "exit");
>
>         begin
>
>             C_Exit (0);
>
>         end Exit_Option;
>
> begin
>
>     X_Support.Xt.Xt_Initializers.Xt_App_Initialize
>
>         (App_Context_Return => App_Con,
>
>         Application_Class => "",
>
>         Argc_In_Out => Argc,
>
>         Argv_In_Out => Argv,
>
>         Widget_Id => Appshell);
>
>         Form :=
X_Support.Xt.Xt_Instance_Management.Xt_Create_Managed_Widget
>
>         ("form", X_Support.Form.Xm_Form_Widget_Class, Appshell);
>
>         Exitbutton :=
>
>             X_Support.Xt.Xt_Instance_Management.Xt_Create_Managed_Widget
>
>                 (Name => "EXIT",
>
>                 Of_Class => X_Support.Push_Button.
>
>                 Xm_Push_Button_Widget_Class,
>
>                 Parent => Form);
>
>         X_Support.Xt.Xt_Callbacks.Xt_Add_Callback
>
>             (Exitbutton, X_Support.Xm_Defs.Nactivatecallback,
>
>             Exit_Option'Address, X_Support.Xt.Null_Xt_Pointer);
>
>         X_Support.Xt.Xt_Instance_Management.Xt_Realize_Widget (Appshell);
>
>         X_Support.Xt.Xt_Event_Management.Xt_App_Main_Loop (App_Con);
>
> end My_Test;
>
> --------------------------------------------------------------------------
--
> --------------------------------------------------------------------------
--
> -
>
> After invoking the callback, I get the following error:
>
>  -> ** MAIN PROGRAM ABANDONED -- EXCEPTION "STORAGE_ERROR" RAISED
>
> If I suppress the Storage_Error check, I get the following:
>
> -> exception_handler: below bottom of user stack
>
>
>
> I suspect that the callback procedure is not being allocated enough stack
> space for me to declare such a string.  I've had similar exceptions when I
> perform a Text_Io, or call another procedure/function within the callback
> procedure.  Oh, I compiled this program using Rational Apex 3.2.0b.  Is
> there a way to increase the stack size allocated to the callback
procedure?
> Any help would be appreciated!  Thanks in advance!
>
> -Tony Yu
>
> P.S.  I appologise if this topic has been mentioned before.
>
>
>





      parent reply	other threads:[~2002-04-26  2:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-23 22:56 Ada / Motif Binding Question Tony Yu
2002-04-24  2:19 ` Ted Dennison
2002-04-24  3:08   ` Tony Yu
2002-04-26  6:28     ` Christopher Green
2002-04-29 22:55       ` Tony Yu
2002-04-26  2:25 ` Greg Bek [this message]
replies disabled

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