[PATCH 5/6] Return an appropriately-typed error from dixLookupResourceByType.

Jamey Sharp jamey at minilop.net
Sun Apr 25 03:35:37 PDT 2010


Rather than always returning BadValue, associate an error status like
BadWindow with a resource type like RT_WINDOW, and return the
appropriate one for the requested type.

This patch only touches the core protocol resource types. Others still
return BadValue and need to be mapped appropriately.

dixLookupResourceByType can now return BadImplementation, if the caller
asked for a resource type that has not been allocated in the server.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
---

As written, this patch relies on the C99 (or C89 with GNU extensions)
syntax for initializing arrays by index and structs by field name. Is
that OK in the server at this point?

 Xext/panoramiXprocs.c                |    2 +-
 Xext/saver.c                         |    4 --
 Xext/shape.c                         |    2 +-
 Xext/xtest.c                         |    2 +-
 Xi/exevents.c                        |    4 +-
 Xi/xichangecursor.c                  |    2 +-
 Xi/xipassivegrab.c                   |    2 +-
 composite/compext.c                  |    5 +--
 dix/cursor.c                         |    4 +-
 dix/dispatch.c                       |   46 +++++++++-------
 dix/dixfonts.c                       |    1 -
 dix/dixutils.c                       |    8 +--
 dix/events.c                         |    8 ++--
 dix/gc.c                             |    8 ++--
 dix/resource.c                       |   95 ++++++++++++++++++++++++----------
 dix/window.c                         |    8 ++--
 hw/xfree86/dixmods/extmod/xf86dga2.c |    4 +-
 render/picture.c                     |    1 -
 render/render.c                      |    2 +-
 xfixes/cursor.c                      |    9 +--
 xfixes/region.c                      |    6 +-
 21 files changed, 128 insertions(+), 95 deletions(-)

diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 6834efb..8b0aeee 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -464,7 +464,7 @@ int PanoramiXConfigureWindow(ClientPtr client)
     result = dixLookupResourceByType((pointer *)&pWin, stuff->window,
 				     RT_WINDOW, client, DixWriteAccess);
     if (result != Success)
-	return (result == BadValue) ? BadWindow : result;
+	return result;
 
     result = dixLookupResourceByType((pointer *)&win, stuff->window,
 				     XRT_WINDOW, client, DixWriteAccess);
diff --git a/Xext/saver.c b/Xext/saver.c
index aa2e614..0640131 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -1048,7 +1048,6 @@ ScreenSaverSetAttributes (ClientPtr client)
 		}
 	        else
 		{
-		    ret = (ret == BadValue) ? BadPixmap : ret;
 		    client->errorValue = pixID;
 		    goto PatchUp;
 		}
@@ -1086,7 +1085,6 @@ ScreenSaverSetAttributes (ClientPtr client)
 		}
     	        else
 		{
-		    ret = (ret == BadValue) ? BadPixmap : ret;
 		    client->errorValue = pixID;
 		    goto PatchUp;
 		}
@@ -1168,7 +1166,6 @@ ScreenSaverSetAttributes (ClientPtr client)
 				    client, DixUseAccess);
 	    if (ret != Success)
 	    {
-		ret = (ret == BadValue) ? BadColor : ret;
 		client->errorValue = cmap;
 		goto PatchUp;
 	    }
@@ -1192,7 +1189,6 @@ ScreenSaverSetAttributes (ClientPtr client)
 					RT_CURSOR, client, DixUseAccess);
 	    	if (ret != Success)
 	    	{
-		    ret = (ret == BadValue) ? BadCursor : ret;
 		    client->errorValue = cursorID;
 		    goto PatchUp;
 	    	}
diff --git a/Xext/shape.c b/Xext/shape.c
index cb4126b..7a1753f 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -415,7 +415,7 @@ ProcShapeMask (ClientPtr client)
 	rc = dixLookupResourceByType((pointer *)&pPixmap, stuff->src, RT_PIXMAP,
 			       client, DixReadAccess);
         if (rc != Success)
-	    return (rc == BadValue) ? BadPixmap : rc;
+	    return rc;
 	if (pPixmap->drawable.pScreen != pScreen ||
 	    pPixmap->drawable.depth != 1)
 	    return BadMatch;
diff --git a/Xext/xtest.c b/Xext/xtest.c
index a1aacc4..1ec1f75 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -153,7 +153,7 @@ ProcXTestCompareCursor(ClientPtr client)
         if (rc != Success)
         {
             client->errorValue = stuff->cursor;
-            return (rc == BadValue) ? BadCursor : rc;
+            return rc;
         }
     }
     rep.type = X_Reply;
diff --git a/Xi/exevents.c b/Xi/exevents.c
index e680f6f..bfd32df 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1460,7 +1460,7 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, DeviceIntPtr modifier_device,
 	if (rc != Success)
 	{
 	    client->errorValue = param->cursor;
-	    return (rc == BadValue) ? BadCursor : rc;
+	    return rc;
 	}
 	access_mode |= DixForceAccess;
     }
@@ -1558,7 +1558,7 @@ GrabWindow(ClientPtr client, DeviceIntPtr dev, int type,
 	if (rc != Success)
 	{
 	    client->errorValue = param->cursor;
-	    return (rc == BadValue) ? BadCursor : rc;
+	    return rc;
 	}
 	access_mode |= DixForceAccess;
     }
diff --git a/Xi/xichangecursor.c b/Xi/xichangecursor.c
index f071e84..e72cfac 100644
--- a/Xi/xichangecursor.c
+++ b/Xi/xichangecursor.c
@@ -103,7 +103,7 @@ int ProcXIChangeCursor(ClientPtr client)
 	rc = dixLookupResourceByType((pointer *)&pCursor, stuff->cursor,
 				     RT_CURSOR, client, DixUseAccess);
 	if (rc != Success)
-	    return (rc == BadValue) ? BadCursor : rc;
+	    return rc;
     }
 
     ChangeWindowDeviceCursor(pWin, pDev, pCursor);
diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 41a56b1..c0991b9 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -147,7 +147,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 	if (status != Success)
 	{
 	    client->errorValue = stuff->cursor;
-	    return (status == BadValue) ? BadCursor : status;
+	    return status;
 	}
     }
 
diff --git a/composite/compext.c b/composite/compext.c
index 17c4bae..04174aa 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -140,10 +140,7 @@ ProcCompositeQueryVersion (ClientPtr client)
 	int err;							\
 	err = dixLookupResourceByType((pointer *) &pWindow, wid,	\
 				      RT_WINDOW, client, mode);		\
-	if (err == BadValue) {						\
-	    client->errorValue = wid;					\
-	    return BadWindow;						\
-	} else if (err != Success) {					\
+	if (err != Success) {						\
 	    client->errorValue = wid;					\
 	    return err;							\
 	}								\
diff --git a/dix/cursor.c b/dix/cursor.c
index 5d9c8b0..c9701f8 100644
--- a/dix/cursor.c
+++ b/dix/cursor.c
@@ -316,14 +316,14 @@ AllocGlyphCursor(Font source, unsigned sourceChar, Font mask, unsigned maskChar,
     if (rc != Success)
     {
 	client->errorValue = source;
-	return (rc == BadValue) ? BadFont : rc;
+	return rc;
     }
     rc = dixLookupResourceByType((pointer *)&maskfont, mask, RT_FONT, client,
 				 DixUseAccess);
     if (rc != Success && mask != None)
     {
 	client->errorValue = mask;
-	return (rc == BadValue) ? BadFont : rc;
+	return rc;
     }
     if (sourcefont != maskfont)
 	pShare = (GlyphSharePtr)NULL;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index a2cffac..f896b92 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1274,7 +1274,7 @@ ProcCloseFont(ClientPtr client)
     else
     {
 	client->errorValue = stuff->id;
-        return (rc == BadValue) ? BadFont : rc;
+        return rc;
     }
 }
 
@@ -1487,7 +1487,7 @@ ProcFreePixmap(ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return (rc == BadValue) ? BadPixmap : rc;
+	return rc;
     }
 }
 
