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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,444c1179ce493ca2 X-Google-Attributes: gid103376,public From: Sandy McPherson Subject: Re: Vads X/Motif & C Date: 1996/09/12 Message-ID: <32381B6B.414B@wgs.estec.esa.nl>#1/1 X-Deja-AN: 180150296 references: <514579$sts@news.sei.cmu.edu> to: Mark Bell content-type: text/plain; charset=us-ascii organization: European Space Agency mime-version: 1.0 newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (X11; I; SunOS 5.4 sun4) Date: 1996-09-12T00:00:00+00:00 List-Id: 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