[MLton-commit] r6859

Wesley Terpstra wesley at mlton.org
Wed Sep 17 18:13:40 PDT 2008


A regression test suite that covers all the forms of linking MLton supports.
It compares the value of pointers to symbols taken from each point where the
symbol is reachable. These should all be equal.

The test doesn't pass on any system yet, but is the goal for all of them.


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

A   mlton/trunk/regression/library/
A   mlton/trunk/regression/library/check.c
A   mlton/trunk/regression/library/check.sml
A   mlton/trunk/regression/library/lib1.c
A   mlton/trunk/regression/library/lib1.sml
A   mlton/trunk/regression/library/lib2.c
A   mlton/trunk/regression/library/lib2.sml
A   mlton/trunk/regression/library/lib3.c
A   mlton/trunk/regression/library/lib3.sml
A   mlton/trunk/regression/library/lib4.c
A   mlton/trunk/regression/library/lib4.sml
A   mlton/trunk/regression/library/lib5.c
A   mlton/trunk/regression/library/lib5.sml
A   mlton/trunk/regression/library/library-test

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

Added: mlton/trunk/regression/library/check.c
===================================================================
--- mlton/trunk/regression/library/check.c	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/check.c	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,53 @@
+#include <assert.h>
+
+#include "check.h"
+#include "lib5.h"
+#include "lib4.h"
+#include "lib3.h"
+
+extern EXTERNAL void* lib3cSymPublic;
+extern EXTERNAL void* lib3cFnPublic(void);
+extern EXTERNAL void* lib4cSymPublic;
+extern EXTERNAL void* lib4cFnPublic(void);
+
+extern PUBLIC void* lib5cSymPublic;
+extern PUBLIC void* lib5cFnPublic(void);
+
+PRIVATE void* checkcSymPrivate = 0;
+PUBLIC  void* checkcSymPublic  = 0;
+
+PRIVATE void* checkcFnPrivate(void) {
+  return &checkcSymPrivate;
+}
+
+PUBLIC void* checkcFnPublic(void) {
+  return &checkcSymPublic;
+}
+
+PRIVATE void checkconfirmC(void) {
+  assert (&checksmlFnPrivate == checksmlSymPrivate);
+  assert (&checksmlFnPublic  == checksmlSymPublic);
+  assert (&checkcFnPrivate   == checkcSymPrivate);
+  assert (&checkcFnPublic    == checkcSymPublic);
+  
+  assert (checksmlFnPrivate() == &checksmlSymPrivate);
+  assert (checksmlFnPublic()  == &checksmlSymPublic);
+  
+  /* Check lib3 */
+  assert (&lib3smlFnPublic  == lib3smlSymPublic);
+  assert (&lib3cFnPublic    == lib3cSymPublic);
+  assert (lib3smlFnPublic() == &lib3smlSymPublic);
+  assert (lib3cFnPublic()   == &lib3cSymPublic);
+  
+  /* Check lib4 */
+  assert (&lib4smlFnPublic  == lib4smlSymPublic);
+  assert (&lib4cFnPublic    == lib4cSymPublic);
+  assert (lib4smlFnPublic() == &lib4smlSymPublic);
+  assert (lib4cFnPublic()   == &lib4cSymPublic);
+  
+  /* Check lib5 */
+  assert (&lib5smlFnPublic  == lib5smlSymPublic);
+  assert (&lib5cFnPublic    == lib5cSymPublic);
+  assert (lib5smlFnPublic() == &lib5smlSymPublic);
+  assert (lib5cFnPublic()   == &lib5cSymPublic);
+}

Added: mlton/trunk/regression/library/check.sml
===================================================================
--- mlton/trunk/regression/library/check.sml	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/check.sml	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,77 @@
+(* Prepare lib5 *)
+val () = _import "lib5_open" : unit -> unit; ()
+
+type p = MLton.Pointer.t
+
+type 'a s = (unit -> 'a) * ('a -> unit)
+val (_, setSI) = _symbol "checksmlSymPrivate" alloc private : p s;
+val (_, setSB) = _symbol "checksmlSymPublic"  alloc public  : p s;
+val (_, setCI) = _symbol "checkcSymPrivate" private : p s;
+val (_, setCB) = _symbol "checkcSymPublic"  public  : p s;
+
+type i = (unit -> p)
+type e = i -> unit
+val () = _export "checksmlFnPrivate" private : e;
+         (fn () => _address "checksmlSymPrivate" private : p;)
+val () = _export "checksmlFnPublic" public : e;
+         (fn () => _address "checksmlSymPublic" public : p;)
+val getCI = _import "checkcFnPrivate" private : i;
+val getCB = _import "checkcFnPublic" public : i;
+
+(* Store our idea of what the function pointers are in symbols *)
+val () = setSI (_address "checksmlFnPrivate" : p;)
+val () = setSB (_address "checksmlFnPublic"  : p;)
+val () = setCI (_address "checkcFnPrivate"   : p;)
+val () = setCB (_address "checkcFnPublic"    : p;)
+
+(* Have C confirm that it sees the same function pointers we do.
+ * C will check the values of the variables against it's own pointers.
+ * C also checks SML functions return his idea of pointers to our exports.
+ *)
+val () = _import "checkconfirmC" private : unit -> unit; ()
+
+(* Confirm that C functions return pointers to address as we expect. *)
+fun check (s, b) = if b then () else print (s ^ " pointers don't match!\n")
+val () = check ("checkcFnPrivate", getCI () = _address "checkcSymPrivate" private : p;)
+val () = check ("checkcFnPublic",  getCB () = _address "checkcSymPublic"  public  : p;)
+
+(* Test symbols in lib3 *)
+val (SB, _) = _symbol "lib3smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib3cSymPublic"   external : p s;
+val getSB = _import "lib3smlFnPublic" external : i;
+val getCB = _import "lib3cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib3smlFnPublic", SB () = _address "lib3smlFnPublic" external : p;)
+val () = check ("lib3cFnPublic",   CB () = _address "lib3cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib3smlSymPublic", getSB () = _address "lib3smlSymPublic" external : p;)
+val () = check ("lib3cSymPublic",   getCB () = _address "lib3cSymPublic"   external : p;)
+
+(* Test symbols in lib4 *)
+val (SB, _) = _symbol "lib4smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib4cSymPublic"   external : p s;
+val getSB = _import "lib4smlFnPublic" external : i;
+val getCB = _import "lib4cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib4smlFnPublic", SB () = _address "lib4smlFnPublic" external : p;)
+val () = check ("lib4cFnPublic",   CB () = _address "lib4cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib4smlSymPublic", getSB () = _address "lib4smlSymPublic" external : p;)
+val () = check ("lib4cSymPublic",   getCB () = _address "lib4cSymPublic"   external : p;)
+
+(* Test symbols in lib5 *)
+val (SB, _) = _symbol "lib5smlSymPublic" public : p s;
+val (CB, _) = _symbol "lib5cSymPublic"   public : p s;
+val getSB = _import "lib5smlFnPublic" public : i;
+val getCB = _import "lib5cFnPublic"   public : i;
+
+(* Check function pointers *)
+val () = check ("lib5smlFnPublic", SB () = _address "lib5smlFnPublic" public : p;)
+val () = check ("lib5cFnPublic",   CB () = _address "lib5cFnPublic"   public : p;)
+(* Check symbol pointers *)
+val () = check ("lib5smlSymPublic", getSB () = _address "lib5smlSymPublic" public : p;)
+val () = check ("lib5cSymPublic",   getCB () = _address "lib5cSymPublic"   public : p;)
+
+val () = print "check pointer test complete.\n"

Added: mlton/trunk/regression/library/lib1.c
===================================================================
--- mlton/trunk/regression/library/lib1.c	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib1.c	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,25 @@
+#include <assert.h>
+
+#define PART_OF_LIBRARY_LIB1
+#include "lib1.h"
+
+PRIVATE void* lib1cSymPrivate = 0;
+PUBLIC  void* lib1cSymPublic  = 0;
+
+PRIVATE void* lib1cFnPrivate(void) {
+  return &lib1cSymPrivate;
+}
+
+PUBLIC void* lib1cFnPublic(void) {
+  return &lib1cSymPublic;
+}
+
+PRIVATE void lib1confirmC(void) {
+  assert (&lib1smlFnPrivate == lib1smlSymPrivate);
+  assert (&lib1smlFnPublic  == lib1smlSymPublic);
+  assert (&lib1cFnPrivate   == lib1cSymPrivate);
+  assert (&lib1cFnPublic    == lib1cSymPublic);
+  
+  assert (lib1smlFnPrivate() == &lib1smlSymPrivate);
+  assert (lib1smlFnPublic()  == &lib1smlSymPublic);
+}

