Yaroslav Kavenchuk wrote:
>> (ffi:def-c-struct my-struct
> (my-str ffi:c-string)
> (str-ptr (ffi:c-pointer ffi:c-string))
> (void-ptr ffi:c-pointer))
>> (setq s1 (ffi:allocate-shallow 'my-struct))
>#<FOREIGN-VARIABLE FFI:FOREIGN-ALLOCATE #x014EDCA0>
>(setf (ffi:slot (ffi:foreign-value s1) 'my-str) "EXAMPLE")
This is not supported syntax. The official syntax to access foreign-variable objects is
(with-c-place (my s1) ; "my" place name chosen arbitrarily
(slot my 'my-str)
(setf (slot my 'my-str) foo)))
>*** - handle_fault error2 ! address = 0x0 not in
>SIGSEGV cannot be cured. Fault address = 0x0.
Allocate-shallow does what the name says: it does not allocate space for substructures, like storage room for the characters of your string.
You did not allocate storage for the string. Therefore, trying and setting the str-ptr slot caused a NULL pointer error.
Possible solution paths:
o Use allocate-shallow a second time to make room for your string, doing storage management by hand. This requires explicit cast'ing to see the str-ptr sometimes as c-string, sometimes as c-pointer.
o Use (c-ptr (c-array-max character NNN)) together with allocate-deep to use bounded buffers instead of unbounded strings. The FFI would then fill the buffer and perform boundary checking.