caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Harry Chomsky" <harry@chomsky.net>
To: "Caml-list" <caml-list@inria.fr>
Subject: [Caml-list] Status of callback_exn bug
Date: Mon, 10 Jun 2002 13:04:29 -0700	[thread overview]
Message-ID: <00c601c210ba$07de5d10$0200a8c0@harry> (raw)

[-- Attachment #1: Type: text/plain, Size: 976 bytes --]

I am having trouble using callback_exn -- my program crashes in bytecode
mode, but works ok if I use the native-code compiler.  I saw a message in
the archive discussing a problem like this:

http://caml.inria.fr/archives/200204/msg00065.html

The CVS shows a change to byterun/interp.c on April 12 that appears to be
related to this problem.  I've tried to apply this change to my own copy of
OCaml, but my program still crashes.  Sometimes it runs a little bit longer
than it did before, but it still crashes within the next few function calls.

Was the April 12 fix supposed to resolve the problem completely?

I'm enclosing a small program that demonstrates the problem.  When prompted
for a string, if you type "hello" the OCaml code will raise an exception,
and the program will crash shortly thereafter.  The timing of the crash
varies depending whether you use "loop" or "loop1" as the main program loop.

(I'm running OCaml 3.04, native Win32 port, on Windows 2000.)

[-- Attachment #2: build.bat --]
[-- Type: application/octet-stream, Size: 79 bytes --]

ocamlc -custom -o exn.exe exn.ml exn_c.c
ocamlopt -o exnopt.exe exn.ml exn_c.c

[-- Attachment #3: exn.ml --]
[-- Type: application/octet-stream, Size: 476 bytes --]

external do_it : (string -> unit) -> unit = "do_it"

let f s =
    print_endline ("Caml says you entered " ^ s);
    flush stdout;
    if s = "hello" then
        failwith "Oops"

let rec loop () =
    print_endline "Spot 1"; flush stdout;
    do_it f;
    print_endline "Spot 2"; flush stdout;
    loop ()

let loop1 () =
    while true do
        print_endline "Spot 1"; flush stdout;
        do_it f;
        print_endline "Spot 2"; flush stdout
    done

let _ = loop1 ()

[-- Attachment #4: exn_c.c --]
[-- Type: application/octet-stream, Size: 511 bytes --]

#include <caml/alloc.h>
#include <caml/callback.h>
#include <caml/custom.h>
#include <caml/fail.h>
#include <caml/memory.h>
#include <caml/mlvalues.h>

CAMLprim value do_it(value func)
{
    CAMLparam1(func);
    char s[256];
    CAMLlocal2(v, result);

    printf("Enter a string: ");
    scanf("%s", s);
    printf("C says you entered %s\n", s);
    v = copy_string(s);
    result = callback_exn(func, v);
    if (Is_exception_result(result))
        printf("Caught exception\n");
    CAMLreturn(Val_unit);
}

             reply	other threads:[~2002-06-10 20:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-10 20:04 Harry Chomsky [this message]
2002-07-11 17:28 Harry Chomsky
2002-07-11 18:50 ` Harry Chomsky

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='00c601c210ba$07de5d10$0200a8c0@harry' \
    --to=harry@chomsky.net \
    --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;
as well as URLs for NNTP newsgroup(s).