[MLton-commit] r7036

Ville Laurikari ville at mlton.org
Tue Apr 7 12:02:16 PDT 2009


Replace use of _const in mlnlffi-lib with a C program which generates
a small .sml file for the constants.

It was not a good idea to use _const.  It forces the Basis Library
archive to carry around values that are only used by mlnlffi-lib.
This means that these constants need to be available on every
platform, regardless of whether or not that platform supports libdl
(some may not).

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

U   mlton/trunk/Makefile
U   mlton/trunk/basis-library/primitive/basis-ffi.sml
A   mlton/trunk/lib/mlnlffi/.ignore
A   mlton/trunk/lib/mlnlffi/Makefile
A   mlton/trunk/lib/mlnlffi/gen-rtld-flags.c
A   mlton/trunk/lib/mlnlffi/memory/.ignore
U   mlton/trunk/lib/mlnlffi/memory/linkage-libdl.sml
U   mlton/trunk/lib/mlnlffi/memory/memory.unix.mlb
U   mlton/trunk/runtime/basis-ffi.h
U   mlton/trunk/runtime/gen/basis-ffi.def
U   mlton/trunk/runtime/gen/basis-ffi.h
U   mlton/trunk/runtime/gen/basis-ffi.sml
U   mlton/trunk/runtime/platform.c

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

Modified: mlton/trunk/Makefile
===================================================================
--- mlton/trunk/Makefile	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/Makefile	2009-04-07 19:02:13 UTC (rev 7036)
@@ -180,6 +180,7 @@
 	mkdir -p "$(LIB)/sml"
 	cd "$(LIB)/sml" && rm -rf $(LIBRARIES)
 	$(MAKE) -C "$(SRC)/lib/ckit-lib"
+	$(MAKE) -C "$(SRC)/lib/mlnlffi"
 	$(MAKE) -C "$(SRC)/lib/mlrisc-lib"
 	$(MAKE) -C "$(SRC)/lib/smlnj-lib"
 	$(CP) "$(SRC)/lib/cml/." "$(LIB)/sml/cml"

Modified: mlton/trunk/basis-library/primitive/basis-ffi.sml
===================================================================
--- mlton/trunk/basis-library/primitive/basis-ffi.sml	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/basis-library/primitive/basis-ffi.sml	2009-04-07 19:02:13 UTC (rev 7036)
@@ -42,13 +42,6 @@
 val setYear = _import "Date_Tm_setYear" private : C_Int.t -> unit;
 end
 end
-structure DynLinkage = 
-struct
-val RTLD_GLOBAL = _const "DynLinkage_RTLD_GLOBAL" : C_UInt.t;
-val RTLD_LAZY = _const "DynLinkage_RTLD_LAZY" : C_UInt.t;
-val RTLD_LOCAL = _const "DynLinkage_RTLD_LOCAL" : C_UInt.t;
-val RTLD_NOW = _const "DynLinkage_RTLD_NOW" : C_UInt.t;
-end
 structure IEEEReal = 
 struct
 structure FloatClass = 

Added: mlton/trunk/lib/mlnlffi/.ignore
===================================================================
--- mlton/trunk/lib/mlnlffi/.ignore	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/lib/mlnlffi/.ignore	2009-04-07 19:02:13 UTC (rev 7036)
@@ -0,0 +1,2 @@
+gen-rtld-flags
+gen-rtld-flags.exe

Added: mlton/trunk/lib/mlnlffi/Makefile
===================================================================
--- mlton/trunk/lib/mlnlffi/Makefile	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/lib/mlnlffi/Makefile	2009-04-07 19:02:13 UTC (rev 7036)
@@ -0,0 +1,9 @@
+CC := gcc -std=gnu99
+CFLAGS := -Wall
+
+.DELETE_ON_ERROR:
+all: memory/rtld-flags.sml
+
+memory/rtld-flags.sml: gen-rtld-flags.c
+	$(CC) $(CFLAGS) -o gen-rtld-flags gen-rtld-flags.c
+	./gen-rtld-flags > memory/rtld-flags.sml

