-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v1.1] Make '_' refer to type var in discipline func within type
Example reproducer script: typeset -T Stopwatch_t=( float starttime stoptime diff function start { ((_.starttime = SECONDS)); } function stop { ((_.stoptime = SECONDS)); } function diff.getn { ((.sh.value = _.stoptime - _.starttime)) save_nameref=$(typeset -p _) } ) Stopwatch_t sw sw.start sleep 0.1 sw.stop printf "time=%f\n" sw.diff print "$save_nameref" Actual output: time=0.000000 typeset -n _=sw.diff Expected output: time=0.105274 typeset -n _=sw The problem is that the automatic nameref '_' within the diff.getn discipline function refers to the diff variable, though it was expected to refer to its parent, the Stopwatch_t sw variable. This is not actually a bug, though. It is documented behaviour that '_' within a discipline function refers to the variable that the discipline function is for. As sh.1 puts it: "The variable _ is a reference to the variable including the subscript if any". However, for discipline functions set for type subvariables, this is not the most useful behaviour, because '_' is generally expected to refer to the type variable when used in its subfunctions. It would be more useful for '_' to always refer to the type variable, inside and outside of a discipline function, so that a script like the reproducer above can be straightforward. '_' was changed to behave like this in the unreleased AT&T ksh 93v- beta (and thus also in the abandoned ksh2020 release). This commit backports that change for the future ksh 93u+m/1.1 release. It does mean we lose '_' as a self-reference to the discipline function variable in that specific case. This is an incompatible change and not really a bugfix, so it would not be reasonable to backport it to the stable 93u+m/1.0.x release series at this point. src/cmd/ksh93/sh/nvtype.c, src/cmd/ksh93/include/name.h: - Backport nv_typeparent() function from ksh 93v- (versions 2013-07-27 and 2013-08-29 in the ast-open-archive repo). This checks if the parent of a variable is of a 'typeset -T' type and, if so, returns a pointer to the node of that type variable. src/cmd/ksh93/sh/xec.c: set_instance(): - Backport a check for parent type when setting '_' that uses the new function. If the variable node has the NV_MINIMAL attribute (what this means exactly remains to be researched), is not itself a type, but has a parent type, then we set '_' to the variable's parent node instead. src/cmd/ksh93/tests/types.sh: - Add regression test that was backported and significantly extended from the 93v- version.
- Loading branch information
Showing
9 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters