[MLton-commit] r6546

Matthew Fluet fluet at mlton.org
Mon Apr 7 11:33:40 PDT 2008


Abstract Posix types with MkAbsRepEq.

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

U   mlton/trunk/basis-library/mlton/proc-env.sml
U   mlton/trunk/basis-library/mlton/process.sml
U   mlton/trunk/basis-library/net/socket.sml
U   mlton/trunk/basis-library/posix/file-sys.sml
U   mlton/trunk/basis-library/posix/io.sml
U   mlton/trunk/basis-library/posix/proc-env.sml
U   mlton/trunk/basis-library/posix/process.sml
U   mlton/trunk/basis-library/posix/sys-db.sml
U   mlton/trunk/basis-library/posix/tty.sml
U   mlton/trunk/basis-library/system/io.sml

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

Modified: mlton/trunk/basis-library/mlton/proc-env.sml
===================================================================
--- mlton/trunk/basis-library/mlton/proc-env.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/mlton/proc-env.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -8,7 +8,8 @@
 
 structure MLtonProcEnv: MLTON_PROC_ENV =
    struct
-      type gid = C_GId.t
+      structure GId = PrePosix.GId
+      type gid = GId.t
 
       fun setenv {name, value} =
          let
@@ -21,10 +22,10 @@
 
       fun setgroups gs =
          let
-            val v = Vector.fromList gs
-            val n = Vector.length v
+            val v = GId.vectorToRep (Vector.fromList gs)
+            val n = C_Int.fromInt (Vector.length v)
          in
             PosixError.SysCall.simple
-            (fn () => PrimitiveFFI.Posix.ProcEnv.setgroups (C_Int.fromInt n, v))
+            (fn () => PrimitiveFFI.Posix.ProcEnv.setgroups (n, v))
          end
    end

Modified: mlton/trunk/basis-library/mlton/process.sml
===================================================================
--- mlton/trunk/basis-library/mlton/process.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/mlton/process.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -15,12 +15,15 @@
          structure FileSys = FileSys
          structure IO = IO
          structure ProcEnv = ProcEnv
-         structure Process = Posix.Process
+         structure Process = Process
+         structure FileDesc = PrePosix.FileDesc
+         structure PId = PrePosix.PId
+         structure Signal = PrePosix.Signal
       end
       structure Mask = MLtonSignal.Mask
       structure SysCall = PosixError.SysCall
 
-      type pid = C_PId.t
+      type pid = PId.t
 
       exception MisuseOfForget
       exception DoublyRedirected
@@ -214,13 +217,14 @@
         case !status of
            NONE =>
               let
-                 val signal' = PosixSignal.toRep signal
+                 val pid' = PId.toRep pid
+                 val signal' = Signal.toRep signal
                  val () =
                     if useWindowsProcess
                        then
                           SysCall.simple
                           (fn () =>
-                           PrimitiveFFI.Windows.Process.terminate (pid, signal'))
+                           PrimitiveFFI.Windows.Process.terminate (pid', signal'))
                     else Process.kill (Process.K_PROC pid, signal)
               in
                  ignore (reap p)
@@ -273,12 +277,12 @@
           end)
 
       fun launchWithCreate (path, args, env, stdin, stdout, stderr) =
-         create 
+         (PId.fromRep o create)
          (path,
           NullString.nullTerm (String.concatWith " "
                                (List.map cmdEscape (path :: args))),
           NullString.nullTerm (String.concatWith "\000" env ^ "\000"),
-          stdin, stdout, stderr)
+          FileDesc.toRep stdin, FileDesc.toRep stdout, FileDesc.toRep stderr)
 
       val launch =
          fn z =>
@@ -298,7 +302,7 @@
                val (fstdout, cstdout) = Param.openOut FileSys.stdout stdout
                val (fstderr, cstderr) = Param.openOut FileSys.stderr stderr
                val closeStdio =