Added: mlton/trunk/regression/library/lib1.sml
===================================================================
--- mlton/trunk/regression/library/lib1.sml	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib1.sml	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,35 @@
+type p = MLton.Pointer.t
+
+type 'a s = (unit -> 'a) * ('a -> unit)
+val (_, setSI) = _symbol "lib1smlSymPrivate" alloc private : p s;
+val (_, setSB) = _symbol "lib1smlSymPublic"  alloc public  : p s;
+val (_, setCI) = _symbol "lib1cSymPrivate" private : p s;
+val (_, setCB) = _symbol "lib1cSymPublic"  public  : p s;
+
+type i = (unit -> p)
+type e = i -> unit
+val () = _export "lib1smlFnPrivate" private : e;
+         (fn () => _address "lib1smlSymPrivate" private : p;)
+val () = _export "lib1smlFnPublic" public : e;
+         (fn () => _address "lib1smlSymPublic" public : p;)
+val getCI = _import "lib1cFnPrivate" private : i;
+val getCB = _import "lib1cFnPublic" public : i;
+
+(* Store our idea of what the function pointers are in symbols *)
+val () = setSI (_address "lib1smlFnPrivate" : p;)
+val () = setSB (_address "lib1smlFnPublic"  : p;)
+val () = setCI (_address "lib1cFnPrivate"   : p;)
+val () = setCB (_address "lib1cFnPublic"    : p;)
+
+(* Have C confirm that it sees the same function pointers we do.
+ * C will check the values of the variables against it's own pointers.
+ * C also checks SML functions return his idea of pointers to our exports.
+ *)
+val () = _import "lib1confirmC" private : unit -> unit; ()
+
+(* Confirm that C functions return pointers to address as we expect. *)
+fun check (s, b) = if b then () else print (s ^ " pointers don't match!\n")
+val () = check ("lib1cFnPrivate", getCI () = _address "lib1cSymPrivate" private : p;)
+val () = check ("lib1cFnPublic",  getCB () = _address "lib1cSymPublic"  public  : p;)
+
+val () = print "lib1 pointer test complete.\n"

Added: mlton/trunk/regression/library/lib2.c
===================================================================
--- mlton/trunk/regression/library/lib2.c	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib2.c	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,35 @@
+#include <assert.h>
+
+#define PART_OF_LIBRARY_LIB2
+#include "lib2.h"
+#include "lib1.h"
+
+extern PUBLIC void* lib1cSymPublic;
+extern PUBLIC void* lib1cFnPublic(void);
+
+PRIVATE void* lib2cSymPrivate = 0;
+PUBLIC  void* lib2cSymPublic  = 0;
+
+PRIVATE void* lib2cFnPrivate(void) {
+  return &lib2cSymPrivate;
+}
+
+PUBLIC void* lib2cFnPublic(void) {
+  return &lib2cSymPublic;
+}
+
+PRIVATE void lib2confirmC(void) {
+  assert (&lib2smlFnPrivate == lib2smlSymPrivate);
+  assert (&lib2smlFnPublic  == lib2smlSymPublic);
+  assert (&lib2cFnPrivate   == lib2cSymPrivate);
+  assert (&lib2cFnPublic    == lib2cSymPublic);
+  
+  assert (lib2smlFnPrivate() == &lib2smlSymPrivate);
+  assert (lib2smlFnPublic()  == &lib2smlSymPublic);
+  
+  /* Check lib1 */
+  assert (&lib1smlFnPublic  == lib1smlSymPublic);
+  assert (&lib1cFnPublic    == lib1cSymPublic);
+  assert (lib1smlFnPublic() == &lib1smlSymPublic);
+  assert (lib1cFnPublic()   == &lib1cSymPublic);
+}

Added: mlton/trunk/regression/library/lib2.sml
===================================================================
--- mlton/trunk/regression/library/lib2.sml	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib2.sml	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,51 @@
+(* Prepare lib1 *)
+val () = _import "lib1_open" : unit -> unit; ()
+
+type p = MLton.Pointer.t
+
+type 'a s = (unit -> 'a) * ('a -> unit)
+val (_, setSI) = _symbol "lib2smlSymPrivate" alloc private : p s;
+val (_, setSB) = _symbol "lib2smlSymPublic"  alloc public  : p s;
+val (_, setCI) = _symbol "lib2cSymPrivate" private : p s;
+val (_, setCB) = _symbol "lib2cSymPublic"  public  : p s;
+
+type i = (unit -> p)
+type e = i -> unit
+val () = _export "lib2smlFnPrivate" private : e;
+         (fn () => _address "lib2smlSymPrivate" private : p;)
+val () = _export "lib2smlFnPublic" public : e;
+         (fn () => _address "lib2smlSymPublic" public : p;)
+val getCI = _import "lib2cFnPrivate" private : i;
+val getCB = _import "lib2cFnPublic" public : i;
+
+(* Store our idea of what the function pointers are in symbols *)
+val () = setSI (_address "lib2smlFnPrivate" : p;)
+val () = setSB (_address "lib2smlFnPublic"  : p;)
+val () = setCI (_address "lib2cFnPrivate"   : p;)
+val () = setCB (_address "lib2cFnPublic"    : p;)
+
+(* Have C confirm that it sees the same function pointers we do.
+ * C will check the values of the variables against it's own pointers.
+ * C also checks SML functions return his idea of pointers to our exports.
+ *)
+val () = _import "lib2confirmC" private : unit -> unit; ()
+
+(* Confirm that C functions return pointers to address as we expect. *)
+fun check (s, b) = if b then () else print (s ^ " pointers don't match!\n")
+val () = check ("lib2cFnPrivate", getCI () = _address "lib2cSymPrivate" private : p;)
+val () = check ("lib2cFnPublic",  getCB () = _address "lib2cSymPublic"  public  : p;)
+
+(* Test symbols in lib1 *)
+val (SB, _) = _symbol "lib1smlSymPublic" public : p s;
+val (CB, _) = _symbol "lib1cSymPublic"   public : p s;
+val getSB = _import "lib1smlFnPublic" public : i;
+val getCB = _import "lib1cFnPublic"   public : i;
+
+(* Check function pointers *)
+val () = check ("lib1smlFnPublic", SB () = _address "lib1smlFnPublic" public : p;)
+val () = check ("lib1cFnPublic",   CB () = _address "lib1cFnPublic"   public : p;)
+(* Check symbol pointers *)
+val () = check ("lib1smlSymPublic", getSB () = _address "lib1smlSymPublic" public : p;)
+val () = check ("lib1cSymPublic",   getCB () = _address "lib1cSymPublic"   public : p;)
+
+val () = print "lib2 pointer test complete.\n"

Added: mlton/trunk/regression/library/lib3.c
===================================================================
--- mlton/trunk/regression/library/lib3.c	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib3.c	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,44 @@
+#include <assert.h>
+
+#define PART_OF_LIBRARY_LIB3
+#include "lib3.h"
+#include "lib2.h"
+#include "lib1.h"
+
+extern EXTERNAL void* lib1cSymPublic;
+extern EXTERNAL void* lib1cFnPublic(void);
+extern EXTERNAL void* lib2cSymPublic;
+extern EXTERNAL void* lib2cFnPublic(void);
+
+PRIVATE void* lib3cSymPrivate = 0;
+PUBLIC  void* lib3cSymPublic  = 0;
+
+PRIVATE void* lib3cFnPrivate(void) {
+  return &lib3cSymPrivate;
+}
+
+PUBLIC void* lib3cFnPublic(void) {
+  return &lib3cSymPublic;
+}
+
+PRIVATE void lib3confirmC(void) {
+  assert (&lib3smlFnPrivate == lib3smlSymPrivate);
+  assert (&lib3smlFnPublic  == lib3smlSymPublic);
+  assert (&lib3cFnPrivate   == lib3cSymPrivate);
+  assert (&lib3cFnPublic    == lib3cSymPublic);
+  
+  assert (lib3smlFnPrivate() == &lib3smlSymPrivate);
+  assert (lib3smlFnPublic()  == &lib3smlSymPublic);
+  
+  /* Check lib1 */
+  assert (&lib1smlFnPublic  == lib1smlSymPublic);
+  assert (&lib1cFnPublic    == lib1cSymPublic);
+  assert (lib1smlFnPublic() == &lib1smlSymPublic);
+  assert (lib1cFnPublic()   == &lib1cSymPublic);
+  
+  /* Check lib2 */
+  assert (&lib2smlFnPublic  == lib2smlSymPublic);
+  assert (&lib2cFnPublic    == lib2cSymPublic);
+  assert (lib2smlFnPublic() == &lib2smlSymPublic);
+  assert (lib2cFnPublic()   == &lib2cSymPublic);
+}

Added: mlton/trunk/regression/library/lib3.sml
===================================================================
--- mlton/trunk/regression/library/lib3.sml	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib3.sml	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,64 @@
+(* Prepare lib2 *)
+val () = _import "lib2_open" : unit -> unit; ()
+
+type p = MLton.Pointer.t
+
+type 'a s = (unit -> 'a) * ('a -> unit)
+val (_, setSI) = _symbol "lib3smlSymPrivate" alloc private : p s;
+val (_, setSB) = _symbol "lib3smlSymPublic"  alloc public  : p s;
+val (_, setCI) = _symbol "lib3cSymPrivate" private : p s;
+val (_, setCB) = _symbol "lib3cSymPublic"  public  : p s;
+
+type i = (unit -> p)
+type e = i -> unit
+val () = _export "lib3smlFnPrivate" private : e;
+         (fn () => _address "lib3smlSymPrivate" private : p;)
+val () = _export "lib3smlFnPublic" public : e;
+         (fn () => _address "lib3smlSymPublic" public : p;)
+val getCI = _import "lib3cFnPrivate" private : i;
+val getCB = _import "lib3cFnPublic" public : i;
+
+(* Store our idea of what the function pointers are in symbols *)
+val () = setSI (_address "lib3smlFnPrivate" : p;)
+val () = setSB (_address "lib3smlFnPublic"  : p;)
+val () = setCI (_address "lib3cFnPrivate"   : p;)
+val () = setCB (_address "lib3cFnPublic"    : p;)
+
+(* Have C confirm that it sees the same function pointers we do.
+ * C will check the values of the variables against it's own pointers.
+ * C also checks SML functions return his idea of pointers to our exports.
+ *)
+val () = _import "lib3confirmC" private : unit -> unit; ()
+
+(* Confirm that C functions return pointers to address as we expect. *)
+fun check (s, b) = if b then () else print (s ^ " pointers don't match!\n")
+val () = check ("lib3cFnPrivate", getCI () = _address "lib3cSymPrivate" private : p;)
+val () = check ("lib3cFnPublic",  getCB () = _address "lib3cSymPublic"  public  : p;)
+
+(* Test symbols in lib1 *)
+val (SB, _) = _symbol "lib1smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib1cSymPublic"   external : p s;
+val getSB = _import "lib1smlFnPublic" external : i;
+val getCB = _import "lib1cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib1smlFnPublic", SB () = _address "lib1smlFnPublic" external : p;)
+val () = check ("lib1cFnPublic",   CB () = _address "lib1cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib1smlSymPublic", getSB () = _address "lib1smlSymPublic" external : p;)
+val () = check ("lib1cSymPublic",   getCB () = _address "lib1cSymPublic"   external : p;)
+
+(* Test symbols in lib2 *)
+val (SB, _) = _symbol "lib2smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib2cSymPublic"   external : p s;
+val getSB = _import "lib2smlFnPublic" external : i;
+val getCB = _import "lib2cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib2smlFnPublic", SB () = _address "lib2smlFnPublic" external : p;)
+val () = check ("lib2cFnPublic",   CB () = _address "lib2cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib2smlSymPublic", getSB () = _address "lib2smlSymPublic" external : p;)
+val () = check ("lib2cSymPublic",   getCB () = _address "lib2cSymPublic"   external : p;)
+
+val () = print "lib3 pointer test complete.\n"

