[MLton] Port to HP-UX

Stephen Weeks MLton@mlton.org
Tue, 25 Apr 2006 11:26:10 -0700


We have two proposals on the table for fixing the type-punning pointer
problem.

  1. Change our typedef for "pointer" to be void* instead of char*.
  2. The other is to cast through a union.

I tried (1) just to see how many problems it would cause.  It was
actually surprisingly easy -- I've appended the patch to the end of
this message.  (2) is awfully verbose, so if (1) is actually correct
in terms of C aliasing rules, I'd prefer to go that way.

Ville, could you try the patch and see if it makes your warnings go
away?

Right now I am hesitant to make too many changes to the runtime, as we
are awaiting the merge of the x86-64 branch into the trunk, and it
massively restructures and rewrites the runtime.  That branch still
leaves pointer as char*.  Matthew, could you try out pointer as void*
on the x86-64 branch and see how much it impacts things?

Patch follows.

--------------------------------------------------------------------------------

Index: gc.h
===================================================================
--- gc.h	(revision 4413)
+++ gc.h	(working copy)
@@ -361,8 +361,8 @@
         ullong bytesMarkCompacted;
         GC_thread callFromCHandler; /* For C calls. */
         bool canMinor; /* TRUE iff there is space for a minor gc. */
-        pointer cardMap;
-        pointer cardMapForMutator;
+        char *cardMap;
+        char *cardMapForMutator;
         uint cardMapSize;
         uint cardSize;
         uint cardSizeLog2;
Index: basis/Net/NetHostDB.c
===================================================================
--- basis/Net/NetHostDB.c	(revision 4413)
+++ basis/Net/NetHostDB.c	(working copy)
@@ -33,7 +33,7 @@
 void NetHostDB_Entry_addrsN(Int n, Pointer addr) {
         int i;
         for (i = 0; i < hostent->h_length; i++) {
-                addr[i] = hostent->h_addr_list[n][i];
+                ((char*)addr)[i] = hostent->h_addr_list[n][i];
         }
         return;
 }
Index: gc.c
===================================================================
--- gc.c	(revision 4413)
+++ gc.c	(working copy)
@@ -381,7 +381,7 @@
         return n >> CARD_SIZE_LOG2;
 }
 
-static inline pointer cardMapAddr (GC_state s, pointer p) {
+static inline char* cardMapAddr (GC_state s, pointer p) {
         pointer res;
 
         res = &s->cardMapForMutator [divCardSize (s, (uint)p)];
@@ -1697,7 +1697,7 @@
 
 /* Walk through all the cards and forward all intergenerational pointers. */
 static void forwardInterGenerationalPointers (GC_state s) {
-        pointer cardMap;
+        char *cardMap;
         uint cardNum;
         pointer cardStart;
         uchar *crossMap;
Index: types.h
===================================================================
--- types.h	(revision 4413)
+++ types.h	(working copy)
@@ -28,7 +28,7 @@
 typedef int16_t Int16;
 typedef int32_t Int32;
 typedef int64_t Int64;
-typedef char *Pointer;
+typedef void *Pointer;
 typedef Pointer pointer;
 typedef float Real32;
 typedef double Real64;