xserver: Branch 'master' - 5 commits

Keith Packard keithp at kemper.freedesktop.org
Wed Oct 7 20:56:13 PDT 2009


 Xext/shm.c                              |   79 ++++++++++++++++++++++++--------
 Xext/xtest.c                            |    6 +-
 composite/compwindow.c                  |    4 -
 dix/events.c                            |    4 -
 glx/glxcmds.c                           |    2 
 glx/indirect_texture_compression.c      |    4 -
 hw/kdrive/linux/bus.c                   |    6 +-
 hw/xfree86/common/xf86Configure.c       |    2 
 hw/xfree86/dri/dri.c                    |    8 ++-
 hw/xfree86/os-support/bus/linuxPci.c    |    2 
 hw/xfree86/os-support/linux/lnx_video.c |    2 
 os/backtrace.c                          |    6 +-
 12 files changed, 85 insertions(+), 40 deletions(-)

New commits:
commit b0dd6be2c8703f7062d45ac9fd646550c7d54e3b
Author: Jamey Sharp <jamey at minilop.net>
Date:   Thu Oct 8 13:38:44 2009 +1100

    Cast small-int values through intptr_t when passed as pointers
    
    On 64-bit systems, int and pointers don't have the same size, so GCC gives
    warnings about casts between int and pointer types. However, in the cases
    covered by this patch, it's always a value that fits in int being stored
    temporarily as a pointer and then converted back later, which is safe.
    Casting through the pointer-sized integer type intptr_t convinces the
    compiler that this is OK.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/xtest.c b/Xext/xtest.c
