From cfe0428c0d96813685b19a191a3bd20336c20001 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 28 Jul 2019 15:26:58 -0700 Subject: FFI: bugfix: properly re-use existing struct type. This is a bug in the prior commit's change. * ffi.c (make_ffi_type_struct, make_ffi_type_union): When using an existing type, do not call cobj to make a new Lisp object for the type structure; pull the existing one out from tft->self. --- ffi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ffi.c b/ffi.c index 07bcb7da..450bc904 100644 --- a/ffi.c +++ b/ffi.c @@ -2843,7 +2843,9 @@ static val make_ffi_type_struct(val syntax, val lisp_type, cnum nmemb = c_num(length(slot_exprs)), i; struct smemb *memb = coerce(struct smemb *, chk_calloc(nmemb, sizeof *memb)); - val obj = cobj(coerce(mem_t *, tft), ffi_type_s, &ffi_type_struct_ops); + val obj = if3(use_existing, + tft->self, + cobj(coerce(mem_t *, tft), ffi_type_s, &ffi_type_struct_ops)); ucnum offs = 0; ucnum most_align = 0; int need_out_handler = 0; @@ -3006,7 +3008,9 @@ static val make_ffi_type_union(val syntax, val use_existing, val self) cnum nmemb = c_num(length(slot_exprs)), i; struct smemb *memb = coerce(struct smemb *, chk_calloc(nmemb, sizeof *memb)); - val obj = cobj(coerce(mem_t *, tft), ffi_type_s, &ffi_type_struct_ops); + val obj = if3(use_existing, + tft->self, + cobj(coerce(mem_t *, tft), ffi_type_s, &ffi_type_struct_ops)); ucnum most_align = 0; ucnum biggest_size = 0; const unsigned bits_int = 8 * sizeof(int); -- cgit v1.2.3