From: "Richard W.M. Jones" <rich@annexia.org>
To: caml-list@inria.fr
Subject: [Caml-list] Initializing CAMLlocalX values to Val_unit
Date: Fri, 24 Feb 2017 10:38:18 +0000 [thread overview]
Message-ID: <20170224103818.GI28111@annexia.org> (raw)
We just corrected a crashing bug in some C bindings. The code
essentially did:
CAMLlocal1 (exn);
call_some_function (&exn);
if (exn != Val_unit) {
// The function wants to raise an exception ...
caml_raise (exn);
}
This crashed with OCaml 4.01 because of Mark's upstream change to how
CAMLlocalX is initialized.
https://github.com/ocaml/ocaml/commit/05100e597e4296a2e79e6c2d9cd75b7e1cc595c9
https://github.com/ocaml/ocaml/commit/2dd92969d254ddae7b49f1478a2ef69ccf70ad42
In OCaml <= 4.01, there was an implicit initialization to 0 in the
macro. In some later version of OCaml this was changed to implicitly
initialize to Val_unit instead.
I have no problem with this change, and the code above was obviously
buggy with the older versions of OCaml. However I do have some
questions ...
(1) The documentation says:
"The macros CAMLlocal1 to CAMLlocal5 declare and initialize one to
five local variables"
which is technically correct, but not very useful. Is the
initialization with Val_unit a permanent change, and will it be
documented as ABI?
(2) We have lots of existing code which does:
CAMLlocal1 (v);
// some code here which might allocate and call the GC
v = ...
It's my understanding that such code might crash with the older
versions of OCaml, because when it calls the GC it will find a local
root which is initialized to 0. We want to continue to support the
older versions (back to 3.12 in fact), so should we change it all to:
CAMLlocal1 (v); v = Val_unit;
// some code here which might allocate and call the GC
v = ...
? Interestingly none of this code has actually crashed in production
as far as I'm aware.
Rich.
next reply other threads:[~2017-02-24 10:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 10:38 Richard W.M. Jones [this message]
2017-02-24 13:43 ` Arlen Cox
2017-02-24 13:58 ` Richard W.M. Jones
2017-02-24 13:50 ` Gerd Stolpmann
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=20170224103818.GI28111@annexia.org \
--to=rich@annexia.org \
--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