1 From 4a060f993bf676cf21ad9784e010f54134da7b40 Mon Sep 17 00:00:00 2001
2 From: Peter Hutterer <peter.hutterer@who-t.net>
3 Date: Mon, 17 Oct 2011 09:45:15 +1000
4 Subject: [PATCH] Add _XGetRequest as substitute for GetReq/GetReqExtra
6 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
7 Reviewed-by: Jamey Sharp <jamey@minilop.net>
9 include/X11/Xlibint.h | 49 ++++++++++++++++---------------------------------
10 src/XlibInt.c | 31 +++++++++++++++++++++++++++++++
11 2 files changed, 47 insertions(+), 33 deletions(-)
13 Upstream-Status: Backport
15 diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
16 index 2ce356d..43d1f2a 100644
17 --- a/include/X11/Xlibint.h
18 +++ b/include/X11/Xlibint.h
19 @@ -420,6 +420,18 @@ extern LockInfoPtr _Xglobal_lock;
24 + * Return a len-sized request buffer for the request type. This function may
25 + * flush the output queue.
27 + * @param dpy The display connection
28 + * @param type The request type
29 + * @param len Length of the request in bytes
31 + * @returns A pointer to the request buffer with a few default values
34 +extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
37 * GetReq - Get the next available X request packet in the buffer and
38 @@ -432,25 +444,10 @@ extern LockInfoPtr _Xglobal_lock;
40 #if !defined(UNIXCPP) || defined(ANSICPP)
41 #define GetReq(name, req) \
43 - if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
45 - req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
46 - req->reqType = X_##name;\
47 - req->length = (SIZEOF(x##name##Req))>>2;\
48 - dpy->bufptr += SIZEOF(x##name##Req);\
51 + req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req))
52 #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */
53 #define GetReq(name, req) \
55 - if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
57 - req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
58 - req->reqType = X_/**/name;\
59 - req->length = (SIZEOF(x/**/name/**/Req))>>2;\
60 - dpy->bufptr += SIZEOF(x/**/name/**/Req);\
62 + req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req))
65 /* GetReqExtra is the same as GetReq, but allocates "n" additional
66 @@ -458,24 +455,10 @@ extern LockInfoPtr _Xglobal_lock;
68 #if !defined(UNIXCPP) || defined(ANSICPP)
69 #define GetReqExtra(name, n, req) \
71 - if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\
73 - req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
74 - req->reqType = X_##name;\
75 - req->length = (SIZEOF(x##name##Req) + n)>>2;\
76 - dpy->bufptr += SIZEOF(x##name##Req) + n;\
78 + req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req) + n)
80 #define GetReqExtra(name, n, req) \
82 - if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\
84 - req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
85 - req->reqType = X_/**/name;\
86 - req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\
87 - dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\
89 + req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req) + n)
93 diff --git a/src/XlibInt.c b/src/XlibInt.c
94 index 3db151e..a8f5d08 100644
97 @@ -1956,6 +1956,37 @@ Screen *_XScreenOfWindow(Display *dpy, Window w)
102 + * WARNING: This implementation's pre-conditions and post-conditions
103 + * must remain compatible with the old macro-based implementations of
104 + * GetReq, GetReqExtra, GetResReq, and GetEmptyReq. The portions of the
105 + * Display structure affected by those macros are part of libX11's
108 +void *_XGetRequest(Display *dpy, CARD8 type, size_t len)
114 + if (dpy->bufptr + len > dpy->bufmax)
119 + "Xlib: request %d length %zd not a multiple of 4.\n",
122 + dpy->last_req = dpy->bufptr;
124 + req = (xReq*)dpy->bufptr;
125 + req->reqType = type;
126 + req->length = len / 4;
127 + dpy->bufptr += len;