summaryrefslogtreecommitdiffstats
path: root/ffi.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-15 21:58:16 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-15 21:58:16 -0700
commitfe8f3d772630e44552adecb3d3d52a6532e88e39 (patch)
tree17984b1a2cc68cd737222837eeb94311bc682a5d /ffi.c
parent6b4f352810b3cbdcf7f16c88998ffbebbc9f24a0 (diff)
downloadtxr-fe8f3d772630e44552adecb3d3d52a6532e88e39.tar.gz
txr-fe8f3d772630e44552adecb3d3d52a6532e88e39.tar.bz2
txr-fe8f3d772630e44552adecb3d3d52a6532e88e39.zip
ffi: don't set up cptr as Lisp type inappropriately.
The type compiler specifies cptr as the Lisp type for various ptr types and the buf type. This will be misleading with the increasing role of cptr. * ffi.c (ffi_get_lisp_type): New static function. (ffi_type_compile): Use buf as the Lisp type for the buf and buf-d FFI types. For ptr and its variants, use the target type's Lisp type as the pointer's Lisp type. For instance (ptr int) has integer as its Lisp type.
Diffstat (limited to 'ffi.c')
-rw-r--r--ffi.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/ffi.c b/ffi.c
index 15b862f9..be08e597 100644
--- a/ffi.c
+++ b/ffi.c
@@ -124,6 +124,12 @@ static ffi_type *ffi_get_type(val obj)
return tffi->ft;
}
+static val ffi_get_lisp_type(val obj)
+{
+ struct txr_ffi_type *tffi = ffi_type_struct_checked(obj);
+ return tffi->lt;
+}
+
static void ffi_type_print_op(val obj, val out, val pretty, struct strm_ctx *ctx)
{
struct txr_ffi_type *tft = ffi_type_struct(obj);
@@ -1524,43 +1530,50 @@ val ffi_type_compile(val syntax)
}
} else if (sym == ptr_in_s) {
val target_type = ffi_type_compile(cadr(syntax));
- return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *),
+ return make_ffi_type_pointer(syntax, ffi_get_lisp_type(target_type),
+ sizeof (mem_t *),
ffi_ptr_in_put, ffi_ptr_get,
ffi_ptr_in_in, ffi_ptr_in_out,
target_type);
} else if (sym == ptr_in_d_s) {
val target_type = ffi_type_compile(cadr(syntax));
- return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *),
+ return make_ffi_type_pointer(syntax, ffi_get_lisp_type(target_type),
+ sizeof (mem_t *),
ffi_ptr_in_put, ffi_ptr_d_get,
ffi_ptr_in_d_in, ffi_ptr_in_out,
target_type);
} else if (sym == ptr_out_s) {
val target_type = ffi_type_compile(cadr(syntax));
- return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *),
+ return make_ffi_type_pointer(syntax, ffi_get_lisp_type(target_type),
+ sizeof (mem_t *),
ffi_ptr_out_put, ffi_ptr_get,
ffi_ptr_out_in, ffi_ptr_out_out,
target_type);
} else if (sym == ptr_out_d_s) {
val target_type = ffi_type_compile(cadr(syntax));
- return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *),
+ return make_ffi_type_pointer(syntax, ffi_get_lisp_type(target_type),
+ sizeof (mem_t *),
ffi_ptr_out_null_put, ffi_ptr_d_get,
ffi_ptr_out_in, ffi_ptr_out_out,
target_type);
} else if (sym == ptr_s) {
val target_type = ffi_type_compile(cadr(syntax));
- return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *),
+ return make_ffi_type_pointer(syntax, ffi_get_lisp_type(target_type),
+ sizeof (mem_t *),
ffi_ptr_in_put, ffi_ptr_get,
ffi_ptr_out_in, ffi_ptr_out_out,
target_type);
} else if (sym == ptr_out_s_s) {
val target_type = ffi_type_compile(cadr(syntax));
- return make_ffi_type_pointer(syntax, cptr_s, sizeof (mem_t *),
+ return make_ffi_type_pointer(syntax, ffi_get_lisp_type(target_type),
+ sizeof (mem_t *),
ffi_ptr_out_null_put, ffi_ptr_get,
ffi_ptr_out_s_in, ffi_ptr_out_out,
target_type);
} else if (sym == buf_s || sym == buf_d_s) {
cnum nelem = c_num(cadr(syntax));
- val type = make_ffi_type_builtin(syntax, cptr_s, sizeof (mem_t *),
+ val type = make_ffi_type_builtin(syntax, buf_s,
+ sizeof (mem_t *),
&ffi_type_pointer,
if3(sym == buf_s,
ffi_buf_put, ffi_buf_d_put),