-                  fn () => (Param.close stdin  fstdin
+                  fn () => (Param.close stdin fstdin
                             ; Param.close stdout fstdout
                             ; Param.close stderr fstderr)
                val pid =
@@ -323,7 +327,7 @@
                   val args = CUtil.StringVector.fromList args
                   val env = CUtil.StringVector.fromList env
                in
-                  SysCall.simpleResult'
+                  (PId.fromRep o SysCall.simpleResult')
                   ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                    Prim.spawne (path, 
                                 #1 args, #2 args, #3 args,
@@ -347,7 +351,7 @@
                   val file = NullString.nullTerm file
                   val args = CUtil.StringVector.fromList args
                in
-                  SysCall.simpleResult'
+                  (PId.fromRep o SysCall.simpleResult')
                   ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                    Prim.spawnp (file, 
                                 #1 args, #2 args, #3 args))

Modified: mlton/trunk/basis-library/net/socket.sml
===================================================================
--- mlton/trunk/basis-library/net/socket.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/net/socket.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -16,8 +16,8 @@
 type sock = C_Sock.t
 val sockToWord = C_Sock.castToSysWord
 val wordToSock = C_Sock.castFromSysWord
-val sockToFD = fn x => x
-val fdToSock = fn x => x
+val sockToFD = PrePosix.FileDesc.fromRep
+val fdToSock = PrePosix.FileDesc.toRep
 
 type pre_sock_addr = Word8.word array
 datatype sock_addr = SA of Word8.word vector
@@ -463,7 +463,7 @@
                val vec = Vector.fromList l
                val arr = Array.array (Vector.length vec, 0)
             in
-               (vec, arr)
+               (PrePosix.FileDesc.vectorToRep vec, arr)
             end
       in
          val (read_vec, read_arr) = mk rds

Modified: mlton/trunk/basis-library/posix/file-sys.sml
===================================================================
--- mlton/trunk/basis-library/posix/file-sys.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/posix/file-sys.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -8,7 +8,16 @@
 
 structure PosixFileSys: POSIX_FILE_SYS_EXTRA =
    struct
+      structure Prim = PrimitiveFFI.Posix.FileSys
+      open Prim
+      structure FileDesc = PrePosix.FileDesc
+      structure GId = PrePosix.GId
+      structure PId = PrePosix.PId
+      structure Stat = Prim.Stat
+      structure UId = PrePosix.UId
+
       structure Error = PosixError
+      structure SysCall = Error.SysCall
 
       (* Patch to make Time look like it deals with C_Time.t
        * instead of LargeInt.int.
@@ -24,19 +33,15 @@
                handle Overflow => Error.raiseSys Error.inval
          end
 
-      structure SysCall = Error.SysCall
-      structure Prim = PrimitiveFFI.Posix.FileSys
-      open Prim
-      structure Stat = Prim.Stat
+      type file_desc = FileDesc.t
+      type gid = GId.t
+      type uid = UId.t
 
-      type file_desc = C_Fd.t
-      type uid = C_UId.t
-      type gid = C_GId.t
+      val fdToWord = C_Fd.castToSysWord o FileDesc.toRep
+      val wordToFD = FileDesc.fromRep o C_Fd.castFromSysWord
 
-      val fdToWord = C_Fd.castToSysWord
-      val wordToFD = C_Fd.castFromSysWord
-      val fdToIOD = fn x => PreOS.IODesc.fromRep x
-      val iodToFD = SOME o (fn x => PreOS.IODesc.toRep x)
+      val fdToIOD = PreOS.IODesc.fromRep o FileDesc.toRep
+      val iodToFD = SOME o FileDesc.fromRep o PreOS.IODesc.toRep
 
       (*------------------------------------*)
       (*             dirstream              *)
@@ -147,9 +152,9 @@
             end
       end
 
-      val stdin : C_Fd.t = 0
-      val stdout : C_Fd.t = 1
-      val stderr : C_Fd.t = 2
+      val stdin : file_desc = FileDesc.fromRep 0
+      val stdout : file_desc = FileDesc.fromRep 1
+      val stderr : file_desc = FileDesc.fromRep 2
 
       structure S =
          struct
@@ -225,7 +230,7 @@
                SysCall.simpleResult
                (fn () => Prim.open3 (pathname, flags, mode))
          in
-            fd
+            FileDesc.fromRep fd
          end
 
       fun openf (pathname, openMode, flags) =
@@ -237,7 +242,7 @@
                SysCall.simpleResult
                (fn () => Prim.open3 (pathname, flags, C_Mode.castFromSysWord 0wx0))
          in 
-            fd
+            FileDesc.fromRep fd
          end
 
       fun creat (s, m) = createf (s, O_WRONLY, O.trunc, m)
@@ -259,12 +264,26 @@
          val rmdir = wrap (Prim.rmdir o NullString.nullTerm)
          val rename = wrapOldNew Prim.rename
          val symlink = wrapOldNew Prim.symlink
-         val chmod = wrap (fn (p, m) => Prim.chmod (NullString.nullTerm p, m))
-         val fchmod = wrap Prim.fchmod 
+         val chmod =
+            wrap
+            (fn (p, m) =>
+             Prim.chmod (NullString.nullTerm p, m))
+         val fchmod =
+            wrap
+            (fn (fd, m) =>
+             Prim.fchmod (FileDesc.toRep fd, m))
          val chown =
-            wrap (fn (s, u, g) => Prim.chown (NullString.nullTerm s, u, g))
-         val fchown = wrap Prim.fchown
-         val ftruncate = wrapRestart Prim.ftruncate
+            wrap
+            (fn (s, uid, gid) =>
+             Prim.chown (NullString.nullTerm s, UId.toRep uid, GId.toRep gid))
+         val fchown =
+            wrap
+            (fn (fd, uid, gid) =>
+             Prim.fchown (FileDesc.toRep fd, UId.toRep uid, GId.toRep gid))
+         val ftruncate =
+            wrapRestart
+            (fn (fd, n) =>
+             Prim.ftruncate (FileDesc.toRep fd, n))
       end           
 
       local
@@ -309,8 +328,8 @@
                   ino = Stat.getINo (),
                   mode = Stat.getMode (),
                   nlink = C_NLink.toInt (Stat.getNLink ()),
-                  uid = Stat.getUId (),
-                  gid = Stat.getGId (),
+                  uid = UId.fromRep (Stat.getUId ()),
+                  gid = GId.fromRep (Stat.getGId ()),
                   size = Stat.getSize (),
                   atime = Time.fromSeconds (Stat.getATime ()),
                   mtime = Time.fromSeconds (Stat.getMTime ()),
@@ -350,7 +369,7 @@
       in
          val stat = (make Prim.Stat.stat) o NullString.nullTerm
          val lstat = (make Prim.Stat.lstat) o NullString.nullTerm
-         val fstat = make Prim.Stat.fstat
+         val fstat = (make Prim.Stat.fstat) o FileDesc.toRep
       end
 
       datatype access_mode = A_READ | A_WRITE | A_EXEC
@@ -448,6 +467,6 @@
               handlers = [(Error.cleared, fn () => NONE)]})
       in
          val pathconf = make (fn (path, s) => Prim.pathconf (NullString.nullTerm path, s))
-         val fpathconf = make Prim.fpathconf
+         val fpathconf = make (fn (fd, s) => Prim.fpathconf (FileDesc.toRep fd, s))
       end
    end

Modified: mlton/trunk/basis-library/posix/io.sml
===================================================================
--- mlton/trunk/basis-library/posix/io.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/posix/io.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -11,29 +11,39 @@
 
 structure Prim = PrimitiveFFI.Posix.IO
 open Prim
+structure FileDesc = PrePosix.FileDesc
+structure PId = PrePosix.PId
+
 structure Error = PosixError
 structure SysCall = Error.SysCall
 structure FS = PosixFileSys
 
-type file_desc = C_Fd.t (* = C_Int.t *)
-type pid = C_PId.t
+type file_desc = FileDesc.t
+type pid = PId.t
 
 local
-   val a: file_desc array = Array.array (2, C_Fd.fromInt 0)
+   val a: C_Fd.t array = Array.array (2, C_Fd.fromInt 0)
+   val get = fn i => FileDesc.fromRep (Array.sub (a, i))
 in
    fun pipe () =
       SysCall.syscall
       (fn () =>
        (Prim.pipe a,
-        fn _ => {infd = Array.sub (a, 0),
-                 outfd = Array.sub (a, 1)}))
+        fn _ => {infd = get 0,
+                 outfd = get 1}))
 end
 
-fun dup fd = SysCall.simpleResult (fn () => Prim.dup fd)
+fun dup fd =
+   (FileDesc.fromRep o SysCall.simpleResult)
+   (fn () => Prim.dup (FileDesc.toRep fd))
 
-fun dup2 {new, old} = SysCall.simple (fn () => Prim.dup2 (old, new))
+fun dup2 {new, old} =
+   SysCall.simple
+   (fn () => Prim.dup2 (FileDesc.toRep old, FileDesc.toRep new))
 
-fun close fd = SysCall.simpleRestart (fn () => Prim.close fd)
+fun close fd =
+   SysCall.simpleRestart
+   (fn () => Prim.close (FileDesc.toRep fd))
 
 structure FD =
    struct
@@ -47,20 +57,21 @@
 datatype open_mode = datatype PosixFileSys.open_mode
 
 fun dupfd {base, old} =
-   SysCall.simpleResultRestart 
-   (fn () => Prim.fcntl3 (old, F_DUPFD, base))
+   (FileDesc.fromRep o SysCall.simpleResultRestart)
+   (fn () => Prim.fcntl3 (FileDesc.toRep old, F_DUPFD, FileDesc.toRep base))
 
 fun getfd fd =
    SysCall.simpleResultRestart 
-   (fn () => Prim.fcntl2 (fd, F_GETFD))
+   (fn () => Prim.fcntl2 (FileDesc.toRep fd, F_GETFD))
 
 fun setfd (fd, flags): unit =
    SysCall.simpleRestart
-   (fn () => Prim.fcntl3 (fd, F_SETFD, flags))
+   (fn () => Prim.fcntl3 (FileDesc.toRep fd, F_SETFD, flags))
 
 fun getfl fd : O.flags * open_mode =
    let 
-      val n = SysCall.simpleResultRestart (fn () => Prim.fcntl2 (fd, F_GETFL))
+      val n = SysCall.simpleResultRestart
+              (fn () => Prim.fcntl2 (FileDesc.toRep fd, F_GETFL))
       val flags = C_Int.andb (n, C_Int.notb O_ACCMODE)
       val mode = C_Int.andb (n, O_ACCMODE)
    in (flags, PosixFileSys.flagsToOpenMode mode)
@@ -68,7 +79,7 @@
 
 fun setfl (fd, flags: O.flags): unit  =
    SysCall.simpleRestart
-   (fn () => Prim.fcntl3 (fd, F_SETFL, flags))
+   (fn () => Prim.fcntl3 (FileDesc.toRep fd, F_SETFL, flags))
 
 datatype whence = SEEK_SET | SEEK_CUR | SEEK_END
 
@@ -80,9 +91,11 @@
 fun lseek (fd, n: Position.int, w: whence): Position.int =
    SysCall.simpleResult'
    ({errVal = C_Off.fromInt ~1}, fn () =>
-    Prim.lseek (fd, n, whenceToInt w))
+    Prim.lseek (FileDesc.toRep fd, n, whenceToInt w))
 
-fun fsync fd : unit = SysCall.simple (fn () => Prim.fsync fd)
+fun fsync fd : unit =
+   SysCall.simple
+   (fn () => Prim.fsync (FileDesc.toRep fd))
 
 val whenceToInt =
    fn SEEK_SET => Prim.FLock.SEEK_SET
@@ -144,12 +157,13 @@
          ; P.setWhence (whenceToInt whence)
          ; P.setStart start
          ; P.setLen len
-         ; P.fcntl (fd, cmd)), fn _ => 
+         ; P.fcntl (FileDesc.toRep fd, cmd)), fn _ =>
         {ltype = intToLockType (P.getType ()),
          whence = intToWhence (P.getWhence ()),
          start = P.getStart (),
          len = P.getLen (),
-         pid = if usepid then SOME (P.getPId ()) else NONE}))
+         pid = if usepid then SOME (PId.fromRep (P.getPId ()))
+               else NONE}))
 in
    val getlk = make (FLock.F_GETLK, true)
    val setlk = make (FLock.F_SETLK, false)
