From fafc828c3e327d17aa0d069faf63253f4f70ab65 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 30 Apr 2017 08:53:45 -0700 Subject: ffi: put function for str-d needed. * ffi.c (ffi_str_d_put): New static function. (ffi_type_compile): Use ffi_str_d_put for str-d instead of ffi_str_put. The difference is that ffi_str_d_put doesn't place the pointer into the rtvec[] array. Doing so is wrong because this ttype of string has no reserved place in that array, and no registered in handler to free it (which would be wrong). --- ffi.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ffi.c b/ffi.c index 298000ad..d384ddeb 100644 --- a/ffi.c +++ b/ffi.c @@ -633,6 +633,21 @@ static void ffi_str_put(struct txr_ffi_type *tft, val s, mem_t *dst, } } +static void ffi_str_d_put(struct txr_ffi_type *tft, val s, mem_t *dst, + mem_t *rtvec[], val self) +{ + (void) rtvec; + + if (s == nil) { + *coerce(const char **, dst) = 0; + } else { + const wchar_t *ws = c_str(s); + char *u8s = utf8_dup_to(ws); + *coerce(const char **, dst) = u8s; + } +} + + static val ffi_str_get(struct txr_ffi_type *tft, mem_t *src, val self) { (void) tft; @@ -1430,7 +1445,7 @@ val ffi_type_compile(val syntax) } else if (syntax == str_d_s) { val type = make_ffi_type_builtin(syntax, str_s, sizeof (mem_t *), &ffi_type_pointer, - ffi_str_put, ffi_str_d_get); + ffi_str_d_put, ffi_str_d_get); return type; } else if (syntax == wstr_s) { return make_ffi_type_builtin(syntax, str_s, sizeof (mem_t *), -- cgit v1.2.3