Added: mlton/trunk/regression/library/lib4.c
===================================================================
--- mlton/trunk/regression/library/lib4.c	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib4.c	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,54 @@
+#include <assert.h>
+
+#define PART_OF_LIBRARY_LIB4
+#include "lib4.h"
+#include "lib3.h"
+#include "lib2.h"
+#include "lib1.h"
+
+extern EXTERNAL void* lib1cSymPublic;
+extern EXTERNAL void* lib1cFnPublic(void);
+extern EXTERNAL void* lib2cSymPublic;
+extern EXTERNAL void* lib2cFnPublic(void);
+
+extern PUBLIC void* lib3cSymPublic;
+extern PUBLIC void* lib3cFnPublic(void);
+
+PRIVATE void* lib4cSymPrivate = 0;
+PUBLIC  void* lib4cSymPublic  = 0;
+
+PRIVATE void* lib4cFnPrivate(void) {
+  return &lib4cSymPrivate;
+}
+
+PUBLIC void* lib4cFnPublic(void) {
+  return &lib4cSymPublic;
+}
+
+PRIVATE void lib4confirmC(void) {
+  assert (&lib4smlFnPrivate == lib4smlSymPrivate);
+  assert (&lib4smlFnPublic  == lib4smlSymPublic);
+  assert (&lib4cFnPrivate   == lib4cSymPrivate);
+  assert (&lib4cFnPublic    == lib4cSymPublic);
+  
+  assert (lib4smlFnPrivate() == &lib4smlSymPrivate);
+  assert (lib4smlFnPublic()  == &lib4smlSymPublic);
+  
+  /* Check lib1 */
+  assert (&lib1smlFnPublic  == lib1smlSymPublic);
+  assert (&lib1cFnPublic    == lib1cSymPublic);
+  assert (lib1smlFnPublic() == &lib1smlSymPublic);
+  assert (lib1cFnPublic()   == &lib1cSymPublic);
+  
+  /* Check lib2 */
+  assert (&lib2smlFnPublic  == lib2smlSymPublic);
+  assert (&lib2cFnPublic    == lib2cSymPublic);
+  assert (lib2smlFnPublic() == &lib2smlSymPublic);
+  assert (lib2cFnPublic()   == &lib2cSymPublic);
+  
+  /* Check lib3 */
+  assert (&lib3smlFnPublic  == lib3smlSymPublic);
+  assert (&lib3cFnPublic    == lib3cSymPublic);
+  assert (lib3smlFnPublic() == &lib3smlSymPublic);
+  assert (lib3cFnPublic()   == &lib3cSymPublic);
+}