@@ -204,9 +218,12 @@
    fun make {RD, WR, fromVector, readArr, setMode, toArraySlice, toVectorSlice,
              vectorLength, writeArr, writeVec} =
       let
-         val primReadArr = readArr
-         val primWriteArr = writeArr
-         val primWriteVec = writeVec
+         val primReadArr = fn (fd, buf, i, sz) =>
+            readArr (FileDesc.toRep fd, buf, C_Int.fromInt i, C_Size.fromInt sz)
+         val primWriteArr = fn (fd, buf, i, sz) =>
+            writeArr (FileDesc.toRep fd, buf, C_Int.fromInt i, C_Size.fromInt sz)
+         val primWriteVec = fn (fd, buf, i, sz) =>
+            writeVec (FileDesc.toRep fd, buf, C_Int.fromInt i, C_Size.fromInt sz)
          val setMode =
             fn fd =>
             if let
@@ -216,7 +233,7 @@
                      MinGW => true
                    | _ => false
                end
-               then setMode fd
+               then setMode (FileDesc.toRep fd)
             else ()
          fun readArr (fd, sl): int =
             let
@@ -224,7 +241,7 @@
                val bytesRead =
                   SysCall.simpleResultRestart'
                   ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
-                   primReadArr (fd, buf, C_Int.fromInt i, C_Size.fromInt sz))
+                   primReadArr (fd, buf, i, sz))
                val bytesRead = C_SSize.toInt bytesRead
             in
                bytesRead
