Version franaise
Home About Download Resources Contact us
Browse thread
Causes for segfaults
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Török Edwin <edwintorok@g...>
Subject: Re: [Caml-list] Causes for segfaults
On Mon, 15 Nov 2010 18:38:18 +0000
Jamie Brandon <jamie@scattered-thoughts.net> wrote:

> > Excessive recursion of a function does raise an exception, on most
> > platforms, doesn't it?
> 
> [root@senldogo0183 texsearch-development2]# uname -a
> Linux senldogo0183 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007
> x86_64 x86_64 x86_64 GNU/Linux
> [root@senldogo0183 texsearch-development2]# ocaml -version
> The Objective Caml toplevel, version 3.12.0
> [root@senldogo0183 texsearch-development2]# cat > segfault.ml
> let rec ints n = n :: ints (n+1)
> let _ = ints 0
> [root@senldogo0183 texsearch-development2]# ocamlopt segfault.ml
> [root@senldogo0183 texsearch-development2]# ./a.out
> Segmentation fault

I get a proper exception:
Fatal error: exception Stack_overflow

Linux debian 2.6.36-phenom #107 SMP PREEMPT Sat Oct 23 10:30:01 EEST
2010 x86_64 GNU/Linux

Although you have to be careful with recursion and calls to C code,
calling the C code may be the one overflowing the stack, and the ocaml
runtime doesn't generate stack overflow exception for that (only for
OCaml code). You will probably need the patch from
http://caml.inria.fr/mantis/view.php?id=5064 for that.

Best regards,
--Edwin