Added: mlton/trunk/lib/mlnlffi/gen-rtld-flags.c
===================================================================
--- mlton/trunk/lib/mlnlffi/gen-rtld-flags.c	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/lib/mlnlffi/gen-rtld-flags.c	2009-04-07 19:02:13 UTC (rev 7036)
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <dlfcn.h>
+
+int main(int argc, char *argv[])
+{
+  printf("structure RTLDFlags = struct\n");
+  printf("   val RTLD_GLOBAL = 0wx%x\n", RTLD_GLOBAL);
+  printf("   val RTLD_LAZY = 0wx%x\n", RTLD_LAZY);
+  printf("   val RTLD_LOCAL = 0wx%x\n", RTLD_LOCAL);
+  printf("   val RTLD_NOW = 0wx%x\n", RTLD_NOW);
+  printf("end\n");
+
+  return 0;
+}

Added: mlton/trunk/lib/mlnlffi/memory/.ignore
===================================================================
--- mlton/trunk/lib/mlnlffi/memory/.ignore	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/lib/mlnlffi/memory/.ignore	2009-04-07 19:02:13 UTC (rev 7036)
@@ -0,0 +1 @@
+rtld-flags.sml

Modified: mlton/trunk/lib/mlnlffi/memory/linkage-libdl.sml
===================================================================
--- mlton/trunk/lib/mlnlffi/memory/linkage-libdl.sml	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/lib/mlnlffi/memory/linkage-libdl.sml	2009-04-07 19:02:13 UTC (rev 7036)
@@ -36,10 +36,7 @@
 
     type mode = C_UInt.word
     local
-       val RTLD_LAZY   = _const "DynLinkage_RTLD_LAZY"   : C_UInt.t;
-       val RTLD_NOW    = _const "DynLinkage_RTLD_NOW"    : C_UInt.t;
-       val RTLD_GLOBAL = _const "DynLinkage_RTLD_GLOBAL" : C_UInt.t;
-       val RTLD_LOCAL  = _const "DynLinkage_RTLD_LOCAL"  : C_UInt.t;
+       open RTLDFlags
     in
        fun mk_mode {lazy: bool, global: bool} : mode=
           C_UInt.orb

Modified: mlton/trunk/lib/mlnlffi/memory/memory.unix.mlb
===================================================================
--- mlton/trunk/lib/mlnlffi/memory/memory.unix.mlb	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/lib/mlnlffi/memory/memory.unix.mlb	2009-04-07 19:02:13 UTC (rev 7036)
@@ -10,10 +10,8 @@
    in
       local
          linkage.sig
-         ann 
-            "allowFFI true"
-            "allowConstant true"
-         in
+         ann "allowFFI true" in
+            rtld-flags.sml
             linkage-libdl.sml
          end
          bitop-fn.sml

Modified: mlton/trunk/runtime/basis-ffi.h
===================================================================
--- mlton/trunk/runtime/basis-ffi.h	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/runtime/basis-ffi.h	2009-04-07 19:02:13 UTC (rev 7036)
@@ -32,10 +32,6 @@
 PRIVATE void Date_Tm_setWDay(C_Int_t);
 PRIVATE void Date_Tm_setYDay(C_Int_t);
 PRIVATE void Date_Tm_setYear(C_Int_t);
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_GLOBAL;
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_LAZY;
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_LOCAL;
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_NOW;
 PRIVATE extern const C_Int_t IEEEReal_FloatClass_FP_INFINITE;
 PRIVATE extern const C_Int_t IEEEReal_FloatClass_FP_NAN;
 PRIVATE extern const C_Int_t IEEEReal_FloatClass_FP_NORMAL;

