From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id A3632BC57 for ; Mon, 15 Nov 2010 19:17:21 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAOsH4UzD2MUqi2dsb2JhbACiWRYBAQoLChgivnaFSgSNYw X-IronPort-AV: E=Sophos;i="4.59,200,1288566000"; d="scan'208";a="77946540" Received: from bluelynx4.ukhost4u.com ([195.216.197.42]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Nov 2010 19:17:21 +0100 Received: from [78.105.203.81] (helo=fresh.lan) by bluelynx4.ukhost4u.com with esmtpa (Exim 4.69) (envelope-from ) id 1PI3cD-0008O9-Db; Mon, 15 Nov 2010 18:17:18 +0000 Message-ID: <4CE1792B.3050603@coherentgraphics.co.uk> Date: Mon, 15 Nov 2010 18:17:15 +0000 From: John Whitington User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: Jamie Brandon Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Causes for segfaults References: <384325291.294734.1288998871132.JavaMail.root@zmbs3.inria.fr> <20101106025118.GA23041@yquem.inria.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bluelynx4.ukhost4u.com X-AntiAbuse: Original Domain - yquem.inria.fr X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - coherentgraphics.co.uk X-Source: X-Source-Args: X-Source-Dir: X-Spam: no; 0.00; segfaults:01 ocaml:01 ocaml:01 recursion:01 segfaults:01 inputs:01 cheers:01 brandon:98 wrote:01 overflows:01 stack:01 rec:01 rec:01 exception:01 caml-list:01 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/