index 6b0e9fd..5af2b5c 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -640,8 +640,8 @@ int AllocXTestDevice (ClientPtr client, char* name,
 
     retval = AllocDevicePair( client, xtestname, ptr, keybd, CorePointerProc, CoreKeyboardProc, FALSE);
     if ( retval == Success ){
-        dixSetPrivate(&((*ptr)->devPrivates), XTestDevicePrivateKey, (void *)master_ptr->id);
-        dixSetPrivate(&((*keybd)->devPrivates), XTestDevicePrivateKey, (void *)master_keybd->id);
+        dixSetPrivate(&((*ptr)->devPrivates), XTestDevicePrivateKey, (void *)(intptr_t)master_ptr->id);
+        dixSetPrivate(&((*keybd)->devPrivates), XTestDevicePrivateKey, (void *)(intptr_t)master_keybd->id);
 
         XIChangeDeviceProperty(*ptr, XIGetKnownProperty(XI_PROP_XTEST_DEVICE),
                 XA_INTEGER, 8, PropModeReplace, 1, &dummy,
@@ -677,7 +677,7 @@ IsXTestDevice(DeviceIntPtr dev, DeviceIntPtr master)
         return is_XTest;
 
     tmp = dixLookupPrivate(&dev->devPrivates, XTestDevicePrivateKey);
-    mid = (int)tmp;
+    mid = (intptr_t)tmp;
 
     /* deviceid 0 is reserved for XIAllDevices, non-zero mid means XTest
      * device */
diff --git a/composite/compwindow.c b/composite/compwindow.c
index 4267a51..9bc43b0 100644
--- a/composite/compwindow.c
+++ b/composite/compwindow.c
@@ -99,7 +99,7 @@ static Bool
 compRepaintBorder (ClientPtr pClient, pointer closure)
 {
     WindowPtr pWindow;
-    int rc = dixLookupWindow(&pWindow, (XID)closure, pClient, DixWriteAccess);
+    int rc = dixLookupWindow(&pWindow, (XID)(intptr_t)closure, pClient, DixWriteAccess);
 
     if (rc == Success) {
 	RegionRec exposed;
@@ -130,7 +130,7 @@ compSetPixmapVisitWindow (WindowPtr pWindow, pointer data)
     SetBorderSize (pWindow);
     if (HasBorder (pWindow))
 	QueueWorkProc (compRepaintBorder, serverClient,
-		       (pointer) pWindow->drawable.id);
+		       (pointer)(intptr_t) pWindow->drawable.id);
     return WT_WALKCHILDREN;
 }
 
diff --git a/dix/events.c b/dix/events.c
index d60b8a5..14e3900 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -1460,7 +1460,7 @@ static DevPrivateKey GrabPrivateKey = &GrabPrivateKeyIndex;
 static void
 DetachFromMaster(DeviceIntPtr dev)
 {
-    int id;
+    intptr_t id;
     if (!dev->u.master)
         return;
 
@@ -1482,7 +1482,7 @@ ReattachToOldMaster(DeviceIntPtr dev)
 
 
     p = dixLookupPrivate(&dev->devPrivates, GrabPrivateKey);
-    id = (int)p; /* silence gcc warnings */
+    id = (intptr_t) p; /* silence gcc warnings */
     dixLookupDevice(&master, id, serverClient, DixUseAccess);
 
     if (master)
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index ba4c123..eedab65 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2057,7 +2057,7 @@ int __glXDisp_BindSwapBarrierSGIX(__GLXclientState *cl, GLbyte *pc)
             if (ret == Success) {
                 if (barrier)
                     /* add source for cleanup when drawable is gone */
-                    AddResource(drawable, __glXSwapBarrierRes, (pointer)screen);
+                    AddResource(drawable, __glXSwapBarrierRes, (pointer)(intptr_t)screen);
                 else
                     /* delete source */
                     FreeResourceByType(drawable, __glXSwapBarrierRes, FALSE);
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index faddfe6..0de9be6 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1277,7 +1277,7 @@ DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
 
 	/* track this in case the client dies */
 	AddResource(FakeClientID(client->index), DRIDrawablePrivResType,
-		    (pointer)pDrawable->id);
+		    (pointer)(intptr_t)pDrawable->id);
 
 	if (pDRIDrawablePriv->hwDrawable) {
 	    drmUpdateDrawableInfo(pDRIPriv->drmFD,
@@ -1348,7 +1348,7 @@ DRIDestroyDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable)
     if (pDrawable->type == DRAWABLE_WINDOW) {
 	LookupClientResourceComplex(client, DRIDrawablePrivResType,
 				    DRIDestroyDrawableCB,
-				    (pointer)pDrawable->id);
+				    (pointer)(intptr_t)pDrawable->id);
     }
     else { /* pixmap (or for GLX 1.3, a PBuffer) */
 	/* NOT_DONE */
@@ -1364,7 +1364,9 @@ DRIDrawablePrivDelete(pointer pResource, XID id)
     WindowPtr pWin;
     int rc;
 
-    id = (XID)pResource;
+    /* For DRIDrawablePrivResType, the XID is the client's fake ID. The
+     * important XID is the value in pResource. */
+    id = (XID)(intptr_t)pResource;
     rc = dixLookupWindow(&pWin, id, serverClient, DixGetAttrAccess);
 
     if (rc == Success) {
diff --git a/hw/xfree86/os-support/bus/linuxPci.c b/hw/xfree86/os-support/bus/linuxPci.c
index 920a149..289315e 100644
--- a/hw/xfree86/os-support/bus/linuxPci.c
+++ b/hw/xfree86/os-support/bus/linuxPci.c
@@ -445,7 +445,7 @@ xf86MapLegacyIO(struct pci_device *dev)
 						  PCIIOC_MMAP_IS_IO);
 	}
 	else { /* legacy_io file exists, encode fd */
-	    DomainMmappedIO[domain] = (pointer)(fd << 24);
+	    DomainMmappedIO[domain] = (pointer)(intptr_t)(fd << 24);
 	}
     }
 
commit b680a89262efcfef4644adb4a61ae42ea0db0c93
Author: Jamey Sharp <jamey at minilop.net>
Date:   Thu Oct 8 13:38:01 2009 +1100

    Fix GCC warnings in xorg_backtrace
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/os/backtrace.c b/os/backtrace.c
index a421140..dafb990 100644
--- a/os/backtrace.c
+++ b/os/backtrace.c
@@ -38,7 +38,7 @@
 void xorg_backtrace(void)
 {
     void *array[64];
-    char *mod;
+    const char *mod;
     int size, i;
     Dl_info info;
     ErrorF("\nBacktrace:\n");
@@ -48,10 +48,10 @@ void xorg_backtrace(void)
 	mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
 	if (info.dli_saddr)
 	    ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
-		   info.dli_sname, array[i] - info.dli_saddr, array[i]);
+		   info.dli_sname, (char *) array[i] - (char *) info.dli_saddr, array[i]);
 	else
 	    ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
-		   info.dli_fbase, array[i] - info.dli_fbase, array[i]);
+		   info.dli_fbase, (char *) array[i] - (char *) info.dli_fbase, array[i]);
     }
 }
 
