From 996e1e4ee69e7c099690e24d8776c7cd0b8c35c2 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 7 May 2017 09:00:16 -0700 Subject: ffi: bufix: elide get if copy flag is false. * ffi.c (ffi_struct_in, ffi_array_in): Only fall back on get if the copy flag is true. If the copy flag is false, we must not extract. That's not ony as an optimization (no point in extracting back from by-value objects). We also avoid extracting from pointers we don't own, like in the case of str-d, where the pointer is owned by the foreign function and may have been freed. --- ffi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ffi.c b/ffi.c index 1a9ebb01..6d41bcff 100644 --- a/ffi.c +++ b/ffi.c @@ -862,7 +862,7 @@ static val ffi_struct_in(struct txr_ffi_type *tft, int copy, mem_t *src, if (mtft->in != 0) { val slval = slot(strct, slsym); slotset(strct, slsym, mtft->in(mtft, copy, src + offs, slval, self)); - } else { + } else if (copy) { val slval = mtft->get(mtft, src + offs, self); slotset(strct, slsym, slval); } @@ -1013,7 +1013,7 @@ static val ffi_array_in(struct txr_ffi_type *tft, int copy, mem_t *src, if (etft->in != 0) { val elval = ref(vec, num_fast(i)); refset(vec, num_fast(i), etft->in(etft, copy, src + offs, elval, self)); - } else { + } else if (copy) { val elval = etft->get(etft, src + offs, self); refset(vec, num_fast(i), elval); } -- cgit v1.2.3