--- xc/lib/X11/QuColors.c.orig 2004-10-30 13:34:19.000000000 +0900 +++ xc/lib/X11/QuColors.c 2004-10-31 03:16:32.000000000 +0900 @@ -36,40 +36,62 @@ XColor *defs; /* RETURN */ int ncolors; { - register int i; - xrgb *color; - xQueryColorsReply rep; - long nbytes; - register xQueryColorsReq *req; + long max; + XColor *next; + unsigned int rest; LockDisplay(dpy); - GetReq(QueryColors, req); - req->cmap = cmap; - req->length += ncolors; /* each pixel is a CARD32 */ - - for (i = 0; i < ncolors; i++) - Data32 (dpy, (long *)&defs[i].pixel, 4L); - /* XXX this isn't very efficient */ - - if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) { - if ((color = (xrgb *) - Xmalloc((unsigned) (nbytes = (long) ncolors * SIZEOF(xrgb))))) { - - _XRead(dpy, (char *) color, nbytes); - - for (i = 0; i < ncolors; i++) { - register XColor *def = &defs[i]; - register xrgb *rgb = &color[i]; - def->red = rgb->red; - def->green = rgb->green; - def->blue = rgb->blue; - def->flags = DoRed | DoGreen | DoBlue; + max = dpy->max_request_size - (sizeof (xQueryColorsReq) >> 2); + if (max > 65535) + max = 65535; + + next = defs; + rest = ncolors; + while (rest) { + register unsigned int i; + xrgb *color; + xQueryColorsReply rep; + long nbytes; + register xQueryColorsReq *req; + unsigned int npixels; + + GetReq(QueryColors, req); + + req->cmap = cmap; + if (rest > max) + npixels = max; + else + npixels = rest; + req->length += npixels; + rest -= npixels; + + for (i = 0; i < npixels; i++) + Data32 (dpy, (long *)&next[i].pixel, 4L); + /* XXX this isn't very efficient */ + + if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) { + if ((color = (xrgb *) + Xmalloc((unsigned) (nbytes = (long) npixels * SIZEOF(xrgb))))) { + + _XRead(dpy, (char *) color, nbytes); + + for (i = 0; i < npixels; i++) { + register XColor *def = &next[i]; + register xrgb *rgb = &color[i]; + def->red = rgb->red; + def->green = rgb->green; + def->blue = rgb->blue; + def->flags = DoRed | DoGreen | DoBlue; + } + Xfree((char *)color); } - Xfree((char *)color); + else _XEatData(dpy, (unsigned long) nbytes); + + next += npixels; } - else _XEatData(dpy, (unsigned long) nbytes); } + UnlockDisplay(dpy); SyncHandle(); return 1;