Added: mlton/trunk/regression/library/lib4.sml
===================================================================
--- mlton/trunk/regression/library/lib4.sml	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib4.sml	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,77 @@
+(* Prepare lib3 *)
+val () = _import "lib3_open" : unit -> unit; ()
+
+type p = MLton.Pointer.t
+
+type 'a s = (unit -> 'a) * ('a -> unit)
+val (_, setSI) = _symbol "lib4smlSymPrivate" alloc private : p s;
+val (_, setSB) = _symbol "lib4smlSymPublic"  alloc public  : p s;
+val (_, setCI) = _symbol "lib4cSymPrivate" private : p s;
+val (_, setCB) = _symbol "lib4cSymPublic"  public  : p s;
+
+type i = (unit -> p)
+type e = i -> unit
+val () = _export "lib4smlFnPrivate" private : e;
+         (fn () => _address "lib4smlSymPrivate" private : p;)
+val () = _export "lib4smlFnPublic" public : e;
+         (fn () => _address "lib4smlSymPublic" public : p;)
+val getCI = _import "lib4cFnPrivate" private : i;
+val getCB = _import "lib4cFnPublic" public : i;
+
+(* Store our idea of what the function pointers are in symbols *)
+val () = setSI (_address "lib4smlFnPrivate" : p;)
+val () = setSB (_address "lib4smlFnPublic"  : p;)
+val () = setCI (_address "lib4cFnPrivate"   : p;)
+val () = setCB (_address "lib4cFnPublic"    : p;)
+
+(* Have C confirm that it sees the same function pointers we do.
+ * C will check the values of the variables against it's own pointers.
+ * C also checks SML functions return his idea of pointers to our exports.
+ *)
+val () = _import "lib4confirmC" private : unit -> unit; ()
+
+(* Confirm that C functions return pointers to address as we expect. *)
+fun check (s, b) = if b then () else print (s ^ " pointers don't match!\n")
+val () = check ("lib4cFnPrivate", getCI () = _address "lib4cSymPrivate" private : p;)
+val () = check ("lib4cFnPublic",  getCB () = _address "lib4cSymPublic"  public  : p;)
+
+(* Test symbols in lib1 *)
+val (SB, _) = _symbol "lib1smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib1cSymPublic"   external : p s;
+val getSB = _import "lib1smlFnPublic" external : i;
+val getCB = _import "lib1cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib1smlFnPublic", SB () = _address "lib1smlFnPublic" external : p;)
+val () = check ("lib1cFnPublic",   CB () = _address "lib1cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib1smlSymPublic", getSB () = _address "lib1smlSymPublic" external : p;)
+val () = check ("lib1cSymPublic",   getCB () = _address "lib1cSymPublic"   external : p;)
+
+(* Test symbols in lib2 *)
+val (SB, _) = _symbol "lib2smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib2cSymPublic"   external : p s;
+val getSB = _import "lib2smlFnPublic" external : i;
+val getCB = _import "lib2cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib2smlFnPublic", SB () = _address "lib2smlFnPublic" external : p;)
+val () = check ("lib2cFnPublic",   CB () = _address "lib2cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib2smlSymPublic", getSB () = _address "lib2smlSymPublic" external : p;)
+val () = check ("lib2cSymPublic",   getCB () = _address "lib2cSymPublic"   external : p;)
+
+(* Test symbols in lib3 *)
+val (SB, _) = _symbol "lib3smlSymPublic" public : p s;
+val (CB, _) = _symbol "lib3cSymPublic"   public : p s;
+val getSB = _import "lib3smlFnPublic" public : i;
+val getCB = _import "lib3cFnPublic"   public : i;
+
+(* Check function pointers *)
+val () = check ("lib3smlFnPublic", SB () = _address "lib3smlFnPublic" public : p;)
+val () = check ("lib3cFnPublic",   CB () = _address "lib3cFnPublic"   public : p;)
+(* Check symbol pointers *)
+val () = check ("lib3smlSymPublic", getSB () = _address "lib3smlSymPublic" public : p;)
+val () = check ("lib3cSymPublic",   getCB () = _address "lib3cSymPublic"   public : p;)
+
+val () = print "lib4 pointer test complete.\n"

