Skip to content

Commit e06e537

Browse files
author
Jacques Garrigue
committed
Fix PR#6443: Ocaml segfault when List.fold_left is traced then executed
git-svn-id: http://caml.inria.fr/svn/ocaml/version/4.02@14922 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent 6ce401c commit e06e537

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ Bug fixes:
234234
- PR#6408: Optional arguments given as ~?arg instead of ?arg in message
235235
(Michael O'Connor)
236236
- PR#6436: Typos in @deprecated text in stdlib/arrayLabels.mli
237+
- PR#6443: ocaml segfault when List.fold_left is traced then executed
237238
- fix -dsource printing of "external _pipe = ..."
238239
(Gabriel Scherer)
239240
- bound-checking bug in caml_string_{get,set}{16,32,64}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#########################################################################
2+
# #
3+
# OCaml #
4+
# #
5+
# Xavier Clerc, SED, INRIA Rocquencourt #
6+
# #
7+
# Copyright 2010 Institut National de Recherche en Informatique et #
8+
# en Automatique. All rights reserved. This file is distributed #
9+
# under the terms of the Q Public License version 1.0. #
10+
# #
11+
#########################################################################
12+
13+
BASEDIR=../..
14+
include $(BASEDIR)/makefiles/Makefile.toplevel
15+
include $(BASEDIR)/makefiles/Makefile.common
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
List.fold_left;;
2+
#trace List.fold_left;;
3+
0;;
4+
List.fold_left (+) 0 [1;2;3];;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# - : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a = <fun>
3+
# List.fold_left is now traced.
4+
# - : int = 0
5+
# List.fold_left <-- <fun>
6+
List.fold_left --> <fun>
7+
List.fold_left* <-- <poly>
8+
List.fold_left* --> <fun>
9+
List.fold_left** <-- [<poly>; <poly>; <poly>]
10+
List.fold_left <-- <fun>
11+
List.fold_left --> <fun>
12+
List.fold_left* <-- <poly>
13+
List.fold_left* --> <fun>
14+
List.fold_left** <-- [<poly>; <poly>]
15+
List.fold_left <-- <fun>
16+
List.fold_left --> <fun>
17+
List.fold_left* <-- <poly>
18+
List.fold_left* --> <fun>
19+
List.fold_left** <-- [<poly>]
20+
List.fold_left <-- <fun>
21+
List.fold_left --> <fun>
22+
List.fold_left* <-- <poly>
23+
List.fold_left* --> <fun>
24+
List.fold_left** <-- []
25+
List.fold_left** --> <poly>
26+
List.fold_left** --> <poly>
27+
List.fold_left** --> <poly>
28+
List.fold_left** --> <poly>
29+
- : int = 6
30+
#

toplevel/trace.ml

+6-2
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ let rec instrument_result env name ppf clos_typ =
9696

9797
(* Same as instrument_result, but for a toplevel closure (modified in place) *)
9898

99+
exception Dummy
100+
let _ = Dummy
101+
99102
let instrument_closure env name ppf clos_typ =
100103
match (Ctype.repr(Ctype.expand_head env clos_typ)).desc with
101104
| Tarrow(l, t1, t2, _) ->
102105
let trace_res = instrument_result env name ppf t2 in
103106
(fun actual_code closure arg ->
104107
if not !may_trace then begin
105-
let res = invoke_traced_function actual_code closure arg
106-
in res (* do not remove let, prevents tail-call to invoke_traced_ *)
108+
try invoke_traced_function actual_code closure arg
109+
with Dummy -> assert false
110+
(* do not remove handler, prevents tail-call to invoke_traced_ *)
107111
end else begin
108112
may_trace := false;
109113
try

0 commit comments

Comments
 (0)