[comp.windows.x] "Sun 4 Xt error"

kral@skvax1.csc.ti.COM (10/07/88)

	I recently got a Sun 4/110.  I was previously working on a Sun 3/60.
I moved my X application over from the Sun3 to the Sun4, recompiled and I get
a BUS error.  Using dbx it seems as if it's a problem with Xt source.  In
particular, the Convert.c file in lib/Xt, routine XtDirectConvert().  I had
thought I was calling something wrong but it turns out that on the MIT
distribution tape the examples/xwidgets comes up with the same error.  Anyways,
I can't find the solution to my problem.  Could someone please look at the
dbx outputs below and see if they can help me?	Maybe this has happened to
others and there is an easy solution (I wish).

In the main program of my application the program bombs on the
call on line 602:


  595				XtSetArg( where[0], XtNlabel, "Filename:       ");
  596				XtSetArg( where[1], XtNvalue, "");
  597				XtSetArg( where[2], XtNborderWidth, 0);
  598				XtSetArg( where[3], XtNfromHoriz, pfdisk);
  599				XtSetArg( where[4], XtNhorizDistance, 15);
  600				XtSetArg( where[5], XtNfromVert, pfdial1);
  601	/* works exit(0); */
  602			pfdial2 = XtCreateManagedWidget(NULL, dialogWidgetClass,
  603					pfform, where, SIX);
  604
  605	/* doesn't exit(0); */


Using dbx I get this error:

