[Ecls-list] [cffi-devel] More patches for ECL

Goffioul Michael goffioul at imec.be
Tue Oct 17 10:21:35 UTC 2006


> > Why in %mem-ref/%mem-set  is used
> >   (+ offset type-size)
> > instead of
> >   (* offset type-size)?
> 
> I don't know. It looks like a bug, but this is a part of 
> cffi-ecl.lsp which I still have not revised: I only changed 
> convert-foreign-type to
> cffi-type->ecl.type

No, this is intentional. %mem-ref dereferences a a pointer starting
at address "ptr" with an offset "offset" in bytes. What the function
is doing is:
1) compute the size of "type" in bytes (-> ffi:size-of-foreign-type)
2) make sure the data pointed by "ptr" is large enough to allow
dereferencing: this means that the data should be at least
(offset+type_size)
bytes large (-> si:foreign-data-recast)
3) dereference the data at address (ptr+offset) of size type_size
(-> si:foreign-data-ref-elt)

Without the step 2, step 3 would fail if the internal data size stored
in the foreign-data object is not large enough. This situation occurs
for instance when dealing with foreign object of type (* :int), where
the actual data size is not known.

Michael.



More information about the cffi-devel mailing list