summaryrefslogtreecommitdiffstats
path: root/ffi.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-04-29 07:56:57 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-04-29 07:56:57 -0700
commit20d0c961509adc3a513c48461024e403bb1bc989 (patch)
tree435b26c1f09db73e6bacc1cc374036405ca9779c /ffi.h
parent47a170b8c143143d0eb2a0b778c583b3a370c587 (diff)
downloadtxr-20d0c961509adc3a513c48461024e403bb1bc989.tar.gz
txr-20d0c961509adc3a513c48461024e403bb1bc989.tar.bz2
txr-20d0c961509adc3a513c48461024e403bb1bc989.zip
ffi: malloc-free variants for str, dstr and buf.
The FFI types str-d, wstr-d and buf-d are like their unsuffixed counterparts, but indicate that ownership of a dynamically allocated object is being passed which the receiver is responsible for freeing. If we pass a str, wstr or buf into a foreign function, we are generally only guaranteeing the lifetime of the buffer over the function call. If we pass a str-d or buf-d, then the callee keeps the pointer indefinitely, and must free it. If we get str or buf return value from a function, it is assumed that the pointer is static or something borrowed with some limited lifetime. A copy of it is made. If we get a str-d, wstr-d or buf-d, it is assumed that the pointer has been malloc-ed for us. The object is either duplicated, and the original one immediately freed, or else the pointer is retained directly in the Lisp object and freed if that object becomes garbage. * ffi.c (str_d_s, wstr_d_s, buf_d_s): New symbol variables. (ffi_str_get): Coalesce assignment with declaration. (ffi_str_d_get, ffi_str_d_put): New static functions. (ffi_buf_d_get, ffi_buf_d_put): New static functions. (ffi_type_compile): Handle buf_d_s, str_d_s and wstr_d_s. (ffi_init): Initialize str_d_s, wstr_d_s and buf_d_s. * ffi.c (str_d_s, wstr_d_s, buf_d_s): Declared.
Diffstat (limited to 'ffi.h')
-rw-r--r--ffi.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/ffi.h b/ffi.h
index fafee40f..99c87a28 100644
--- a/ffi.h
+++ b/ffi.h
@@ -37,7 +37,9 @@ extern val long_s, ulong_s;
extern val double_s;
-extern val wstr_s;
+extern val str_d_s, wstr_s, wstr_d_s;
+
+extern val buf_d_s;
extern val ptr_in_s, ptr_out_s, ptr_in_out_s;