From 153c4b56e8ba5d48349538ffae238c87c0d06a02 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 16 May 2021 04:27:57 +0200 Subject: [PATCH] Hopefully good fix for va_listval build fails (re: 41ed8047, etc.) The last commit still failed to build on macOS M1. That va_listval macro keeps causing trouble. It's an AST thing that is defined in src/lib/libast/features/common. That looks like some incredibly opaque attempt to make it compatible with everything, and clearly it no longer works properly on all systems. I don't dare touch it, though. That code looks like any minimal change will probably break the build on some system or other. src/lib/libast/features/hack: - Add feature test to check if that macro needs (0) no workaround, or (1) the workaround from the 93v- beta, or (2) the FreeBSD one. Whichever version compiles first, it will use. If none does, this test will not output a value, which will be treated as 0. src/lib/libast/hash/hashalloc.c, src/lib/libast/string/tokscan.c: - Update to use the result of the hack feature test. src/lib/libast/Mamfile: - Update for new #include dependencies. --- src/lib/libast/Mamfile | 15 ++++++---- src/lib/libast/features/hack | 50 +++++++++++++++++++++++++++++++++ src/lib/libast/hash/hashalloc.c | 8 ++++-- src/lib/libast/string/tokscan.c | 8 ++++-- 4 files changed, 71 insertions(+), 10 deletions(-) diff --git a/src/lib/libast/Mamfile b/src/lib/libast/Mamfile index 273546c65..3466d2be2 100644 --- a/src/lib/libast/Mamfile +++ b/src/lib/libast/Mamfile @@ -523,6 +523,13 @@ make install done fastfind.o generated make hashalloc.o make hash/hashalloc.c + make FEATURE/hack implicit + meta FEATURE/hack features/%>FEATURE/% features/hack hack + make features/hack + prev FEATURE/common implicit + done features/hack + exec - iffe ${IFFEFLAGS} -v -X ast -X std -c "${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS}" run features/hack + done FEATURE/hack generated make hash/hashlib.h implicit make include/hash.h implicit make include/hashpart.h implicit @@ -909,6 +916,7 @@ make install done tokline.o generated make tokscan.o make string/tokscan.c + prev FEATURE/hack implicit prev include/tok.h implicit prev include/ast.h implicit done string/tokscan.c @@ -3118,12 +3126,7 @@ make install make locale_attr.h implicit done locale_attr.h dontcare virtual done comp/gross_sgi.h dontcare - make FEATURE/hack implicit - meta FEATURE/hack features/%>FEATURE/% features/hack hack - make features/hack - done features/hack - exec - iffe ${IFFEFLAGS} -v -X ast -X std -c "${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS}" run features/hack - done FEATURE/hack generated + prev FEATURE/hack implicit prev include/ls.h implicit prev include/ast.h implicit done comp/gross.c diff --git a/src/lib/libast/features/hack b/src/lib/libast/features/hack index 2be7af982..1bfdd17e3 100644 --- a/src/lib/libast/features/hack +++ b/src/lib/libast/features/hack @@ -1 +1,51 @@ hdr locale_attr + +tst - -DVAL=0 - -DVAL=1 - -DVAL=2 note{ probing need for va_listval() workaround }end output{ + /* + * This workaround test is needed until libast's va_listval macro from + * features/common can be made to work properly on all systems (if ever). + * It is used in hash/hashalloc.c and string/tokscan.c. + */ + #include "FEATURE/common" + #if _STD_ && _hdr_stdarg + #include + #else + #include + #endif + void foo(int bar, ...) + { + va_list ap; + va_start(ap, bar); + if (bar==1) + { + #if VAL == 0 + /* + * Normal version. On some systems, it won't compile. + */ + va_copy(ap, va_listval(va_arg(ap, va_listarg))); + #elif VAL == 1 + /* + * This is the workaround from the ksh 93v- beta distribution. + */ + va_list np; + np = va_listval(va_arg(ap, va_listarg)); + va_copy(ap, np); + #elif VAL == 2 + /* + * This is the workaround from the FreeBSD port. + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255308 + */ + va_listarg np; + np = va_listval(va_arg(ap, va_listarg)); + va_copy(ap, np); + #endif + } + va_end(ap); + } + int main() + { + foo(0,"one",2); + printf("#define _need_va_listval_workaround %d\n",VAL); + return 0; + } +}end diff --git a/src/lib/libast/hash/hashalloc.c b/src/lib/libast/hash/hashalloc.c index 0791f3193..050ef4f2f 100644 --- a/src/lib/libast/hash/hashalloc.c +++ b/src/lib/libast/hash/hashalloc.c @@ -31,6 +31,7 @@ static const char id_hash[] = "\n@(#)$Id: hash (AT&T Research) 1996-08-11 $\0\n"; #include "hashlib.h" +#include "FEATURE/hack" Hash_info_t hash_info = { 0 }; @@ -152,10 +153,13 @@ hashalloc(Hash_table_t* ref, ...) va_copy(*vp, ap); vp++; } -#if __clang__ && __SIZEOF_POINTER__ == 4 && !__APPLE__ +#if _need_va_listval_workaround { +# if _need_va_listval_workaround == 2 + va_listarg np; +# else va_list np; - +# endif np = va_listval(va_arg(ap, va_listarg)); va_copy(ap, np); } diff --git a/src/lib/libast/string/tokscan.c b/src/lib/libast/string/tokscan.c index c1881eb2f..28a7d008e 100644 --- a/src/lib/libast/string/tokscan.c +++ b/src/lib/libast/string/tokscan.c @@ -64,6 +64,7 @@ #include #include +#include "FEATURE/hack" static char empty[1]; @@ -234,10 +235,13 @@ tokscan(register char* s, char** nxt, const char* fmt, ...) prv_f = f; f = va_arg(ap, char*); va_copy(prv_ap, ap); -#if __clang__ && __SIZEOF_POINTER__ == 4 && !__APPLE__ +#if _need_va_listval_workaround { +# if _need_va_listval_workaround == 2 + va_listarg np; +# else va_list np; - +# endif np = va_listval(va_arg(ap, va_listarg)); va_copy(ap, np); }