summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-07 00:18:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-07 00:18:54 -0700
commit557bc63442fd7e9a6fb0650a7f80c5eb5781e23a (patch)
tree03d8fcad755626139525dfe55b41567d744375b3 /ffi.c
parentc7bc467dbbde7ab531f1bd6b0593fe26bfe85991 (diff)
downloadtxr-557bc63442fd7e9a6fb0650a7f80c5eb5781e23a.tar.gz
txr-557bc63442fd7e9a6fb0650a7f80c5eb5781e23a.tar.bz2
txr-557bc63442fd7e9a6fb0650a7f80c5eb5781e23a.zip
ffi: bugfix: bstr needs in operation, like str.
* ffi.c (ffi_bstr_in): New function. (ffi_init_types): Give bstr type ffi_bstr_in as the in function.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/ffi.c b/ffi.c
index 49601339..6c366738 100644
--- a/ffi.c
+++ b/ffi.c
@@ -635,6 +635,17 @@ static val ffi_wstr_d_get(struct txr_ffi_type *tft, mem_t *src, val self)
return p ? string_own(p) : nil;
}
+static val ffi_bstr_in(struct txr_ffi_type *tft, int copy,
+ mem_t *src, val obj, val self)
+{
+ unsigned char **loc = coerce(unsigned char **, src);
+ if (copy)
+ obj = if2(*loc, string_8bit(*loc));
+ free(*loc);
+ *loc = 0;
+ return obj;
+}
+
static void ffi_bstr_put(struct txr_ffi_type *tft, val s, mem_t *dst,
val self)
{
@@ -1528,6 +1539,15 @@ static void ffi_init_types(void)
ffi_typedef(str_s, type);
}
+ {
+ val type = make_ffi_type_builtin(bstr_s, str_s, sizeof (mem_t *),
+ &ffi_type_pointer,
+ ffi_bstr_put, ffi_bstr_get);
+ struct txr_ffi_type *tft = ffi_type_struct(type);
+ tft->in = ffi_bstr_in;
+ ffi_typedef(bstr_s, type);
+ }
+
ffi_typedef(str_d_s, make_ffi_type_builtin(str_d_s, str_s,
sizeof (mem_t *), &ffi_type_pointer,
ffi_str_put, ffi_str_d_get));
@@ -1537,9 +1557,6 @@ static void ffi_init_types(void)
ffi_typedef(wstr_d_s, make_ffi_type_builtin(wstr_d_s, str_s,
sizeof (mem_t *), &ffi_type_pointer,
ffi_wstr_d_put, ffi_wstr_d_get));
- ffi_typedef(bstr_s, make_ffi_type_builtin(bstr_s, str_s,
- sizeof (mem_t *), &ffi_type_pointer,
- ffi_bstr_put, ffi_bstr_get));
ffi_typedef(bstr_d_s, make_ffi_type_builtin(bstr_d_s, str_s,
sizeof (mem_t *), &ffi_type_pointer,
ffi_bstr_put, ffi_bstr_d_get));