From: Stas B. <sta...@gm...> - 2014-01-17 15:36:11
|
Stas Boukarev <sta...@gm...> writes: > "Dmitry Ivanov" <div...@gm...> writes: > >> Hello folks, >> >> Is it possible to pass an alien-value directly to the sb-ext:octets-to-string >> or to another similar function? >> For example: >> >> (with-alien ((ptr ...) >> (sb-ext:octets-to-string (some-routine ptr) >> :external-format external-format)))) >> >> The brute force approach is >> - call make-array to create an (unsigned-byte 8) vector, >> - copy the contents of foreign memory pointed by ptr to the vector, >> - pass the vector to sb-ext:octets-to-string. >> >> I believe the built-in FFI mechanics do this "behind the curtain". > It is possible, but there's no API exposed. But if you're not afraid of unexported APIs which can change at any time, you can do: (sb-alien::c-string-to-string (sb-sys:vector-sap (string 'list)) :ascii 'base-char) => "LIST" -- With best regards, Stas. |