Ciao,
while it is clear that, at the C level, to allocate a new
bytevector one has to do:
ikpcb pcb;
long int size;
ikptr bv;
uint8_t * data_area;
pcb = ...;
size = ...;
bv = ik_safe_alloc(pcb, align(disp_bytevector_data+size))
+ bytevector_tag;
ref(bv, off_bytevector_length) = fix(size);
data_area = bv + off_bytevector_data;
where "size" is the number of bytes in the data area stored
in the bytevector memory block as a fixnum ("fix(size)"), it
is not clear to me how the size is stored in the vector
objects.
For example this function exists (and it seems to be
used):
ikptr
ikrt_make_vector1(ikptr len, ikpcb* pcb){
int intlen = (int)len;
if(is_fixnum(len) && (intlen >= 0)){
ikptr s = ik_safe_alloc(pcb, align(len + disp_vector_data));
ref(s, 0) = len;
memset((char*)(long)(s+disp_vector_data), 0, len);
return s+vector_tag;
} else {
return 0;
}
}
here, first "len" is tested with "fixnum()" which seems to
indicate that "len" is an "ikptr" value with with a fixnum
tag (2 least significant bits set to zero, on 32 bits
platforms); but then the number of bytes to allocate on the
heap (before alignment normalisation) is computed as:
len + disp_vector_data
where "len" is used raw, without "unfix(len)"; finally the
length is stored in the vector memory block:
ref(s, 0) = len;
I still have not reverse engineered in my mind the way,
for example, VECTOR-LENGTH is implemented, so I only have a
partial understanding of how things go; has someone already
understood this?
TIA
--
Marco Maggi