Browse thread
Causes for segfaults
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | John Whitington <john@c...> |
| Subject: | Re: [Caml-list] Causes for segfaults |
Hi, On 15/11/2010 17:58, Jamie Brandon wrote: > I do feel that this would have been much easier to fix if ocaml raised > more informative errros. The change to Array.make and String.make to > raise exceptions instead of segfaulting is welcome. Is there a way to > cause stack overflows to raise exceptions in native compiled ocaml as > well? Excessive recursion of a function does raise an exception, on most platforms, doesn't it? However, this doesn't seem to be the case with excessive nested exceptions. I got caught by this the other day: let rec lex_stream i acc = try lex_stream i (lex_next i::acc) with LexingEnd -> rev acc (I had been replacing option types with exceptions in some places for speed and wasn't concentrating...) This segfaults on OS X Intel with OCaml 3.12.0 on large inputs. The workaround is to add a null constructor for the type e.g LexNone. In the absence of one, I think you have to do: let rec lex_stream i acc = match try Some (lex_stream i) with LexingEnd -> None with | None -> rev acc | Some s -> lex_stream i (a::acc) Hopefully that option type doesn't slow things down too much. Cheers, -- John Whitington Director, Coherent Graphics Ltd http://www.coherentpdf.com/