commit 9bf2ff4faf730913de3073f346646a8727be41d4
Author: Jamey Sharp <jamey at minilop.net>
Date:   Thu Oct 8 13:36:44 2009 +1100

    Fix "possibly uninitialized" warnings in glx
    
    In both functions, "answer" was uninitialized if "compsize" was 0, but in
    that case __GLX_SEND_VOID_ARRAY(compsize) results in a call to
    WriteToClient for 0 bytes, which returns immediately without examining the
    "answer" argument. So initializing to a null pointer is as good as
    anything else.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/glx/indirect_texture_compression.c b/glx/indirect_texture_compression.c
index 25c6eb3..5f44d7b 100644
--- a/glx/indirect_texture_compression.c
+++ b/glx/indirect_texture_compression.c
@@ -52,7 +52,7 @@ int __glXDisp_GetCompressedTexImageARB(struct __GLXclientStateRec *cl, GLbyte *p
 	const GLenum target = *(GLenum *)(pc + 0);
 	const GLint  level  = *(GLint  *)(pc + 4);
 	GLint compsize = 0;
-	char *answer, answerBuffer[200];
+	char *answer = NULL, answerBuffer[200];
 
 	CALL_GetTexLevelParameteriv(GET_DISPATCH(), (target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compsize));
 
@@ -92,7 +92,7 @@ int __glXDispSwap_GetCompressedTexImageARB(struct __GLXclientStateRec *cl, GLbyt
 	const GLenum target = (GLenum) bswap_32( *(int *)(pc + 0) );
 	const GLint  level =  (GLint ) bswap_32( *(int *)(pc + 4) );
 	GLint compsize = 0;
-	char *answer, answerBuffer[200];
+	char *answer = NULL, answerBuffer[200];
 
 	CALL_GetTexLevelParameteriv(GET_DISPATCH(), (target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &compsize));
 
commit b422b532f3dcab54c53f61a66f2ad76059d1874a
Author: Jamey Sharp <jamey at minilop.net>
Date:   Thu Oct 8 13:29:27 2009 +1100

    Remove static MAXSCREENS limit from Xext/shm.c
    
    Dynamically allocate per-screen data in the SHM extension, instead of
    having a single static-sized array.
    
    Signed-off-by: Jamey Sharp <jamey at minilop.net>
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/Xext/shm.c b/Xext/shm.c
index a6f804c..8106c40 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -99,6 +99,12 @@ typedef struct _ShmDesc {
     unsigned long size;
 } ShmDescRec, *ShmDescPtr;
 
+typedef struct _ShmScrPrivateRec {
+    CloseScreenProcPtr CloseScreen;
+    ShmFuncsPtr shmFuncs;
+    DestroyPixmapProcPtr destroyPixmap;
+} ShmScrPrivateRec;
+
 static PixmapPtr fbShmCreatePixmap(XSHM_CREATE_PIXMAP_ARGS);
 static int ShmDetachSegment(
     pointer		/* value */,
@@ -135,13 +141,16 @@ int BadShmSegCode;
 RESTYPE ShmSegType;
 static ShmDescPtr Shmsegs;
 static Bool sharedPixmaps;
-static ShmFuncsPtr shmFuncs[MAXSCREENS];
-static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS];
+static DrawablePtr *drawables;
+static int shmScrPrivateKeyIndex;
+static DevPrivateKey shmScrPrivateKey = &shmScrPrivateKeyIndex;
 static int shmPixmapPrivateIndex;
 static DevPrivateKey shmPixmapPrivate = &shmPixmapPrivateIndex;
 static ShmFuncs miFuncs = {NULL, NULL};
 static ShmFuncs fbFuncs = {fbShmCreatePixmap, NULL};
 
+#define ShmGetScreenPriv(s) ((ShmScrPrivateRec *)dixLookupPrivate(&(s)->devPrivates, shmScrPrivateKey))
+
 #define VERIFY_SHMSEG(shmseg,shmdesc,client) \
 { \
     int rc; \
@@ -212,6 +221,30 @@ static Bool CheckForShmSyscall(void)
 
 #endif
 
+static Bool
+ShmCloseScreen(int i, ScreenPtr pScreen)
+{
+    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);
+    pScreen->CloseScreen = screen_priv->CloseScreen;
+    dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, NULL);
+    xfree (screen_priv);
+    return (*pScreen->CloseScreen) (i, pScreen);
+}
+
+static ShmScrPrivateRec *
+ShmInitScreenPriv(ScreenPtr pScreen)
+{
+    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);
+    if (!screen_priv)
+    {
+	screen_priv = xcalloc (1, sizeof (ShmScrPrivateRec));
+	screen_priv->CloseScreen = pScreen->CloseScreen;
+	dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, screen_priv);
+	pScreen->CloseScreen = ShmCloseScreen;
+    }
+    return screen_priv;
+}
+
 void
 ShmExtensionInit(INITARGS)
 {
@@ -226,20 +259,29 @@ ShmExtensionInit(INITARGS)
     }
 #endif
 
