FFI function call fails by passing pointer contains struct
Issue #60
resolved
This fails with panic.
(import (rnrs) (sagittarius ffi))
(define-c-struct bar
(int bi)
(char* bc*))
(define-c-struct foo
(struct bar fb)
(long fl))
(define so (open-shared-library "foo.so"))
(define dump-foo (c-function so void dump_foo (void*)))
(let ((fp (allocate-c-struct foo))
(bp (allocate-c-struct bar)))
(bar-bi-set! bp 1234)
(bar-bc*-set! bp "hello world")
(foo-fb-set! fp bp)
(print (foo-fb-ref fp))
(foo-fl-set! 98765)
(dump-foo fp))
Where the foo.so
is defined like this
#include <stdio.h>
#ifdef _MSC_VER
# define EXPORT __declspec(dllexport)
#else
# define EXPORT
#endif
struct foo
{
struct {
int bi;
char *bc;
} bar;
long fl;
};
EXPORT void dump_foo(struct foo *st_foo)
{
fprintf(stderr, "foo.bar.bi [%d]\n", st_foo->bar.bi);
fprintf(stderr, "foo.bar.bc* [%s]\n", st_foo->bar.bc);
fprintf(stderr, "foo.fl [%ld]\n", st_foo->fl);
}
Comments (2)
-
reporter -
reporter - changed status to resolved
Handling internal struct set separately. (Fixes
#60)→ <<cset 3e6cff9b9498>>
- Log in to comment
The issue is
c-struct-set!
. It's passing the value topointer-set-c-pointer!
but this doesn't support struct member properly (and it's impossible to resolve). Soc-struct-set!
should handle internal struct differently.