From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA14642 for caml-redistribution; Tue, 22 Feb 2000 11:55:00 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA08119 for ; Tue, 22 Feb 2000 10:16:34 +0100 (MET) Received: from air.irisa.fr (air.irisa.fr [131.254.60.130]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id KAA05070; Tue, 22 Feb 2000 10:16:31 +0100 (MET) Received: from parate.irisa.fr (parate.irisa.fr [131.254.12.25]) by air.irisa.fr (8.9.3/8.9.3) with ESMTP id KAA01106; Tue, 22 Feb 2000 10:16:32 +0100 (MET) Sender: weis To: Markus Mottl 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) References: <200002212010.VAA07719@miss.wu-wien.ac.at> From: David.Mentre@irisa.fr (David=?iso-8859-1?q?_Mentr=E9?=) Date: 22 Feb 2000 10:16:32 +0100 In-Reply-To: Markus Mottl's message of "Mon, 21 Feb 2000 21:10:34 +0100 (MET)" Message-ID: User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Hi Markus, Hi all camlists, You were right Markus. Using directly the Field macro fixed my bug. Markus Mottl 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.