* Ada / Motif Binding Question
@ 2002-04-23 22:56 Tony Yu
2002-04-24 2:19 ` Ted Dennison
2002-04-26 2:25 ` Greg Bek
0 siblings, 2 replies; 6+ messages in thread
From: Tony Yu @ 2002-04-23 22:56 UTC (permalink / raw)
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada / Motif Binding Question
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 2:25 ` Greg Bek
1 sibling, 1 reply; 6+ messages in thread
From: Ted Dennison @ 2002-04-24 2:19 UTC (permalink / raw)
Tony Yu wrote:
> 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;
>
> After invoking the callback, I get the following error:
>
> -> ** MAIN PROGRAM ABANDONED -- EXCEPTION "STORAGE_ERROR" RAISED
You didn't say what Motif bindings you are using. There's no one
standard set that comes with every compiler (which makes sense, as Win32
compilers don't typically have Motif around to bind to).
One possibility I see is that "Exit_Option" does not have a "pragma
Convention (C, ...)" on it. Ada procedures and C functions usually have
different calling sequences, and Motif expects to be "talking C" to its
callbacks.
However, some bindings take care of this for you, which is why it
matters what bindings you have.
Another possibility is that C_Exit() (whatever that is) is causing you
grief. You could try changing that line to "null;" to see if the crash
goes away.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada / Motif Binding Question
2002-04-24 2:19 ` Ted Dennison
@ 2002-04-24 3:08 ` Tony Yu
2002-04-26 6:28 ` Christopher Green
0 siblings, 1 reply; 6+ messages in thread
From: Tony Yu @ 2002-04-24 3:08 UTC (permalink / raw)
"Ted Dennison" <dennison@telepath.com> wrote in message
news:3CC6165F.90104@telepath.com...
>
> You didn't say what Motif bindings you are using. There's no one
> standard set that comes with every compiler (which makes sense, as Win32
> compilers don't typically have Motif around to bind to).
I believe I am using the AXI bindings. For the most part, I've seen legacy
STARS packages referenced. Not sure if they are the same.
> One possibility I see is that "Exit_Option" does not have a "pragma
> Convention (C, ...)" on it. Ada procedures and C functions usually have
> different calling sequences, and Motif expects to be "talking C" to its
> callbacks.
>
> However, some bindings take care of this for you, which is why it
> matters what bindings you have.
>
>
> Another possibility is that C_Exit() (whatever that is) is causing you
> grief. You could try changing that line to "null;" to see if the crash
> goes away.
I tried commenting out the entire exit import, but I still seem to get the
Storage_Error. Whats interesting is that; When I had the pragma, I could
only declare a string of 584 characters in length, and when commenting out
the entire pragma import, I can then declare a string of 624 characters in
length. With string lengths of 585, 625 respectively, the Storage_Error
exception occurs. This is the reason why I suspect somehow the Motif
binding is limiting the amount of stack space available for the callback
procedure.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada / Motif Binding Question
2002-04-24 3:08 ` Tony Yu
@ 2002-04-26 6:28 ` Christopher Green
2002-04-29 22:55 ` Tony Yu
0 siblings, 1 reply; 6+ messages in thread
From: Christopher Green @ 2002-04-26 6:28 UTC (permalink / raw)
On Wed, 24 Apr 2002 03:08:48 GMT, "Tony Yu" <tonyyu99@attbi.com>
wrote:
>"Ted Dennison" <dennison@telepath.com> wrote in message
>news:3CC6165F.90104@telepath.com...
>>
>> You didn't say what Motif bindings you are using. There's no one
>> standard set that comes with every compiler (which makes sense, as Win32
>> compilers don't typically have Motif around to bind to).
>I believe I am using the AXI bindings. For the most part, I've seen legacy
>STARS packages referenced. Not sure if they are the same.
I do AXI support for ATC, and that looks like the STARS dialect of
AXI.
A 'pragma Export' or 'pragma Convention' on Exit_Option would be
needed on many hosts. Otherwise, Ada stack-checking code gets confused
when it encounters a non-Ada stack frame.
It can also be the case that you're running on a task stack or a
thread stack that really is too small or cluttered to allocate your
string.
A more difficult example of this is when you use threads with an Ada
runtime that wasn't written to use threads. The thread stack is not
where the Ada runtime thinks the stack is, and any Ada code you call
raises Storage_Error.
If you have more difficulties than can be solved by supplying the
right pragma and making sure your stack is large enough, write us at
support@atc.com.
--
Chris Green
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada / Motif Binding Question
2002-04-26 6:28 ` Christopher Green
@ 2002-04-29 22:55 ` Tony Yu
0 siblings, 0 replies; 6+ messages in thread
From: Tony Yu @ 2002-04-29 22:55 UTC (permalink / raw)
Thankyou! The 'pragma export' was the key to the mystery!
-Tony
"Christopher Green" <cj.green@worldnet.att.net> wrote in message
news:3cc4fb1c.32152679@netnews.att.net...
> On Wed, 24 Apr 2002 03:08:48 GMT, "Tony Yu" <tonyyu99@attbi.com>
> wrote:
>
> >"Ted Dennison" <dennison@telepath.com> wrote in message
> >news:3CC6165F.90104@telepath.com...
> >>
> >> You didn't say what Motif bindings you are using. There's no one
> >> standard set that comes with every compiler (which makes sense, as
Win32
> >> compilers don't typically have Motif around to bind to).
> >I believe I am using the AXI bindings. For the most part, I've seen
legacy
> >STARS packages referenced. Not sure if they are the same.
>
> I do AXI support for ATC, and that looks like the STARS dialect of
> AXI.
>
> A 'pragma Export' or 'pragma Convention' on Exit_Option would be
> needed on many hosts. Otherwise, Ada stack-checking code gets confused
> when it encounters a non-Ada stack frame.
>
> It can also be the case that you're running on a task stack or a
> thread stack that really is too small or cluttered to allocate your
> string.
>
> A more difficult example of this is when you use threads with an Ada
> runtime that wasn't written to use threads. The thread stack is not
> where the Ada runtime thinks the stack is, and any Ada code you call
> raises Storage_Error.
>
> If you have more difficulties than can be solved by supplying the
> right pragma and making sure your stack is large enough, write us at
> support@atc.com.
>
> --
> Chris Green
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada / Motif Binding Question
2002-04-23 22:56 Ada / Motif Binding Question Tony Yu
2002-04-24 2:19 ` Ted Dennison
@ 2002-04-26 2:25 ` Greg Bek
1 sibling, 0 replies; 6+ messages in thread
From: Greg Bek @ 2002-04-26 2:25 UTC (permalink / raw)
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.
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-04-29 22:55 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox