caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Initializing CAMLlocalX values to Val_unit
@ 2017-02-24 10:38 Richard W.M. Jones
  2017-02-24 13:43 ` Arlen Cox
  2017-02-24 13:50 ` Gerd Stolpmann
  0 siblings, 2 replies; 4+ messages in thread
From: Richard W.M. Jones @ 2017-02-24 10:38 UTC (permalink / raw)
  To: caml-list

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-24 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-24 10:38 [Caml-list] Initializing CAMLlocalX values to Val_unit Richard W.M. Jones
2017-02-24 13:43 ` Arlen Cox
2017-02-24 13:58   ` Richard W.M. Jones
2017-02-24 13:50 ` Gerd Stolpmann

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).