Running: symbol2
signal BUS (bus error) in XtDirectConvert at line 270 in file "Convert.c"
  270		 && (p->num_args == num_args)) {

Here is what the source for XtDirectConvert in lib/Xt/Convert.c looks like:

  250	void XtDirectConvert(converter, args, num_args, from, to)
  251	    XtConverter     converter;
  252	    XrmValuePtr     args;
  253	    Cardinal	    num_args;
  254	    register XrmValuePtr from;
  255	    XrmValuePtr     to;
  256	{
  257	    register CachePtr	p;
  258	    register int	hash;
  259	    register Cardinal	i;
  260
  261	    /* Try to find cache entry for conversion */
  262	    hash = ((int)(converter) >> 2) + from->size + *((char *) from->addr);
  263	    if (from->size > 1) hash += ((char *) from->addr)[1];
  264
  265	    for (p = cacheHashTable[hash & CACHEHASHMASK]; p != NULL; p = p->next)
{
  266		if ((p->hash == hash)
  267		 && (p->converter == converter)
  268		 && (p->from.size == from->size)
  269		 && (! XtBCmp(p->from.addr, from->addr, from->size))
  270		 && (p->num_args == num_args)) {
  271		    /* Are all args the same data ? */
  272		    for (i = 0; i < num_args; i++) {
  273			if (   p->args[i].size != args[i].size
  274			    || XtBCmp(p->args[i].addr, args[i].addr, args[i].size))
 {
  275			    break;
  276			}
  277		    }
  278		    if (i == num_args) {
  279			/* Perfect match */
  280			(*to) = p->to;
  281			return;
  282		    }
  283		}
  284	    }
  285
  286	    /* Didn't find it, call converter procedure and entry result in cache *
/
  287	    (*to).size = 0;
  288	    (*to).addr = NULL;
  289	    (*converter)(args, &num_args, from, to);
  290	    CacheEnter(converter, args, num_args, from, to, hash);
  291	}


The calls to XtDirectConvert after the XtCreateManagedWidget() in line 602
of my application program are listed below:

Using display variables in dbx this is what the variables of
the 'if' statement look like just before crashing:

(dbx) cont
`Convert`XtDirectConvert`p->hash = 37455
`Convert`XtDirectConvert`hash = 37455
`Convert`XtDirectConvert`p->converter = &CvtDefaultColorToPixel() at 0x2492c
`Convert`XtDirectConvert`converter = &CvtDefaultColorToPixel() at 0x2492c
`Convert`XtDirectConvert`p->from.size = 4
`Convert`XtDirectConvert`from->size = 149804
`Convert`XtDirectConvert`p->num_args = 1
`Convert`XtDirectConvert`num_args = 1

(dbx) cont
`Convert`XtDirectConvert`p->hash = 37455
`Convert`XtDirectConvert`hash = 37455
`Convert`XtDirectConvert`p->converter = &CvtDefaultColorToPixel() at 0x2492c
`Convert`XtDirectConvert`converter = &CvtDefaultColorToPixel() at 0x2492c
`Convert`XtDirectConvert`p->from.size = 4
`Convert`XtDirectConvert`from->size = 149804
`Convert`XtDirectConvert`p->num_args = 1
`Convert`XtDirectConvert`num_args = 1

(dbx) cont
`Convert`XtDirectConvert`p->hash = 37457
`Convert`XtDirectConvert`hash = 37457
`Convert`XtDirectConvert`p->converter = &CvtStringToInt() at 0x24798
`Convert`XtDirectConvert`converter = &CvtStringToInt() at 0x24798
`Convert`XtDirectConvert`p->from.size = 4
`Convert`XtDirectConvert`from->size = 149400
`Convert`XtDirectConvert`p->num_args = 0
`Convert`XtDirectConvert`num_args = 0

(dbx) cont
signal BUS (bus error) in XtDirectConvert at line 270 in file "Convert.c"
  270		 && (p->num_args == num_args)) {

=======================================================

Same problem with examples/xwidgets.c:

Line 142 in main() of xwidgets.c is the call which blows up:

  135		    label = XtCreateManagedWidget(  "label", labelWidgetClass,
  136						    box1, NULL, ZERO );
  137		    button = XtCreateManagedWidget( "command", commandWidgetClass,
  138						    box1, NULL, ZERO );
  139		    XtAddCallback( button, XtNcallback, Count, (caddr_t)label );
  140
  141	    XtSetArg( arg[0], XtNmin, 16 );
  142	    XtCreateManagedWidget( NULL, clockWidgetClass, outer, arg, ONE );
  143
  144	    XtCreateManagedWidget( NULL, loadWidgetClass, outer, NULL, ZERO );
  145


dbx output when stepping into line 142 and stopping at 270 of XtDirectConvert
looks like:

(dbx)cont
`Convert`XtDirectConvert`p->hash = 27117
`Convert`XtDirectConvert`hash = 27117
`Convert`XtDirectConvert`p->converter = &CvtDefaultColorToPixel() at 0x1a7a4
`Convert`XtDirectConvert`converter = &CvtDefaultColorToPixel() at 0x1a7a4
`Convert`XtDirectConvert`p->from.size = 4
`Convert`XtDirectConvert`from->size = 108452
`Convert`XtDirectConvert`p->num_args = 1
`Convert`XtDirectConvert`num_args = 1

`Convert`XtDirectConvert`p->hash = 27117
`Convert`XtDirectConvert`hash = 27117
`Convert`XtDirectConvert`p->converter = &CvtDefaultColorToPixel() at 0x1a7a4
`Convert`XtDirectConvert`converter = &CvtDefaultColorToPixel() at 0x1a7a4
`Convert`XtDirectConvert`p->from.size = 4
`Convert`XtDirectConvert`from->size = 108452
`Convert`XtDirectConvert`p->num_args = 1
`Convert`XtDirectConvert`num_args = 1

`Convert`XtDirectConvert`p->hash = 27119
`Convert`XtDirectConvert`hash = 27119
`Convert`XtDirectConvert`p->converter = &CvtStringToInt() at 0x1a610
`Convert`XtDirectConvert`converter = &CvtStringToInt() at 0x1a610
`Convert`XtDirectConvert`p->from.size = 4
`Convert`XtDirectConvert`from->size = 108048
`Convert`XtDirectConvert`p->num_args = 0
`Convert`XtDirectConvert`num_args = 0

(dbx) cont
signal BUS (bus error) in XtDirectConvert at line 270 in file "Convert.c"

===================================

  266		if ((p->hash == hash)
  267		 && (p->converter == converter)
  268		 && (p->from.size == from->size)
  269		 && (! XtBCmp(p->from.addr, from->addr, from->size))
  270		 && (p->num_args == num_args)) {
  271		    /* Are all args the same data ? */
  272		    for (i = 0; i < num_args; i++) {
  273			if (   p->args[i].size != args[i].size

	The only other puzzling thing to me is on line 269 of the 'if'
statement in XtDirectConvert, what is XtBCmp()?  Is it a macro? If it is a
module, function, or procedure I can't find it.
	If someone can help solve this I would greatly appreciate it.  Thanks.

				Kral Ferch
				Texas Instruments
				kral@skvax1.ti.com


-------------------
Kral Ferch	    Texas Instruments, Inc.
ARPANET:	    kral@skvax1.ti.com

jim@expo.lcs.mit.EDU (Jim Fulton) (10/07/88)

The problem probably arised from the XtBCopy, XtBZero, and XtBCmp macros in
lib/Xt/IntrinsicI.h.  If you change them as follows, things should work much
better (i.e. I chased this same problem down with someone else):

*** R2/IntrinsicI.h	Fri Feb 26 12:41:24 1988
--- IntrinsicI.h	Fri Oct  7 11:27:14 1988
***************
*** 40,67 ****
  
  extern void bcopy();
  #define XtBCopy(src, dst, size)				    \
!     if (size == sizeof(int) &&				    \
! 	!((unsigned int) src & 0x3) &&			    \
! 	!((unsigned int) dst & 0x3))			    \
! 	*((int *) (dst)) = *((int *) (src));		    \
!     else if (size == sizeof(char))			    \
! 	*((char *) (dst)) = *((char *) (src));		    \
!     else						    \
! 	bcopy((char *) (src), (char *) (dst), (int) (size));
  
  extern void bzero();
  #define XtBZero(dst, size)				    \
!     if (size == sizeof(int))				    \
! 	*((int *) (dst)) = 0;				    \
!     else						    \
! 	bzero((char *) (dst), (int) (size));
  
  extern int bcmp();
  #define XtBCmp(b1, b2, size)				    \
!     (size == sizeof(int) ?				    \
! 	*((int *) (b1)) != *((int *) (b2))		    \
!     :   bcmp((char *) (b1), (char *) (b2), (int) (size))    \
!     )
  
  
  
--- 40,54 ----
  
  extern void bcopy();
  #define XtBCopy(src, dst, size)				    \
! 	bcopy((char *) (src), (char *) (dst), (int) (size))
  
  extern void bzero();
  #define XtBZero(dst, size)				    \
! 	bzero((char *) (dst), (int) (size))
  
  extern int bcmp();
  #define XtBCmp(b1, b2, size)				    \
! 	bcmp((char *) (b1), (char *) (b2), (int) (size))