+    drawables = xcalloc(screenInfo.numScreens, sizeof(DrawablePtr));
+    if (!drawables)
+    {
+	ErrorF("MIT-SHM extension disabled: no memory for per-screen drawables\n");
+	return;
+    }
+
     sharedPixmaps = xFalse;
     {
       sharedPixmaps = xTrue;
       for (i = 0; i < screenInfo.numScreens; i++)
       {
-	if (!shmFuncs[i])
-	    shmFuncs[i] = &miFuncs;
-	if (!shmFuncs[i]->CreatePixmap)
+	ShmScrPrivateRec *screen_priv = ShmInitScreenPriv(screenInfo.screens[i]);
+	if (!screen_priv->shmFuncs)
+	    screen_priv->shmFuncs = &miFuncs;
+	if (!screen_priv->shmFuncs->CreatePixmap)
 	    sharedPixmaps = xFalse;
       }
       if (sharedPixmaps)
 	for (i = 0; i < screenInfo.numScreens; i++)
 	{
-	    destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap;
+	    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(screenInfo.screens[i]);
+	    screen_priv->destroyPixmap = screenInfo.screens[i]->DestroyPixmap;
 	    screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
 	}
     }
@@ -261,23 +303,21 @@ static void
 ShmResetProc(ExtensionEntry *extEntry)
 {
     int i;
-
-    for (i = 0; i < MAXSCREENS; i++)
-    {
-	shmFuncs[i] = NULL;
-    }
+    for (i = 0; i < screenInfo.numScreens; i++)
+	ShmRegisterFuncs(screenInfo.screens[i], NULL);
 }
 
 void
 ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs)
 {
-    shmFuncs[pScreen->myNum] = funcs;
+    ShmInitScreenPriv(pScreen)->shmFuncs = funcs;
 }
 
 static Bool
 ShmDestroyPixmap (PixmapPtr pPixmap)
 {
     ScreenPtr	    pScreen = pPixmap->drawable.pScreen;
+    ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);
     Bool	    ret;
     if (pPixmap->refcnt == 1)
     {
@@ -288,9 +328,9 @@ ShmDestroyPixmap (PixmapPtr pPixmap)
 	    ShmDetachSegment ((pointer) shmdesc, pPixmap->drawable.id);
     }
     
-    pScreen->DestroyPixmap = destroyPixmap[pScreen->myNum];
+    pScreen->DestroyPixmap = screen_priv->destroyPixmap;
     ret = (*pScreen->DestroyPixmap) (pPixmap);
-    destroyPixmap[pScreen->myNum] = pScreen->DestroyPixmap;
+    screen_priv->destroyPixmap = pScreen->DestroyPixmap;
     pScreen->DestroyPixmap = ShmDestroyPixmap;
     return ret;
 }
@@ -298,7 +338,7 @@ ShmDestroyPixmap (PixmapPtr pPixmap)
 void
 ShmRegisterFbFuncs(ScreenPtr pScreen)
 {
-    shmFuncs[pScreen->myNum] = &fbFuncs;
+    ShmRegisterFuncs(pScreen, &fbFuncs);
 }
 
 static int
