From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id EF623BC50 for ; Fri, 18 Aug 2006 16:59:34 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7IExF6K021388 for ; Fri, 18 Aug 2006 16:59:34 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA15280 for ; Fri, 18 Aug 2006 16:45:13 +0200 (MET DST) Received: from [128.93.8.130] (macadam.inria.fr [128.93.8.130]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k7I8k8dm016242 for ; Fri, 18 Aug 2006 10:46:08 +0200 Mime-Version: 1.0 (Apple Message framework v752.2) In-Reply-To: References: Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <86D76069-A8CF-4EBD-B9D6-E988652E46F3@inria.fr> Content-Transfer-Encoding: 7bit From: Damien Doligez Subject: Re: [Caml-list] Help interfacing with C Date: Fri, 18 Aug 2006 10:46:27 +0200 To: Caml List X-Mailer: Apple Mail (2.752.2) X-Miltered: at concorde with ID 44E57E50.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; damien:01 damien:01 interfacing:01 camlparam:01 camlreturn:01 error-prone:01 fdlist:01 pairs:01 fdset:01 fdlist:01 fdset:01 newres:01 val:01 newres:01 val:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hello, On 2006-08-16, at 21:34, Nathaniel Gray wrote: > I'm having a heck of a time figuring out why this code *doesn't* work: Unless you really know what you're doing, you should use the new macros (CAMLparam*, CAMLlocal*, CAMLreturn) instead of Begin_roots/End_roots. They are slightly less error-prone. > /* fdlist is a list of (file_descr * 'a) pairs. Filter by FD_ISSET */ > static value fdset_to_fdlist2(value fdlist, fd_set *fdset) > { > value l, p, newres; > value res = Val_int(0); > > Begin_roots4(l, p, res, newres); /* I know, this is aggressive */ > for (l = fdlist; l != Val_int(0); l = Field(l, 1)) { > p = Field(l, 0); > int fd = Int_val(Field(p, 0)); > if (FD_ISSET(fd, fdset)) { > newres = alloc_small(2, 0); > Field(newres, 0) = p; > Field(newres, 1) = res; > res = newres; > } > } > End_roots(); > return res; > } Look at your Begin_roots4. One of the four parameters is uninitialized when you first call alloc_small. If the minor GC is triggered by this allocation, it can result in a segment violation or worse. -- Damien PS. Maybe there are some other bugs in your code.