@@ -2462,7 +2462,7 @@ ProcFreeColormap(ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return (rc == BadValue) ? BadColor : rc;
+	return rc;
     }
 }
 
@@ -2491,7 +2491,7 @@ ProcCopyColormapAndFree(ClientPtr client)
     else
     {
 	client->errorValue = stuff->srcCmap;
-	return (rc == BadValue) ? BadColor : rc;
+	return rc;
     }
 }
 
@@ -2509,15 +2509,18 @@ ProcInstallColormap(ClientPtr client)
 	goto out;
 
     rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess);
-    if (rc != Success)
+    if (rc != Success) {
+	if (rc == BadValue)
+	    rc = BadColor;
 	goto out;
+    }
 
     (*(pcmp->pScreen->InstallColormap)) (pcmp);
 
     rc = client->noClientException;
 out:
     client->errorValue = stuff->id;
-    return (rc == BadValue) ? BadColor : rc;
+    return rc;
 }
 
 int
@@ -2534,8 +2537,11 @@ ProcUninstallColormap(ClientPtr client)
 	goto out;
 
     rc = XaceHook(XACE_SCREEN_ACCESS, client, pcmp->pScreen, DixSetAttrAccess);
-    if (rc != Success)
+    if (rc != Success) {
+	if (rc == BadValue)
+	    rc = BadColor;
 	goto out;
+    }
 
     if(pcmp->mid != pcmp->pScreen->defColormap)
 	(*(pcmp->pScreen->UninstallColormap)) (pcmp);
@@ -2543,7 +2549,7 @@ ProcUninstallColormap(ClientPtr client)
     rc = client->noClientException;
 out:
     client->errorValue = stuff->id;
-    return (rc == BadValue) ? BadColor : rc;
+    return rc;
 }
 
 int
@@ -2623,7 +2629,7 @@ ProcAllocColor (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2674,7 +2680,7 @@ ProcAllocNamedColor (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2741,7 +2747,7 @@ ProcAllocColorCells (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2806,7 +2812,7 @@ ProcAllocColorPlanes(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2841,7 +2847,7 @@ ProcFreeColors(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2875,7 +2881,7 @@ ProcStoreColors (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2909,7 +2915,7 @@ ProcStoreNamedColor (ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -2962,7 +2968,7 @@ ProcQueryColors(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 } 
 
@@ -3001,7 +3007,7 @@ ProcLookupColor(ClientPtr client)
     else
     {
         client->errorValue = stuff->cmap;
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
@@ -3027,7 +3033,7 @@ ProcCreateCursor (ClientPtr client)
 			   DixReadAccess);
     if (rc != Success) {
 	client->errorValue = stuff->source;
-	return (rc == BadValue) ? BadPixmap : rc;
+	return rc;
     }
 
     rc = dixLookupResourceByType((pointer *)&msk, stuff->mask, RT_PIXMAP, client,
@@ -3037,7 +3043,7 @@ ProcCreateCursor (ClientPtr client)
 	if (stuff->mask != None)
 	{
 	    client->errorValue = stuff->mask;
-	    return (rc == BadValue) ? BadPixmap : rc;
+	    return rc;
 	}
     }
     else if (  src->drawable.width != msk->drawable.width
@@ -3138,7 +3144,7 @@ ProcFreeCursor (ClientPtr client)
     else 
     {
 	client->errorValue = stuff->id;
-	return (rc == BadValue) ? BadCursor : rc;
+	return rc;
     }
 }
 
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 6dc8193..b5b5991 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1238,7 +1238,6 @@ doPolyText(ClientPtr client, PTclosurePtr c)
 					  client, DixReadAccess);
 	    if (err != Success)
 	    {
-		err = (err == BadValue) ? BadFont : err;
 		/* restore pFont and fid for step 4 (described below) */
 		pFont = oldpFont;
 		fid = oldfid;
diff --git a/dix/dixutils.c b/dix/dixutils.c
index d610836..da4036b 100644
--- a/dix/dixutils.c
+++ b/dix/dixutils.c
@@ -231,9 +231,7 @@ dixLookupWindow(WindowPtr *pWin, XID id, ClientPtr client, Mask access)
 int
 dixLookupGC(GCPtr *pGC, XID id, ClientPtr client, Mask access)
 {
-    int rc;
-    rc = dixLookupResourceByType((pointer *)pGC, id, RT_GC, client, access);
-    return (rc == BadValue) ? BadGC : rc;
+    return dixLookupResourceByType((pointer *)pGC, id, RT_GC, client, access);
 }
 
 int
@@ -243,10 +241,10 @@ dixLookupFontable(FontPtr *pFont, XID id, ClientPtr client, Mask access)
     GC *pGC;
     client->errorValue = id;		/* EITHER font or gc */
     rc = dixLookupResourceByType((pointer *) pFont, id, RT_FONT, client, access);
-    if (rc != BadValue)
+    if (rc != BadFont)
 	return rc;
     rc = dixLookupResourceByType((pointer *) &pGC, id, RT_GC, client, access);
-    if (rc == BadValue)
+    if (rc == BadGC)
 	return BadFont;
     if (rc == Success)
 	*pFont = pGC->font;
diff --git a/dix/events.c b/dix/events.c
index b26e28a..65c8680 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4709,7 +4709,7 @@ ProcChangeActivePointerGrab(ClientPtr client)
 	if (rc != Success)
 	{
 	    client->errorValue = stuff->cursor;
-	    return (rc == BadValue) ? BadCursor : rc;
+	    return rc;
 	}
     }
 
@@ -4832,7 +4832,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
 	if (rc != Success)
 	{
 	    client->errorValue = curs;
-	    return (rc == BadValue) ? BadCursor : rc;
+	    return rc;
 	}
 	access_mode |= DixForceAccess;
     }
@@ -5357,7 +5357,7 @@ ProcGrabButton(ClientPtr client)
 	if (rc != Success)
 	{
 	    client->errorValue = stuff->cursor;
-	    return (rc == BadValue) ? BadCursor : rc;
+	    return rc;
 	}
 	access_mode |= DixForceAccess;
     }
@@ -5620,7 +5620,7 @@ ProcRecolorCursor(ClientPtr client)
     if (rc != Success)
     {
 	client->errorValue = stuff->cursor;
-	return (rc == BadValue) ? BadCursor : rc;
+	return rc;
     }
 
     pCursor->foreRed = stuff->foreRed;
diff --git a/dix/gc.c b/dix/gc.c
index 6490165..e7e72c2 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -295,7 +295,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		else
 		{
 		    clientErrorValue = newpix;
-		    error = (rc == BadValue) ? BadPixmap : rc;
+		    error = rc;
 		}
 		break;
 	    }
@@ -331,7 +331,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		else
 		{
 		    clientErrorValue = newstipple;
-		    error = (rc == BadValue) ? BadPixmap : rc;
+		    error = rc;
 		}
 		break;
 	    }
@@ -366,7 +366,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 		else
 		{
 		    clientErrorValue = newfont;
-		    error = (rc == BadValue) ? BadFont : rc;
+		    error = rc;
 		}
 		break;
 	    }
@@ -425,7 +425,7 @@ dixChangeGC(ClientPtr client, GC *pGC, BITS32 mask, CARD32 *pC32, ChangeGCValPtr
 					       DixReadAccess);
 			if (rc != Success) {
 			    clientErrorValue = pid;
-			    error = (rc == BadValue) ? BadPixmap : rc;
+			    error = rc;
 			}
 		    }
 		}
diff --git a/dix/resource.c b/dix/resource.c
index 91d0cfb..6938569 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -183,7 +183,54 @@ RESTYPE lastResourceType;
 static RESTYPE lastResourceClass;
 RESTYPE TypeMask;
 
