From db49aeca0b8cdf6695c3fc0754274398da0234d5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 15 Oct 2022 00:13:58 -0700 Subject: args: don't use alloca for const size cases. * args.h (args_decl_list): This macro now handles only constant values of N. It declares an anonyous container struct type which juxtaposes the struc args header with exactly N values. This is simply defined as a local variable without alloca. (args_decl_constsize): Like args_decl, but requiring a constant N; implemented via args_decl_list. (args_decl_list_dyn): New name for the old args_decl_list which calls alloca. No places in the code depend on this at all, except the definition of args_decl. (args_decl): Retargeted to args_decl_list_dyn. There is some inconsistency in the macro naming in that args_decl_constsize depends on args_decl_list, and args_decl depends on arg_decl_list_dyn. This was done to minimize diffs. Most direct uses of args_decl_list have a constant size, but a large number of args_decl uses do not have a constant size. * eval.c (op_catch): Use args_decl_constsize. * ffi.c (ffi_struct_in, ffi_struct_get, union_out): Likewise. * ftw.c (ftw_callback): Likewise. * lib.c (funcall, funcall1, funcall2, funcall3, funcall4, uniq, relate): Likewise. * socket.c (sockaddr_in_unpack, sockaddr_in6_unpack, sockaddr_un_unpack): Likewise. * stream.c (formatv): Likewise. * struct.c (struct_from_plist, struct_from_args, make_struct_lit): Likewise. * sysif.c (termios_unpack): Likewise. * time.c (broken_time_struct): Likewise. --- args.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'args.h') diff --git a/args.h b/args.h index 6f4baa43..df8cb3db 100644 --- a/args.h +++ b/args.h @@ -64,14 +64,19 @@ INLINE void args_set_fill(struct args *args, cnum fill) } #define args_decl_list(NAME, N, L) \ + struct { struct args args; val arg[N]; } _ac; \ + struct args *NAME = args_init_list(&_ac.args, N, L) + +#define args_decl_constsize(NAME, N) args_decl_list(NAME, N, nil) + +#define args_decl_list_dyn(NAME, N, L) \ mem_t *NAME ## _mem = \ coerce(mem_t *, \ alloca(offsetof(struct args, arg) + (N)*sizeof (val))); \ struct args *NAME = args_init_list(coerce(struct args *, \ NAME ## _mem), N, L) -#define args_decl(NAME, N) args_decl_list(NAME, N, nil) - +#define args_decl(NAME, N) args_decl_list_dyn(NAME, N, nil) INLINE val args_add(struct args *args, val arg) { -- cgit v1.2.3