Path: utzoo!attcan!uunet!husc6!bloom-beacon!ZERMATT.LCS.MIT.EDU!RWS
From: RWS@ZERMATT.LCS.MIT.EDU (Robert Scheifler)
Newsgroups: comp.windows.x
Subject: XlibInt.c bug revisited
Message-ID: <19880818121332.1.RWS@KILLINGTON.LCS.MIT.EDU>
Date: 18 Aug 88 12:13:00 GMT
References: <2765@amiga.UUCP>
Sender: daemon@bloom-beacon.MIT.EDU
Organization: The Internet
Lines: 115


    Date: 18 Aug 88 09:08:56 GMT
    From: oliveb!amiga!dale@AMES.ARC.NASA.GOV  (Dale Luck)

    Did anyone else try fixing the _XReadEvents bug that I found in
    the same way I tried?

No, we fixed it differently.  (The diff below has a few unrelated things
included.)  I know, I know, we did this a long time ago, and shame on us
for not having published it.

*** /tmp/,RCSt1a12252	Thu Aug 18 08:10:29 1988
--- lib/X/XlibInt.c	Thu Aug 18 08:10:36 1988
***************
*** 2,8 ****
  /* Copyright    Massachusetts Institute of Technology    1985, 1986, 1987 */
  
  #ifndef lint
! static char rcsid[] = "$Header: XlibInt.c,v 11.63 88/02/20 20:21:11 rws Exp $";
  #endif
  
  /*
--- 2,8 ----
  /* Copyright    Massachusetts Institute of Technology    1985, 1986, 1987 */
  
  #ifndef lint
! static char rcsid[] = "$Header: XlibInt.c,v 11.66 88/05/24 14:34:09 swick Exp $";
  #endif
  
  /*
***************
*** 99,105 ****
  	if (BytesReadable(dpy->fd, (char *) &pend) < 0)
  	    (*_XIOErrorFunction)(dpy);
  	if ((len = pend) < sizeof(xReply))
! 	    return(0);
  	else if (len > BUFSIZE)
  	    len = BUFSIZE;
  	len /= sizeof(xReply);
--- 99,105 ----
  	if (BytesReadable(dpy->fd, (char *) &pend) < 0)
  	    (*_XIOErrorFunction)(dpy);
  	if ((len = pend) < sizeof(xReply))
! 	    return(dpy->qlen);	/* _XFlush can enqueue events */
  	else if (len > BUFSIZE)
  	    len = BUFSIZE;
  	len /= sizeof(xReply);
***************
*** 115,121 ****
  }
  
  /* _XReadEvents - Flush the output queue,
!  * then read as many events as possible and enqueue them
   */
  _XReadEvents(dpy)
  	register Display *dpy;
--- 115,121 ----
  }
  
  /* _XReadEvents - Flush the output queue,
!  * then read as many events as possible (but at least 1) and enqueue them
   */
  _XReadEvents(dpy)
  	register Display *dpy;
***************
*** 124,131 ****
--- 124,134 ----
  	long pend_not_register; /* because can't "&" a register variable */
  	register long pend;
  	register xEvent *ev;
+ 	int qlen = dpy->qlen;
  
  	_XFlush (dpy);
+ 	if (qlen != dpy->qlen)
+ 	    return;
  	do {
  	    /* find out how much data can be read */
  	    if (BytesReadable(dpy->fd, (char *) &pend_not_register) < 0)
***************
*** 360,366 ****
      while (newseq < lastseq) {
  	newseq += 0x10000;
  	if (newseq > dpy->request) {
! 	    (void) fprintf(stderr, "sequence lost!\n");
  	    newseq -= 0x10000;
  	    break;
  	}
--- 363,372 ----
      while (newseq < lastseq) {
  	newseq += 0x10000;
  	if (newseq > dpy->request) {
! 	    (void) fprintf (stderr, 
! 	    "Xlib:  sequence lost (0x%lx > 0x%lx) in reply type 0x%x!\n",
! 	                           newseq, dpy->request, 
! 				   (unsigned int) rep->type);
  	    newseq -= 0x10000;
  	    break;
  	}
***************
*** 1011,1017 ****
      XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
  	mesg, BUFSIZ);
      (void) fprintf(stderr, mesg, dpy->request);
!     fputs("\n  ", stderr);
      if (event->error_code == BadImplementation) return 0;
      exit(1);
      /*NOTREACHED*/
--- 1017,1023 ----
      XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
  	mesg, BUFSIZ);
      (void) fprintf(stderr, mesg, dpy->request);
!     fputs("\n", stderr);
      if (event->error_code == BadImplementation) return 0;
      exit(1);
      /*NOTREACHED*/