[PATCH 05/12] Xi: add helper functions to alloc/free InputClientPtrs
Peter Hutterer
peter.hutterer at who-t.net
Tue Nov 8 19:08:37 PST 2011
On Mon, Nov 07, 2011 at 06:01:32PM -0800, Chase Douglas wrote:
> On 11/07/2011 01:39 PM, Peter Hutterer wrote:
> > Currently not needed since the InputClientRec is a self-contained struct. As
> > part of the touch rework that won't be the case in the future and a function
> > to allocate/free memory appropriately is required.
> >
> > Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> > ---
> > Xi/exevents.c | 23 ++++++++++++++++++-----
> > 1 files changed, 18 insertions(+), 5 deletions(-)
> >
> > diff --git a/Xi/exevents.c b/Xi/exevents.c
> > index 53db036..7f8e6db 100644
> > --- a/Xi/exevents.c
> > +++ b/Xi/exevents.c
> > @@ -1628,6 +1628,19 @@ SelectForWindow(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client,
> > return Success;
> > }
> >
> > +static void
> > +FreeInputClient(InputClientsPtr *other)
> > +{
> > + free((*other));
>
> I thought double parens has been taboo for quite some time now... why
> did you use one here?
copy/paste error, amended locally. thanks.
Cheers,
Peter
>
> > + *other = NULL;
> > +}
> > +
> > +static InputClientsPtr
> > +AllocInputClient(void)
> > +{
> > + return calloc(1, sizeof(InputClients));
> > +}
> > +
> > int
> > AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
> > {
> > @@ -1635,7 +1648,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
> >
> > if (!pWin->optional && !MakeWindowOptional(pWin))
> > return BadAlloc;
> > - others = calloc(1, sizeof(InputClients));
> > + others = AllocInputClient();
> > if (!others)
> > return BadAlloc;
> > if (!pWin->optional->inputMasks && !MakeInputMasks(pWin))
> > @@ -1649,7 +1662,7 @@ AddExtensionClient(WindowPtr pWin, ClientPtr client, Mask mask, int mskidx)
> > return Success;
> >
> > bail:
> > - free(others);
> > + FreeInputClient(&others);
> > return BadAlloc;
> > }
> >
> > @@ -1721,14 +1734,14 @@ InputClientGone(WindowPtr pWin, XID id)
> > if (other->resource == id) {
> > if (prev) {
> > prev->next = other->next;
> > - free(other);
> > + FreeInputClient(&other);
> > } else if (!(other->next)) {
> > if (ShouldFreeInputMasks(pWin, TRUE)) {
> > wOtherInputMasks(pWin)->inputClients = other->next;
> > free(wOtherInputMasks(pWin));
> > pWin->optional->inputMasks = (OtherInputMasks *) NULL;
> > CheckWindowOptionalNeed(pWin);
> > - free(other);
> > + FreeInputClient(&other);
> > } else {
> > other->resource = FakeClientID(0);
> > if (!AddResource(other->resource, RT_INPUTCLIENT,
> > @@ -1737,7 +1750,7 @@ InputClientGone(WindowPtr pWin, XID id)
> > }
> > } else {
> > wOtherInputMasks(pWin)->inputClients = other->next;
> > - free(other);
> > + FreeInputClient(&other);
> > }
> > RecalculateDeviceDeliverableEvents(pWin);
> > return Success;
>
More information about the xorg-devel
mailing list