* Re: Toplevel script mode
@ 1999-04-06 8:43 Ian T Zimmerman
0 siblings, 0 replies; 2+ messages in thread
From: Ian T Zimmerman @ 1999-04-06 8:43 UTC (permalink / raw)
To: caml-list
Right after sending off my preceding message I stepped into the shower
and immediately I had another brilliant idea :-) Why not make the
initfile name mutable, then user extensions can load a different one
(if they change the ref in the files they link).
Patch is cummulative:
--- /home/itz/toploop.ml Tue Apr 6 00:57:59 1999
+++ /usr/src/ocaml-2.02/toplevel/toploop.ml Tue Apr 6 01:32:49 1999
@@ -271,8 +271,11 @@
Clflags.thread_safe := true;
Compile.init_path()
+let initfile_name =
+ ref ".ocamlinit"
+
let load_ocamlinit () =
- if Sys.file_exists ".ocamlinit" then ignore(use_silently ".ocamlinit")
+ if Sys.file_exists !initfile_name then ignore(use_silently !initfile_name)
(* The interactive loop *)
@@ -311,7 +314,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_
^ permalink raw reply [flat|nested] 2+ messages in thread
* Toplevel script mode
@ 1999-04-06 8:07 Ian T Zimmerman
0 siblings, 0 replies; 2+ messages in thread
From: Ian T Zimmerman @ 1999-04-06 8:07 UTC (permalink / raw)
To: caml-list
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_
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-04-06 16:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-06 8:43 Toplevel script mode Ian T Zimmerman
-- strict thread matches above, loose matches on Subject: below --
1999-04-06 8:07 Ian T Zimmerman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox