Can you get a struct *
from the out parameter of a C function in Chibi Scheme?
I'm trying to get a struct archive_entry *
from this C function:
int archive_read_next_header(
struct archive *archive,
struct archive_entry **out_entry);
In C one would do it like this:
struct archive_entry *entry;
archive_read_next_header(archive, &entry);
My Chibi FFI code is:
(define-c-struct archive)
(define-c-struct archive_entry)
(define-c int
archive-read-next-header
(archive (result reference archive_entry)))
But it's not generating the right C code to get the archive_entry
. I
think reference
is the wrong thing to use. I also tried pointer
but it didn't work either.
I still don't know if it can be done directly.
But I was able to work around the problem by writing a custom thunk function in C:
So the key is that Scheme doesn't need to deal with any double-indirection (
**
) in this version. The C code converts double-indirection into single-indirection for Scheme so it all works out.Example usage from a Scheme program:
I copied the technique from the chibi-sqlite3 bindings where they face a similar problem having to get a
sqlite3_stmt *
from an out parameter: