Browse thread
How to find out free diskspace?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien Doligez <damien.doligez@i...> |
| Subject: | Re: [Caml-list] How to find out free diskspace? |
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