From 0b814b53bd2c6754a7fb283959b98aae896c82e1 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 21 Mar 2021 04:17:05 +0000 Subject: [PATCH] Remove more legacy libast code (re: f9c127e3, 651bbd56) This removes #ifdefs checking for the existence of SH_PLUGIN_VERSION (version check for dynamically loaded builtins) and the SFIO identifiers SF_BUFCONST, SF_CLOSING, SF_APPENDWR, SF_ATEXIT, all of which are defined by the bundled libast. --- src/cmd/ksh93/bltins/typeset.c | 12 ++---------- src/cmd/ksh93/edit/history.c | 19 +++---------------- src/cmd/ksh93/include/io.h | 7 ------- src/cmd/ksh93/sh/io.c | 2 -- src/cmd/ksh93/sh/lex.c | 20 +++----------------- src/cmd/ksh93/sh/name.c | 4 ---- src/cmd/ksh93/sh/parse.c | 16 ++++++++++------ src/cmd/ksh93/sh/path.c | 18 ------------------ 8 files changed, 18 insertions(+), 80 deletions(-) diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index e2e729d03..223293478 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -1027,7 +1027,7 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) Stk_t *stkp; void *library=0; char *errmsg; -#ifdef SH_PLUGIN_VERSION +#if SHOPT_DYNAMIC unsigned long ver; int list = 0; char path[1024]; @@ -1055,7 +1055,7 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) #endif /* SHOPT_DYNAMIC */ break; case 'l': -#ifdef SH_PLUGIN_VERSION +#if SHOPT_DYNAMIC list = 1; #endif break; @@ -1083,7 +1083,6 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) #if SHOPT_DYNAMIC if(arg) { -#ifdef SH_PLUGIN_VERSION if(!(library = dllplugin(SH_ID, arg, NiL, SH_PLUGIN_VERSION, &ver, RTLD_LAZY, path, sizeof(path)))) { errormsg(SH_DICT,ERROR_exit(0),"%s: %s",arg,dllerror(0)); @@ -1091,13 +1090,6 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context) } if(list) sfprintf(sfstdout, "%s %08lu %s\n", arg, ver, path); -#else - if(!(library = dllplug(SH_ID,arg,NIL(char*),RTLD_LAZY,NIL(char*),0))) - { - errormsg(SH_DICT,ERROR_exit(0),"%s: %s",arg,dlerror()); - return(1); - } -#endif sh_addlib(tdata.sh,library,arg,NiL); } else diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index 7d50ee072..974371643 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -110,14 +110,8 @@ static History_t* hist_trim(History_t*, int); static int hist_nearend(History_t*,Sfio_t*, off_t); static int hist_check(int); static int hist_clean(int); -#ifdef SF_BUFCONST - static ssize_t hist_write(Sfio_t*, const void*, size_t, Sfdisc_t*); - static int hist_exceptf(Sfio_t*, int, void*, Sfdisc_t*); -#else - static int hist_write(Sfio_t*, const void*, int, Sfdisc_t*); - static int hist_exceptf(Sfio_t*, int, Sfdisc_t*); -#endif - +static ssize_t hist_write(Sfio_t*, const void*, size_t, Sfdisc_t*); +static int hist_exceptf(Sfio_t*, int, void*, Sfdisc_t*); static int histinit; static mode_t histmode; @@ -788,11 +782,7 @@ void hist_flush(register History_t *hp) * a zero byte. Line sequencing is added as required */ -#ifdef SF_BUFCONST static ssize_t hist_write(Sfio_t *iop,const void *buff,register size_t insize,Sfdisc_t* handle) -#else -static int hist_write(Sfio_t *iop,const void *buff,register int insize,Sfdisc_t* handle) -#endif { register History_t *hp = (History_t*)handle; register char *bufptr = ((char*)buff)+insize; @@ -1174,14 +1164,11 @@ done: /* * Handle history file exceptions */ -#ifdef SF_BUFCONST static int hist_exceptf(Sfio_t* fp, int type, void *data, Sfdisc_t *handle) -#else -static int hist_exceptf(Sfio_t* fp, int type, Sfdisc_t *handle) -#endif { register int newfd,oldfd; History_t *hp = (History_t*)handle; + NOT_USED(data); if(type==SF_WRITE) { if(errno==ENOSPC || hp->histwfail++ >= 10) diff --git a/src/cmd/ksh93/include/io.h b/src/cmd/ksh93/include/io.h index eca543aba..79eb81496 100644 --- a/src/cmd/ksh93/include/io.h +++ b/src/cmd/ksh93/include/io.h @@ -32,13 +32,6 @@ #endif /* IOBSIZE */ #define IOMAXTRY 20 -#ifndef SF_CLOSING -#define SF_CLOSING SF_CLOSE -#endif -#ifndef SF_APPENDWR -#define SF_APPENDWR SF_APPEND -#endif - /* used for output of shell errors */ #define ERRIO 2 diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 4b83a7e38..8877df4bd 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -2386,13 +2386,11 @@ static int subexcept(Sfio_t* sp,register int mode, void *data, Sfdisc_t* handle) free((void*)disp); return(0); } -#ifdef SF_ATEXIT else if (mode==SF_ATEXIT) { sfdisc(sp, SF_POPDISC); return(0); } -#endif else if(mode==SF_READ) return(0); return(-1); diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 1b7cee923..359bb46f0 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -123,11 +123,7 @@ struct lexdata #define poplevel(lp) (lp->lexd.lastc=lp->lexd.lex_match[--lp->lexd.level]) static char *fmttoken(Lex_t*, int, char*); -#ifdef SF_BUFCONST - static int alias_exceptf(Sfio_t*, int, void*, Sfdisc_t*); -#else - static int alias_exceptf(Sfio_t*, int, Sfdisc_t*); -#endif +static int alias_exceptf(Sfio_t*, int, void*, Sfdisc_t*); static void setupalias(Lex_t*,const char*, Namval_t*); static int comsub(Lex_t*,int); static void nested_here(Lex_t*); @@ -2414,22 +2410,12 @@ struct alias /* * This code gets called whenever an end of string is found with alias */ - -#ifndef SF_ATEXIT -# define SF_ATEXIT 0 -#endif -/* - * This code gets called whenever an end of string is found with alias - */ -#ifdef SF_BUFCONST static int alias_exceptf(Sfio_t *iop,int type,void *data, Sfdisc_t *handle) -#else -static int alias_exceptf(Sfio_t *iop,int type,Sfdisc_t *handle) -#endif { register struct alias *ap = (struct alias*)handle; register Namval_t *np; register Lex_t *lp; + NOT_USED(data); if(type==0 || type==SF_ATEXIT || !ap) return(0); lp = ap->lp; @@ -2448,7 +2434,7 @@ static int alias_exceptf(Sfio_t *iop,int type,Sfdisc_t *handle) } if(ap->nextc) { - /* if last character is a blank, then next work can be alias */ + /* if last character is a blank, then next word can be alias */ register int c = fcpeek(-1); if(isblank(c)) lp->aliasok = 1; diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 17a2114ae..23ebde43a 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -108,10 +108,6 @@ struct adata char nv_local = 0; static void(*nullscan)(Namval_t*,void*); -#if ( SFIO_VERSION <= 20010201L ) -# define _data data -#endif - /* ======== name value pair routines ======== */ #include "shnodes.h" diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index af6f0db7c..241695fec 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -46,12 +46,6 @@ #define HERE_MEM SF_BUFSIZE /* size of here-docs kept in memory */ -#if CDT_VERSION < 20111111L -#define hash nvlink.hl._hash -#else -#define hash nvlink.lh.__hash -#endif - /* These routines are local to this module */ static Shnode_t *makeparent(Lex_t*, int, Shnode_t*); @@ -1999,6 +1993,15 @@ static Shnode_t *test_primary(Lex_t *lexp) } #if SHOPT_KIA +/* + * ksh is currently compiled with -D_API_ast=20100309, which sets CDT_VERSION to 20100309 in src/lib/libast/include/cdt.h + * which enables a legacy Cdt API also used elsewhere in ksh. Do not remove this version check as it is not yet obsolete. + */ +#if CDT_VERSION < 20111111L +#define hash nvlink.hl._hash +#else +#define hash nvlink.lh.__hash +#endif /* * return an entity checksum * The entity is created if it doesn't exist @@ -2035,6 +2038,7 @@ unsigned long kiaentity(Lex_t *lexp,const char *name,int len,int type,int first, } return(np->hash); } +#undef hash static void kia_add(register Namval_t *np, void *data) { diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 3af47a4e0..af38df146 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -851,26 +851,8 @@ Pathcomp_t *path_absolute(Shell_t *shp,register const char *name, Pathcomp_t *pp shp->bltin_dir = 0; return(oldpp); } -#ifdef SH_PLUGIN_VERSION if (dll = dllplugin(SH_ID, stakptr(m), NiL, SH_PLUGIN_VERSION, NiL, RTLD_LAZY, NiL, 0)) sh_addlib(shp,dll,stakptr(m),oldpp); -#else - if (dll = dllplug(SH_ID, stakptr(m), NiL, RTLD_LAZY, NiL, 0)) - { - /* - * this detects the 2007-05-11 builtin context change and also - * the 2008-03-30 opt_info.num change that hit libcmd::b_head - */ - - if (libcmd && !dlllook(dll, "b_pids")) - { - dlclose(dll); - dll = 0; - } - else - sh_addlib(shp,dll,stakptr(m),oldpp); - } -#endif if(dll && (addr=(Shbltin_f)dlllook(dll,stakptr(n))) && (!(np = sh_addbuiltin(stakptr(PATH_OFFSET),NiL,NiL)) || np->nvalue.bfp!=(Nambfp_f)addr) &&