Added: mlton/trunk/regression/library/lib5.c
===================================================================
--- mlton/trunk/regression/library/lib5.c	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib5.c	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,44 @@
+#include <assert.h>
+
+#define PART_OF_LIBRARY_LIB5
+#include "lib5.h"
+#include "lib4.h"
+#include "lib3.h"
+
+extern EXTERNAL void* lib3cSymPublic;
+extern EXTERNAL void* lib3cFnPublic(void);
+extern EXTERNAL void* lib4cSymPublic;
+extern EXTERNAL void* lib4cFnPublic(void);
+
+PRIVATE void* lib5cSymPrivate = 0;
+PUBLIC  void* lib5cSymPublic  = 0;
+
+PRIVATE void* lib5cFnPrivate(void) {
+  return &lib5cSymPrivate;
+}
+
+PUBLIC void* lib5cFnPublic(void) {
+  return &lib5cSymPublic;
+}
+
+PRIVATE void lib5confirmC(void) {
+  assert (&lib5smlFnPrivate == lib5smlSymPrivate);
+  assert (&lib5smlFnPublic  == lib5smlSymPublic);
+  assert (&lib5cFnPrivate   == lib5cSymPrivate);
+  assert (&lib5cFnPublic    == lib5cSymPublic);
+  
+  assert (lib5smlFnPrivate() == &lib5smlSymPrivate);
+  assert (lib5smlFnPublic()  == &lib5smlSymPublic);
+  
+  /* Check lib3 */
+  assert (&lib3smlFnPublic  == lib3smlSymPublic);
+  assert (&lib3cFnPublic    == lib3cSymPublic);
+  assert (lib3smlFnPublic() == &lib3smlSymPublic);
+  assert (lib3cFnPublic()   == &lib3cSymPublic);
+  
+  /* Check lib4 */
+  assert (&lib4smlFnPublic  == lib4smlSymPublic);
+  assert (&lib4cFnPublic    == lib4cSymPublic);
+  assert (lib4smlFnPublic() == &lib4smlSymPublic);
+  assert (lib4cFnPublic()   == &lib4cSymPublic);
+}

