<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/07/90829853dc49798bf101a9cfeb7983e1"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-31T17:31:58"
  subject="Re: [Caml-list] Dynlink problems"
  prev="2003/07/159363fd41d8d458c431107765f3a1f9"
  next="2003/07/d683c78a91330f2c9cb62a6e96e4a2e6"
  prev-in-thread="2003/07/d4af9359cdc183f21897cd610a09561c"
  prev-thread="2003/07/61117640c01e53ce9c5abd6333cd32b3"
  next-thread="2003/07/8d067f3472c9db2843900ad04bc1ddfd"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Dynlink problems">
<msg 
  url="2003/07/976c83213750a167f0a635b7687ffe81"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-28T09:49:21"
  subject="[Caml-list] Dynlink problems">
<msg 
  url="2003/07/9a64ca5030c2ffb1a7eff3aa619c37e1"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-07-28T10:07:36"
  subject="Re: [Caml-list] Dynlink problems">
</msg>
<msg 
  url="2003/07/ab88f0ef9aad4a672172cac3798039fb"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-07-28T10:22:20"
  subject="Re: [Caml-list] Dynlink problems">
<msg 
  url="2003/07/01ec52a086a48ba9f37cf34e09d2a702"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-28T17:41:56"
  subject="Re: [Caml-list] Dynlink problems">
<msg 
  url="2003/07/9e1cdbeb2581b104e19c252cae4b4b29"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-07-29T08:48:00"
  subject="Re: [Caml-list] Dynlink problems">
<msg 
  url="2003/07/6ffbb61144ba7f83cf04a524a7aabde8"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-29T15:43:56"
  subject="Re: [Caml-list] Dynlink problems">
<msg 
  url="2003/07/d4af9359cdc183f21897cd610a09561c"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-29T16:28:46"
  subject="Re: [Caml-list] Dynlink problems">
<msg 
  url="2003/07/90829853dc49798bf101a9cfeb7983e1"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-07-31T17:31:58"
  subject="Re: [Caml-list] Dynlink problems">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>
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 -&gt; unit
+val init_toplevel_from_executable: string -&gt; unit
 val update_global_table: unit -&gt; unit
 val get_global_value: Ident.t -&gt; Obj.t
 val assign_global_value: Ident.t -&gt; Obj.t -&gt; 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 -&gt; unit
 (** Initialize the library. Must be called before [loadfile]. *)
 
+val init_from_executable : string -&gt; 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 -&gt; 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

</contents>

</message>

