summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-06-14 08:23:35 -0700
committerKaz Kylheku <kaz@kylheku.com>2025-06-14 08:23:35 -0700
commiteabadb2d4e22c6f166bb1a3079eaca3ae305a39c (patch)
treeb2aff455ccbbcb41a075c78d5837bf7cab5764cc
parentd5e64053aa5073065e90dfa9c576c1a09757ebb8 (diff)
downloadtxr-eabadb2d4e22c6f166bb1a3079eaca3ae305a39c.tar.gz
txr-eabadb2d4e22c6f166bb1a3079eaca3ae305a39c.tar.bz2
txr-eabadb2d4e22c6f166bb1a3079eaca3ae305a39c.zip
ffi: remove dud elements array of ffi types.
We compute an array of ffi_type for aggregates, but never actually use it for anything; we don't give it to libffi. Let's get rid of it. * ffi.c (struct txr_ffi_type): Remove elements member. (ffi_type_struct_destroy_op): Remove freeing of elements and assignment to zero. (ffi_struct_calcft, ffi_union_calcft, ffi_array_calcft): Remove allocation and calculation of elements. (make_ffi_type_struct, make_ffi_type_union): No need to free elements when we are replacing the existing type.
-rw-r--r--ffi.c27
1 files changed, 0 insertions, 27 deletions
diff --git a/ffi.c b/ffi.c
index 6b6c448f..834c6013 100644
--- a/ffi.c
+++ b/ffi.c
@@ -201,7 +201,6 @@ struct txr_ffi_type {
val self;
ffi_kind_t kind;
ffi_type *ft;
- ffi_type **elements;
val lt;
val syntax;
val eltype;
@@ -284,8 +283,6 @@ static void ffi_type_struct_destroy_op(val obj)
struct txr_ffi_type *tft = ffi_type_struct(obj);
#if HAVE_LIBFFI
- free(tft->elements);
- tft->elements = 0;
free(tft->ft);
tft->ft = 0;
#endif
@@ -3674,16 +3671,13 @@ static void ffi_struct_calcft(struct txr_ffi_type *tft)
{
cnum nmemb = tft->nelem;
ffi_type *ft = coerce(ffi_type *, chk_calloc(1, sizeof *ft));
- ffi_type **elem = coerce(ffi_type **, chk_calloc(nmemb + 1, sizeof *elem));
cnum i, e, po;
tft->ft = ft;
- tft->elements = elem;
ft->type = FFI_TYPE_STRUCT;
ft->size = tft->size;
ft->alignment = tft->align;
- ft->elements = tft->elements;
for (i = e = po = 0; i < nmemb; i++)
{
@@ -3694,7 +3688,6 @@ static void ffi_struct_calcft(struct txr_ffi_type *tft)
po = memb->offs;
if (mtft->calcft)
mtft->calcft(mtft);
- elem[e++] = mtft->ft;
}
}
}
@@ -3715,39 +3708,21 @@ static void ffi_union_calcft(struct txr_ffi_type *tft)
most_aligned = mtft;
}
- {
- ucnum units = tft->size / most_aligned->size, u;
- ffi_type **elem = coerce(ffi_type **, chk_calloc(units + 1, sizeof *elem));
- for (u = 0; u < units; u++)
- elem[i] = most_aligned->ft;
- tft->elements = elem;
- }
-
tft->ft = ft;
ft->type = FFI_TYPE_STRUCT;
ft->size = tft->size;
ft->alignment = tft->align;
- ft->elements = tft->elements;
}
static void ffi_array_calcft(struct txr_ffi_type *tft)
{
- cnum nmemb = tft->nelem;
ffi_type *ft = coerce(ffi_type *, chk_calloc(1, sizeof *ft));
- ffi_type **elem = coerce(ffi_type **, chk_calloc(nmemb + 1, sizeof *elem));
- struct txr_ffi_type *etft = ffi_type_struct(tft->eltype);
- cnum i;
tft->ft = ft;
- tft->elements = elem;
ft->type = FFI_TYPE_STRUCT;
ft->size = tft->size;
ft->alignment = tft->align;
- ft->elements = tft->elements;
-
- for (i = 0; i < nmemb; i++)
- elem[i] = etft->ft;
}
#endif
@@ -3784,7 +3759,6 @@ static val make_ffi_type_struct(val syntax, val lisp_type,
}
#if HAVE_LIBFFI
free(tft->ft);
- free(tft->elements);
#endif
free(tft->memb);
memset(tft, 0, sizeof *tft);
@@ -3973,7 +3947,6 @@ static val make_ffi_type_union(val syntax, val use_existing, val self)
}
#if HAVE_LIBFFI
free(tft->ft);
- free(tft->elements);
#endif
free(tft->memb);
memset(tft, 0, sizeof *tft);