Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "<Brad Knotwell" <knotwell@f5.com>
To: caml-list@inria.fr
Subject: small code problem
Date: Fri, 2 Jul 1999 15:30:34 -0700 (PDT)	[thread overview]
Message-ID: <14205.15754.427409.474325@knotwell.f5.com> (raw)


Hello all--

I'm having a problem with a core dump due to an uncaught exception.
The following snippet of code best illustrates the problem:

let usage = lazy (Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1);;
let filename =
        try
           Sys.argv.(1)
        with Invalid_argument("Array.get") ->
           Lazy.force usage;;

When I compile using the byte-code compiler, it seems to work fine.

         [knotwell@knotwell stock]$ ocamlc junk.ml
	 [knotwell@knotwell stock]$ ./a.out
	 Usage: ./a.out file
	 [knotwell@knotwell stock]$ 

On the other hand, when I compile with the optimizing compiler, I
receive the following:

	[knotwell@knotwell stock]$ ocamlopt junk.ml
	[knotwell@knotwell stock]$ ./a.out
	Segmentation fault (core dumped)
        [knotwell@knotwell stock]$	
When I change the code slightly:


let usage = lazy (Printf.printf "Usage: %s file\n" Sys.argv.(0); exit ~-1);;
let filename =
        try
           Sys.argv.(1)
        with _ ->          (* note the pattern matching change *)
           Lazy.force usage;;

I then get correct results:

       [knotwell@knotwell stock]$ ocamlopt junk.ml
       [knotwell@knotwell stock]$ a.out
       Usage: a.out file
       [knotwell@knotwell stock]$	

Why do the two compilers exhibit different behaviors with the same code?

As an aside, I don't particular like my use of lazy and force.  Is
there a cleaner way do the same thing?

Thanks.

--Brad




             reply	other threads:[~1999-07-08  1:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-02 22:30 <Brad Knotwell [this message]
1999-07-08  4:56 ` Markus Mottl
1999-07-08 22:49 ` Gerd Stolpmann
1999-07-09  0:27   ` <Brad Knotwell
1999-07-09  1:37     ` Fabrice Le Fessant
1999-07-08 18:23 Damien Doligez
     [not found] <199907090927.KAA09195@toy.william.bogus>
1999-07-09 13:56 ` Gerd Stolpmann
1999-07-11 19:23   ` Markus Mottl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14205.15754.427409.474325@knotwell.f5.com \
    --to=knotwell@f5.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox