summaryrefslogtreecommitdiffstats
path: root/args.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-10-15 00:13:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-10-15 00:13:58 -0700
commitdb49aeca0b8cdf6695c3fc0754274398da0234d5 (patch)
tree126a5c227ec88b0649730aa5e4466279d7fb52dc /args.h
parent227d89b5ec4b967c87cd24d7074ec71e8aad0448 (diff)
downloadtxr-db49aeca0b8cdf6695c3fc0754274398da0234d5.tar.gz
txr-db49aeca0b8cdf6695c3fc0754274398da0234d5.tar.bz2
txr-db49aeca0b8cdf6695c3fc0754274398da0234d5.zip
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.
Diffstat (limited to 'args.h')
-rw-r--r--args.h9
1 files changed, 7 insertions, 2 deletions
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)
{