summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-07 09:00:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-07 09:00:16 -0700
commitb6b83892c085740529d0c38e9cf45ee1df42f97c (patch)
tree7b2c37e646c807a3e64eb207325c23346a9bc291
parent7d9aa1c81c6342417602ff051fe17814e814cfb6 (diff)
downloadtxr-b6b83892c085740529d0c38e9cf45ee1df42f97c.tar.gz
txr-b6b83892c085740529d0c38e9cf45ee1df42f97c.tar.bz2
txr-b6b83892c085740529d0c38e9cf45ee1df42f97c.zip
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.
-rw-r--r--ffi.c4
1 files 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);
}