summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-18 20:04:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-18 20:04:55 -0700
commitfd6324c9b82117399bc7cfa189f26c5fc615141c (patch)
tree53d8d52a36bebea7547f8864c4081b649ef50f57 /ffi.c
parentc51a26976c735531cf2f63d503f125da87f90133 (diff)
downloadtxr-fd6324c9b82117399bc7cfa189f26c5fc615141c.tar.gz
txr-fd6324c9b82117399bc7cfa189f26c5fc615141c.tar.bz2
txr-fd6324c9b82117399bc7cfa189f26c5fc615141c.zip
ffi: bugfix: broken buf in semantics, bad doc.
* ffi.c (ffi_buf_in): The bug in this one is that if *loc has been mutated to a null pointer, we want to produce a nil, rather than to try to duplicate the buffer. (ffi_buf_d_in): The bug here is that *loc is always different from origptr, because origptr is from the original buffer object, whereas we placed a copy of it into *loc. The semantics is changed. We take ownership of whatever pointer is there. If it is null, then yield nil. * txr.1: buf and buf-d documentation revised.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/ffi.c b/ffi.c
index b2ce6441..693c700f 100644
--- a/ffi.c
+++ b/ffi.c
@@ -706,7 +706,7 @@ static val ffi_buf_in(struct txr_ffi_type *tft, int copy, mem_t *src,
mem_t *origptr = buf_get(obj, self);
if (copy && *loc != origptr)
- obj = make_duplicate_buf(length_buf(obj), *loc);
+ obj = if2(*loc, make_duplicate_buf(length_buf(obj), *loc));
return obj;
}
@@ -732,15 +732,10 @@ static val ffi_buf_d_in(struct txr_ffi_type *tft, int copy, mem_t *src,
val obj, val self)
{
mem_t **loc = coerce(mem_t **, src);
- mem_t *origptr = buf_get(obj, self);
- if (*loc != origptr) {
- if (copy) {
- obj = make_borrowed_buf(length_buf(obj), *loc);
- } else {
- free(*loc);
- *loc = 0;
- }
+ if (copy) {
+ obj = if2(*loc, make_borrowed_buf(length_buf(obj), *loc));
+ *loc = 0;
}
return obj;