Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Dynlink problems
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Dynlink problems
The following patch to OCaml fixes this bug in Dynlink. It allows you
to specify an alternate executable name, and also improves debugging
by printing a useful message if the system tries to use
Sys.executable_name when it is empty.

Rich.

----------------------------------------------------------------------
diff -ur ocaml-3.06.orig/bytecomp/symtable.ml ocaml-3.06/bytecomp/symtable.ml
--- ocaml-3.06.orig/bytecomp/symtable.ml	2002-02-11 14:08:43.000000000 +0000
+++ ocaml-3.06/bytecomp/symtable.ml	2003-07-31 18:16:48.000000000 +0100
@@ -243,10 +243,10 @@
 
 (* Initialize the linker for toplevel use *)
 
-let init_toplevel () =
+let init_toplevel_from_executable filename =
   (* Read back the known global symbols and the known primitives
      from the executable file *)
-  let ic = open_in_bin Sys.executable_name in
+  let ic = open_in_bin filename in
   begin try
     Bytesections.read_toc ic;
     ignore(Bytesections.seek_section ic "SYMB");
@@ -267,6 +267,11 @@
   (* Initialize the Dll machinery for toplevel use *)
   Dll.init_toplevel dllpath
 
+let init_toplevel () =
+  if Sys.executable_name = "" then
+    fatal_error "Sys.executable_name is \"\"";
+  init_toplevel_from_executable Sys.executable_name
+
 (* Find the value of a global identifier *)
 
 let get_global_position id = slot_for_getglobal id
diff -ur ocaml-3.06.orig/bytecomp/symtable.mli ocaml-3.06/bytecomp/symtable.mli
--- ocaml-3.06.orig/bytecomp/symtable.mli	2000-03-06 22:11:11.000000000 +0000
+++ ocaml-3.06/bytecomp/symtable.mli	2003-07-31 18:15:22.000000000 +0100
@@ -29,6 +29,7 @@
 (* Functions for the toplevel *)
 
 val init_toplevel: unit -> unit
+val init_toplevel_from_executable: string -> unit
 val update_global_table: unit -> unit
 val get_global_value: Ident.t -> Obj.t
 val assign_global_value: Ident.t -> Obj.t -> unit
diff -ur ocaml-3.06.orig/otherlibs/dynlink/dynlink.ml ocaml-3.06/otherlibs/dynlink/dynlink.ml
--- ocaml-3.06.orig/otherlibs/dynlink/dynlink.ml	2002-04-24 08:57:17.000000000 +0100
+++ ocaml-3.06/otherlibs/dynlink/dynlink.ml	2003-07-31 18:17:18.000000000 +0100
@@ -39,6 +39,9 @@
 let init () =
   Symtable.init_toplevel()  
 
+let init_from_executable =
+  Symtable.init_toplevel_from_executable
+
 (* Check that the object file being loaded has been compiled against
    the same interfaces as the program itself. In addition, check that
    only authorized compilation units are referenced. *)
diff -ur ocaml-3.06.orig/otherlibs/dynlink/dynlink.mli ocaml-3.06/otherlibs/dynlink/dynlink.mli
--- ocaml-3.06.orig/otherlibs/dynlink/dynlink.mli	2001-12-28 23:21:49.000000000 +0000
+++ ocaml-3.06/otherlibs/dynlink/dynlink.mli	2003-07-31 18:18:59.000000000 +0100
@@ -18,6 +18,12 @@
 val init : unit -> unit
 (** Initialize the library. Must be called before [loadfile]. *)
 
+val init_from_executable : string -> unit
+(** Initialize the library. Must be called before [loadfile].
+    This version takes the bytecode executable filename as an argument,
+    rather than using Sys.executable_name which will not be defined in
+    all cases (eg. if the main program is a C program or shared library). *)
+
 val loadfile : string -> unit
 (** Load the given bytecode object file and link it.
    All toplevel expressions in the loaded compilation unit
----------------------------------------------------------------------

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
NET::FTPSERVER is a full-featured, secure, configurable, database-backed
FTP server written in Perl: http://www.annexia.org/freeware/netftpserver/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners