caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <mottl@miss.wu-wien.ac.at>
To: David.Mentre@irisa.fr (David Mentré)
Cc: caml-list@inria.fr (OCAML)
Subject: Re: Congratulation! Bug found!! (GC & C interfacing problems)
Date: Tue, 22 Feb 2000 17:27:45 +0100 (MET)	[thread overview]
Message-ID: <200002221627.RAA09713@miss.wu-wien.ac.at> (raw)
In-Reply-To: <wd8n1otmwb3.fsf@parate.irisa.fr> from "David=?iso-8859-1?q?_Mentr=E9?=" at Feb 22, 2000 10:16:32 AM

>   3. However, this macro is calling modify (function defined in
>      byterun/memory.c) which in turn calls the Modify macro (defined in
>      byterun/memory.h). As Markus said, this macro adds the address
>      given in argument to a list of memory addresses (ref_table_ptr)
>      that should be examined by the GC at collection time.
[...]
> I also subscribe to this documentation revision. I also volunteer, if
> needed, to review/rewrite the doc part related to Interfacing C with
> OCaml.

I guess that the confusion about the real things happening as explained in
"3" above comes from "rule 6" in the documentation of the C-interface,
which says:

  Direct assignment to a field of a block, as in

          Field(v, n) = w;

  is safe only if v is a block newly allocated by alloc_small; that
  is, if no allocation took place between the allocation of v and the
  assignment to the field. In all other cases, never assign directly.

This "safe only" and "in all other cases, never assign directly" leaves the
impression that the "Field" macro is a bit "evil" and could be avoided,
possibly by using this nice "Store_field"-macro. However, it is not only
"safe" to use "Field" in this case, it seems (?) that this is the only way
to do it correctly. Furthermore, I did not find any documentation on
correctly placing values into blocks created with "alloc_final", which
seems to be pretty similar to "alloc_small" in this respect.

The only information I found concerning "alloc_small" which appears to
indicate correct usage is:

  alloc_small(n, t) returns a fresh small block of size n <=
  Max_young_wosize words, with tag t. If this block is a structured block
  (i.e. if t < No_scan_tag), then the fields of the block (initially
  containing garbage) must be initialized with legal values (using direct
  assignment to the fields of the block) before the next allocation.

The intention of "using direct assignment to the fields" is obviously meant
as hint to use the "Field"-macro. Because most people don't know that
"Store_field" not only assigns directly, but does unexpected other things,
this information does probably not help...

Best regards,
Markus Mottl

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl



  reply	other threads:[~2000-02-22 17:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-21 14:09 Still strange GC problems with OCaml and C: OCaml 2.04 bug? David Mentré
2000-02-21 20:10 ` Markus Mottl
2000-02-22  9:16   ` Congratulation! Bug found!! (GC & C interfacing problems) David Mentré
2000-02-22 16:27     ` Markus Mottl [this message]
2000-02-23 19:33 Damien Doligez

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=200002221627.RAA09713@miss.wu-wien.ac.at \
    --to=mottl@miss.wu-wien.ac.at \
    --cc=David.Mentre@irisa.fr \
    --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).