]> code.ossystems Code Review - openembedded-core.git/blob
aedb5c4366adf9de667289ca477dd38a1bc14c07
[openembedded-core.git] /
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
5
6 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
7 Reviewed-by: Jamey Sharp <jamey@minilop.net>
8 ---
9  include/X11/Xlibint.h |   49 ++++++++++++++++---------------------------------
10  src/XlibInt.c         |   31 +++++++++++++++++++++++++++++++
11  2 files changed, 47 insertions(+), 33 deletions(-)
12
13 Upstream-Status: Backport
14
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;
20  #define WORD64ALIGN
21  #endif /* WORD64 */
22  
23 +/**
24 + * Return a len-sized request buffer for the request type. This function may
25 + * flush the output queue.
26 + *
27 + * @param dpy The display connection
28 + * @param type The request type
29 + * @param len Length of the request in bytes
30 + *
31 + * @returns A pointer to the request buffer with a few default values
32 + * initialized.
33 + */
34 +extern void *_XGetRequest(Display *dpy, CARD8 type, size_t len);
35  
36  /*
37   * GetReq - Get the next available X request packet in the buffer and
38 @@ -432,25 +444,10 @@ extern LockInfoPtr _Xglobal_lock;
39  
40  #if !defined(UNIXCPP) || defined(ANSICPP)
41  #define GetReq(name, req) \
42 -        WORD64ALIGN\
43 -       if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
44 -               _XFlush(dpy);\
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);\
49 -       dpy->request++
50 -
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) \
54 -        WORD64ALIGN\
55 -       if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
56 -               _XFlush(dpy);\
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);\
61 -       dpy->request++
62 +       req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req))
63  #endif
64  
65  /* GetReqExtra is the same as GetReq, but allocates "n" additional
66 @@ -458,24 +455,10 @@ extern LockInfoPtr _Xglobal_lock;
67  
68  #if !defined(UNIXCPP) || defined(ANSICPP)
69  #define GetReqExtra(name, n, req) \
70 -        WORD64ALIGN\
71 -       if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\
72 -               _XFlush(dpy);\
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;\
77 -       dpy->request++
78 +       req = (x##name##Req *) _XGetRequest(dpy, X_##name, SIZEOF(x##name##Req) + n)
79  #else
80  #define GetReqExtra(name, n, req) \
81 -        WORD64ALIGN\
82 -       if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\
83 -               _XFlush(dpy);\
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;\
88 -       dpy->request++
89 +       req = (x/**/name/**/Req *) _XGetRequest(dpy, X_/**/name, SIZEOF(x/**/name/**/Req) + n)
90  #endif
91  
92  
93 diff --git a/src/XlibInt.c b/src/XlibInt.c
94 index 3db151e..a8f5d08 100644
95 --- a/src/XlibInt.c
96 +++ b/src/XlibInt.c
97 @@ -1956,6 +1956,37 @@ Screen *_XScreenOfWindow(Display *dpy, Window w)
98  }
99  
100  
101 +/*
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
106 + * ABI.
107 + */
108 +void *_XGetRequest(Display *dpy, CARD8 type, size_t len)
109 +{
110 +    xReq *req;
111 +
112 +    WORD64ALIGN
113 +
114 +    if (dpy->bufptr + len > dpy->bufmax)
115 +       _XFlush(dpy);
116 +
117 +    if (len % 4)
118 +       fprintf(stderr,
119 +               "Xlib: request %d length %zd not a multiple of 4.\n",
120 +               type, len);
121 +
122 +    dpy->last_req = dpy->bufptr;
123 +
124 +    req = (xReq*)dpy->bufptr;
125 +    req->reqType = type;
126 +    req->length = len / 4;
127 +    dpy->bufptr += len;
128 +    dpy->request++;
129 +    return req;
130 +}
131 +
132  #if defined(WIN32)
133  
134  /*
135 -- 
136 1.7.8.3
137