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
commit996e1e4ee69e7c099690e24d8776c7cd0b8c35c2 (patch)
tree7b2c37e646c807a3e64eb207325c23346a9bc291
parent581d95e976938d62e79a54af2dd1c23955201b11 (diff)
downloadtxr-996e1e4ee69e7c099690e24d8776c7cd0b8c35c2.tar.gz
txr-996e1e4ee69e7c099690e24d8776c7cd0b8c35c2.tar.bz2
txr-996e1e4ee69e7c099690e24d8776c7cd0b8c35c2.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);
}