@@ -578,7 +618,6 @@ static int
 ProcPanoramiXShmGetImage(ClientPtr client)
 {
     PanoramiXRes	*draw;
-    DrawablePtr 	drawables[MAXSCREENS];
     DrawablePtr 	pDraw;
     xShmGetImageReply	xgi;
     ShmDescPtr		shmdesc;
@@ -767,9 +806,11 @@ CreatePmap:
     result = (client->noClientException);
 
     FOR_NSCREENS(j) {
+	ShmScrPrivateRec *screen_priv;
 	pScreen = screenInfo.screens[j];
 
-	pMap = (*shmFuncs[j]->CreatePixmap)(pScreen, 
+	screen_priv = ShmGetScreenPriv(pScreen);
+	pMap = (*screen_priv->shmFuncs->CreatePixmap)(pScreen,
 				stuff->width, stuff->height, stuff->depth,
 				shmdesc->addr + stuff->offset);
 
@@ -1052,6 +1093,7 @@ ProcShmCreatePixmap(ClientPtr client)
     DepthPtr pDepth;
     int i, rc;
     ShmDescPtr shmdesc;
+    ShmScrPrivateRec *screen_priv;
     REQUEST(xShmCreatePixmapReq);
     unsigned int width, height, depth;
     unsigned long size;
@@ -1100,7 +1142,8 @@ CreatePmap:
 	return BadAlloc;
 
     VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
-    pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
+    screen_priv = ShmGetScreenPriv(pDraw->pScreen);
+    pMap = (*screen_priv->shmFuncs->CreatePixmap)(
 			    pDraw->pScreen, stuff->width,
 			    stuff->height, stuff->depth,
 			    shmdesc->addr + stuff->offset);
commit 4df3e8c8053d9d4b3043f339a73d0de97020d884
Author: Martin Ettl <ettl.martin at gmx.de>
Date:   Thu Oct 8 13:27:30 2009 +1100

    Resource leakage: 0 is a valid file descriptor
    
    When testing if an fd is valid, the required construct is >= 0, not > 0.
    
    [Daniel: Fixed up the Linux MTRR case as well.]
    
    Signed-off-by: Martin Ettl <ettl.martin at gmx.de>
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/linux/bus.c b/hw/kdrive/linux/bus.c
index ba8a6cd..93c3ea5 100644
--- a/hw/kdrive/linux/bus.c
+++ b/hw/kdrive/linux/bus.c
@@ -72,7 +72,7 @@ BusInit (KdPointerInfo *pi)
     {
         for (i = 0; i < NUM_BUS_NAMES; i++)
         {
-            if ((fd = open (BusNames[i], 0)) > 0)
+            if ((fd = open (BusNames[i], 0)) >= 0)
             {
                 close(fd);
                 if (pi->path)
@@ -84,7 +84,7 @@ BusInit (KdPointerInfo *pi)
     }
     else
     {
-        if ((fd = open(pi->path, 0)) > 0)
+        if ((fd = open(pi->path, 0)) >= 0)
         {
             close(fd);
             return Success;
@@ -99,7 +99,7 @@ BusEnable (KdPointerInfo *pi)
 {
     int fd = open(pi->path, 0);
 
-    if (fd > 0)
+    if (fd >= 0)
     {
         KdRegisterFd(fd, BusRead, pi);
         pi->driverPrivate = (void *)fd;
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index bce5aae..3b7828a 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -253,7 +253,7 @@ configureInputSection (void)
 	int fd;
 #ifdef WSCONS_SUPPORT
 	fd = open("/dev/wsmouse", 0);
-	if (fd > 0) {
+	if (fd >= 0) {
 	    DFLT_MOUSE_DEV = "/dev/wsmouse";
 	    DFLT_MOUSE_PROTO = "wsmouse";
 	    close(fd);
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 73409df..09d1787 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -336,7 +336,7 @@ mtrr_undo_wc_region(int screenNum, struct mtrr_wc_region *wcr)
 {
 	struct mtrr_wc_region *p, *prev;
 
-	if (mtrr_fd > 0) {
+	if (mtrr_fd >= 0) {
 		p = wcr;
 		while (p) {
 			if (p->added)


More information about the xorg-commit mailing list