summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamey Sharp <jamey@minilop.net>2006-03-02 15:35:31 -0800
committerJamey Sharp <jamey@minilop.net>2006-03-02 15:35:31 -0800
commit5e115e2441ed32f5fa495370b36b01c03bbff66d (patch)
treecf1695c201016f291ab8e9ca717796871660a0ce
parented823bf65192a72f8c3060698c9bded9f77d49c2 (diff)
API/ABI change: XCBSendRequest callers must pad to 4-byte boundaries now. When not in RAW mode, a null pointer for iov_base is replaced by up to 3 padding bytes.
-rw-r--r--configure.ac1
-rw-r--r--src/c-client.xsl12
-rw-r--r--src/xcb_out.c70
3 files changed, 29 insertions, 54 deletions
diff --git a/configure.ac b/configure.ac
index a07a89e..5e4405c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,6 @@ AC_MSG_RESULT($XCBPROTO_XCBINCLUDEDIR)
AC_SUBST(XCBPROTO_XCBINCLUDEDIR)
AC_HEADER_STDC
-AC_FUNC_ALLOCA
AC_SEARCH_LIBS(gethostbyname, nsl)
AC_SEARCH_LIBS(connect, socket)
diff --git a/src/c-client.xsl b/src/c-client.xsl
index 3ab2889..bee7275 100644
--- a/src/c-client.xsl
+++ b/src/c-client.xsl
@@ -567,7 +567,7 @@ authorization from the authors.
<xsl:variable name="struct"
select="$pass1/xcb/struct[@name=current()/@ref]" />
- <xsl:variable name="num-parts" select="1+count($struct/list)" />
+ <xsl:variable name="num-parts" select="1+count($struct/list)*2" />
<l>static const XCBProtocolRequest xcb_req = {</l>
<indent>
@@ -586,7 +586,7 @@ authorization from the authors.
<l>};</l>
<l />
- <l>struct iovec xcb_parts[<xsl:value-of select="$num-parts" />];</l>
+ <l>struct iovec xcb_parts[<xsl:value-of select="$num-parts+2" />];</l>
<l><xsl:value-of select="../@type" /> xcb_ret;</l>
<l><xsl:value-of select="@ref" /> xcb_out;</l>
@@ -598,17 +598,21 @@ authorization from the authors.
<l />
<l>xcb_parts[0].iov_base = &amp;xcb_out;</l>
<l>xcb_parts[0].iov_len = sizeof(xcb_out);</l>
+ <l>xcb_parts[1].iov_base = 0;</l>
+ <l>xcb_parts[1].iov_len = -xcb_parts[0].iov_len &amp; 3;</l>
<xsl:for-each select="$struct/list">
- <l>xcb_parts[<xsl:number />].iov_base = (void *) <!--
+ <l>xcb_parts[<xsl:number /> * 2].iov_base = (void *) <!--
--><xsl:value-of select="@name" />;</l>
- <l>xcb_parts[<xsl:number />].iov_len = <!--
+ <l>xcb_parts[<xsl:number /> * 2].iov_len = <!--
--><xsl:apply-templates mode="output-expression" /><!--
--><xsl:if test="not(@type = 'void')">
<xsl:text> * sizeof(</xsl:text>
<xsl:value-of select="@type" />
<xsl:text>)</xsl:text>
</xsl:if>;</l>
+ <l>xcb_parts[<xsl:number /> * 2 + 1].iov_base = 0;</l>
+ <l>xcb_parts[<xsl:number /> * 2 + 1].iov_len = -xcb_parts[<xsl:number /> * 2].iov_len &amp; 3;</l>
</xsl:for-each>
<l>XCBSendRequest(c, &amp;xcb_ret.sequence, <!--
diff --git a/src/xcb_out.c b/src/xcb_out.c
index 42050f5..054a2ae 100644
--- a/src/xcb_out.c
+++ b/src/xcb_out.c
@@ -31,16 +31,6 @@
#include <string.h>
#include <errno.h>
-#ifndef __GNUC__
-# if HAVE_ALLOCA_H
-# include <alloca.h>
-# else
-# ifdef _AIX
- #pragma alloca
-# endif
-# endif
-#endif
-
#include "xcb.h"
#include "xcbext.h"
#include "xcbint.h"
@@ -81,12 +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;
CARD32 prefix[2];
- struct iovec *padded;
- int padlen = 0;
+ int veclen = req->count;
enum workarounds workaround = WORKAROUND_NONE;
assert(c != 0);
@@ -94,18 +81,12 @@ 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 + 2) * 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;
/* set the major opcode, and the minor opcode for extensions */
if(req->ext)
{
@@ -120,7 +101,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)
{
@@ -135,29 +125,18 @@ int XCBSendRequest(XCBConnection *c, unsigned int *request, int flags, struct io
((CARD16 *) vector[0].iov_base)[1] = shortlen;
if(!shortlen)
{
- padded[0].iov_base = prefix;
- padded[0].iov_len = sizeof(prefix);
+ 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[0].iov_base = ((char *) vector[0].iov_base) + sizeof(CARD32);
- vector[0].iov_len -= sizeof(CARD32);
- padlen = 1;
+ 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;
}