summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-06 09:00:22 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-06 09:00:22 -0700
commitbd56945aaead936ff077bb33ddcaac5583cb1523 (patch)
tree6d2028b42f356377812993a1ef3ddaec48f98ca1
parentd9d8aeb709d25a0b2691ef1bb9e35b8f5f972af2 (diff)
downloadtxr-bd56945aaead936ff077bb33ddcaac5583cb1523.tar.gz
txr-bd56945aaead936ff077bb33ddcaac5583cb1523.tar.bz2
txr-bd56945aaead936ff077bb33ddcaac5583cb1523.zip
ffi: handle copy flag in str type's in virtual.
This solves the second issue described in parent commit. When a str type is passed in-out using (ptr str) in a struct or array, the struct or array is not picking up the new string. The pointer is freed, but the old object persists. * ffi.c (ffi_str_in): Function renamed to ffi_str_in. If the copy flag is true, retrieves a string from the pointer and that string is returned instead of the incoming one, mapping a null pointer to nil. Either way, the pointer is freed. Since ffi_ptr_out_in passes 1 for the copy flag, that ensures we extract the new string and plant it into the array.
-rw-r--r--ffi.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/ffi.c b/ffi.c
index b295e989..c4d3ee23 100644
--- a/ffi.c
+++ b/ffi.c
@@ -564,10 +564,12 @@ static mem_t *ffi_cptr_alloc(struct txr_ffi_type *tft, val ptr, val self)
return coerce(mem_t *, cptr_addr_of(ptr));
}
-static val ffi_freeing_in(struct txr_ffi_type *tft, int copy,
- mem_t *src, val obj, val self)
+static val ffi_str_in(struct txr_ffi_type *tft, int copy,
+ mem_t *src, val obj, val self)
{
- mem_t **loc = coerce(mem_t **, src);
+ char **loc = coerce(char **, src);
+ if (copy)
+ obj = if2(*loc, string_utf8(*loc));
free(*loc);
*loc = 0;
return obj;
@@ -1517,7 +1519,7 @@ static void ffi_init_types(void)
&ffi_type_pointer,
ffi_str_put, ffi_str_get);
struct txr_ffi_type *tft = ffi_type_struct(type);
- tft->in = ffi_freeing_in;
+ tft->in = ffi_str_in;
ffi_typedef(str_s, type);
}