From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!sun-barr!news2me.ebay.sun.com!cronkite.Central.Sun.COM!texsun!ttsi!mse@ucbvax.Berkeley.EDU (Mark Evans)
Newsgroups: fj.mail-lists.apollo
Subject: xfig problem solved:  Bug in HP libXt!
Date: 7 Apr 92 16:53:30 GMT
Distribution: fj
Organization: st
Return-Path: <apollo-list-errors@srvr1.engin.umich.edu>


DomainOS 10.3.5, BSD, UEDK, Xdomain, X11/R4

I recently posted a plea for help in getting xfig V2.3.1 running on 
Apollo.  You may recall that I was running into a memory fault when
popping up a dialog box for a second time.  I have traced the 
problem to a bug in the Xt library provided by HP in the UEDK.

The C routine listed below is an xfig routine that pops up a 
dialog.  On the first pass through this routine, everything
works ok.  On the second pass, however, a memory fault occurs with
the following traceback:

Process        8574 (parent 1145, group 8574)
Time           92/04/07.07:13(CST)
Program        //topgun/usr.local.src/misc/xfig/xfig
Status         00040004: reference to illegal address (OS/MST manager)
In routine     "XrmStringToQuark" line 405
Called from    "CompileActionTable" line 77
Called from    "XtAppAddActions" line 764
Called from    "popup_nval_panel" line 751
Called from    "sel_ind_but" line 406
Called from    "DispatchEvent" line 683
Called from    "DecideToDispatch" line 1106
Called from    "XtDispatchEvent" line 1147
Called from    "XtAppMainLoop" line 1325
Called from    "main" line 454
Called from    "unix_$main" line 114
Called from    "_start" line 132
Called from    "PM_$CALL" line 176
Called from    "pgm_$load_run" line 903
Called from    "pgm_$invoke_uid_pn" line 1124

Proc2 Uid       58055211.6002F14C
Parent Process  1145 (57DD9DD2.1002F14C)
Process Group   8574 (58055211.6002F14C)
Fault Status    00040004: reference to illegal address (OS/MST manager)
Access Addr     00000287
IR              0000
Acc. Info       0521
User Fault PC   000BDC6E
D0-D3:          0018B3F0 FFFFFFFC 00000000 00000000
D4-D7:          00000001 0018A700 7537EA14 00000004
A0-A3:          00000287 7537E31C 00000287 00118C1C
A4-A7:          00000000 00136998 7537E4AC 7537E488
Supervisor ECB  00000000
Supervisor SR   0000
Supervisor PC   00000000

The problem is due to CompileActionTable, called by XtAppAddActions,
clobbering a user data item in a structure passed as input to 
XtAppAddActions.  See the annotation in the code for the rest of
the story.


static XtActionsRec set_actions[] =
{
    {"SetValue", (XtActionProc) nval_panel_set},
};

