X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fxcb_out.c;h=78ec8ca9cd70e59a5ff60d683a2c0ae72b2afc31;hb=87905f0579e749ac6d92843780af246160318eca;hp=145bddd7725c7151d7cc78f1c7ace1818872611f;hpb=f27166f49b9ef6bdcce78429bffc724d1e4fb360;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/xcb_out.c b/src/xcb_out.c index 145bddd..78ec8ca 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" @@ -79,15 +69,11 @@ CARD32 XCBGetMaximumRequestLength(XCBConnection *c) return c->out.maximum_request_length; } -int XCBSendRequest(XCBConnection *c, unsigned int *request, struct iovec *vector, const XCBProtocolRequest *req) +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; - CARD16 shortlen = 0; - CARD32 longlen = 0; + CARD32 prefix[2]; + int veclen = req->count; enum workarounds workaround = WORKAROUND_NONE; assert(c != 0); @@ -95,95 +81,87 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, struct iovec *vector assert(vector != 0); assert(req->count > 0); - /* set the major opcode, and the minor opcode for extensions */ - if(req->ext) + if(!(flags & XCB_REQUEST_RAW)) { - const XCBQueryExtensionRep *extension = XCBGetExtensionData(c, req->ext); - /* TODO: better error handling here, please! */ - assert(extension && extension->present); - ((CARD8 *) vector[0].iov_base)[0] = extension->major_opcode; - ((CARD8 *) vector[0].iov_base)[1] = req->opcode; - - /* do we need to work around the X server bug described in glx.xml? */ - if(strcmp(req->ext->name, "GLX") && - ((req->opcode == 17 && ((CARD32 *) vector[0].iov_base)[0] == 0x10004) || - req->opcode == 21)) - workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG; - } - else - ((CARD8 *) vector[0].iov_base)[0] = req->opcode; + static const char pad[3]; + int i; + CARD16 shortlen = 0; + size_t longlen = 0; + assert(vector[0].iov_len >= 4); + /* set the major opcode, and the minor opcode for extensions */ + if(req->ext) + { + const XCBQueryExtensionRep *extension = XCBGetExtensionData(c, req->ext); + /* TODO: better error handling here, please! */ + assert(extension && extension->present); + ((CARD8 *) vector[0].iov_base)[0] = extension->major_opcode; + ((CARD8 *) vector[0].iov_base)[1] = req->opcode; + } + else + ((CARD8 *) vector[0].iov_base)[0] = req->opcode; - /* put together the length field, possibly using BIGREQUESTS */ - for(i = 0; i < req->count; ++i) - longlen += (vector[i].iov_len + 3) >> 2; + /* put together the length field, possibly using BIGREQUESTS */ + for(i = 0; i < req->count; ++i) + { + 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) - { - if(longlen > XCBGetMaximumRequestLength(c)) + if(longlen <= c->setup->maximum_request_length) + { + /* we don't need BIGREQUESTS. */ + shortlen = longlen; + longlen = 0; + } + else if(longlen > XCBGetMaximumRequestLength(c)) return 0; /* server can't take this; maybe need BIGREQUESTS? */ - } - else - { - /* we don't need BIGREQUESTS. */ - shortlen = longlen; - longlen = 0; - } - padded = -#ifdef HAVE_ALLOCA - alloca -#else - malloc -#endif - ((req->count * 2 + 3) * sizeof(struct iovec)); - /* set the length field. */ - ((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; + /* set the length field. */ + ((CARD16 *) vector[0].iov_base)[1] = shortlen; + if(!shortlen) + { + memmove(vector + 1, vector, veclen++ * sizeof(*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) || + req->opcode == 21)) + workaround = WORKAROUND_GLX_GET_FB_CONFIGS_BUG; /* get a sequence number and arrange for delivery. */ pthread_mutex_lock(&c->iolock); if(req->isvoid && !force_sequence_wrap(c)) { pthread_mutex_unlock(&c->iolock); -#ifndef HAVE_ALLOCA - free(padded); -#endif return -1; } + /* wait for other writing threads to get out of my way. */ + while(c->out.writing) + pthread_cond_wait(&c->out.cond, &c->iolock); + *request = ++c->out.request; - if(!req->isvoid) - _xcb_in_expect_reply(c, *request, workaround); + _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; } @@ -254,8 +232,6 @@ int _xcb_out_write(XCBConnection *c) int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count) { - while(c->out.writing) - pthread_cond_wait(&c->out.cond, &c->iolock); assert(!c->out.vec && !c->out.vec_len); while(count && c->out.queue_len + vector[0].iov_len < sizeof(c->out.queue)) {