[MLton-commit] r6963

Vesa Karvonen vesak at mlton.org
Mon Oct 27 00:16:24 PST 2008


Fixed phantom typing of sockects by hiding the representation of socket
types.

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

U   mlton/trunk/basis-library/net/generic-sock.sml
U   mlton/trunk/basis-library/net/socket.sig
U   mlton/trunk/basis-library/net/socket.sml
U   mlton/trunk/doc/changelog

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

Modified: mlton/trunk/basis-library/net/generic-sock.sml
===================================================================
--- mlton/trunk/basis-library/net/generic-sock.sml	2008-10-27 08:11:03 UTC (rev 6962)
+++ mlton/trunk/basis-library/net/generic-sock.sml	2008-10-27 08:16:22 UTC (rev 6963)
@@ -12,19 +12,19 @@
       structure PESC = PE.SysCall
 
       fun socket' (af, st, p) =
-         (Net.Sock.fromRep o PESC.simpleResult)
+         (Socket.fromRep o PESC.simpleResult)
          (fn () => Prim.socket (Net.AddrFamily.toRep af, 
-                                Net.SockType.toRep st, 
+                                Socket.SOCKExtra.toRep st, 
                                 C_Int.fromInt p))
 
       fun socketPair' (af, st, p) =
          let
             val a : C_Sock.t array = Array.array (2, C_Sock.fromInt 0)
-            val get = fn i => Net.Sock.fromRep (Array.sub (a, i))
+            val get = fn i => Socket.fromRep (Array.sub (a, i))
          in
             PESC.syscall
             (fn () => (Prim.socketPair (Net.AddrFamily.toRep af, 
-                                        Net.SockType.toRep st, 
+                                        Socket.SOCKExtra.toRep st, 
                                         C_Int.fromInt p, 
                                         a), 
                        fn _ => (get 0, get 1)))

Modified: mlton/trunk/basis-library/net/socket.sig
===================================================================
--- mlton/trunk/basis-library/net/socket.sig	2008-10-27 08:11:03 UTC (rev 6962)
+++ mlton/trunk/basis-library/net/socket.sig	2008-10-27 08:16:22 UTC (rev 6963)
@@ -165,14 +165,21 @@
 signature SOCKET_EXTRA =
   sig
     include SOCKET
+    val fromRep : C_Sock.t -> ('af, 'sock_type) sock
+    val toRep : ('af, 'sock_type) sock -> C_Sock.t
     val sockToWord: ('af, 'sock_type) sock -> SysWord.word
     val wordToSock: SysWord.word -> ('af, 'sock_type) sock
     val sockToFD: ('af, 'sock_type) sock -> Posix.FileSys.file_desc
     val fdToSock: Posix.FileSys.file_desc -> ('af, 'sock_type) sock
-    type pre_sock_addr
+    type pre_sock_addr = Word8.word array
     val unpackSockAddr: 'af sock_addr -> Word8.word vector
     val newSockAddr: unit -> (pre_sock_addr * C_Socklen.t ref * (unit -> 'af sock_addr))
 
+    structure SOCKExtra:
+      sig
+         val toRep : SOCK.sock_type -> C_Sock.t
+      end
+
     structure CtlExtra:
        sig
           type level = C_Int.int

Modified: mlton/trunk/basis-library/net/socket.sml
===================================================================
--- mlton/trunk/basis-library/net/socket.sml	2008-10-27 08:11:03 UTC (rev 6962)
+++ mlton/trunk/basis-library/net/socket.sml	2008-10-27 08:16:22 UTC (rev 6963)
@@ -5,7 +5,7 @@
  * See the file MLton-LICENSE for details.
  *)
 
-structure Socket : SOCKET_EXTRA =
+structure Socket :> SOCKET_EXTRA =
 struct
 
 structure Prim = PrimitiveFFI.Socket
@@ -15,6 +15,8 @@
 
 structure Sock = Net.Sock
 type sock = Sock.t
+val fromRep = Sock.fromRep
+val toRep = Sock.toRep
 val sockToWord = C_Sock.castToSysWord o Sock.toRep
 val wordToSock = Sock.fromRep o C_Sock.castFromSysWord
 val sockToFD = PrePosix.FileDesc.fromRep o Sock.toRep
@@ -64,6 +66,7 @@
 structure SOCK =
    struct
       type sock_type = SockType.t
+      val toRep = SockType.toRep
       val stream = SockType.fromRep Prim.SOCK.STREAM
       val dgram = SockType.fromRep Prim.SOCK.DGRAM
       val names : (string * sock_type) list = 
@@ -80,6 +83,7 @@
             SOME (_, st) => SOME st
           | NONE => NONE
    end
+structure SOCKExtra = SOCK
 
 structure CtlExtra =
    struct

Modified: mlton/trunk/doc/changelog
===================================================================
--- mlton/trunk/doc/changelog	2008-10-27 08:11:03 UTC (rev 6962)
+++ mlton/trunk/doc/changelog	2008-10-27 08:16:22 UTC (rev 6963)
@@ -1,5 +1,10 @@
 Here are the changes from version 20070826 to version YYYYMMDD.
 
+* 2008-10-27
+   - Fixed phantom typing of sockets by hiding the representation of socket
+     types.  Previously the representation of sockets was revealed rendering
+     the phantom types useless.
+
 * 2008-07-24
    - Added support for compiling to a C library. The relevant new compiler
      options are '-ar' and '-format'. Libraries are named based on the




More information about the MLton-commit mailing list