caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] How to find out free diskspace?
Date: Sun, 3 Jul 2005 13:54:15 +0200	[thread overview]
Message-ID: <5e9289d19ec1f235b8fff3c89e360bae@inria.fr> (raw)
In-Reply-To: <20050701181950.GA2557@furbychan.cocan.org>

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


  reply	other threads:[~2005-07-03 11:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-01 16:28 Bernd Kuhls
2005-07-01 18:06 ` [Caml-list] " Sylvain LE GALL
2005-07-01 18:19 ` Richard Jones
2005-07-03 11:54   ` Damien Doligez [this message]
2005-07-03 12:35     ` Richard Jones
2005-07-21 15:52   ` Bernd Kuhls
2005-07-21 16:18     ` [Caml-list] " Stephane Glondu
2005-07-22 12:46       ` Bernd Kuhls
2005-07-22 14:10         ` [Caml-list] " Eric Cooper
2005-07-22 17:40       ` Bernd Kuhls

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=5e9289d19ec1f235b8fff3c89e360bae@inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@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).