Guest User

Untitled

a guest
Feb 16th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. From a0b7d7ea9d4f330e0e0c239c89989b769872d27f Mon Sep 17 00:00:00 2001
  2. From: Thomas Leonard <talex5@gmail.com>
  3. Date: Fri, 19 Jul 2013 09:57:04 +0100
  4. Subject: [PATCH] ocaml toplevel: add script's directory to the search path
  5.  
  6. Before, we added the current directory instead, which is less useful and
  7. a security risk (e.g. consider running a program while in /tmp).
  8. ---
  9. driver/compile.ml | 15 ++++++++++++---
  10. driver/compile.mli | 1 +
  11. driver/optcompile.ml | 14 +++++++++++---
  12. driver/optcompile.mli | 1 +
  13. toplevel/opttoploop.ml | 2 +-
  14. toplevel/toploop.ml | 2 +-
  15. 6 files changed, 27 insertions(+), 8 deletions(-)
  16.  
  17. diff --git a/driver/compile.ml b/driver/compile.ml
  18. index 501ca90..3865ead 100644
  19. --- a/driver/compile.ml
  20. +++ b/driver/compile.ml
  21. @@ -20,21 +20,30 @@ open Format
  22. open Typedtree
  23.  
  24. (* Initialize the search path.
  25. - The current directory is always searched first,
  26. + [first] is always searched first,
  27. then the directories specified with the -I option (in command-line order),
  28. then the standard library directory (unless the -nostdlib option is given).
  29. *)
  30.  
  31. -let init_path () =
  32. +let init_path_with first =
  33. let dirs =
  34. if !Clflags.use_threads then "+threads" :: !Clflags.include_dirs
  35. else if !Clflags.use_vmthreads then "+vmthreads" :: !Clflags.include_dirs
  36. else !Clflags.include_dirs in
  37. let exp_dirs =
  38. List.map (expand_directory Config.standard_library) dirs in
  39. - load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ());
  40. + load_path := first :: List.rev_append exp_dirs (Clflags.std_include_dir ());
  41. Env.reset_cache ()
  42.  
  43. +(* Initialize the search path.
  44. + The current directory is always searched first,
  45. + then the directories specified with the -I option (in command-line order),
  46. + then the standard library directory (unless the -nostdlib option is given).
  47. + *)
  48. +
  49. +let init_path () =
  50. + init_path_with ""
  51. +
  52. (* Return the initial environment in which compilation proceeds. *)
  53.  
  54. (* Note: do not do init_path() in initial_env, this breaks
  55. diff --git a/driver/compile.mli b/driver/compile.mli
  56. index a4965a4..afd9c6a 100644
  57. --- a/driver/compile.mli
  58. +++ b/driver/compile.mli
  59. @@ -22,3 +22,4 @@ val c_file: string -> unit
  60.  
  61. val initial_env: unit -> Env.t
  62. val init_path: unit -> unit
  63. +val init_path_with: string -> unit
  64. diff --git a/driver/optcompile.ml b/driver/optcompile.ml
  65. index 7cd1867..130cab8 100644
  66. --- a/driver/optcompile.ml
  67. +++ b/driver/optcompile.ml
  68. @@ -20,20 +20,28 @@ open Format
  69. open Typedtree
  70.  
  71. (* Initialize the search path.
  72. - The current directory is always searched first,
  73. + [first] is always searched first,
  74. then the directories specified with the -I option (in command-line order),
  75. then the standard library directory. *)
  76.  
  77. -let init_path () =
  78. +let init_path_with first =
  79. let dirs =
  80. if !Clflags.use_threads
  81. then "+threads" :: !Clflags.include_dirs
  82. else !Clflags.include_dirs in
  83. let exp_dirs =
  84. List.map (expand_directory Config.standard_library) dirs in
  85. - load_path := "" :: List.rev_append exp_dirs (Clflags.std_include_dir ());
  86. + load_path := first :: List.rev_append exp_dirs (Clflags.std_include_dir ());
  87. Env.reset_cache ()
  88.  
  89. +(* Initialize the search path.
  90. + The current directory is always searched first,
  91. + then the directories specified with the -I option (in command-line order),
  92. + then the standard library directory. *)
  93. +
  94. +let init_path () =
  95. + init_path_with ""
  96. +
  97. (* Return the initial environment in which compilation proceeds. *)
  98.  
  99. let initial_env () =
  100. diff --git a/driver/optcompile.mli b/driver/optcompile.mli
  101. index d1e3f6b..947c049 100644
  102. --- a/driver/optcompile.mli
  103. +++ b/driver/optcompile.mli
  104. @@ -22,3 +22,4 @@ val c_file: string -> unit
  105.  
  106. val initial_env: unit -> Env.t
  107. val init_path: unit -> unit
  108. +val init_path_with: string -> unit
  109. diff --git a/toplevel/opttoploop.ml b/toplevel/opttoploop.ml
  110. index 9bce61f..6f4dd60 100644
  111. --- a/toplevel/opttoploop.ml
  112. +++ b/toplevel/opttoploop.ml
  113. @@ -448,7 +448,7 @@ let run_script ppf name args =
  114. Array.blit args 0 Sys.argv 0 len;
  115. Obj.truncate (Obj.repr Sys.argv) len;
  116. Arg.current := 0;
  117. - Optcompile.init_path();
  118. + Optcompile.init_path_with (Filename.dirname name); (* Note: would use Filename.abspath here, if we had it. *)
  119. toplevel_env := Optcompile.initial_env();
  120. Sys.interactive := false;
  121. use_silently ppf name
  122. diff --git a/toplevel/toploop.ml b/toplevel/toploop.ml
  123. index 88bd3cc..4ef4207 100644
  124. --- a/toplevel/toploop.ml
  125. +++ b/toplevel/toploop.ml
  126. @@ -440,7 +440,7 @@ let run_script ppf name args =
  127. Array.blit args 0 Sys.argv 0 len;
  128. Obj.truncate (Obj.repr Sys.argv) len;
  129. Arg.current := 0;
  130. - Compile.init_path();
  131. + Compile.init_path_with (Filename.dirname name); (* Note: would use Filename.abspath here, if we had it. *)
  132. toplevel_env := Compile.initial_env();
  133. Sys.interactive := false;
  134. use_silently ppf name
  135. --
  136. 1.8.5.1
Add Comment
Please, Sign In to add comment