summaryrefslogtreecommitdiffstats
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
commit8c3be195547f11b0212147f2ccc3c0adbc0a777f (patch)
tree03d8fcad755626139525dfe55b41567d744375b3
parentfd1ab98af87e69055a7f5d42128f5a8bde6acf2c (diff)
downloadtxr-8c3be195547f11b0212147f2ccc3c0adbc0a777f.tar.gz
txr-8c3be195547f11b0212147f2ccc3c0adbc0a777f.tar.bz2
txr-8c3be195547f11b0212147f2ccc3c0adbc0a777f.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.
-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));