Added: mlton/trunk/regression/library/lib5.sml
===================================================================
--- mlton/trunk/regression/library/lib5.sml	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/lib5.sml	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,64 @@
+(* Prepare lib4 *)
+val () = _import "lib4_open" : unit -> unit; ()
+
+type p = MLton.Pointer.t
+
+type 'a s = (unit -> 'a) * ('a -> unit)
+val (_, setSI) = _symbol "lib5smlSymPrivate" alloc private : p s;
+val (_, setSB) = _symbol "lib5smlSymPublic"  alloc public  : p s;
+val (_, setCI) = _symbol "lib5cSymPrivate" private : p s;
+val (_, setCB) = _symbol "lib5cSymPublic"  public  : p s;
+
+type i = (unit -> p)
+type e = i -> unit
+val () = _export "lib5smlFnPrivate" private : e;
+         (fn () => _address "lib5smlSymPrivate" private : p;)
+val () = _export "lib5smlFnPublic" public : e;
+         (fn () => _address "lib5smlSymPublic" public : p;)
+val getCI = _import "lib5cFnPrivate" private : i;
+val getCB = _import "lib5cFnPublic" public : i;
+
+(* Store our idea of what the function pointers are in symbols *)
+val () = setSI (_address "lib5smlFnPrivate" : p;)
+val () = setSB (_address "lib5smlFnPublic"  : p;)
+val () = setCI (_address "lib5cFnPrivate"   : p;)
+val () = setCB (_address "lib5cFnPublic"    : p;)
+
+(* Have C confirm that it sees the same function pointers we do.
+ * C will check the values of the variables against it's own pointers.
+ * C also checks SML functions return his idea of pointers to our exports.
+ *)
+val () = _import "lib5confirmC" private : unit -> unit; ()
+
+(* Confirm that C functions return pointers to address as we expect. *)
+fun check (s, b) = if b then () else print (s ^ " pointers don't match!\n")
+val () = check ("lib5cFnPrivate", getCI () = _address "lib5cSymPrivate" private : p;)
+val () = check ("lib5cFnPublic",  getCB () = _address "lib5cSymPublic"  public  : p;)
+
+(* Test symbols in lib3 *)
+val (SB, _) = _symbol "lib3smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib3cSymPublic"   external : p s;
+val getSB = _import "lib3smlFnPublic" external : i;
+val getCB = _import "lib3cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib3smlFnPublic", SB () = _address "lib3smlFnPublic" external : p;)
+val () = check ("lib3cFnPublic",   CB () = _address "lib3cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib3smlSymPublic", getSB () = _address "lib3smlSymPublic" external : p;)
+val () = check ("lib3cSymPublic",   getCB () = _address "lib3cSymPublic"   external : p;)
+
+(* Test symbols in lib4 *)
+val (SB, _) = _symbol "lib4smlSymPublic" external : p s;
+val (CB, _) = _symbol "lib4cSymPublic"   external : p s;
+val getSB = _import "lib4smlFnPublic" external : i;
+val getCB = _import "lib4cFnPublic"   external : i;
+
+(* Check function pointers *)
+val () = check ("lib4smlFnPublic", SB () = _address "lib4smlFnPublic" external : p;)
+val () = check ("lib4cFnPublic",   CB () = _address "lib4cFnPublic"   external : p;)
+(* Check symbol pointers *)
+val () = check ("lib4smlSymPublic", getSB () = _address "lib4smlSymPublic" external : p;)
+val () = check ("lib4cSymPublic",   getCB () = _address "lib4cSymPublic"   external : p;)
+
+val () = print "lib5 pointer test complete.\n"

Added: mlton/trunk/regression/library/library-test
===================================================================
--- mlton/trunk/regression/library/library-test	2008-09-17 21:38:32 UTC (rev 6858)
+++ mlton/trunk/regression/library/library-test	2008-09-18 01:13:38 UTC (rev 6859)
@@ -0,0 +1,29 @@
+#! /usr/bin/env bash
+
+ML=mlton
+
+O[0]='-default-ann'
+O[1]='allowFFI true'
+O[2]='-link-opt'
+O[3]='-L.'
+O[4]='-target'
+O[5]='x86_64'
+
+LIB="-link-opt -l"
+set -ex
+
+# Compile DSO #1
+$ML "${O[@]}" -format libarchive -export-header lib1.h lib1.sml lib1.c
+$ML "${O[@]}" ${LIB}1 -format library -export-header lib2.h lib2.sml lib2.c
+
+# Compile DSO #2
+$ML "${O[@]}" -format libarchive -export-header lib3.h lib3.sml lib3.c
+$ML "${O[@]}" ${LIB}2 ${LIB}3 -format library -export-header lib4.h lib4.sml lib4.c
+
+# Compile executable
+$ML "${O[@]}" -format archive -export-header lib5.h lib5.sml lib5.c
+$ML "${O[@]}" ${LIB}4 ${LIB}5 -format executable -export-header check.h check.sml check.c
+
+# Check that symbols resolved correctly
+export LD_LIBRARY_PATH=.
+./check


Property changes on: mlton/trunk/regression/library/library-test
___________________________________________________________________
Name: svn:executable
   + *




More information about the MLton-commit mailing list