@@ -235,7 +252,7 @@
                val bytesRead = 
                   SysCall.simpleResultRestart'
                   ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
-                   primReadArr (fd, buf, C_Int.fromInt 0, C_Size.fromInt n))
+                   primReadArr (fd, buf, 0, n))
                val bytesRead = C_SSize.toInt bytesRead
             in 
                fromVector
@@ -249,7 +266,7 @@
                val bytesWrote =
                   SysCall.simpleResultRestart'
                   ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
-                   primWriteArr (fd, buf, C_Int.fromInt i, C_Size.fromInt sz))
+                   primWriteArr (fd, buf, i, sz))
                val bytesWrote = C_SSize.toInt bytesWrote
             in
                bytesWrote
@@ -260,7 +277,7 @@
                val bytesWrote =
                   SysCall.simpleResultRestart'
                   ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
-                   primWriteVec (fd, buf, C_Int.fromInt i, C_Size.fromInt sz))
+                   primWriteVec (fd, buf, i, sz))
                val bytesWrote = C_SSize.toInt bytesWrote
             in
                bytesWrote

Modified: mlton/trunk/basis-library/posix/proc-env.sml
===================================================================
--- mlton/trunk/basis-library/posix/proc-env.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/posix/proc-env.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -9,39 +9,48 @@
 structure PosixProcEnv: POSIX_PROC_ENV =
    struct
       structure Prim = PrimitiveFFI.Posix.ProcEnv
