Re: [PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-06 Thread Eric Anholt
On Mon, 2009-10-05 at 15:35 -0400, Adam Jackson wrote:
 On Sun, 2009-10-04 at 12:08 +1100, Daniel Stone wrote:
  On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
   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 ja...@minilop.net
  
  Alan, Matthieu -- is this portable enough?
 
 intptr_t is part of stdint.h in C99, but seems to also be in unistd.h in
 UNIX98, which is nearly universal by this point unlike C99.
 
 I would love love love to see us move entirely to stdint types instead
 of the mess we've got now.

Yes.  Yes yes yes.

-- 
Eric Anholt
e...@anholt.net eric.anh...@intel.com




signature.asc
Description: This is a digitally signed message part
___
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-05 Thread Adam Jackson
On Sun, 2009-10-04 at 12:08 +1100, Daniel Stone wrote:
 On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
  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 ja...@minilop.net
 
 Alan, Matthieu -- is this portable enough?

intptr_t is part of stdint.h in C99, but seems to also be in unistd.h in
UNIX98, which is nearly universal by this point unlike C99.

I would love love love to see us move entirely to stdint types instead
of the mess we've got now.

- ajax


signature.asc
Description: This is a digitally signed message part
___
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-05 Thread Daniel Stone
On Mon, Oct 05, 2009 at 11:04:18AM -0700, Alan Coopersmith wrote:
 Daniel Stone wrote:
  On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
  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 ja...@minilop.net
  
  Alan, Matthieu -- is this portable enough?
 
 intptr_t has been in Solaris since 64-bit support was added in Solaris 7.

Okay, looks like we can use it no problems then.

Acked-by: Daniel Stone dan...@fooishbar.org

Merged into ~daniels/xserver.

Cheers,
Daniel


pgpWRxJICHI2q.pgp
Description: PGP signature
___
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-04 Thread Matthieu Herrb
Daniel Stone wrote:
 On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
 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 ja...@minilop.net
 
 Alan, Matthieu -- is this portable enough?

OpenBSD has intptr_t. But afaik there's a mess between different systems
to find out which header provide the definition.

I haven't tried to build an xserver with tht patch yet. I'll check that
later today.

-- 
Matthieu Herrb
___
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-04 Thread Matthieu Herrb
Matthieu Herrb wrote:
 Daniel Stone wrote:
 On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
 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 ja...@minilop.net
 Alan, Matthieu -- is this portable enough?
 
 OpenBSD has intptr_t. But afaik there's a mess between different systems
 to find out which header provide the definition.
 
 I haven't tried to build an xserver with tht patch yet. I'll check that
 later today.
 

Yes this patch is ok for OpenBSD.

-- 
Matthieu Herrb
___
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel


Re: [PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-03 Thread Daniel Stone
On Fri, Oct 02, 2009 at 01:42:50PM -0700, Jamey Sharp wrote:
 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 ja...@minilop.net

Alan, Matthieu -- is this portable enough?

Cheers,
Daniel


pgpyrfOpS6ltP.pgp
Description: PGP signature
___
xorg-devel mailing list
xorg-devel@lists.x.org
http://lists.x.org/mailman/listinfo/xorg-devel


[PATCH] Cast small-int values through intptr_t when they're passed as pointers.

2009-10-02 Thread Jamey Sharp
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 ja...@minilop.net
---
 Xext/xtest.c |6 +++---
 composite/compwindow.c   |4 ++--
 dix/events.c |4 ++--
 glx/glxcmds.c|2 +-
 hw/xfree86/dri/dri.c |8 +---
 hw/xfree86/os-support/bus/linuxPci.c |2 +-
 6 files changed, 14 insertions(+), 12 deletions(-)

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);
+