Skip to content

Commit

Permalink
Detecter le cas ou l'on trace deux fois la meme fonction sous divers …
Browse files Browse the repository at this point in the history
…noms.

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@770 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information
xavierleroy committed Apr 29, 1996
1 parent 4946407 commit 6b09d92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
27 changes: 14 additions & 13 deletions toplevel/topdirs.ml
Expand Up @@ -198,15 +198,17 @@ external current_environment: unit -> Obj.t = "get_current_environment"
let dir_trace lid =
try
let (path, desc) = Env.lookup_value lid !toplevel_env in
if is_traced path then begin
Printtyp.path path; print_string " is already traced.";
print_newline()
end else begin
let clos = eval_path path in
(* Nothing to do if it's not a closure *)
if Obj.is_block clos & Obj.tag clos = 250 then begin
let old_clos = copy_closure clos in
let clos = eval_path path in
(* Nothing to do if it's not a closure *)
if Obj.is_block clos & Obj.tag clos = 250 then begin
match is_traced clos with
Some opath ->
Printtyp.path path; print_string " is already traced (under the name ";
Printtyp.path opath; print_string ")";
print_newline()
| None ->
(* Instrument the old closure *)
let old_clos = copy_closure clos in
traced_functions :=
{ path = path;
closure = clos;
Expand All @@ -228,11 +230,10 @@ let dir_trace lid =
| _ ->
Printtyp.longident lid; print_string " is now traced.";
print_newline()
end else begin
Printtyp.longident lid; print_string " is not a function.";
print_newline()
end
end
end else begin
Printtyp.longident lid; print_string " is not a function.";
print_newline()
end
with Not_found ->
print_string "Unbound value "; Printtyp.longident lid;
print_newline()
Expand Down
6 changes: 3 additions & 3 deletions toplevel/trace.ml
Expand Up @@ -30,10 +30,10 @@ let traced_functions = ref ([] : traced_function list)

(* Check if a function is already traced *)

let is_traced path =
let is_traced clos =
let rec is_traced = function
[] -> false
| tf :: rem -> Path.same path tf.path or is_traced rem
[] -> None
| tf :: rem -> if tf.closure == clos then Some tf.path else is_traced rem
in is_traced !traced_functions

(* Make a copy of a closure *)
Expand Down
2 changes: 1 addition & 1 deletion toplevel/trace.mli
Expand Up @@ -20,7 +20,7 @@ type traced_function =
instrumented_fun: Obj.t }

val traced_functions: traced_function list ref
val is_traced: Path.t -> bool
val is_traced: Obj.t -> Path.t option
val copy_closure: Obj.t -> Obj.t
val overwrite_closure: Obj.t -> Obj.t -> unit
val instrument_closure:
Expand Down

0 comments on commit 6b09d92

Please sign in to comment.