Skip to content

Commit

Permalink
typeset: only run sh_assignok() for variables (re: a2f13c1)
Browse files Browse the repository at this point in the history
src/cmd/ksh93/bltins/typeset.c:
- setall(): Only run sh_assignok() if troot points to the variable
  tree. For instance, it's pointless to run it for an alias.
- Remove vestigial SHOPT_BSH code. The ast-open-history repo shows
  that earlier SHOPT_BSH code was removed on 2008-06-02 and
  2005-05-22. This may have been experimental code for increased
  compatibility with the ancient Bourne shell. There was never any
  documentation.
  • Loading branch information
McDutchie committed Apr 30, 2021
1 parent 7439e3d commit 72fe631
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/cmd/ksh93/bltins/typeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,24 +782,19 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
if(!comvar && !iarray)
continue;
}

/* Create local scope for virtual subshell */
if(shp->subshell)
if(troot==shp->var_tree)
{
if(!nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np))
if(shp->subshell)
{
/*
* Variables with internal trap/discipline functions (LC_*, LINENO, etc.) need to be
* cloned, as moving them will remove the discipline function.
* Create local scope for virtual subshell. Variables with discipline functions
* (LC_*, LINENO, etc.) need to be cloned, as moving them will remove the discipline.
*/
np=sh_assignok(np,2);
if(!nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np))
np=sh_assignok(np,2);
else
np=sh_assignok(np,0);
}
else
np=sh_assignok(np,0);
}

if(troot==shp->var_tree)
{
if(iarray)
{
if(tp->tname)
Expand Down Expand Up @@ -884,10 +879,6 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
errormsg(SH_DICT,ERROR_exit(1),e_badexport,name);
UNREACHABLE();
}
#if SHOPT_BSH
if(flag&NV_EXPORT)
nv_offattr(np,NV_IMPORT);
#endif /* SHOPT_BSH */
newflag = curflag;
if(flag&~NV_NOCHANGE)
newflag &= NV_NOCHANGE;
Expand Down Expand Up @@ -1355,22 +1346,18 @@ static int unall(int argc, char **argv, register Dt_t *troot, Shell_t* shp)
r=1;
continue;
}

if(shp->subshell)
{
/*
* Create local scope for virtual subshell. Variables with discipline functions
* (LC_*, LINENO, etc.) need to be cloned, as moving them will remove the discipline.
*/
if(!nv_isattr(np,NV_NODISC|NV_ARRAY) && !nv_isvtree(np))
{
/*
* Variables with internal trap/discipline functions (LC_*, LINENO, etc.) need to be
* cloned, as moving them will remove the discipline function.
*/
np=sh_assignok(np,2);
}
else
np=sh_assignok(np,0);
}
}

/*
* When aliases are removed from the tree, the NV_NOFREE attribute must be used for
* preset aliases since those are given the NV_NOFREE attribute. _nv_unset discards
Expand Down

0 comments on commit 72fe631

Please sign in to comment.