X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_out.c;h=b20156538c945b623cce99e2243ab98e4ca3ef92;hb=255c21b17f61147388bab6e1d42623a008a4a8d2;hp=b89af56bf6526ee4b79df367baee7cda216ae841;hpb=8f991bdd389f6c419cb18cdaea966304529de165;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_out.c b/src/xcb_out.c index b89af56..b201565 100644 --- a/src/xcb_out.c +++ b/src/xcb_out.c @@ -31,16 +31,6 @@ #include #include -#ifndef __GNUC__ -# if HAVE_ALLOCA_H -# include -# else -# ifdef _AIX - #pragma alloca -# endif -# endif -#endif - #include "xcb.h" #include "xcbext.h" #include "xcbint.h" @@ -81,11 +71,9 @@ CARD32 XCBGetMaximumRequestLength(XCBConnection *c) int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct iovec *vector, const XCBProtocolRequest *req) { - static const char pad[3]; int ret; - int i; - struct iovec *padded; - int padlen = 0; + CARD32 prefix[2]; + int veclen = req->count; enum workarounds workaround = WORKAROUND_NONE; assert(c != 0); @@ -93,18 +81,13 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct io assert(vector != 0); assert(req->count > 0); - padded = -#ifdef HAVE_ALLOCA - alloca -#else - malloc -#endif - ((req->count * 2 + 3) * sizeof(struct iovec)); - if(!(flags & XCB_REQUEST_RAW)) { + static const char pad[3]; + int i; CARD16 shortlen = 0; - CARD32 longlen = 0; + size_t longlen = 0; + assert(vector[0].iov_len >= 4); /* set the major opcode, and the minor opcode for extensions */ if(req->ext) { @@ -119,7 +102,16 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct io /* put together the length field, possibly using BIGREQUESTS */ for(i = 0; i < req->count; ++i) - longlen += (vector[i].iov_len + 3) >> 2; + { + longlen += vector[i].iov_len; + if(!vector[i].iov_base) + { + vector[i].iov_base = (caddr_t) pad; + assert(vector[i].iov_len <= sizeof(pad)); + } + } + assert((longlen & 3) == 0); + longlen >>= 2; if(longlen <= c->setup->maximum_request_length) { @@ -134,30 +126,17 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct io ((CARD16 *) vector[0].iov_base)[1] = shortlen; if(!shortlen) { - padded[0].iov_base = vector[0].iov_base; - padded[0].iov_len = sizeof(CARD32); - vector[0].iov_base = ((char *) vector[0].iov_base) + sizeof(CARD32); - vector[0].iov_len -= sizeof(CARD32); - ++longlen; - padded[1].iov_base = &longlen; - padded[1].iov_len = sizeof(CARD32); - padlen = 2; + --vector, ++veclen; + vector[0].iov_base = prefix; + vector[0].iov_len = sizeof(prefix); + prefix[0] = ((CARD32 *) vector[0].iov_base)[0]; + prefix[1] = ++longlen; + vector[1].iov_base = ((char *) vector[1].iov_base) + sizeof(CARD32); + vector[1].iov_len -= sizeof(CARD32); } } flags &= ~XCB_REQUEST_RAW; - for(i = 0; i < req->count; ++i) - { - if(!vector[i].iov_len) - continue; - padded[padlen].iov_base = vector[i].iov_base; - padded[padlen++].iov_len = vector[i].iov_len; - if(!XCB_PAD(vector[i].iov_len)) - continue; - padded[padlen].iov_base = (caddr_t) pad; - padded[padlen++].iov_len = XCB_PAD(vector[i].iov_len); - } - /* do we need to work around the X server bug described in glx.xml? */ if(req->ext && !req->isvoid && strcmp(req->ext->name, "GLX") && ((req->opcode == 17 && ((CARD32 *) vector[0].iov_base)[0] == 0x10004) || @@ -169,9 +148,6 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct io if(req->isvoid && !force_sequence_wrap(c)) { pthread_mutex_unlock(&c->iolock); -#ifndef HAVE_ALLOCA - free(padded); -#endif return -1; } @@ -183,12 +159,8 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct io _xcb_in_expect_reply(c, *request, workaround, flags); - ret = _xcb_out_write_block(c, padded, padlen); + ret = _xcb_out_write_block(c, vector, veclen); pthread_mutex_unlock(&c->iolock); -#ifndef HAVE_ALLOCA - free(padded); -#endif - return ret; } @@ -264,12 +236,14 @@ int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count) { memcpy(c->out.queue + c->out.queue_len, vector[0].iov_base, vector[0].iov_len); c->out.queue_len += vector[0].iov_len; + vector[0].iov_base = (char *) vector[0].iov_base + vector[0].iov_len; + vector[0].iov_len = 0; ++vector, --count; } if(!count) return 1; - memmove(vector + 1, vector, count++ * sizeof(struct iovec)); + --vector, ++count; vector[0].iov_base = c->out.queue; vector[0].iov_len = c->out.queue_len; c->out.queue_len = 0;