+      structure FileDesc = PrePosix.FileDesc
+      structure GId = PrePosix.GId
+      structure PId = PrePosix.PId
+      structure UId = PrePosix.UId
+
       structure Error = PosixError
       structure SysCall = Error.SysCall
       structure CS = CUtil.C_String
       structure CSS = CUtil.C_StringArray
 
-      type pid = C_PId.t
-      type uid = C_UId.t
-      type gid = C_GId.t
-      type file_desc = C_Fd.t
+      type file_desc = FileDesc.t
+      type gid = GId.t
+      type pid = PId.t
+      type uid = UId.t
 
+      val uidToWord = C_UId.castToSysWord o UId.toRep
+      val wordToUid = UId.fromRep o C_UId.castFromSysWord
+      val gidToWord = C_GId.castToSysWord o GId.toRep
+      val wordToGid = GId.fromRep o C_GId.castFromSysWord
+
       local
          open Prim
       in
-         val getpgrp = getpgrp (* No error checking required *)
-         val getegid = getegid (* No error checking required *)
-         val geteuid = geteuid (* No error checking required *)
-         val getgid = getgid (* No error checking required *)
-         val getpid = getpid (* No error checking required *)
-         val getppid = getppid (* No error checking required *)
-         val getuid = getuid (* No error checking required *)
-         val setgid = fn gid => SysCall.simple (fn () => setgid gid)
-         val setuid = fn uid => SysCall.simple (fn () => setuid uid)
+         val getpgrp = PId.fromRep o getpgrp (* No error checking required *)
+         val getegid = GId.fromRep o getegid (* No error checking required *)
+         val geteuid = UId.fromRep o geteuid (* No error checking required *)
+         val getgid = GId.fromRep o getgid (* No error checking required *)
+         val getpid = PId.fromRep o getpid (* No error checking required *)
+         val getppid = PId.fromRep o  getppid (* No error checking required *)
+         val getuid = UId.fromRep o getuid (* No error checking required *)
+         val setgid = fn gid => let val gid = GId.toRep gid
+                                in SysCall.simple (fn () => setgid gid)
+                                end
+         val setuid = fn uid => let val uid = UId.toRep uid
+                                in SysCall.simple (fn () => setuid uid)
+                                end
       end
 
       fun setsid () = 
-        SysCall.simpleResult' 
-        ({errVal = C_PId.castFromFixedInt ~1}, Prim.setsid)
+         (PId.fromRep o SysCall.simpleResult')
+         ({errVal = C_PId.castFromFixedInt ~1}, Prim.setsid)
 
-      val uidToWord = C_UId.castToSysWord
-      val wordToUid = C_UId.castFromSysWord
-      val gidToWord = C_GId.castToSysWord
-      val wordToGid = C_GId.castFromSysWord
-
       fun getgroups () =
          SysCall.syscall
          (fn () =>
@@ -50,7 +59,8 @@
              val a: C_GId.t array = Array.arrayUninit (C_Int.toInt n)
           in
              (Prim.getgroups (n, a), fn n => 
-              ArraySlice.toList (ArraySlice.slice (a, 0, SOME (C_Int.toInt n))))
+              (GId.listFromRep o ArraySlice.toList)
+              (ArraySlice.slice (a, 0, SOME (C_Int.toInt n))))
           end)
 
       fun getlogin () =
@@ -61,8 +71,8 @@
 
       fun setpgid {pid, pgid} =
          let
-            val pid = case pid of NONE => 0 | SOME pid => pid
-            val pgid = case pgid of NONE => 0 | SOME pgid => pgid
+            val pid = case pid of NONE => 0 | SOME pid => PId.toRep pid
+            val pgid = case pgid of NONE => 0 | SOME pgid => PId.toRep pgid
          in
             SysCall.simple
             (fn () => Prim.setpgid (pid, pgid))
@@ -264,11 +274,11 @@
 
       fun ctermid () = CS.toString (Prim.ctermid ())
 
-      fun isatty fd = (Prim.isatty fd) <> C_Int.zero
+      fun isatty fd = (Prim.isatty (FileDesc.toRep fd)) <> C_Int.zero
 
       fun ttyname fd =
          SysCall.syscall'
          ({errVal = CUtil.C_Pointer.null}, fn () =>
-          (Prim.ttyname fd, fn cs => 
+          (Prim.ttyname (FileDesc.toRep fd), fn cs =>
            CS.toString cs))
    end

Modified: mlton/trunk/basis-library/posix/process.sml
===================================================================
--- mlton/trunk/basis-library/posix/process.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/posix/process.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -10,20 +10,26 @@
    struct
       structure Prim = PrimitiveFFI.Posix.Process
       open Prim
+      structure FileDesc = PrePosix.FileDesc
+      structure PId = PrePosix.PId
+      structure Signal = PrePosix.Signal
+
       structure Error = PosixError
       structure SysCall = Error.SysCall
 
-      type signal = PosixSignal.signal
-      type pid = C_PId.t
+      type signal = Signal.t
+      type pid = PId.t
 
-      val wordToPid = C_PId.castFromSysWord
-      val pidToWord = C_PId.castToSysWord
+      val pidToWord = C_PId.castToSysWord o PId.toRep
+      val wordToPid = PId.fromRep o C_PId.castFromSysWord
 
       fun fork () =
          SysCall.syscall'
          ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
           (Prim.fork (), fn p =>
-           if p = C_PId.castFromFixedInt 0 then NONE else SOME p))
+           if p = C_PId.castFromFixedInt 0
+              then NONE
+           else SOME (PId.fromRep p)))
 
       val fork =
          if Primitive.MLton.Platform.OS.forkIsEnabled
@@ -104,12 +110,12 @@
                val pid =
                   case wa of
                      W_ANY_CHILD => C_PId.castFromFixedInt ~1
-                   | W_CHILD pid => pid
+                   | W_CHILD pid => PId.toRep pid
                    | W_SAME_GROUP => C_PId.castFromFixedInt 0
-                   | W_GROUP pid => C_PId.~ pid
+                   | W_GROUP pid => C_PId.~ (PId.toRep pid)
                val flags = W.flags flags
             in
