On Tue, Aug 16, 2011 at 5:06 PM, John Carr <jfc@mit.edu> wrote:

Richard W.M. Jones <rich@annexia.org> wrote:

> On Tue, Aug 16, 2011 at 11:37:03AM +0400, Dmitry Bely wrote:
> > C compiler first puts "list" pointer on stack and then calls
> > caml_copy_string(*s), potentially invalidating "list". Of course, the
> > stack copy of "list" is not registered as a global root so wrp_ml_cons
> > gets an invalid value.
>
> I think this must be a bug in your C compiler.  The address of list is
> stashed in the roots struct, so the C compiler should know that list
> can be changed by the call to caml_copy_string.

Maybe looking at the assembly output would help. If you can post the output with gcc -S flag.

Cheers;
Wojciech

The call

  f(g(), x)

can behave as either

 temp1 = g()
 temp2 = x
 f(temp1, temp2)

or

 temp1 = x
 temp2 = g()
 f(temp2, temp1)

The order does not need to be deterministic.

If the call to g() changes x, the second order results in the
function f() receiving the "wrong" value.

   --John Carr (jfc@mit.edu)

--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs