[PATCH libXi 7/7] Refactor XGetExtensionVersion.

Peter Hutterer peter.hutterer at who-t.net
Sun Nov 2 21:29:10 PST 2014


On Sat, Nov 01, 2014 at 08:00:57PM +0200, Michal Srb wrote:
> _XiGetExtensionVersion was called from XGetExtensionVersion and from
> _XiCheckExtInit. When called from _XiCheckExtInit, nothing accounted for the
> fact that it can return ((XExtensionVersion *) NoSuchExtension) in case of
> error. Also it recursively calls _XiCheckExtInit potentionally causing multiple
> unlocks if _XiCheckExtInit fails.
> -> Remove it and call directly _XiGetExtensionVersionRequest and only call
> _XiCheckExtInit only from XGetExtensionVersion.
> 
> Signed-off-by: Michal Srb <msrb at suse.com>

Thanks, pushed except for patch 5, please send me an updated version of that
and I'll push that one too

Cheers,
   Peter

> ---
>  src/XExtInt.c  |  2 +-
>  src/XGetVers.c | 28 +++++++++++-----------------
>  src/XIint.h    |  1 -
>  3 files changed, 12 insertions(+), 19 deletions(-)
> 
> diff --git a/src/XExtInt.c b/src/XExtInt.c
> index d3c6b7c..672d69a 100644
> --- a/src/XExtInt.c
> +++ b/src/XExtInt.c
> @@ -380,7 +380,7 @@ _XiCheckExtInit(
>  	    return (-1);
>  	}
>  	((XInputData *) info->data)->vers =
> -	    _XiGetExtensionVersion(dpy, "XInputExtension", info);
> +	    _XiGetExtensionVersionRequest(dpy, "XInputExtension", info->codes->major_opcode);
>      }
>  
>      if (_XiCheckVersion(info, version_index) < 0) {
> diff --git a/src/XGetVers.c b/src/XGetVers.c
> index 0751b98..f7e22e6 100644
> --- a/src/XGetVers.c
> +++ b/src/XGetVers.c
> @@ -68,12 +68,16 @@ XGetExtensionVersion(register Display * dpy, _Xconst char *name)
>      XExtDisplayInfo *info = XInput_find_display(dpy);
>  
>      LockDisplay(dpy);
> -    ext = _XiGetExtensionVersion(dpy, name, info);
> -    if (ext != (XExtensionVersion *) NoSuchExtension) {
> -	UnlockDisplay(dpy);
> -	SyncHandle();
> -    }
> -    return (ext);
> +
> +    if (_XiCheckExtInit(dpy, Dont_Check, info) == -1)
> +        return NULL;
> +
> +    ext = _XiGetExtensionVersionRequest(dpy, name, info->codes->major_opcode);
> +
> +    UnlockDisplay(dpy);
> +    SyncHandle();
> +
> +    return ext;
>  }
>  
>  _X_HIDDEN XExtensionVersion*
> @@ -91,7 +95,7 @@ _XiGetExtensionVersionRequest(Display *dpy, _Xconst char *name, int xi_opcode)
>      _XSend(dpy, name, (long)req->nbytes);
>  
>      if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
> -	return (XExtensionVersion *) NULL;
> +	return NULL;
>      }
>  
>      ext = (XExtensionVersion *) Xmalloc(sizeof(XExtensionVersion));
> @@ -105,13 +109,3 @@ _XiGetExtensionVersionRequest(Display *dpy, _Xconst char *name, int xi_opcode)
>  
>      return ext;
>  }
> -
> -_X_HIDDEN XExtensionVersion *
> -_XiGetExtensionVersion(register Display * dpy, _Xconst char *name,
> -                       XExtDisplayInfo *info)
> -{
> -    if (_XiCheckExtInit(dpy, Dont_Check, info) == -1)
> -	return ((XExtensionVersion *) NoSuchExtension);
> -
> -    return _XiGetExtensionVersionRequest(dpy, name, info->codes->major_opcode);
> -}
> diff --git a/src/XIint.h b/src/XIint.h
> index 99f3652..9479a79 100644
> --- a/src/XIint.h
> +++ b/src/XIint.h
> @@ -29,7 +29,6 @@ extern XExtDisplayInfo *XInput_find_display(Display *);
>  extern int _XiCheckExtInit(Display *, int, XExtDisplayInfo *);
>  extern int _XiCheckVersion(XExtDisplayInfo *info, int version_index);
>  
> -extern XExtensionVersion *_XiGetExtensionVersion(Display *, _Xconst char *, XExtDisplayInfo *);
>  extern XExtensionVersion* _XiGetExtensionVersionRequest(Display *dpy, _Xconst char *name, int xi_opcode);
>  extern Status _xiQueryVersion(Display *dpy, int*, int*, XExtDisplayInfo *);
>  
> -- 
> 1.8.4.5
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list