When I compile the following program as byte code I see a stack overflow
(expected). When using ocamlopt it seems that the program dies and I do
not see the expected overflow exception?
>type overflow.ml
let array_1=Array.make 229376 42;;
let _ = Printf.printf "A\n";;
flush stdout;;
let array_2=Array.make 32768 43;;
let _ = Printf.printf "B\n";;
flush stdout;;
let list_1 = Array.to_list(array_1);;
let _ = Printf.printf "C\n";;
flush stdout;;
let list_2 = Array.to_list(array_2);;
let _ = Printf.printf "D\n";;
flush stdout;;
let list_3 = list_1@list_2;;
let _ = Printf.printf "E\n";;
flush stdout;;
>ocamlc overflow.ml -o overflow_ocamlc.exe
>overflow_ocamlc.exe
A
B
C
D
Fatal error: exception Stack_overflow
>echo %ERRORLEVEL%
2
>ocamlopt overflow.ml -o overflow_ocamlopt.exe
>overflow_ocamlopt.exe
A
B
C
D
>echo %ERRORLEVEL%
-1073741819
Is this a bug?
Thanks,
- Jakob Lichtenberg
OCaml doesn't always throw the Stack_overflow exception from native code. On
some systems it seg faults.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
Does it _ever_ throw a Stack_overflow in native code?? I've never
seen it.
Rich.
--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Internet Marketing and AdWords courses - http://merjis.com/courses - NEW!
Merjis blog - http://blog.merjis.com - NEW!
Sometimes. Depends on the platform and how well-debugged the ocaml
runtime for the platform is. This is quite tricky because you need to
catch the segfault (that always happens), switch to an alternate stack,
and then unwind the original stack.
Gerd
--
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
ge...@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------
- Jakob
Sometimes. My x86 Debian box with swap on throws an exception.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
_______________________________________________
No - rather, it is the ugly intrusion of reality. ;)
As has been already pointed out, it isn't easy to generate code that
detects this at runtime under a widely varying set of environments and
conditions... to tighten it up further would likely start costing in
performance (and what is ocamlopt for?).
A related veiwpoint says that while you still don't understand your
app's logic and control paths well enough to predict/avoid things like
runaway stack usage - you use the interpreted version. THEN you
switch to the ocamlopt version when you think you are ready (and be
prepared to switch back if you are proven wrong).
> On Wednesday 11 October 2006 19:46, Jakob Lichtenberg wrote:
>> When I compile the following program as byte code I see a stack
> overflow
>> (expected). When using ocamlopt it seems that the program dies and I
> do
>> not see the expected overflow exception?
>
> OCaml doesn't always throw the Stack_overflow exception from native
> code. On
> some systems it seg faults.
Robert Roessler
roes...@rftp.com
http://www.rftp.com
Right. Given your e-mail address, you might actually understand
better than I why it is so. Let me explain:
The machine code generated by ocamlopt does not test explicitly for
stack overflows, relying instead on the operating system to detect and
report them. However, handling of stack overflow conditions varies
greatly between processors and operating systems. Currently:
- Under Linux/IA32 and Linux/AMD64, stack overflows are properly
turned into a Stack_overflow Caml exception. Similar handling is
in the CVS for MacOSX/PPC, and MacOSX/Intel might be feasible soon.
- Other Unix-like operating systems just report stack overflows
as a "segmentation violation" or "bus error" fatal signal.
- Windows, as you noticed, behaves strangely. Stack overflows are turned
into Win32 system exceptions, but apparently the structured
exception handling of Win32 just fails to handle them and silently
exits the program. That might be because the stack frames generated
by ocamlopt are nothing like what Win32 expects.
If you happen to know how to do better under Windows, you're most
welcome to let me know.
- Xavier Leroy
________________________________
From: Xavier Leroy [mailto:Xavier...@inria.fr]
Sent: Sun 10/15/2006 8:58 AM
To: Jakob Lichtenberg
Cc: caml...@yquem.inria.fr
Subject: Re: [Caml-list] Missing overflow exception message in ocamlopt