Re: More on 64-bit code changes


I've looked over the code again for any additions to the diff I sent in
on Monday.  I have a few more so ...

First up, we've removed all change of GPOINTER_TO_[U]INT macros.  I know
you'll tell me I told you so, but I check all usage in glib and there
were no issues.  That's not to say that they aren't misused elsewhere. 
An example is in the gal library, in util/e-util.c.  The function
signature indicates two const pointers, and if you pass in two pointers
to integers then it breaks.  

For future use, we'd like to include GPOINTER_TO_SIZE and
GSIZE_TO_POINTER if that's okay.

Anyway, enough of shooting the messanger.  As we go through any
libraries we'll fix broken instances.

Second up, I've made a change to the implemenation of
g_hook_compare_ids.  Its not much of a change but the existing
implementation is not 64-bit safe.  It now basically does the same as
any GCompareFunc function(even if its not one).  Should anyone be
interested I've attached a small test program that displays the problem
on a 32-bit machine.

We're also going to leave the GHashFunc functions alone for the moment. 
There probably will not be a problem, but I don't have any stats to say
otherwise for the moment.

Until library freeze, we can't be sure that new problems won't arise, so
there may be more changes made in the future.  



Mark Murnane
Desktop, Applications & Middleware
Sun Microsystems Ireland
#include <stdio.h>

void main() {
	unsigned long a = 0xfffe0001;
	unsigned long b = 0xffff0000;

	long c;
	short d;

	printf ("Value of a: %lu\n", a);
	printf ("Value of b: %lu\n\n", b);

	printf ("Signed value of a: %ld\n", (long)a);
	printf ("Signed value of b: %ld\n\n", (long)b);

	c = (long)a - (long)b;
	d = (long)a - (long)b;
	if (c < 0)
	  printf ("Compare: -1\n");
	else if (c == 0)
	  printf ("Compare: 0\n");
	else if (c > 0)
	  printf ("Compare: 1\n");	

	printf ("Value of d: %hd\n", d);
RCS file: /sgnome/cvsroots/GNOME-devel/glib/,v
retrieving revision
diff -u -r1.1.1.5
---	2001/05/22 10:41:50
+++	2001/05/23 14:32:05
@@ -1622,6 +1622,9 @@
 #define GINT_TO_POINTER(i)	((gpointer) ${glib_gpi_cast} (i))
 #define GUINT_TO_POINTER(u)	((gpointer) ${glib_gpui_cast} (u))
+#define GPOINTER_TO_SIZE(p)	((gsize) (p))
+#define GSIZE_TO_POINTER(s)	((gpointer) (gsize) (s))
 	  echo '#error SIZEOF_VOID_P unknown - This should never happen' >>$outfile
Index: ghook.c
RCS file: /sgnome/cvsroots/GNOME-devel/glib/ghook.c,v
retrieving revision
diff -u -r1.1.1.1 ghook.c
--- ghook.c	2001/05/10 00:22:54
+++ ghook.c	2001/05/23 14:32:26
@@ -631,5 +631,10 @@
 g_hook_compare_ids (GHook *new_hook,
 		    GHook *sibling)
-  return ((glong) new_hook->hook_id) - ((glong) sibling->hook_id);
+  if (new_hook->hook_id < sibling->hook_id)
+    return -1;
+  else if (new_hook->hook_id > sibling->hook_id)
+    return 1;
+  return 0;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]