summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-04-30 08:53:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-04-30 08:53:45 -0700
commit310bc8183d5b3d794618ace3122f3aa2f16dc47a (patch)
tree3c1648fc5542c6bec72371c79061d20bb85c2ad8 /ffi.c
parentdde97c714b4303f1fa715dae9adb1978afe8c8ef (diff)
downloadtxr-310bc8183d5b3d794618ace3122f3aa2f16dc47a.tar.gz
txr-310bc8183d5b3d794618ace3122f3aa2f16dc47a.tar.bz2
txr-310bc8183d5b3d794618ace3122f3aa2f16dc47a.zip
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).
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c17
1 files changed, 16 insertions, 1 deletions
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 *),