To: caml-list@inria.fr
Subject: Toplevel script mode
From: Ian T Zimmerman <itz@transbay.net>
Date: 06 Apr 1999 01:07:27 -0700
Here's some code from ocaml-2.02/toplevel/toploop.ml:
[...]
(* Toplevel initialization. Performed here instead of at the
beginning of loop() so that user code linked in with ocamlmktop
can call directives from Topdirs. *)
let _ =
Sys.interactive := true;
Symtable.init_toplevel();
Clflags.thread_safe := true;
Compile.init_path()
let load_ocamlinit () =
if Sys.file_exists ".ocamlinit" then ignore(use_silently ".ocamlinit")
(* The interactive loop *)
[...]
(* Execute a script *)
let run_script name =
Compile.init_path();
toplevel_env := Compile.initial_env();
Format.set_formatter_out_channel stderr;
use_silently name
So, in script mode, Compile.init_path() is called twice, defeating the
purpose of hoisting it into pre-main code in the first place, as the
first comment explains it. I think this is a bug.
Also, I don't see any reason why script mode should omit calling
.ocamlinit. It does present a security risk, I think, but that
applies to the interactive case as well, and should be best handled by
adding a command line option to the toplevel to disable it.
Here's a patch (without the new option :-)
--- /home/itz/toploop.ml Tue Apr 6 00:57:59 1999
+++ /usr/src/ocaml-2.02/toplevel/toploop.ml Sat Apr 3 23:33:31 1999
@@ -311,7 +311,7 @@
(* Execute a script *)
let run_script name =
- Compile.init_path();
toplevel_env := Compile.initial_env();
Format.set_formatter_out_channel stderr;
+ load_ocamlinit ();
use_silently name
-- Ian T Zimmerman <itz@transbay.net> I came to the conclusion that what was wrong about the guillotine was that the condemned man had no chance at all, absolutely none. Albert Camus, _The Outsider_
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:21 MET