Version française
Home     About     Download     Resources     Contact us    
Browse thread
how to enlarge header of blocks?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christian Lindig <lindig@c...>
Subject: Re: [Caml-list] how to enlarge header of blocks?

On Aug 30, 2005, at 1:16 PM, Mark Shinwell wrote:

> If the extra field obeys the GC structure constraints (see the Caml
> documentation on interfacing to C) then you shouldn't have any
> problem...

Maybe we have different things in mind, so I'll elaborate my idea 
briefly and why it was too simple: I changed the allocation routine in 
the bytecode runtime to allocate one extra word where I intended to 
store some information as an Ocaml value. However, I overlooked that 
Array.length and String.length use the block size denoted by the header 
to determine the length. Hence, code looping over an array or string 
would run into my value - and crash. For example, here is the code for 
Array.get:

CAMLprim value caml_array_get_addr(value array, value index)
{
   long idx = Long_val(index);
   if (idx < 0 || idx >= Wosize_val(array)) caml_array_bound_error();
   return Field(array, idx);
}


To make this work I either must refrain from tucking an extra word to 
strings and arrays or change the implementations for the length 
functions and code that checks array and string bounds.

-- Christian