[PATCH 3/4] devPrivates rework (v3): compatibility updates

Eamon Walsh ewalsh at tycho.nsa.gov
Thu Mar 8 13:52:53 PST 2007


Pre-allocates one DevUnion in old devPrivates arrays for use by new mechanism.
This allows old and new mechanisms to co-exist.

--
 devices.c  |   11 +++++++++--
 main.c     |   32 +++++++++++++++++++++-----------
 privates.c |   42 ++++++++++++++++++++++++------------------
 3 files changed, 54 insertions(+), 31 deletions(-)

--
diff --git a/dix/devices.c b/dix/devices.c
index 9f42184..2e04403 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -124,8 +124,15 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
 #ifdef XKB
     dev->xkb_interest = NULL;
 #endif
-    dev->nPrivates = 0;
-    dev->devPrivates = NULL;
+    /* must pre-allocate one private for the new devPrivates support */
+    dev->nPrivates = 1;
+    dev->devPrivates = (DevUnion *)xalloc(sizeof(DevUnion));
+    if (!dev->devPrivates) {
+	xfree(dev);
+	return NULL;
+    }
+    dev->devPrivates[0].ptr = NULL;
+
     dev->unwrapProc = NULL;
     dev->coreEvents = TRUE;
     dev->inited = FALSE;
diff --git a/dix/main.c b/dix/main.c
index c40dfdd..852cbcb 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -715,18 +715,28 @@ AddScreen(
 	xfree(pScreen);
 	return -1;
     }
+
+    /* must pre-allocate one private for the new devPrivates support */
+    pScreen->WindowPrivateLen = 1;
+    pScreen->WindowPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->totalWindowSize = PadToLong(sizeof(WindowRec)) + sizeof(DevUnion);
+    pScreen->GCPrivateLen = 1;
+    pScreen->GCPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->totalGCSize = PadToLong(sizeof(GC)) + sizeof(DevUnion);
+    pScreen->PixmapPrivateLen = 1;
+    pScreen->PixmapPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    pScreen->totalPixmapSize = BitmapBytePad(8 * (sizeof(PixmapRec) +
+						  sizeof(DevUnion)));
+    if (pScreen->WindowPrivateSizes && pScreen->GCPrivateSizes &&
+	pScreen->PixmapPrivateSizes)
+	*pScreen->WindowPrivateSizes = *pScreen->GCPrivateSizes =
+	    *pScreen->PixmapPrivateSizes = 0;
+    else {
+	xfree(pScreen);
+	return -1;
+    }
+
     pScreen->myNum = i;
-    pScreen->WindowPrivateLen = 0;
-    pScreen->WindowPrivateSizes = (unsigned *)NULL;
-    pScreen->totalWindowSize =
-        ((sizeof(WindowRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
-    pScreen->GCPrivateLen = 0;
-    pScreen->GCPrivateSizes = (unsigned *)NULL;
-    pScreen->totalGCSize =
-        ((sizeof(GC) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
-    pScreen->PixmapPrivateLen = 0;
-    pScreen->PixmapPrivateSizes = (unsigned *)NULL;
-    pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
     pScreen->ClipNotify = 0;	/* for R4 ddx compatibility */
     pScreen->CreateScreenResources = 0;
     
diff --git a/dix/privates.c b/dix/privates.c
index 48ba675..57da0fa 100644
--- a/dix/privates.c
+++ b/dix/privates.c
@@ -343,15 +347,18 @@ int extensionPrivateLen;
 unsigned *extensionPrivateSizes;
 unsigned totalExtensionSize;
 
-static void
+static int
 ResetExtensionPrivates()
 {
-    extensionPrivateCount = 0;
-    extensionPrivateLen = 0;
+    extensionPrivateCount = 1;
+    extensionPrivateLen = 1;
     xfree(extensionPrivateSizes);
-    extensionPrivateSizes = (unsigned *)NULL;
-    totalExtensionSize =
-	((sizeof(ExtensionEntry) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
+    extensionPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    if (!extensionPrivateSizes)
+	return FALSE;
+    *extensionPrivateSizes = 0;
+    totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
+    return TRUE;
 }
 
 _X_EXPORT int
@@ -400,15 +407,18 @@ int clientPrivateLen;
 unsigned *clientPrivateSizes;
 unsigned totalClientSize;
 
-static void
+static int
 ResetClientPrivates()
 {
-    clientPrivateCount = 0;
-    clientPrivateLen = 0;
+    clientPrivateCount = 1;
+    clientPrivateLen = 1;
     xfree(clientPrivateSizes);
-    clientPrivateSizes = (unsigned *)NULL;
-    totalClientSize =
-	((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
+    clientPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
+    if (!clientPrivateSizes)
+	return FALSE;
+    *clientPrivateSizes = 0;
+    totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
+    return TRUE;
 }
 
 _X_EXPORT int
@@ -457,7 +467,7 @@ int  screenPrivateCount;
 static void
 ResetScreenPrivates()
 {
-    screenPrivateCount = 0;
+    screenPrivateCount = 1;
 }
 
 /* this can be called after some screens have been created,
@@ -499,7 +509,7 @@ static int  windowPrivateCount;
 static void
 ResetWindowPrivates()
 {
-    windowPrivateCount = 0;
+    windowPrivateCount = 1;
 }
 
 _X_EXPORT int
@@ -549,7 +559,7 @@ static int  gcPrivateCount;
 static void
 ResetGCPrivates()
 {
-    gcPrivateCount = 0;
+    gcPrivateCount = 1;
 }
 
 _X_EXPORT int
@@ -598,7 +608,7 @@ static int  pixmapPrivateCount;
 static void
 ResetPixmapPrivates()
 {
-    pixmapPrivateCount = 0;
+    pixmapPrivateCount = 1;
 }
 
 _X_EXPORT int
@@ -649,7 +659,7 @@ int  colormapPrivateCount;
 static void
 ResetColormapPrivates()
 {
-    colormapPrivateCount = 0;
+    colormapPrivateCount = 1;
 }
 
 
@@ -734,6 +744,6 @@ AllocateDevicePrivate(DeviceIntPtr device, int index)
 static void
 ResetDevicePrivateIndex(void)
 {
-    devicePrivateIndex = 0;
+    devicePrivateIndex = 1;
 }





More information about the xorg mailing list