-static DeleteType *DeleteFuncs = (DeleteType *)NULL;
+struct ResourceType {
+    DeleteType deleteFunc;
+    int errorValue;
+};
+
+static struct ResourceType *resourceTypes;
+static const struct ResourceType predefTypes[] = {
+    [RT_NONE & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = (DeleteType)NoopDDA,
+	.errorValue = BadValue,
+    },
+    [RT_WINDOW & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = DeleteWindow,
+	.errorValue = BadWindow,
+    },
+    [RT_PIXMAP & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = dixDestroyPixmap,
+	.errorValue = BadPixmap,
+    },
+    [RT_GC & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = FreeGC,
+	.errorValue = BadGC,
+    },
+    [RT_FONT & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = CloseFont,
+	.errorValue = BadFont,
+    },
+    [RT_CURSOR & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = FreeCursor,
+	.errorValue = BadCursor,
+    },
+    [RT_COLORMAP & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = FreeColormap,
+	.errorValue = BadColor,
+    },
+    [RT_CMAPENTRY & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = FreeClientPixels,
+	.errorValue = BadColor,
+    },
+    [RT_OTHERCLIENT & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = OtherClientGone,
+	.errorValue = BadValue,
+    },
+    [RT_PASSIVEGRAB & (RC_LASTPREDEF - 1)] = {
+	.deleteFunc = DeletePassiveGrab,
+	.errorValue = BadValue,
+    },
+};
 
 CallbackListPtr ResourceStateCallback;
 
@@ -200,20 +247,20 @@ RESTYPE
 CreateNewResourceType(DeleteType deleteFunc, char *name)
 {
     RESTYPE next = lastResourceType + 1;
-    DeleteType *funcs;
+    struct ResourceType *types;
 
     if (next & lastResourceClass)
 	return 0;
-    funcs = (DeleteType *)xrealloc(DeleteFuncs,
-				   (next + 1) * sizeof(DeleteType));
-    if (!funcs)
+    types = xrealloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
+    if (!types)
 	return 0;
     if (!dixRegisterPrivateOffset(next, -1))
 	return 0;
 
     lastResourceType = next;
-    DeleteFuncs = funcs;
-    DeleteFuncs[next] = deleteFunc;
+    resourceTypes = types;
+    resourceTypes[next].deleteFunc = deleteFunc;
+    resourceTypes[next].errorValue = BadValue;
 
     /* Called even if name is NULL, to remove any previous entry */
     RegisterResourceName(next, name);
@@ -251,21 +298,11 @@ InitClientResources(ClientPtr client)
 	lastResourceType = RT_LASTPREDEF;
 	lastResourceClass = RC_LASTPREDEF;
 	TypeMask = RC_LASTPREDEF - 1;
-	if (DeleteFuncs)
-	    xfree(DeleteFuncs);
-	DeleteFuncs = xalloc((lastResourceType + 1) * sizeof(DeleteType));
-	if (!DeleteFuncs)
+	xfree(resourceTypes);
+	resourceTypes = xalloc(sizeof(predefTypes));
+	if (!resourceTypes)
 	    return FALSE;
-	DeleteFuncs[RT_NONE & TypeMask] = (DeleteType)NoopDDA;
-	DeleteFuncs[RT_WINDOW & TypeMask] = DeleteWindow;
-	DeleteFuncs[RT_PIXMAP & TypeMask] = dixDestroyPixmap;
-	DeleteFuncs[RT_GC & TypeMask] = FreeGC;
-	DeleteFuncs[RT_FONT & TypeMask] = CloseFont;
-	DeleteFuncs[RT_CURSOR & TypeMask] = FreeCursor;
-	DeleteFuncs[RT_COLORMAP & TypeMask] = FreeColormap;
-	DeleteFuncs[RT_CMAPENTRY & TypeMask] = FreeClientPixels;
-	DeleteFuncs[RT_OTHERCLIENT & TypeMask] = OtherClientGone;
-	DeleteFuncs[RT_PASSIVEGRAB & TypeMask] = DeletePassiveGrab;
+	memcpy(resourceTypes, predefTypes, sizeof(predefTypes));
     }
     clientTable[i = client->index].resources =
 	xalloc(INITBUCKETS*sizeof(ResourcePtr));
