[MLton] Port of OpenBSD to MLton
Jesper Louis Andersen
jlouis@mongers.org
Sat, 12 Jun 2004 23:30:27 +0200
Quoting Jesper Louis Andersen (jlouis@mongers.org):
Patch for OpenBSD follows. Here are my notes to the patch:
; OpenBSD does not define _PC_SYNC_IO for the fpathconf()
system call. I've set the value to 0, but I am not sure
this is correct.
; The socket.sml regression fails, but this is due to
OpenBSD handling it that way rather than an error in
MLton. A little test I made with my webserver pulled
data from it without problems.
; Nitpick: Do we want the OS's listed in alphabetical
order? I've done it for the #defines, but not for the
case xxx of ... statements
; http://j.mongers.org/pub/mlton/mlton-openbsd-20040612.tar.gz
; Diff to CVS-head
Index: mlton/basis-library/misc/primitive.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/misc/primitive.sml,v
retrieving revision 1.112
diff -u -r1.112 primitive.sml
--- mlton/basis-library/misc/primitive.sml 11 Jun 2004 02:48:55 -0000 1.112
+++ mlton/basis-library/misc/primitive.sml 12 Jun 2004 15:38:55 -0000
@@ -770,7 +770,7 @@
structure OS =
struct
- datatype t = Cygwin | FreeBSD | Linux | NetBSD | Solaris
+ datatype t = Cygwin | FreeBSD | Linux | NetBSD | OpenBSD | Solaris
val host: t =
case _const "MLton_Platform_OS_host": int; of
@@ -779,6 +779,7 @@
| 2 => Linux
| 3 => NetBSD
| 4 => Solaris
+ | 5 => OpenBSD
| _ => raise Fail "strange MLton_Platform_OS_Host"
end
end
Index: mlton/basis-library/mlton/platform.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/mlton/platform.sig,v
retrieving revision 1.5
diff -u -r1.5 platform.sig
--- mlton/basis-library/mlton/platform.sig 6 Jan 2004 05:12:27 -0000 1.5
+++ mlton/basis-library/mlton/platform.sig 12 Jun 2004 15:38:55 -0000
@@ -11,7 +11,7 @@
structure OS:
sig
- datatype t = Cygwin | FreeBSD | Linux | NetBSD | Solaris
+ datatype t = Cygwin | FreeBSD | Linux | NetBSD | OpenBSD | Solaris
val fromString: string -> t option
val host: t
Index: mlton/basis-library/mlton/platform.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/mlton/platform.sml,v
retrieving revision 1.4
diff -u -r1.4 platform.sml
--- mlton/basis-library/mlton/platform.sml 6 Jan 2004 05:12:27 -0000 1.4
+++ mlton/basis-library/mlton/platform.sml 12 Jun 2004 15:38:55 -0000
@@ -29,6 +29,7 @@
(FreeBSD, "FreeBSD"),
(Linux, "Linux"),
(NetBSD, "NetBSD"),
+ (OpenBSD, "OpenBSD"),
(Solaris, "Solaris")]
fun fromString s =
Index: mlton/basis-library/real/real.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/real/real.fun,v
retrieving revision 1.22
diff -u -r1.22 real.fun
--- mlton/basis-library/real/real.fun 23 Apr 2004 08:06:39 -0000 1.22
+++ mlton/basis-library/real/real.fun 12 Jun 2004 15:38:56 -0000
@@ -232,6 +232,7 @@
case host of
FreeBSD => true
| NetBSD => true
+ | OpenBSD => true
| Solaris => true
| _ => false
end
Index: mlton/bin/platform
===================================================================
RCS file: /cvsroot/mlton/mlton/bin/platform,v
retrieving revision 1.2
diff -u -r1.2 platform
--- mlton/bin/platform 18 Dec 2003 06:23:11 -0000 1.2
+++ mlton/bin/platform 12 Jun 2004 15:38:57 -0000
@@ -38,6 +38,9 @@
NetBSD*)
HOST_OS='netbsd'
;;
+OpenBSD*)
+ HOST_OS='openbsd'
+;;
SunOS)
HOST_OS='solaris'
;;
Index: mlton/bin/upgrade-basis
===================================================================
RCS file: /cvsroot/mlton/mlton/bin/upgrade-basis,v
retrieving revision 1.8
diff -u -r1.8 upgrade-basis
--- mlton/bin/upgrade-basis 21 Jan 2004 17:12:22 -0000 1.8
+++ mlton/bin/upgrade-basis 12 Jun 2004 15:38:57 -0000
@@ -113,6 +113,9 @@
netbsd)
os='NetBSD'
;;
+openbsd)
+ os='OpenBSD'
+;;
solaris)
os='Solaris'
;;
@@ -152,13 +155,14 @@
structure OS =
struct
- datatype t = Cygwin | FreeBSD | Linux | NetBSD | Solaris
+ datatype t = Cygwin | FreeBSD | Linux | NetBSD | Solaris | OpenBSD
val all = [(Cygwin, "Cygwin"),
(FreeBSD, "FreeBSD"),
(Linux, "Linux"),
(NetBSD, "NetBSD"),
- (Solaris, "Solaris")]
+ (Solaris, "Solaris"),
+ (OpenBSD, "OpenBSD")]
fun fromString s =
let
Index: mlton/include/x86-main.h
===================================================================
RCS file: /cvsroot/mlton/mlton/include/x86-main.h,v
retrieving revision 1.13
diff -u -r1.13 x86-main.h
--- mlton/include/x86-main.h 13 May 2004 16:38:37 -0000 1.13
+++ mlton/include/x86-main.h 12 Jun 2004 15:38:58 -0000
@@ -37,7 +37,7 @@
#if (defined (__CYGWIN__))
#define ReturnToC "_Thread_returnToC"
-#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
#define ReturnToC "Thread_returnToC"
#else
#error ReturnToC not defined
Index: mlton/lib/mlton-stubs/mlton.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/lib/mlton-stubs/mlton.sml,v
retrieving revision 1.33
diff -u -r1.33 mlton.sml
--- mlton/lib/mlton-stubs/mlton.sml 19 May 2004 00:22:36 -0000 1.33
+++ mlton/lib/mlton-stubs/mlton.sml 12 Jun 2004 15:39:01 -0000
@@ -167,7 +167,7 @@
structure OS =
struct
- datatype t = Cygwin | FreeBSD | Linux | NetBSD | Solaris
+ datatype t = Cygwin | FreeBSD | Linux | NetBSD | OpenBSD | Solaris
val host: t = Linux
@@ -175,6 +175,7 @@
(FreeBSD, "freebsd"),
(Linux, "linux"),
(NetBSD, "netbsd"),
+ (OpenBSD, "openbsd"),
(Solaris, "solaris")]
fun fromString s = omap (peek (all, fn (_, s') => s = s'), #1)
Index: mlton/lib/mlton-stubs/platform.sig
===================================================================
RCS file: /cvsroot/mlton/mlton/lib/mlton-stubs/platform.sig,v
retrieving revision 1.5
diff -u -r1.5 platform.sig
--- mlton/lib/mlton-stubs/platform.sig 6 Jan 2004 05:12:28 -0000 1.5
+++ mlton/lib/mlton-stubs/platform.sig 12 Jun 2004 15:39:01 -0000
@@ -11,7 +11,7 @@
structure OS:
sig
- datatype t = Cygwin | FreeBSD | Linux | NetBSD | Solaris
+ datatype t = Cygwin | FreeBSD | Linux | NetBSD | OpenBSD | Solaris
val fromString: string -> t option
val host: t
Index: mlton/mlton/main/main.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/mlton/main/main.fun,v
retrieving revision 1.40
diff -u -r1.40 main.fun
--- mlton/mlton/main/main.fun 3 Jun 2004 00:17:22 -0000 1.40
+++ mlton/mlton/main/main.fun 12 Jun 2004 15:39:06 -0000
@@ -524,6 +524,7 @@
| SOME lib => [lib]
end
| NetBSD => ["-Wl,-R/usr/pkg/lib", "-L/usr/pkg/lib", "-lgmp"]
+ | OpenBSD => ["-L/usr/local/lib/", "-lgmp"]
| Solaris => ["-lgmp"]
val linkOpts =
List.concat [[concat ["-L", !libTargetDir],
Index: mlton/runtime/IntInf.h
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/IntInf.h,v
retrieving revision 1.14
diff -u -r1.14 IntInf.h
--- mlton/runtime/IntInf.h 4 Apr 2004 18:21:42 -0000 1.14
+++ mlton/runtime/IntInf.h 12 Jun 2004 15:39:09 -0000
@@ -17,9 +17,9 @@
#if (defined (__CYGWIN__))
#include "gmp.h"
-#elif (defined (__FreeBSD__))
-/* On FreeBSD, the default gmp.h is installed in /usr/include, but that is
- * version 2. We want gmp version 4, which the is installed in
+#elif (defined (__FreeBSD__) || (__OpenBSD__))
+/* On FreeBSD and OpenBSD, the default gmp.h is installed in /usr/include,
+ * but that is version 2. We want gmp version 4, which the is installed in
* /usr/local/include, and is ensured to exist because it is required by the
* MLton package.
*/
Index: mlton/runtime/basis-constants.h
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/basis-constants.h,v
retrieving revision 1.17
diff -u -r1.17 basis-constants.h
--- mlton/runtime/basis-constants.h 4 Apr 2004 18:21:42 -0000 1.17
+++ mlton/runtime/basis-constants.h 12 Jun 2004 15:39:10 -0000
@@ -54,6 +54,8 @@
#define MLton_Platform_OS_host 3
#elif (defined (__sun__))
#define MLton_Platform_OS_host 4
+#elif (defined (__OpenBSD__))
+#define MLton_Platform_OS_host 5
#else
#error MLton_Platform_OS_host not defined
#endif
@@ -79,9 +81,9 @@
/* Nothing to do -- everything comes from sys/ptrace.h. */
-#elif (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__sun__))
+#elif (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
-/* Note: NetBSD has a ptrace() interface, but for now, we ignore it */
+/* Note: NetBSD and OpenBSD has a ptrace() interface, but for now, we ignore it */
#define PTRACE_BOGUS 0xFFFFFFFF
#define PTRACE_SYSCALL PTRACE_BOGUS
Index: mlton/runtime/gc.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/gc.c,v
retrieving revision 1.184
diff -u -r1.184 gc.c
--- mlton/runtime/gc.c 19 May 2004 17:55:47 -0000 1.184
+++ mlton/runtime/gc.c 12 Jun 2004 15:39:21 -0000
@@ -16,7 +16,7 @@
#include <sys/sysctl.h>
#endif
-#if (defined (__NetBSD__))
+#if (defined (__NetBSD__) || defined (__OpenBSD__))
#include <sys/param.h>
#include <sys/sysctl.h>
#endif
@@ -50,11 +50,11 @@
#include "IntInf.h"
/* SUPPORTS_WEAK is true if the platform supports the weak attribute. */
-#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
#define SUPPORTS_WEAK 1
#elif (defined (__CYGWIN__))
#define SUPPORTS_WEAK 0
-#elif
+#else
#error SUPPORTS_WEAK not defined on platform
#endif
@@ -157,7 +157,7 @@
return n << 2;
}
-#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
static inline uint min (uint x, uint y) {
return ((x < y) ? x : y);
}
@@ -331,7 +331,7 @@
(void)system (buffer);
}
-#elif (defined (__linux__) || defined (__NetBSD__))
+#elif (defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__))
static void showMem () {
static char buffer[256];
@@ -362,7 +362,7 @@
PAGE_READWRITE);
if (NULL == result)
result = (void*)-1;
-#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__))
+#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__))
result = mmap (start, length, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON, -1, 0);
#elif (defined (__sun__))
@@ -397,7 +397,7 @@
return result;
}
-#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
static void smunmap (void *base, size_t length) {
if (DEBUG_MEM)
fprintf (stderr, "smunmap (0x%08x, %s)\n",
@@ -411,7 +411,7 @@
}
#endif
-#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
/* A super-safe mmap.
* Allocates a region of memory with dead zones at the high and low ends.
* Any attempt to touch the dead zone (read or write) will cause a
@@ -448,7 +448,7 @@
#if (defined (__CYGWIN__))
if (0 == VirtualFree (base, 0, MEM_RELEASE))
die ("VirtualFree release failed");
-#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
smunmap (base, length);
#else
#error release not defined
@@ -462,7 +462,7 @@
#if (defined (__CYGWIN__))
if (0 == VirtualFree (base, length, MEM_DECOMMIT))
die ("VirtualFree decommit failed");
-#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
smunmap (base, length);
#else
#error decommit not defined
@@ -2692,7 +2692,7 @@
/* heapRemap */
/* ---------------------------------------------------------------- */
-#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
static bool heapRemap (GC_state s, GC_heap h, W32 desired, W32 minSize) {
return FALSE;
@@ -3858,12 +3858,17 @@
setProfTimer (10000);
}
-#elif (defined (__CYGWIN__))
+#elif (defined (__CYGWIN__) || defined (__OpenBSD__))
/* No time profiling on Cygwin.
* There is a check in mlton/main/main.fun to make sure that time profiling is
* never turned on on Cygwin.
*/
+
+/* OpenBSD can probably do time profiling, but at the moment, we disable it to
+ * get a working implementation fast
+ */
+
static void profileTimeInit (GC_state s) {
die ("no time profiling on Cygwin");
}
@@ -3904,7 +3909,7 @@
/* Nothing */
-#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
static stack_t altstack;
size_t ss_size = align (SIGSTKSZ, s->pageSize);
@@ -3963,7 +3968,7 @@
return mem;
}
-#elif (defined (__NetBSD__))
+#elif (defined (__NetBSD__) || defined (__OpenBSD__))
static W32 totalRam (GC_state s) {
uint mem;
Index: mlton/runtime/mlton-basis.h
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/mlton-basis.h,v
retrieving revision 1.31
diff -u -r1.31 mlton-basis.h
--- mlton/runtime/mlton-basis.h 29 Apr 2004 02:58:58 -0000 1.31
+++ mlton/runtime/mlton-basis.h 12 Jun 2004 15:39:22 -0000
@@ -7,7 +7,7 @@
#ifndef _MLTON_BASIS_H_
#define _MLTON_BASIS_H_
-#if (defined (__FreeBSD__))
+#if (defined (__FreeBSD__) || defined (__OpenBSD__))
#include <sys/time.h>
#endif
#include <sys/resource.h>
@@ -163,7 +163,7 @@
#define MLton_Rlimit_numProcesses RLIMIT_NPROC
#define MLton_Rlimit_residentSetSize RLIMIT_RSS
#define MLton_Rlimit_stackSize RLIMIT_STACK
-#if (defined (__FreeBSD__) || defined (__NetBSD__))
+#if (defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__))
#define MLton_Rlimit_virtualMemorySize RLIMIT_DATA
#elif (defined (__CYGWIN__) || defined (__linux__) || defined (__sun__))
#define MLton_Rlimit_virtualMemorySize RLIMIT_AS
Index: mlton/runtime/my-lib.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/my-lib.c,v
retrieving revision 1.23
diff -u -r1.23 my-lib.c
--- mlton/runtime/my-lib.c 4 Apr 2004 18:21:43 -0000 1.23
+++ mlton/runtime/my-lib.c 12 Jun 2004 15:39:22 -0000
@@ -65,7 +65,7 @@
if (0 == n)
buf[i--] = '0';
-#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
#define MININT 0x80000000
#endif
else if (MININT == n) {
Index: mlton/runtime/posix-constants.h
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/posix-constants.h,v
retrieving revision 1.11
diff -u -r1.11 posix-constants.h
--- mlton/runtime/posix-constants.h 4 Apr 2004 18:21:43 -0000 1.11
+++ mlton/runtime/posix-constants.h 12 Jun 2004 15:39:23 -0000
@@ -84,7 +84,7 @@
/* Nothing. */
-#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#elif (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
#define O_BINARY 0
#define O_TEXT 0
@@ -101,7 +101,7 @@
#define Posix_FileSys_O_excl O_EXCL
#define Posix_FileSys_O_noctty O_NOCTTY
#define Posix_FileSys_O_nonblock O_NONBLOCK
-#if (defined (__CYGWIN__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__CYGWIN__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
#define Posix_FileSys_O_sync O_SYNC
#elif (defined (__FreeBSD__))
#define Posix_FileSys_O_sync 0
@@ -143,12 +143,16 @@
#define Posix_FileSys_PATH_MAX _PC_PATH_MAX
#define Posix_FileSys_PIPE_BUF _PC_PIPE_BUF
#define Posix_FileSys_VDISABLE _PC_VDISABLE
+#if (defined (__OpenBSD__))
+#define Posix_FileSys_SYNC_IO 0
+#else
#define Posix_FileSys_SYNC_IO _PC_SYNC_IO
+#endif
#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__linux__) || defined (__sun__))
#define Posix_FileSys_ASYNC_IO _PC_ASYNC_IO
#define Posix_FileSys_PRIO_IO _PC_PRIO_IO
-#elif (defined (__NetBSD__))
+#elif (defined (__NetBSD__) || defined (__OpenBSD__))
/* NetBSD does not define these constants in version 1.6.1, so we
* define them here.
*/
@@ -251,7 +255,7 @@
#define Posix_Signal_block SIG_BLOCK
#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__NetBSD__) || defined (__sun__))
#define Posix_Signal_numSignals NSIG
-#elif (defined (__linux__))
+#elif (defined (__linux__) || defined (__OpenBSD__))
#define Posix_Signal_numSignals _NSIG
#else
#error Posix_Signal_numSignals not defined
Index: mlton/runtime/Posix/ProcEnv/setenv.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/Posix/ProcEnv/setenv.c,v
retrieving revision 1.3
diff -u -r1.3 setenv.c
--- mlton/runtime/Posix/ProcEnv/setenv.c 18 Aug 2003 06:19:53 -0000 1.3
+++ mlton/runtime/Posix/ProcEnv/setenv.c 12 Jun 2004 15:39:24 -0000
@@ -1,7 +1,7 @@
#include <stdlib.h>
#include "mlton-posix.h"
-#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__))
+#if (defined (__CYGWIN__) || defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__))
Int Posix_ProcEnv_setenv (NullString s, NullString v) {
return setenv ((char *)s, (char *)v, 1);
Index: mlton/runtime/Posix/Signal/Signal.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/Posix/Signal/Signal.c,v
retrieving revision 1.15
diff -u -r1.15 Signal.c
--- mlton/runtime/Posix/Signal/Signal.c 29 Apr 2004 02:58:59 -0000 1.15
+++ mlton/runtime/Posix/Signal/Signal.c 12 Jun 2004 15:39:24 -0000
@@ -10,7 +10,7 @@
}
enum {
-#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__sun__))
+#if (defined (__FreeBSD__) || defined (__linux__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__sun__))
SA_FLAGS = SA_ONSTACK,
#elif (defined (__CYGWIN__))
SA_FLAGS = 0,
Index: mlton/runtime/basis/MLton/rusage.c
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/basis/MLton/rusage.c,v
retrieving revision 1.2
diff -u -r1.2 rusage.c
--- mlton/runtime/basis/MLton/rusage.c 27 Jun 2002 17:29:27 -0000 1.2
+++ mlton/runtime/basis/MLton/rusage.c 12 Jun 2004 15:39:24 -0000
@@ -1,4 +1,4 @@
-#if (defined (__FreeBSD__))
+#if (defined (__FreeBSD__) || defined (__OpenBSD__))
#include <sys/time.h>
#endif
#include <sys/resource.h>
--
j.