diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2017-05-06 09:00:22 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2017-05-06 09:00:22 -0700 |
commit | c70fc2f8762f5afaacb5d71389ac3f24ddd89f4a (patch) | |
tree | 6d2028b42f356377812993a1ef3ddaec48f98ca1 | |
parent | 5c4f3f64e5c83d2d59c80c37d6340b439119ac6b (diff) | |
download | txr-c70fc2f8762f5afaacb5d71389ac3f24ddd89f4a.tar.gz txr-c70fc2f8762f5afaacb5d71389ac3f24ddd89f4a.tar.bz2 txr-c70fc2f8762f5afaacb5d71389ac3f24ddd89f4a.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.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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); } |