caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Hyun-Goo Kang <hgkang@ropas.kaist.ac.kr>
Cc: caml-list@inria.fr
Subject: Re: [Q] Callbacking a ocaml function from VC++
Date: Mon, 11 Dec 2000 10:47:24 +0100	[thread overview]
Message-ID: <20001211104724.B5346@pauillac.inria.fr> (raw)
In-Reply-To: <002c01c05f1f$55fb95b0$8e5cf88f@plus>; from hgkang@ropas.kaist.ac.kr on Wed, Dec 06, 2000 at 09:56:15AM +0900

> [Q] Callbacking a ocaml function which uses Unix socket lib from VC++
> function"

I had a look at your example.  The problem is that the Caml code
raises an exception, and the callback() function tries to propagate
the exception upwards to Caml code that is calling the current C code,
and since there is none it stops the program.  Better use
callback_exn() and check for exceptions yourself:

int connect_it()
{
  static value *connect = NULL;
  value res;
  if (connect == NULL)
   connect = caml_named_value("connect");
  res = callback(*connect,Val_unit);
  if (Is_exception_result(res)) {
    // do something to report an error
  } else {
    return Int_val(res);
  }
}

Now, why is it that the Caml code raises an exception?  In my test
run, it's Unix.socket that raises an exception, because apparently the
wsock32 subsystem hasn't been initialized.  Adding the following lines
in the main function cured the problem:

  WSADATA wsaData;
  (void) WSAStartup(MAKEWORD(2, 0), &wsaData);

Still, this is surprising because normally the initialization of
wsock32 is performed by the Caml Unix library when it starts up.  I
haven't been able yet to track the problem down.

- Xavier Leroy



      reply	other threads:[~2000-12-11 17:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-06  0:56 Hyun-Goo Kang
2000-12-11  9:47 ` Xavier Leroy [this message]

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=20001211104724.B5346@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=hgkang@ropas.kaist.ac.kr \
    /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).