@@ -462,7 +499,7 @@ AddResource(XID id, RESTYPE type, pointer value)
     res = xalloc(sizeof(ResourceRec));
     if (!res)
     {
-	(*DeleteFuncs[type & TypeMask])(value, id);
+	(*resourceTypes[type & TypeMask].deleteFunc)(value, id);
 	return FALSE;
     }
     res->next = *head;
@@ -557,7 +594,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
 		CallResourceStateCallback(ResourceStateFreeing, res);
 
 		if (rtype != skipDeleteFuncType)
-		    (*DeleteFuncs[rtype & TypeMask])(res->value, res->id);
+		    (*resourceTypes[rtype & TypeMask].deleteFunc)(res->value, res->id);
 		xfree(res);
 		if (*eltptr != elements)
 		    prev = head; /* prev may no longer be valid */
@@ -593,7 +630,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
 		CallResourceStateCallback(ResourceStateFreeing, res);
 
 		if (!skipFree)
-		    (*DeleteFuncs[type & TypeMask])(res->value, res->id);
+		    (*resourceTypes[type & TypeMask].deleteFunc)(res->value, res->id);
 		xfree(res);
 		break;
 	    }
@@ -756,7 +793,7 @@ FreeClientNeverRetainResources(ClientPtr client)
 
 		CallResourceStateCallback(ResourceStateFreeing, this);
 
-		(*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
+		(*resourceTypes[rtype & TypeMask].deleteFunc)(this->value, this->id);
 		xfree(this);
 	    }
 	    else
@@ -807,7 +844,7 @@ FreeClientResources(ClientPtr client)
 
 	    CallResourceStateCallback(ResourceStateFreeing, this);
 
-	    (*DeleteFuncs[rtype & TypeMask])(this->value, this->id);
+	    (*resourceTypes[rtype & TypeMask].deleteFunc)(this->value, this->id);
 	    xfree(this);
 	}
     }
@@ -865,6 +902,8 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype,
     ResourcePtr res = NULL;
 
     *result = NULL;
+    if ((rtype & TypeMask) > lastResourceType)
+	return BadImplementation;
 
     if ((cid < MAXCLIENTS) && clientTable[cid].buckets) {
 	res = clientTable[cid].resources[Hash(cid, id)];
@@ -874,12 +913,14 @@ dixLookupResourceByType(pointer *result, XID id, RESTYPE rtype,
 		break;
     }
     if (!res)
-	return BadValue;
+	return resourceTypes[rtype & TypeMask].errorValue;
 
     if (client) {
 	client->errorValue = id;
 	cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type,
 		       res->value, RT_NONE, NULL, mode);
+	if (cid == BadValue)
+	    return resourceTypes[rtype & TypeMask].errorValue;
 	if (cid != Success)
 	    return cid;
     }
diff --git a/dix/window.c b/dix/window.c
index c7201df..3808e29 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1056,7 +1056,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 		}
 		else
 		{
-		    error = (rc == BadValue) ? BadPixmap : rc;
+		    error = rc;
 		    client->errorValue = pixID;
 		    goto PatchUp;
 		}
@@ -1116,7 +1116,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 	    }
 	    else
 	    {
-		error = (rc == BadValue) ? BadPixmap : rc;
+		error = rc;
 		client->errorValue = pixID;
 		goto PatchUp;
 	    }
@@ -1264,7 +1264,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 				   client, DixUseAccess);
 	    if (rc != Success)
 	    {
-		error = (rc == BadValue) ? BadColor : rc;
+		error = rc;
 		client->errorValue = cmap;
 		goto PatchUp;
 	    }
@@ -1340,7 +1340,7 @@ ChangeWindowAttributes(WindowPtr pWin, Mask vmask, XID *vlist, ClientPtr client)
 				       RT_CURSOR, client, DixUseAccess);
 		if (rc != Success)
 		{
-		    error = (rc == BadValue) ? BadCursor : rc;
+		    error = rc;
 		    client->errorValue = cursorID;
 		    goto PatchUp;
 		}
diff --git a/hw/xfree86/dixmods/extmod/xf86dga2.c b/hw/xfree86/dixmods/extmod/xf86dga2.c
index 5367bcc..758b970 100644
--- a/hw/xfree86/dixmods/extmod/xf86dga2.c
+++ b/hw/xfree86/dixmods/extmod/xf86dga2.c
@@ -436,7 +436,7 @@ ProcXDGAInstallColormap(ClientPtr client)
         DGAInstallCmap(cmap);
         return (client->noClientException);
     } else {
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 
     return (client->noClientException);
@@ -878,7 +878,7 @@ ProcXF86DGAInstallColormap(ClientPtr client)
 	DGAInstallCmap(pcmp);
         return (client->noClientException);
     } else {
-        return (rc == BadValue) ? BadColor : rc;
+        return rc;
     }
 }
 
diff --git a/render/picture.c b/render/picture.c
index 48693b8..8ddec22 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1176,7 +1176,6 @@ ChangePicture (PicturePtr	pPicture,
 			if (error != Success)
 			{
 			    client->errorValue = pid;
-			    error = (error == BadValue) ? BadPixmap : error;
 			    break;
 			}
 		    }
diff --git a/render/render.c b/render/render.c
index 3c505d6..726d2ec 100644
--- a/render/render.c
+++ b/render/render.c
@@ -1859,7 +1859,7 @@ ProcRenderCreateAnimCursor (ClientPtr client)
 	if (ret != Success)
 	{
 	    xfree (cursors);
-	    return (ret == BadValue) ? BadCursor : ret;
+	    return ret;
 	}
 	deltas[i] = elt->delay;
 	elt++;
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 1471a58..f42a32b 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -70,10 +70,7 @@ static void deleteCursorHideCountsForScreen (ScreenPtr pScreen);
 	int err;							\
 	err = dixLookupResourceByType((pointer *) &pCursor, cursor,	\
 				      RT_CURSOR, client, access);	\
-	if (err == BadValue) {						\
-	    client->errorValue = cursor;				\
-	    return BadCursor;						\
-	} else if (err != Success) {					\
+	if (err != Success) {						\
 	    client->errorValue = cursor;				\
 	    return err;							\
 	}								\
@@ -884,7 +881,7 @@ ProcXFixesHideCursor (ClientPtr client)
 			    client, DixGetAttrAccess);
     if (ret != Success) {
 	client->errorValue = stuff->window;
-	return (ret == BadValue) ? BadWindow : ret;
+	return ret;
     }
 
     /* 
@@ -947,7 +944,7 @@ ProcXFixesShowCursor (ClientPtr client)
 			   client, DixGetAttrAccess);
     if (rc != Success) {
 	client->errorValue = stuff->window;
-	return (rc == BadValue) ? BadWindow : rc;
+	return rc;
     }
 
     /* 
diff --git a/xfixes/region.c b/xfixes/region.c
index 5d195a3..a02aecc 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -119,7 +119,7 @@ ProcXFixesCreateRegionFromBitmap (ClientPtr client)
     if (rc != Success)
     {
 	client->errorValue = stuff->bitmap;
-	return (rc == BadValue) ? BadPixmap : rc;
+	return rc;
     }
     if (pPixmap->drawable.depth != 1)
 	return BadMatch;
@@ -164,7 +164,7 @@ ProcXFixesCreateRegionFromWindow (ClientPtr client)
     if (rc != Success)
     {
 	client->errorValue = stuff->window;
-	return (rc == BadValue) ? BadWindow : rc;
+	return rc;
     }
     switch (stuff->kind) {
     case WindowRegionBounding:
@@ -681,7 +681,7 @@ ProcXFixesSetWindowShapeRegion (ClientPtr client)
     if (rc != Success)
     {
 	client->errorValue = stuff->dest;
-	return (rc == BadValue) ? BadWindow : rc;
+	return rc;
     }
     VERIFY_REGION_OR_NONE(pRegion, stuff->region, client, DixWriteAccess);
     pScreen = pWin->drawable.pScreen;
-- 
1.7.0



More information about the xorg-devel mailing list