comp.lang.ada
 help / color / mirror / Atom feed
From: Sandy McPherson <sandy@wgs.estec.esa.nl>
To: Mark Bell <msb@sei.cmu.edu>
Subject: Re: Vads X/Motif & C
Date: 1996/09/12
Date: 1996-09-12T00:00:00+00:00	[thread overview]
Message-ID: <32381B6B.414B@wgs.estec.esa.nl> (raw)
In-Reply-To: 514579$sts@news.sei.cmu.edu


Mark Bell wrote:
> 
> Folks --
> 
snip...
> I believe I have this solved by modifying the v_usr_confb.a file
> to use malloc() instead of sbrk() in the kernel allocation
> function V_KRN_ALLOC_CALLOUT.  After this was done, I no
> longer get segmentation faults after malloc calls in the
> government C software.
> 

Motif uses XtMalloc and so should all applications written using Xt. You
may find that stuff allocated by Motif cannot be freed using free().Try
changing the thing to use XtMalloc and then do a #define in the C code
to get it to use XtMalloc as well,maybe this will work.. No promises
though

> Xt.Xt_Resource_Management.Xt_Set_Arg(
>   Arg => An_Arg_List(0),
>   Name => Xt_Stringdefs.Xt_N_background,
>   Value => blank_color'Address);
> 
> Xt.Xt_Resource_Management.Xt_Get_Values(
>   W    => Presentation_Drawing_Area,
>   Args => An_Arg_List(0..0));
> 
> Xt.Xt_Resource_Management.Xt_Set_Values(
>    W    => Presentation_Drawing_Area,
>    Args => An_Arg_List(0..0));
> 
> (Segmentation fault occurs)
> 
> Any suggestions as to why this happens ??
> 
Yup!

consider the equivalent in C

XtSetArg( arg_list[0], XtNbackground, &colour );
XtGetValues( w, arg_list, 1 );
XtSetValues( w, arg_list, 1 );

Oh dear! you've just set the pixel value of the background colour to a
pointer to colour!!!!

The correct thingy in C is

XtSetArg( arg_list[0], XtNbackground, &colour );
XtGetValues( w, arg_list, 1 );
XtSetArg( arg_list[0], XtNbackground, colour );
XtSetValues( w, arg_list, 1 );

This is because C needs to be able to write into the area given by the
address of colour on the get, but can take the value directly from
colour on the set. The solution in Ada is therefere that you cannot use
the 'ADDRESS in the set operation....

Xt.Xt_Resource_Management.Xt_Set_Arg(
  Arg => An_Arg_List(0),
  Name => Xt_Stringdefs.Xt_N_background,
  Value => blank_color);

should work...

Motif, Xt, X11 and Ada are not a good mixture in my experience, as the
API is too dependent on the concepts common in C and (rightly) alien to
Ada. In my experience it is usually easier to call Ada from C than vice
versa, so I prefer to control the GUI using C code and write my actual
application in Ada, the danger here is the temptation to to more than
widget mangling in the C code, which can lead to disaster. If you
restrict your C code to extracting stuff from the widgets and passing it
to Ada and extracting stuff from Ada and passing it to the widgets, you
shouldn't come to any harm and you will retain your sanity- which will
be severely tried once you try to handle the null terminated strings
which Motif demands directly in Ada (before everybody jumps on me, I
know you can do it, but it drove me nuts). If you are worried about
mis-use of C then use lint religiously or better still get QAC and
Purify (or tools of that ilk, I believe there are some good ones from
GNU).

hope this helps.... 
-- 
Sandy McPherson	MBCS CEng.	tel: 	+31 71 565 4288 (w)
ESTEC/WAS
P.O. Box 299
NL-2200AG Noordwijk




  parent reply	other threads:[~1996-09-12  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-10  0:00 Vads X/Motif & C Mark Bell
1996-09-11  0:00 ` Brian Crouch
1996-09-12  0:00 ` Frank Petranka
1996-09-12  0:00 ` Sandy McPherson [this message]
  -- strict thread matches above, loose matches on Subject: below --
1996-09-13  0:00 Mark Bell
replies disabled

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