Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From a0b7d7ea9d4f330e0e0c239c89989b769872d27f Mon Sep 17 00:00:00 2001
- From: Thomas Leonard <talex5@gmail.com>
- Date: Fri, 19 Jul 2013 09:57:04 +0100
- Subject: [PATCH] ocaml toplevel: add script's directory to the search path
- Before, we added the current directory instead, which is less useful and
- a security risk (e.g. consider running a program while in /tmp).
- ---
- driver/compile.ml | 15 ++++++++++++---
- driver/compile.mli | 1 +
- driver/optcompile.ml | 14 +++++++++++---
- driver/optcompile.mli | 1 +
- toplevel/opttoploop.ml | 2 +-
- toplevel/toploop.ml | 2 +-
- 6 files changed, 27 insertions(+), 8 deletions(-)
- diff --git a/driver/compile.ml b/driver/compile.ml
- index 501ca90..3865ead 100644
- --- a/driver/compile.ml
- +++ b/driver/compile.ml
- @@ -20,21 +20,30 @@ open Format
- open Typedtree
- (* Initialize the search path.
- - The current directory is always searched first,
- + [first] is always searched first,
- then the directories specified with the -I option (in command-line order),
- then the standard library directory (unless the -nostdlib option is given).
- *)
- -let init_path () =
- +let init_path_with first =
- let dirs =
- if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs
- else if !Clflags.use_vmthreads then "+vmthreads" :: !Clflags.include_dirs
- else !Clflags.include_dirs in
- let exp_dirs =
- List.map (expand_directory Config.standard_library) dirs in
- - load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ());
- + load_path := first :: List.rev_append exp_dirs (Clflags.std_include_dir ());
- Env.reset_cache ()
- +(* Initialize the search path.
- + The current directory is always searched first,
- + then the directories specified with the -I option (in command-line order),
- + then the standard library directory (unless the -nostdlib option is given).
- + *)
- +
- +let init_path () =
- + init_path_with ""
- +
- (* Return the initial environment in which compilation proceeds. *)
- (* Note: do not do init_path() in initial_env, this breaks
- diff --git a/driver/compile.mli b/driver/compile.mli
- index a4965a4..afd9c6a 100644
- --- a/driver/compile.mli
- +++ b/driver/compile.mli
- @@ -22,3 +22,4 @@ val c_file: string -> unit
- val initial_env: unit -> Env.t
- val init_path: unit -> unit
- +val init_path_with: string -> unit
- diff --git a/driver/optcompile.ml b/driver/optcompile.ml
- index 7cd1867..130cab8 100644
- --- a/driver/optcompile.ml
- +++ b/driver/optcompile.ml
- @@ -20,20 +20,28 @@ open Format
- open Typedtree
- (* Initialize the search path.
- - The current directory is always searched first,
- + [first] is always searched first,
- then the directories specified with the -I option (in command-line order),
- then the standard library directory. *)
- -let init_path () =
- +let init_path_with first =
- let dirs =
- if !Clflags.use_threads
- then "+threads" :: !Clflags.include_dirs
- else !Clflags.include_dirs in
- let exp_dirs =
- List.map (expand_directory Config.standard_library) dirs in
- - load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ());
- + load_path := first :: List.rev_append exp_dirs (Clflags.std_include_dir ());
- Env.reset_cache ()
- +(* Initialize the search path.
- + The current directory is always searched first,
- + then the directories specified with the -I option (in command-line order),
- + then the standard library directory. *)
- +
- +let init_path () =
- + init_path_with ""
- +
- (* Return the initial environment in which compilation proceeds. *)
- let initial_env () =
- diff --git a/driver/optcompile.mli b/driver/optcompile.mli
- index d1e3f6b..947c049 100644
- --- a/driver/optcompile.mli
- +++ b/driver/optcompile.mli
- @@ -22,3 +22,4 @@ val c_file: string -> unit
- val initial_env: unit -> Env.t
- val init_path: unit -> unit
- +val init_path_with: string -> unit
- diff --git a/toplevel/opttoploop.ml b/toplevel/opttoploop.ml
- index 9bce61f..6f4dd60 100644
- --- a/toplevel/opttoploop.ml
- +++ b/toplevel/opttoploop.ml
- @@ -448,7 +448,7 @@ let run_script ppf name args =
- Array.blit args 0 Sys.argv 0 len;
- Obj.truncate (Obj.repr Sys.argv) len;
- Arg.current := 0;
- - Optcompile.init_path();
- + Optcompile.init_path_with (Filename.dirname name); (* Note: would use Filename.abspath here, if we had it. *)
- toplevel_env := Optcompile.initial_env();
- Sys.interactive := false;
- use_silently ppf name
- diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml
- index 88bd3cc..4ef4207 100644
- --- a/toplevel/toploop.ml
- +++ b/toplevel/toploop.ml
- @@ -440,7 +440,7 @@ let run_script ppf name args =
- Array.blit args 0 Sys.argv 0 len;
- Obj.truncate (Obj.repr Sys.argv) len;
- Arg.current := 0;
- - Compile.init_path();
- + Compile.init_path_with (Filename.dirname name); (* Note: would use Filename.abspath here, if we had it. *)
- toplevel_env := Compile.initial_env();
- Sys.interactive := false;
- use_silently ppf name
- --
- 1.8.5.1
Add Comment
Please, Sign In to add comment