summaryrefslogtreecommitdiff
path: root/otherlibs/dynlink
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2010-05-25 10:00:39 +0000
committerAlain Frisch <alain@frisch.fr>2010-05-25 10:00:39 +0000
commit47dbbc7d7f08b5eae905979eb09921ee50cd0d43 (patch)
treec943c5a71190b3cae9578f503dcbba7a8e0a120e /otherlibs/dynlink
parent9d27a7fc8ec929763a78a46845f3deef5ee8aebe (diff)
downloadocaml-47dbbc7d7f08b5eae905979eb09921ee50cd0d43.tar.gz
Decide at config time if natdynlink is supported or not, but always compile/install dynlink.cmxa to simplify 3rd party packages. A runtime exception signals an unsupported natdynlink.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10461 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/dynlink')
-rw-r--r--otherlibs/dynlink/Makefile4
-rw-r--r--otherlibs/dynlink/dynlink.ml5
-rw-r--r--otherlibs/dynlink/dynlink.mli5
-rw-r--r--otherlibs/dynlink/natdynlink.ml6
4 files changed, 18 insertions, 2 deletions
diff --git a/otherlibs/dynlink/Makefile b/otherlibs/dynlink/Makefile
index 9b72fe5988..da58af3daf 100644
--- a/otherlibs/dynlink/Makefile
+++ b/otherlibs/dynlink/Makefile
@@ -58,9 +58,9 @@ dynlinkaux.cmo: $(COMPILEROBJS)
dynlinkaux.cmi: dynlinkaux.cmo
dynlink.cmx: dynlink.cmi natdynlink.ml
- cp natdynlink.ml dynlink.mlopt
+ sed -e 's|%%NATDYNLINK%%|$(NATDYNLINK)|' natdynlink.ml > dynlink.mlopt
$(CAMLOPT) -c $(COMPFLAGS) -impl dynlink.mlopt
- rm -f dynlink.mlopt
+# rm -f dynlink.mlopt
extract_crc: dynlink.cma extract_crc.cmo
$(CAMLC) $(COMPFLAGS) -o extract_crc dynlink.cma extract_crc.cmo
diff --git a/otherlibs/dynlink/dynlink.ml b/otherlibs/dynlink/dynlink.ml
index 0d324a8540..d8d2f11623 100644
--- a/otherlibs/dynlink/dynlink.ml
+++ b/otherlibs/dynlink/dynlink.ml
@@ -18,6 +18,8 @@
open Dynlinkaux (* REMOVE_ME for ../../debugger/dynlink.ml *)
open Cmo_format
+let supported = true
+
type linking_error =
Undefined_global of string
| Unavailable_primitive of string
@@ -33,6 +35,7 @@ type error =
| File_not_found of string
| Cannot_open_dll of string
| Inconsistent_implementation of string
+ | Dynlink_not_supported
exception Error of error
@@ -268,6 +271,8 @@ let error_message = function
"error loading shared library: " ^ reason
| Inconsistent_implementation name ->
"implementation mismatch on " ^ name
+ | Dynlink_not_supported ->
+ "dynlink not supported"
let is_native = false
let adapt_filename f = f
diff --git a/otherlibs/dynlink/dynlink.mli b/otherlibs/dynlink/dynlink.mli
index 7cca68c5a0..ae87547988 100644
--- a/otherlibs/dynlink/dynlink.mli
+++ b/otherlibs/dynlink/dynlink.mli
@@ -19,6 +19,10 @@ val is_native: bool
(** [true] if the program is native,
[false] if the program is bytecode. *)
+val supported: bool
+(** [true] if dynlink is supported for the current platform (always
+ [true] in bytecode, can be [false] for native code). *)
+
(** {6 Dynamic loading of compiled files} *)
val loadfile : string -> unit
@@ -127,6 +131,7 @@ type error =
| File_not_found of string
| Cannot_open_dll of string
| Inconsistent_implementation of string
+ | Dynlink_not_supported
exception Error of error
(** Errors in dynamic linking are reported by raising the [Error]
diff --git a/otherlibs/dynlink/natdynlink.ml b/otherlibs/dynlink/natdynlink.ml
index 6ab9b9850a..e481dd870f 100644
--- a/otherlibs/dynlink/natdynlink.ml
+++ b/otherlibs/dynlink/natdynlink.ml
@@ -15,6 +15,8 @@
(* Dynamic loading of .cmx files *)
+let supported = %%NATDYNLINK%%
+
type handle
external ndl_open: string -> bool -> handle * string = "caml_natdynlink_open"
@@ -37,6 +39,7 @@ type error =
| File_not_found of string
| Cannot_open_dll of string
| Inconsistent_implementation of string
+ | Dynlink_not_supported
exception Error of error
@@ -93,6 +96,7 @@ let allow_extension = ref true
let inited = ref false
let default_available_units () =
+ if not supported then raise (Error Dynlink_not_supported);
let map : (string*Digest.t*Digest.t*string list) list =
Marshal.from_string (ndl_getmap ()) 0 in
let exe = Sys.executable_name in
@@ -244,6 +248,8 @@ let error_message = function
"error loading shared library: " ^ reason
| Inconsistent_implementation name ->
"implementation mismatch on " ^ name
+ | Dynlink_not_supported ->
+ "dynlink not supported"
let is_native = true
let adapt_filename f = Filename.chop_extension f ^ ".cmxs"