1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Remove abandoned SHOPT_ENV experiment

SHOPT_ENV is an undocumented compile-time option implementing an
experimental method for handling environment variables, which is
implemented in env.h and env.c. There is no mention in the docs or
Makefile, and no mention in the mailing list archives. It adds no
new functionality, but at first glance it's a clean-looking
interface.

However, unfortunately, it's broken. Compiling with -DSHOPT_ENV
added to CCFLAGS causes bin/shtests to show these regressions:

functions.sh[341]: export not restored name=value function call -- expected 'base', got ''
functions.sh[1274]: Environment variable is not passed to a function
substring.sh[236]: export not restored name=value function call
variables.sh[782]: SHLVL should be 3 not 2

In addition, 'export' stops working on unset variables.

In the 93v- beta this code is still present, unchanged, though 93v-
made lots of incompatible changes. By the time ksh2020 noticed it,
it was no longer compiling, so it probably wasn't compiling in the
93v- beta either. Discussion: https://github.com/att/ast/issues/504
So the experiment was already abandoned by D. Korn and his team.

Meanwhile it was leaving sh/name.c with two versions of several
enviornment-related functions, and it's not clear which one is
actually compiled without doing detective work tracing header files
(most of the code was made conditional on _ENV_H, which is defined
in env.h, which is included by defs.h if SHOPT_ENV is defined).
This actively hinders understanding of the codebase. And any
changes to these functions would need to be implemented twice.

src/cmd/ksh93/include/env.h,
src/cmd/ksh93/sh/env.c:
- Removed.

src/cmd/ksh93/DESIGN,
src/cmd/ksh93/Makefile,
src/cmd/ksh93/Mamfile:
- Update accordingly.

All other changed files:
- Remove deactivated code behind SHOPT_ENV and _ENV_H.
This commit is contained in:
Martijn Dekker 2020-09-02 15:52:41 +01:00
parent bc4dbe0627
commit 8d7f616e75
10 changed files with 57 additions and 488 deletions

View file

@ -59,10 +59,8 @@ pathnative(const char* path, char* buf, size_t siz)
#endif /* _lib_pathnative */
static void attstore(Namval_t*,void*);
#ifndef _ENV_H
static void pushnam(Namval_t*,void*);
static char *staknam(Namval_t*, char*);
#endif
static void pushnam(Namval_t*,void*);
static char *staknam(Namval_t*, char*);
static void rightjust(char*, int, int);
static char *lastdot(char*, int);
@ -109,9 +107,7 @@ struct adata
#endif
char nv_local = 0;
#ifndef _ENV_H
static void(*nullscan)(Namval_t*,void*);
#endif
#if ( SFIO_VERSION <= 20010201L )
# define _data data
@ -137,29 +133,6 @@ static char *getbuf(size_t len)
return(buf);
}
#ifdef _ENV_H
void sh_envput(Env_t* ep,Namval_t *np)
{
int offset = staktell();
Namarr_t *ap = nv_arrayptr(np);
char *val;
if(ap)
{
if(ap->nelem&ARRAY_UNDEF)
nv_putsub(np,"0",0L);
else if(!(val=nv_getsub(np)) || strcmp(val,"0"))
return;
}
if(!(val = nv_getval(np)))
return;
stakputs(nv_name(np));
stakputc('=');
stakputs(val);
stakseek(offset);
env_add(ep,stakptr(offset),ENV_STRDUP);
}
#endif
/*
* output variable name in format for re-input
*/
@ -2120,7 +2093,6 @@ static void rightjust(char *str, int size, int fill)
}
#endif /* SHOPT_MULTIBYTE */
#ifndef _ENV_H
static char *staknam(register Namval_t *np, char *value)
{
register char *p,*q;
@ -2133,35 +2105,10 @@ static char *staknam(register Namval_t *np, char *value)
}
return(q);
}
#endif
/*
* put the name and attribute into value of attributes variable
*/
#ifdef _ENV_H
static void attstore(register Namval_t *np, void *data)
{
register int flag, c = ' ';
NOT_USED(data);
if(!(nv_isattr(np,NV_EXPORT)))
return;
flag = nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER);
stakputc('=');
if((flag&NV_DOUBLE) == NV_DOUBLE)
{
/* export doubles as integers for ksh88 compatibility */
stakputc(c+NV_INTEGER|(flag&~(NV_DOUBLE|NV_EXPNOTE)));
}
else
{
stakputc(c+flag);
if(flag&NV_INTEGER)
c += nv_size(np);
}
stakputc(c);
stakputs(nv_name(np));
}
#else
static void attstore(register Namval_t *np, void *data)
{
register int flag = np->nvflag;
@ -2194,9 +2141,7 @@ static void attstore(register Namval_t *np, void *data)
}
ap->attval = strcopy(++ap->attval,nv_name(np));
}
#endif
#ifndef _ENV_H
static void pushnam(Namval_t *np, void *data)
{
register char *value;
@ -2210,31 +2155,11 @@ static void pushnam(Namval_t *np, void *data)
if(nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER))
ap->attsize += (strlen(nv_name(np))+4);
}
#endif
/*
* Generate the environment list for the child.
*/
#ifdef _ENV_H
char **sh_envgen(void)
{
Shell_t *shp = sh_getinterp();
int offset,tell;
register char **er;
env_delete(shp->env,"_");
er = env_get(shp->env);
offset = staktell();
stakputs(e_envmarker);
tell = staktell();
nv_scan(shp->var_tree, attstore,(void*)0,0,(NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER));
if(tell ==staktell())
stakseek(offset);
else
*--er = stakfreeze(1)+offset;
return(er);
}
#else
char **sh_envgen(void)
{
register char **er;
@ -2264,7 +2189,6 @@ char **sh_envgen(void)
*data.argnam = 0;
return(er);
}
#endif
struct scan
{