Modified: mlton/trunk/runtime/gen/basis-ffi.def
===================================================================
--- mlton/trunk/runtime/gen/basis-ffi.def	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/runtime/gen/basis-ffi.def	2009-04-07 19:02:13 UTC (rev 7036)
@@ -25,10 +25,6 @@
 Date.localTime = _import PRIVATE : C_Time.t ref -> C_Int.t C_Errno.t
 Date.mkTime = _import PRIVATE : unit -> C_Time.t C_Errno.t
 Date.strfTime = _import PRIVATE : Char8.t array * C_Size.t * NullString8.t -> C_Size.t
-DynLinkage.RTLD_GLOBAL = _const : C_UInt.t
-DynLinkage.RTLD_LAZY = _const : C_UInt.t
-DynLinkage.RTLD_LOCAL = _const : C_UInt.t
-DynLinkage.RTLD_NOW = _const : C_UInt.t
 IEEEReal.FloatClass.FP_INFINITE = _const : C_Int.t
 IEEEReal.FloatClass.FP_NAN = _const : C_Int.t
 IEEEReal.FloatClass.FP_NORMAL = _const : C_Int.t

Modified: mlton/trunk/runtime/gen/basis-ffi.h
===================================================================
--- mlton/trunk/runtime/gen/basis-ffi.h	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/runtime/gen/basis-ffi.h	2009-04-07 19:02:13 UTC (rev 7036)
@@ -32,10 +32,6 @@
 PRIVATE void Date_Tm_setWDay(C_Int_t);
 PRIVATE void Date_Tm_setYDay(C_Int_t);
 PRIVATE void Date_Tm_setYear(C_Int_t);
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_GLOBAL;
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_LAZY;
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_LOCAL;
-PRIVATE extern const C_UInt_t DynLinkage_RTLD_NOW;
 PRIVATE extern const C_Int_t IEEEReal_FloatClass_FP_INFINITE;
 PRIVATE extern const C_Int_t IEEEReal_FloatClass_FP_NAN;
 PRIVATE extern const C_Int_t IEEEReal_FloatClass_FP_NORMAL;

Modified: mlton/trunk/runtime/gen/basis-ffi.sml
===================================================================
--- mlton/trunk/runtime/gen/basis-ffi.sml	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/runtime/gen/basis-ffi.sml	2009-04-07 19:02:13 UTC (rev 7036)
@@ -42,13 +42,6 @@
 val setYear = _import "Date_Tm_setYear" private : C_Int.t -> unit;
 end
 end
-structure DynLinkage = 
-struct
-val RTLD_GLOBAL = _const "DynLinkage_RTLD_GLOBAL" : C_UInt.t;
-val RTLD_LAZY = _const "DynLinkage_RTLD_LAZY" : C_UInt.t;
-val RTLD_LOCAL = _const "DynLinkage_RTLD_LOCAL" : C_UInt.t;
-val RTLD_NOW = _const "DynLinkage_RTLD_NOW" : C_UInt.t;
-end
 structure IEEEReal = 
 struct
 structure FloatClass = 

Modified: mlton/trunk/runtime/platform.c
===================================================================
--- mlton/trunk/runtime/platform.c	2009-04-07 15:37:52 UTC (rev 7035)
+++ mlton/trunk/runtime/platform.c	2009-04-07 19:02:13 UTC (rev 7036)
@@ -6,16 +6,9 @@
  */
 
 #include "platform.h"
-#include <dlfcn.h>
 
 Bool MLton_Platform_CygwinUseMmap = FALSE;
 
-/* These are needed in the DynLinkage structure in mlnlffi-lib. */
-const C_UInt_t DynLinkage_RTLD_GLOBAL = RTLD_GLOBAL;
-const C_UInt_t DynLinkage_RTLD_LAZY   = RTLD_LAZY;
-const C_UInt_t DynLinkage_RTLD_LOCAL  = RTLD_LOCAL;
-const C_UInt_t DynLinkage_RTLD_NOW    = RTLD_NOW;
-
 void GC_setCygwinUseMmap (bool b) {
   MLton_Platform_CygwinUseMmap = b;
 }




More information about the MLton-commit mailing list