From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 17BAFBCAF for ; Sun, 3 Jul 2005 13:54:18 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j63BsHl5015738 for ; Sun, 3 Jul 2005 13:54:17 +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 NAA06378 for ; Sun, 3 Jul 2005 13:54:17 +0200 (MET DST) Received: from [192.168.0.3] (planar.net0.nerim.net [213.41.168.102]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j63BsGAK008706 for ; Sun, 3 Jul 2005 13:54:16 +0200 Mime-Version: 1.0 (Apple Message framework v622) In-Reply-To: <20050701181950.GA2557@furbychan.cocan.org> References: <20050701181950.GA2557@furbychan.cocan.org> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <5e9289d19ec1f235b8fff3c89e360bae@inria.fr> Content-Transfer-Encoding: 7bit From: Damien Doligez Subject: Re: [Caml-list] How to find out free diskspace? Date: Sun, 3 Jul 2005 13:54:15 +0200 To: caml users X-Mailer: Apple Mail (2.622) X-j-chkmail-Score: MSGID : 42C7D1E8.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at concorde with ID 42C7D1E9.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 42C7D1E8.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; damien:01 damien:01 caml-list:01 struct:01 buf:01 camlparam:01 alloc:01 bug:01 compiler:01 computed:01 struct:01 buf:01 camlparam:01 alloc:01 bsize:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Jul 1, 2005, at 20:19, Richard Jones wrote: > static value > copy_statfs (struct statfs *buf) > { > CAMLparam0 (); > CAMLlocal1 (bufv); > bufv = caml_alloc (9, 0); > caml_modify (&Field (bufv, 0), copy_int64 (buf->f_type)); > [...] > There's a nasty bug lurking in this code. Depending on your C compiler, you might be computing &Field (bufv, 0) before the call to copy_int64, which can trigger a GC and change the value of bufv, hence invalidating the address you've just computed. You should do it this way: static value copy_statfs (struct statfs *buf) { CAMLparam0 (); CAMLlocal1 (bufv, v); bufv = caml_alloc (9, 0); v = copy_int64 (buf->f_type); caml_modify (&Field (bufv, 0), v); v = copy_int64 (buf->f_bsize); caml_modify (&Field (bufv, 1), v); v = copy_int64 (buf->f_blocks); caml_modify (&Field (bufv, 2), v); v = copy_int64 (buf->f_bfree); caml_modify (&Field (bufv, 3), v); v = copy_int64 (buf->f_bavail); caml_modify (&Field (bufv, 4), v); v = copy_int64 (buf->f_files); caml_modify (&Field (bufv, 5), v); v = copy_int64 (buf->f_ffree); caml_modify (&Field (bufv, 6), v); caml_modify (&Field (bufv, 7), Val_unit); v = copy_int64 (buf->f_namelen); caml_modify (&Field (bufv, 8), v); CAMLreturn (bufv); } -- Damien