-               SysCall.simpleResultRestart'
+               (PId.fromRep o SysCall.simpleResultRestart')
                ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                 let
                    val pid = 
@@ -133,7 +139,7 @@
             let
                val pid = wait (wa, status, W.nohang :: flags)
             in
-               if C_PId.castFromFixedInt 0 = pid
+               if PId.fromRep (C_PId.castFromFixedInt 0) = pid
                   then NONE
                else SOME (pid, getStatus ())
             end
@@ -157,9 +163,9 @@
          let
             val pid =
                case ka of
-                  K_PROC pid => pid
+                  K_PROC pid => PId.toRep pid
                 | K_SAME_GROUP => C_PId.castFromFixedInt ~1
-                | K_GROUP pid => C_PId.~ pid
+                | K_GROUP pid => C_PId.~ (PId.toRep pid)
             val s = PosixSignal.toRep s
          in
             SysCall.simple (fn () => Prim.kill (pid, s))

Modified: mlton/trunk/basis-library/posix/sys-db.sml
===================================================================
--- mlton/trunk/basis-library/posix/sys-db.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/posix/sys-db.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -9,11 +9,14 @@
 structure PosixSysDB: POSIX_SYS_DB =
    struct
       structure Prim = PrimitiveFFI.Posix.SysDB
+      structure GId = PrePosix.GId
+      structure UId = PrePosix.UId
+
       structure Error = PosixError
       structure SysCall = Error.SysCall
 
-      type uid = C_UId.t
-      type gid = C_GId.t
+      type gid = GId.t
+      type uid = UId.t
 
       structure Passwd =
          struct
@@ -30,8 +33,8 @@
                ({clear = true, restart = false, errVal = C_Int.zero}, fn () =>
                 {return = f (),
                  post = fn _ => {name = CUtil.C_String.toString (Passwd.getName ()),
-                                 uid = Passwd.getUId (),
-                                 gid = Passwd.getGId (),
+                                 uid = UId.fromRep (Passwd.getUId ()),
+                                 gid = GId.fromRep (Passwd.getGId ()),
                                  home = CUtil.C_String.toString (Passwd.getDir ()),
                                  shell = CUtil.C_String.toString (Passwd.getShell ())},
                  handlers = [(Error.cleared, fn () => 
@@ -53,7 +56,9 @@
          end
 
       fun getpwuid uid = 
-         Passwd.fromC (fn () => Prim.getpwuid uid, "getpwuid", "user id")
+         let val uid = UId.toRep uid
+         in Passwd.fromC (fn () => Prim.getpwuid uid, "getpwuid", "user id")
+         end
 
       structure Group =
          struct
@@ -68,7 +73,7 @@
                ({clear = true, restart = false, errVal = C_Int.zero}, fn () =>
                 {return = f (),
                  post = fn _ => {name = CUtil.C_String.toString (Group.getName ()),
-                                 gid = Group.getGId (),
+                                 gid = GId.fromRep (Group.getGId ()),
                                  members = CUtil.C_StringArray.toList (Group.getMem ())},
                  handlers = [(Error.cleared, fn () => 
                               raise Error.SysErr (concat ["Posix.SysDB.",
@@ -87,5 +92,7 @@
          end
 
       fun getgrgid gid = 
-         Group.fromC (fn () => Prim.getgrgid gid, "getgrgid", "group id")
+         let val gid = GId.toRep gid
+         in Group.fromC (fn () => Prim.getgrgid gid, "getgrgid", "group id")
+         end
    end

Modified: mlton/trunk/basis-library/posix/tty.sml
===================================================================
--- mlton/trunk/basis-library/posix/tty.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/posix/tty.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -10,13 +10,15 @@
    struct
       structure Prim = PrimitiveFFI.Posix.TTY
       open Prim
+      structure FileDesc = PrePosix.FileDesc
+      structure PId = PrePosix.PId
+
       structure Error = PosixError
       structure SysCall = Error.SysCall
 
-      type pid = C_PId.t
+      type file_desc = FileDesc.t
+      type pid = PId.t
 
-      type file_desc = C_Fd.t
-
       structure V =
          struct
             open V
@@ -232,7 +234,7 @@
             fun getattr fd =
                SysCall.syscallRestart
                (fn () =>
-                (Prim.TC.getattr fd, fn _ =>
+                (Prim.TC.getattr (FileDesc.toRep fd), fn _ =>
                  {iflag = Termios.getIFlag (),
                   oflag = Termios.getOFlag (),
                   cflag = Termios.getCFlag (),
@@ -254,25 +256,31 @@
                  ; SysCall.simple (fn () => Termios.cfSetOSpeed ospeed)
                  ; SysCall.simple (fn () => Termios.cfSetISpeed ispeed)
                  ; Termios.setCC cc
-                 ; (Prim.TC.setattr (fd, a), fn _ => ())))
+                 ; (Prim.TC.setattr (FileDesc.toRep fd, a), fn _ => ())))
 
             fun sendbreak (fd, n) =
-               SysCall.simpleRestart (fn () => Prim.TC.sendbreak (fd, C_Int.fromInt n))
+               SysCall.simpleRestart
+               (fn () => Prim.TC.sendbreak (FileDesc.toRep fd, C_Int.fromInt n))
 
-            fun drain fd = SysCall.simpleRestart (fn () => Prim.TC.drain fd)
+            fun drain fd =
+               SysCall.simpleRestart
+               (fn () => Prim.TC.drain (FileDesc.toRep fd))
 
             fun flush (fd, n) =
-               SysCall.simpleRestart (fn () => Prim.TC.flush (fd, n))
+               SysCall.simpleRestart
+               (fn () => Prim.TC.flush (FileDesc.toRep fd, n))
 
             fun flow (fd, n) =
-               SysCall.simpleRestart (fn () => Prim.TC.flow (fd, n))
+               SysCall.simpleRestart
+               (fn () => Prim.TC.flow (FileDesc.toRep fd, n))
 
             fun getpgrp fd =
-               SysCall.simpleResultRestart'
+               (PId.fromRep o SysCall.simpleResultRestart')
                ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
-                Prim.TC.getpgrp fd)
+                Prim.TC.getpgrp (FileDesc.toRep fd))
 
             fun setpgrp (fd, pid) = 
-               SysCall.simpleRestart (fn () => Prim.TC.setpgrp (fd, pid))
+               SysCall.simpleRestart
+               (fn () => Prim.TC.setpgrp (FileDesc.toRep fd, PId.toRep pid))
          end
    end

Modified: mlton/trunk/basis-library/system/io.sml
===================================================================
--- mlton/trunk/basis-library/system/io.sml	2008-04-07 18:33:34 UTC (rev 6545)
+++ mlton/trunk/basis-library/system/io.sml	2008-04-07 18:33:38 UTC (rev 6546)
@@ -24,8 +24,8 @@
 
     datatype iodesc_kind = K of string
 
-    val iodToFd = fn x => PreOS.IODesc.toRep x
-    val fdToIod = fn x => PreOS.IODesc.fromRep x
+    val iodToFd = PrePosix.FileDesc.fromRep o PreOS.IODesc.toRep
+    val fdToIod = PreOS.IODesc.fromRep o PrePosix.FileDesc.toRep
 
     val iodescToWord = C_Fd.castToSysWord o PreOS.IODesc.toRep
 
@@ -108,10 +108,10 @@
             })
     in
     fun poll (pds, timeOut) = let
-          val (fds, eventss) = ListPair.unzip (List.map fromPollDesc pds)
+          val (fds, events) = ListPair.unzip (List.map fromPollDesc pds)
           val fds = Vector.fromList fds
           val n = Vector.length fds
-          val eventss = Vector.fromList eventss
+          val events = Vector.fromList events
           val timeOut =
              case timeOut of
                 NONE => ~1
@@ -120,9 +120,13 @@
                       then Error.raiseSys Error.inval
                    else (C_Int.fromLarge (Time.toMilliseconds t)
                          handle Overflow => Error.raiseSys Error.inval)
-          val reventss = Array.array (n, 0)
+          val revents = Array.array (n, 0)
           val _ = Posix.Error.SysCall.simpleRestart
-                  (fn () => Prim.poll (fds, eventss, C_NFds.fromInt n, timeOut, reventss))
+                  (fn () => Prim.poll (PrePosix.FileDesc.vectorToRep fds,
+                                       events,
+                                       C_NFds.fromInt n,
+                                       timeOut,
+                                       revents))
           in
             Array.foldri
             (fn (i, w, l) => 
@@ -130,7 +134,7 @@
                then (toPollInfo (Vector.sub (fds, i), w))::l
                else l)
             []
-            reventss
+            revents
           end
     end (* local *)
 




More information about the MLton-commit mailing list