popup_nval_panel(isw)
    ind_sw_info    *isw;
{
    Position        x_val, y_val;
    Dimension       width, height;
    char            buf[32];

    nval_i = isw;
    XtSetSensitive(nval_i->widget, False);

    FirstArg(XtNwidth, &width);
    NextArg(XtNheight, &height);
    GetValues(tool);
    /* position the popup 1/3 in from left and 2/3 down from top */
    XtTranslateCoords(tool, (Position) (width / 3), (Position) (2 * height / 3),
                      &x_val, &y_val);

    FirstArg(XtNx, x_val);
    NextArg(XtNy, y_val);
    NextArg(XtNwidth, 240);

    nval_popup = XtCreatePopupShell("xfig_set_indicator_panel",
                                    transientShellWidgetClass, tool,
                                    Args, ArgCount);

    form = XtCreateManagedWidget("form", formWidgetClass, nval_popup, NULL, 0);

    FirstArg(XtNborderWidth, 0);
    sprintf(buf, "%s %s", isw->line1, isw->line2);
    label = XtCreateManagedWidget(buf, labelWidgetClass, form, Args, ArgCount);

    FirstArg(XtNfromVert, label);
    NextArg(XtNborderWidth, 0);
    NextArg(XtNlabel, "Value =");
    newvalue = XtCreateManagedWidget("value", labelWidgetClass,
                                     form, Args, ArgCount);
    /* int or float? */
    if (isw->type == I_IVAL)
            sprintf(buf, "%d", (*isw->i_varadr));
    else
            sprintf(buf, "%4.1f", (*isw->f_varadr));
    FirstArg(XtNfromVert, label);
    NextArg(XtNborderWidth, INTERNAL_BW);
    NextArg(XtNfromHoriz, newvalue);
    NextArg(XtNstring, buf);
    NextArg(XtNinsertPosition, strlen(buf));
    NextArg(XtNeditType, "append");
    NextArg(XtNwidth, 40);
    newvalue = XtCreateManagedWidget(buf, asciiTextWidgetClass,
                                     form, Args, ArgCount);

    /* add translation and action to set value on carriage return */

/* **************************** BUG in HP libXt ************************** */

    XtAppAddActions(tool_app, set_actions, XtNumber(set_actions));
/*                            ^^^^^^^^^^^
 * ARGH!!!                    set_actions.string gets clobbered
 *
 * Before the call:
 *
 *   \\w_indpanel\set_actions: (array)
 *   \\w_indpanel\set_actions[0]: (record)
 *   \\w_indpanel\set_actions[0].string: 00118C0C
 *   +\\w_indpanel\set_actions[0].string: "SetValue"
 *   \\w_indpanel\set_actions[0].proc: 00080BE6
 *   +\\w_indpanel\set_actions[0].proc: ?(dde) Values of type "entry" are not supported in this context.
 *
 * After the call:
 *
 *   \\w_indpanel\set_actions: (array)
 *   \\w_indpanel\set_actions[0]: (record)
 *   \\w_indpanel\set_actions[0].string: 00000287
 *   ?(dde/tgt_apollo_m68k) Cannot read from virtual address 00000287 of process 1484.
 *   \\w_indpanel\set_actions[0].proc: 00080BE6
 *   +\\w_indpanel\set_actions[0].proc: ?(dde) Values of type "entry" are not supported in this context.
 *
 * Setting watchpoint on set_actions[0].string catches the culprit:
 *
 *   Stopped at: \\TMaction\CompileActionTable\76 (000B8DA4)
 *   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *   PLEASE FIX ME PLEASE FIX ME PLEASE FIX ME PLEASE FIX ME
 */

    XtOverrideTranslations(newvalue, XtParseTranslationTable(set_translations));

    FirstArg(XtNlabel, "cancel");
    NextArg(XtNfromVert, newvalue);
    NextArg(XtNborderWidth, INTERNAL_BW);
    cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
                                   form, Args, ArgCount);
    XtAddEventHandler(cancel, ButtonReleaseMask, (Boolean) 0,
                      (XtEventHandler)nval_panel_cancel, (XtPointer) NULL);

    FirstArg(XtNlabel, "set");
    NextArg(XtNfromVert, newvalue);
    NextArg(XtNfromHoriz, cancel);
    NextArg(XtNborderWidth, INTERNAL_BW);
    set = XtCreateManagedWidget("set", commandWidgetClass,
                                form, Args, ArgCount);
    XtAddEventHandler(set, ButtonReleaseMask, (Boolean) 0,
                      (XtEventHandler)nval_panel_set, (XtPointer) NULL);

    XtPopup(nval_popup, XtGrabExclusive);
}


Is it concievable that HP might publish its changes/enhancements to
the MIT libraries to give users a fighting chance of being able to
build common X window applications?  Chasing problems like this in the
blind is getting old.

Even better, might HP consider expanding its X11 test suite to
include popular applications freely available on the network?

Thanks
-- 
Mark S. Evans                 Tandem Telecommunications Systems Inc.
Phone: 214-516-6201           1255 W 15th St.
Fax:   214-516-6805           Plano, TX 75075
Mail:  mse@ttsi.lonestar.org