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 concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E6DC1BB83 for ; Fri, 18 Aug 2006 22:09:11 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k7IK9Beb003768 for ; Fri, 18 Aug 2006 22:09:11 +0200 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 WAA09790 for ; Fri, 18 Aug 2006 22:09:11 +0200 (MET DST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.184]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7IK9A5Z029560 for ; Fri, 18 Aug 2006 22:09:10 +0200 Received: by nf-out-0910.google.com with SMTP id y38so1684499nfb for ; Fri, 18 Aug 2006 13:09:10 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=smdzogFmhwM6BkxeRroKZS8tPvpJBMDJ5iHsvSxHYorGSF3XuwKzq89+EBmX5wLq6HPjXn3xB2a9Fov5sMua5wzUEbU90mN89S6kA1l/YhIHCVq7INMdB+PGNk6Q4BCBNBTTMszb+EndfO6Q6LHMOeoZvs996UFwNqcTXq2WoWo= Received: by 10.49.10.3 with SMTP id n3mr4501747nfi; Fri, 18 Aug 2006 13:09:10 -0700 (PDT) Received: by 10.78.158.8 with HTTP; Fri, 18 Aug 2006 13:09:10 -0700 (PDT) Message-ID: Date: Fri, 18 Aug 2006 13:09:10 -0700 From: "Nathaniel Gray" To: "Damien Doligez" Subject: Re: [Caml-list] Help interfacing with C Cc: "Caml List" In-Reply-To: <86D76069-A8CF-4EBD-B9D6-E988652E46F3@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <86D76069-A8CF-4EBD-B9D6-E988652E46F3@inria.fr> X-Miltered: at concorde with ID 44E61E67.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; interfacing:01 damien:01 damien:01 camlparam:01 camlreturn:01 error-prone:01 unix:01 compiler:01 fdlist:01 pairs:01 fdset:01 fdlist:01 fdset: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=RCVD_BY_IP autolearn=disabled version=3.0.3 On 8/18/06, Damien Doligez wrote: > 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. This is a patch to unix.c in the compiler so I'm following the idiom used there. > > /* 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. That's not the problem, but thanks for the tip. The code crashes after alloc_small, and quite reliably. > PS. Maybe there are some other bugs in your code. You're being too kind. ;^) There certainly is at least one other bug, and I still don't know what it is. Any other ideas? Cheers, -n8 -- >>>-- Nathaniel Gray -- Caltech Computer Science ------> >>>-- Mojave Project -- http://mojave.cs.caltech.edu -->