Andreas Fuchs <asf@...> writes:
> Hi there,
> I would like (unsigned-byte 8) arrays (as returned by, e.g.
> sb-ext:string-to-octets) to be acceptable for c-string arguments in FFI
> calls. While hacking on this, I found a few comments in sb-alien's
> c-string handling code (in src/code/host-c-call.lisp) which complain
> about the non-GC-safety of passing lisp string vector SAPs into C code.
> I believe the attached patch should fix this problem (and allow
> unsigned-byte arrays to be passed as c strings) at least on gencgc,
> provided the C code doesn't retain a pointer to the string. It does this
> by pinning the array objects with the same technique that is used by
> with-pinned-objects: push a word on the C stack before calling the alien
> I'm sure this will need more polishing, especially for cheneygc; still,
> I'd like to ask at this point if this looks like it's going in the right
It seems to me that the decision of whether to pin or not to pin
should not be done at runtime. The way to do the decision at
compile-time would be by defining some new alien-type-methods, for
example by breaking the current :deport alien-type-method into two
parts: one for allocation and another for taking the sap.
I did an implementation sketch for this scheme shortly after adding
the aforementioned comments about GC safety. I don't remember to what
extent (if any) that implementation worked, but if you're interested
in working on this I can try to find it.