From 8a7aaea1c65efa10b23a70513b33707e208ca944 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 7 May 2017 11:17:58 -0700 Subject: ffi: semantics: ptr-in should recurse on in. * ffi.c (ffi_ptr_in_in): Don't just free the buffer for the pointer itself, but call the in handler of the target type if it has one. Pass a false copy flag to it, so that that a ptr-in pass semantically resembles a by-value pass. (ffi_ptr_in_d_in): New static function. (ffi_type_compile): Give ptr-in-d type the ffi_ptr_in_d_in function. --- ffi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ffi.c') diff --git a/ffi.c b/ffi.c index f98f70fe..89c8d5f8 100644 --- a/ffi.c +++ b/ffi.c @@ -736,11 +736,24 @@ static val ffi_ptr_in_in(struct txr_ffi_type *tft, int copy, mem_t *src, val tgttype = tft->mtypes; struct txr_ffi_type *tgtft = ffi_type_struct(tgttype); mem_t **loc = coerce(mem_t **, src); + if (tgtft->in != 0) + tgtft->in(tgtft, 0, *loc, obj, self); tgtft->free(*loc); *loc = 0; return obj; } +static val ffi_ptr_in_d_in(struct txr_ffi_type *tft, int copy, mem_t *src, + val obj, val self) +{ + val tgttype = tft->mtypes; + struct txr_ffi_type *tgtft = ffi_type_struct(tgttype); + mem_t **loc = coerce(mem_t **, src); + if (tgtft->in != 0) + tgtft->in(tgtft, 0, *loc, obj, self); + return obj; +} + static void ffi_ptr_in_out(struct txr_ffi_type *tft, int copy, val s, mem_t *dst, val self) { @@ -1394,7 +1407,7 @@ val ffi_type_compile(val syntax) val target_type = ffi_type_compile(cadr(syntax)); return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *), ffi_ptr_in_put, ffi_ptr_d_get, - 0, ffi_ptr_in_out, + ffi_ptr_in_d_in, ffi_ptr_in_out, target_type); } else if (sym == ptr_out_s) { val target_type = ffi_type_compile(cadr(syntax)); -- cgit v1.2.3