[Ecls-list] Arrays to C and C to Arrays....
Waldek Hebisch
hebisch at math.uni.wroc.pl
Sun Nov 8 23:24:59 UTC 2009
Juan Jose Garcia-Ripoll wrote:
> On Sun, Nov 8, 2009 at 4:52 AM, Brad Beer <bradwbeer at gmail.com> wrote:
> > How can I convert C arrays to Lisp Arrays and vice-versa using only the FFI?
>
> You mean without copying data? That is not supported because your FFI
> data might not be even created by the garbage collector at all. The
> converse, extracting the pointer from a lisp array, is plain easy: use
> c-inline. But again: you have to keep a valid reference to the lisp
> array object (not data) somewhere.
>
I wander when exactly I need to keep such references and what is
the best way to to this. I am mostly interested in case where
C part uses array for computation but does not try to store
pointers, in particular in tight inline loops. When array
is accessed by inline code C compiler is expected to drop
original reference and keep only data pointer. It seems
that safe way is like this:
volatile cl_object trash;
.....
ecl_uint32_t * ptr = x->array.self.b32;
/* Do something with ptr */
.....
trash = x;
However, is it really necessary? At first glance it looks that
ECL itself does not take special measures to protect original
references from elimination by C compiler.
I wonder if ECL garbage collector is synchronous (runs only
when all threads are in "safe" state) or can it run when
other threads are in the middle of some arbitrary code?
--
Waldek Hebisch
hebisch at math.uni.wroc.pl
More information about the ecl-devel
mailing list