From 366efa4b06124d20fc5378b8b6d30e30c1e6ac33 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 3 Jul 2022 17:58:49 +0200 Subject: [PATCH] restore C90 compat: do not repeat a typedef (re: 3e0da770) We try to stay compatibile with C90. Turns out that repeating a typedef is valid only from C11 onwards, as a feature taken from C++. So I goofed and broke the build on old or strict compilers. src/cmd/ksh93/include/{name,shell}.h: - union Value: Since we will now once again have to typecast to use nvalue.bfp in any case, just make it a void pointer; that is how pointers that require typecasts are handled in every other case. - Since the funptr() macro needs a typecast to Shbltin_f which is defined in libast's shcmd.h, move this macro to shell.h which (unlike name.h) includes that header. src/cmd/ksh93/sh/{init,nvdisc}.c: - Typecast to void* when assigning to *->nvalue.bfp. src/lib/libast/include/shcmd.h: - Use shell_h_defined (introduced in 4491bc6a) and defs_h_defined to check if ksh's shell.h or defs.h were included before shcmd.h, instead of random macros defined by them; much clearer. --- src/cmd/ksh93/include/name.h | 6 +----- src/cmd/ksh93/include/shell.h | 3 +++ src/cmd/ksh93/sh/init.c | 2 +- src/cmd/ksh93/sh/nvdisc.c | 2 +- src/lib/libast/include/shcmd.h | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cmd/ksh93/include/name.h b/src/cmd/ksh93/include/name.h index 05efa74d6..fd9c34f1d 100644 --- a/src/cmd/ksh93/include/name.h +++ b/src/cmd/ksh93/include/name.h @@ -31,9 +31,6 @@ #include #include -typedef struct Shbltin_s Shbltin_t; -typedef int (*Shbltin_f)(int, char**, Shbltin_t*); - /* Nodes can have all kinds of values */ union Value { @@ -55,7 +52,7 @@ union Value struct Ufunction *rp; /* shell user defined functions */ struct Namfun *funp; /* discipline pointer */ struct Namref *nrp; /* name reference */ - Shbltin_f bfp; /* builtin entry point function pointer */ + void *bfp; /* pointer to built-in command's entry function (typecast to Shbltin_f) */ }; #include "nval.h" @@ -150,7 +147,6 @@ struct Ufunction #define is_abuiltin(n) (nv_isattr(n,NV_BLTIN|NV_INTEGER)==NV_BLTIN) #define is_afunction(n) (nv_isattr(n,NV_FUNCTION|NV_REF)==NV_FUNCTION) #define nv_funtree(n) ((n)->nvalue.rp->ptree) -#define funptr(n) ((n)->nvalue.bfp) /* NAMNOD MACROS */ /* ... for attributes */ diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h index da2e426a5..96ad0ca73 100644 --- a/src/cmd/ksh93/include/shell.h +++ b/src/cmd/ksh93/include/shell.h @@ -52,6 +52,9 @@ typedef struct Shell_s Shell_t; #include +/* get pointer to a built-in command's entry function */ +#define funptr(n) ((Shbltin_f)(n)->nvalue.bfp) + typedef void (*Shinit_f)(Shell_t*, int); #ifndef SH_wait_f_defined typedef int (*Shwait_f)(int, long, int); diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index e35922f0d..217b9d223 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1992,7 +1992,7 @@ Dt_t *sh_inittree(const struct shtable2 *name_vals) } np->nvenv = 0; if(name_vals==(const struct shtable2*)shtab_builtins) - np->nvalue.bfp = ((struct shtable3*)tp)->sh_value; + np->nvalue.bfp = (void*)((struct shtable3*)tp)->sh_value; else { if(name_vals == shtab_variables) diff --git a/src/cmd/ksh93/sh/nvdisc.c b/src/cmd/ksh93/sh/nvdisc.c index b2fa557f1..f4c5a02f2 100644 --- a/src/cmd/ksh93/sh/nvdisc.c +++ b/src/cmd/ksh93/sh/nvdisc.c @@ -1173,7 +1173,7 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra) np->nvfun = 0; if(bltin) { - np->nvalue.bfp = bltin; + np->nvalue.bfp = (void*)bltin; nv_onattr(np,NV_BLTIN|NV_NOFREE); np->nvfun = (Namfun_t*)extra; } diff --git a/src/lib/libast/include/shcmd.h b/src/lib/libast/include/shcmd.h index 09f1e128c..4d40cb073 100644 --- a/src/lib/libast/include/shcmd.h +++ b/src/lib/libast/include/shcmd.h @@ -69,7 +69,7 @@ struct Shbltin_s int invariant; }; -#if defined(SH_VERSION) || defined(_SH_PRIVATE) +#if defined(shell_h_defined) || defined(defs_h_defined) # undef Shell_t # undef Namval_t #else