caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David.Mentre@irisa.fr (David Mentré)
To: Markus Mottl <mottl@miss.wu-wien.ac.at>
Cc: caml-list@inria.fr (OCAML),
	xavier.leroy@inria.fr, colcombe@irisa.fr,
	damien.doliguez@inria.fr
Subject: Congratulation! Bug found!! (GC & C interfacing problems)
Date: 22 Feb 2000 10:16:32 +0100	[thread overview]
Message-ID: <wd8n1otmwb3.fsf@parate.irisa.fr> (raw)
In-Reply-To: Markus Mottl's message of "Mon, 21 Feb 2000 21:10:34 +0100 (MET)"

Hi Markus, Hi all camlists,

You were right Markus. Using directly the Field macro fixed my bug.

Markus Mottl <mottl@miss.wu-wien.ac.at> writes:

> You use "Store_field" throughout the code to assign pointers to fields in
> structures which were allocated using "alloc_final".
> 
> I once had a similar bug in my PCRE-library, but Gerd Stolpmann was so kind
> to send me the patch and explain the problem. Here his translated
> explanation (seems reasonable):
> 
>   - after "alloc_small" the fields have to be initialized with
>     "Field(var, n) = ...", not with "Store_field". The last version writes
>     (with some bad luck) the address of the field into a list of addresses
>     which have to be moved in case of a minor GC.
> 
>   - The fields of "alloc_final" are not considered by the GC. Therefore,
>     they, too, have to be written to using "Field(var, n)" (or you may
>     cast them to a normal C-struct). "Store_field" has, again, unexpected
>     side effects.

The explanation (or a guess ;) :

  1. a memory block is allocated with alloc_final, therefore this block
     internals should not be considered by the GC.

  2. I use the Store_field macro to update block content. 

  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.

  4. So, we have a GC-opaque memory block whose content adresses have
     been added to a GC to-examine-later list. Therefore, at GC time:
     crash.


> In case this is really the bug (probably), I'd suggest a revision of the
> C-interface-documentation. At least to me it was not obvious that
> "Store_field" leads to such additional, unexpected behaviour.

I also subscribe to this documentation revision. I also volunteer, if
needed, to review/rewrite the doc part related to Interfacing C with
OCaml.


> Good luck squeezing the bug,

I've squeezed it, with your help. :)

One again, many many thanks,
Best regards,
david
-- 
 David.Mentre@irisa.fr -- http://www.irisa.fr/prive/dmentre/
 Opinions expressed here are only mine.




  reply	other threads:[~2000-02-22 10:55 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   ` David Mentré [this message]
2000-02-22 16:27     ` Congratulation! Bug found!! (GC & C interfacing problems) Markus Mottl
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=wd8n1otmwb3.fsf@parate.irisa.fr \
    --to=david.mentre@irisa.fr \
    --cc=caml-list@inria.fr \
    --cc=colcombe@irisa.fr \
    --cc=damien.doliguez@inria.fr \
    --cc=mottl@miss.wu-wien.ac.at \
    --cc=xavier.leroy@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).