Skip to content

Commit

Permalink
Fix minor typeset attribute regressions (re: 95fe07d, fdb9781)
Browse files Browse the repository at this point in the history
This fixes the following regressions marked TODO in attributes.sh:

$ typeset -L 13 bar; readonly bar; typeset -p bar
typeset -r -L 0 foo		# exp.: typeset -r -L 13 foo
$ typeset -R 13 bar; readonly bar; typeset -p bar
typeset -r -R 0 bar		# exp.: typeset -r -R 13 bar
$ typeset -Z 13 baz; readonly baz; typeset -p baz
typeset -r -Z 0 -R 0 baz	# exp.: typeset -r Z 13 -R 13 baz

I've discovered that these were briefly fixed between fdb9781 (Red
Hat patch for typeset -xu/-xl) and 95fe07d (reversal of patch,
different -xu/-xl fix, but reintroduced these regressions).

src/cmd/ksh93/sh/name.c: nv_newattr():
- Replace check from 95fe07d with a new one that combines its
  approach with that of fdb9781: do not change size (and hence
  return early) if NV_RDONLY and/or NV_EXPORT are the only
  attributes that are changing.

src/cmd/ksh93/tests/attributes.sh:
- Enable the TODO regression tests.
  • Loading branch information
McDutchie committed Feb 2, 2021
1 parent fe05350 commit 0e4c4d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/cmd/ksh93/sh/name.c
Original file line number Diff line number Diff line change
Expand Up @@ -2966,11 +2966,10 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size)
nv_onattr(np,NV_EXPORT);
sh_envput(shp->env,np);
}
if((n^newatts)==NV_EXPORT && !trans)
/* Only EXPORT attribute has changed and thus all work has been done. */
return;
}
oldsize = nv_size(np);
if(((n^newatts) & ~(NV_EXPORT|NV_RDONLY))==0)
size = oldsize;
if((size==oldsize|| (n&NV_INTEGER)) && !trans && ((n^newatts)&~NV_NOCHANGE)==0)
{
if(size>0)
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/tests/attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ typeset -A expect=(
[F12]='typeset -x -r -F 12 foo'
[H]='typeset -x -r -H foo'
[L]='typeset -x -r -L 0 foo'
# [L17]='typeset -x -r -L 17 foo' # TODO: outputs '-L 0'
[L17]='typeset -x -r -L 17 foo'
[Mtolower]='typeset -x -r -l foo'
[Mtoupper]='typeset -x -r -u foo'
[R]='typeset -x -r -R 0 foo'
# [R17]='typeset -x -r -R 17 foo' # TODO: outputs '-L 0'
[R17]='typeset -x -r -R 17 foo'
[X17]='typeset -x -r -X 17 foo'
[S]='typeset -x -r foo'
[T]='typeset -x -r foo'
[Z]='typeset -x -r -Z 0 -R 0 foo'
# [Z13]='typeset -x -r -Z 13 -R 13 foo' # TODO: outputs 'typeset -x -r -Z 0 -R 0 foo'
[Z13]='typeset -x -r -Z 13 -R 13 foo'
)
for flag in "${!expect[@]}"
do unset foo
Expand Down

2 comments on commit 0e4c4d6

@hyenias
Copy link

@hyenias hyenias commented on 0e4c4d6 Feb 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@McDutchie, I will look into this further. I just recently saw those TODOs in attributes.sh. I just did not understand why having a size change from 17/13 to 0 on an undefined readonly variable meant anything as I would hope the result of the variable output would be empty string.

@hyenias
Copy link

@hyenias hyenias commented on 0e4c4d6 Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See a61430f for the completion of the readonly attribute size fix.

Please sign in to comment.