[libX11] include: Add GetReqSized() for request buffers of specific size

Submitted by Peter Hutterer on Oct. 14, 2011, 12:17 p.m.

Details

Message ID 20111014051745.GA2029@barra.bne.redhat.com
State Deferred, archived
Headers show

Not browsing as part of any series.

Commit Message

Peter Hutterer Oct. 14, 2011, 12:17 p.m.
Some XI2 requests change in size over different versions and libXi would
need to hack around GetReq and GetReqExtra. Add a new GetReqSized so the
library can explicitly specify the size of the request in 4-byte units.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
---
Instead of hacking around in libXi with GetReq, let's just add a new macro.

 include/X11/Xlibint.h |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

Patch hide | download patch | download mbox

diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
index 2ce356d..083498f 100644
--- a/include/X11/Xlibint.h
+++ b/include/X11/Xlibint.h
@@ -478,6 +478,31 @@  extern LockInfoPtr _Xglobal_lock;
 	dpy->request++
 #endif
 
+/* GetReqSized is the same as GetReq but allows the caller to specify the
+ * size in 4-byte units */
+#if !defined(UNIXCPP) || defined(ANSICPP)
+#define GetReqSized(name, sz, req) \
+        WORD64ALIGN\
+	if ((dpy->bufptr + sz * 4) > dpy->bufmax)\
+		_XFlush(dpy);\
+	req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
+	req->reqType = X_##name;\
+	req->length = sz; \
+	dpy->bufptr += sz * 4;\
+	dpy->request++
+#else
+#define GetReqSized(name, sz, req) \
+        WORD64ALIGN\
+	if ((dpy->bufptr + sz * 4) > dpy->bufmax)\
+		_XFlush(dpy);\
+	req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
+	req->reqType = X_/**/name;\
+	req->length = sz; \
+	dpy->bufptr += sz * 4; \
+	dpy->request++
+#endif
+
+
 
 /*
  * GetResReq is for those requests that have a resource ID

Comments

On 10/13/2011 10:17 PM, Peter Hutterer wrote:
> Some XI2 requests change in size over different versions and libXi would
> need to hack around GetReq and GetReqExtra. Add a new GetReqSized so the
> library can explicitly specify the size of the request in 4-byte units.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>

Yes, this will help with XIAllowEvents in XI 2.2.

Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
The GetReq family of macros is so evil. I'm not going to go so far as
to NAK this patch or anything, but please consider whether you can
implement this as a proper function or something. Perhaps:

void *XGetReq(CARD8 reqType, size_t sz);

(I think the other macros could be re-implemented on top of that
function, so long as the function continues to behave in a manner
compatible with code compiled using the current macros.)

Also, do you care about big-requests here? I can't remember how Xlib
handles that extension.

Jamey

On 10/14/11, Peter Hutterer <peter.hutterer@who-t.net> wrote:
> Some XI2 requests change in size over different versions and libXi would
> need to hack around GetReq and GetReqExtra. Add a new GetReqSized so the
> library can explicitly specify the size of the request in 4-byte units.
>
> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
> ---
> Instead of hacking around in libXi with GetReq, let's just add a new macro.
>
>  include/X11/Xlibint.h |   25 +++++++++++++++++++++++++
>  1 files changed, 25 insertions(+), 0 deletions(-)
>
> diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
> index 2ce356d..083498f 100644
> --- a/include/X11/Xlibint.h
> +++ b/include/X11/Xlibint.h
> @@ -478,6 +478,31 @@ extern LockInfoPtr _Xglobal_lock;
>  	dpy->request++
>  #endif
>
> +/* GetReqSized is the same as GetReq but allows the caller to specify the
> + * size in 4-byte units */
> +#if !defined(UNIXCPP) || defined(ANSICPP)
> +#define GetReqSized(name, sz, req) \
> +        WORD64ALIGN\
> +	if ((dpy->bufptr + sz * 4) > dpy->bufmax)\
> +		_XFlush(dpy);\
> +	req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
> +	req->reqType = X_##name;\
> +	req->length = sz; \
> +	dpy->bufptr += sz * 4;\
> +	dpy->request++
> +#else
> +#define GetReqSized(name, sz, req) \
> +        WORD64ALIGN\
> +	if ((dpy->bufptr + sz * 4) > dpy->bufmax)\
> +		_XFlush(dpy);\
> +	req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
> +	req->reqType = X_/**/name;\
> +	req->length = sz; \
> +	dpy->bufptr += sz * 4; \
> +	dpy->request++
> +#endif
> +
> +
>
>  /*
>   * GetResReq is for those requests that have a resource ID
> --
> 1.7.6.4
>
> _______________________________________________
> xorg-devel@lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
On Fri, Oct 14, 2011 at 06:42:02PM +0200, Jamey Sharp wrote:
> The GetReq family of macros is so evil. I'm not going to go so far as
> to NAK this patch or anything, but please consider whether you can
> implement this as a proper function or something. Perhaps:
> 
> void *XGetReq(CARD8 reqType, size_t sz);
> 
> (I think the other macros could be re-implemented on top of that
> function, so long as the function continues to behave in a manner
> compatible with code compiled using the current macros.)
> 
> Also, do you care about big-requests here? I can't remember how Xlib
> handles that extension.

fwiw, GetReqSized is more-or-less a copy of GetReqExtra with one parameter
replaced. And GetReqExtra in turn is a copy of GetReq. From a quick glance
neither of them handle big-req directly.

I'll have a look at getting this to a function instead of a macro.

Cheers,
  Peter

> On 10/14/11, Peter Hutterer <peter.hutterer@who-t.net> wrote:
> > Some XI2 requests change in size over different versions and libXi would
> > need to hack around GetReq and GetReqExtra. Add a new GetReqSized so the
> > library can explicitly specify the size of the request in 4-byte units.
> >
> > Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
> > ---
> > Instead of hacking around in libXi with GetReq, let's just add a new macro.
> >
> >  include/X11/Xlibint.h |   25 +++++++++++++++++++++++++
> >  1 files changed, 25 insertions(+), 0 deletions(-)
> >
> > diff --git a/include/X11/Xlibint.h b/include/X11/Xlibint.h
> > index 2ce356d..083498f 100644
> > --- a/include/X11/Xlibint.h
> > +++ b/include/X11/Xlibint.h
> > @@ -478,6 +478,31 @@ extern LockInfoPtr _Xglobal_lock;
> >  	dpy->request++
> >  #endif
> >
> > +/* GetReqSized is the same as GetReq but allows the caller to specify the
> > + * size in 4-byte units */
> > +#if !defined(UNIXCPP) || defined(ANSICPP)
> > +#define GetReqSized(name, sz, req) \
> > +        WORD64ALIGN\
> > +	if ((dpy->bufptr + sz * 4) > dpy->bufmax)\
> > +		_XFlush(dpy);\
> > +	req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
> > +	req->reqType = X_##name;\
> > +	req->length = sz; \
> > +	dpy->bufptr += sz * 4;\
> > +	dpy->request++
> > +#else
> > +#define GetReqSized(name, sz, req) \
> > +        WORD64ALIGN\
> > +	if ((dpy->bufptr + sz * 4) > dpy->bufmax)\
> > +		_XFlush(dpy);\
> > +	req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
> > +	req->reqType = X_/**/name;\
> > +	req->length = sz; \
> > +	dpy->bufptr += sz * 4; \
> > +	dpy->request++
> > +#endif
> > +
> > +
> >
> >  /*
> >   * GetResReq is for those requests that have a resource ID
> > --
> > 1.7.6.4
> >
> > _______________________________________________
> > xorg-devel@lists.x.org: X.Org development
> > Archives: http://lists.x.org/archives/xorg-devel
> > Info: http://lists.x.org/mailman/listinfo/xorg-devel
> >
On Mon, Oct 17, 2011 at 09:19:02AM +1000, Peter Hutterer wrote:
> On Fri, Oct 14, 2011 at 06:42:02PM +0200, Jamey Sharp wrote:
> > The GetReq family of macros is so evil. I'm not going to go so far as
> > to NAK this patch or anything, but please consider whether you can
> > implement this as a proper function or something. Perhaps:
> > 
> > void *XGetReq(CARD8 reqType, size_t sz);
> > 
> > (I think the other macros could be re-implemented on top of that
> > function, so long as the function continues to behave in a manner
> > compatible with code compiled using the current macros.)
> > 
> > Also, do you care about big-requests here? I can't remember how Xlib
> > handles that extension.
> 
> fwiw, GetReqSized is more-or-less a copy of GetReqExtra with one parameter
> replaced. And GetReqExtra in turn is a copy of GetReq.

I certainly recognized the pattern. It's an awful pattern and I want it
to stop. :-)

> From a quick glance neither of them handle big-req directly.

If I had looked at the source, I'd have noticed that SetReqLen is
apparently the standard way to fix up a request to be a big-request,
after GetReq returns a standard one.

> I'll have a look at getting this to a function instead of a macro.

Thanks!

Jamey