mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix the readonly builtin's scope in functions (#51)
* Fix the readonly builtin's scope in functions This bug was first reported at https://github.com/att/ast/issues/881 'tdata.sh->prefix' is only set to the correct value when 'b_readonly' is called as 'export', which breaks 'readonly' in functions because the correct scope isn't set. As a result, the following example will only print a newline: $ function show_bar { readonly foo=bar; echo $foo; }; show_bar The fix is to move the required code out of the if statement for 'export', as it needs to be run for 'readonly' as well. This bugfix is from https://github.com/att/ast/pull/906 src/cmd/ksh93/bltins/typeset.c: - Set 'tdata.sh->prefix' to the correct value, otherwise 'readonly' uses the wrong scope. src/cmd/ksh93/tests/builtins.sh: - Add the regression test from ksh2020, modified to run in a subshell. src/cmd/ksh93/data/builtins.c, src/cmd/ksh93/sh.1: - Add documentation of 'readonly' vs. 'typeset -r' difference: 'readonly' does not create a function-local scope. Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
10b6ba801d
commit
1b5bc1802a
5 changed files with 28 additions and 5 deletions
|
@ -1360,7 +1360,7 @@ USAGE_LICENSE
|
|||
;
|
||||
|
||||
const char sh_optreadonly[] =
|
||||
"[-1c?\n@(#)$Id: readonly (AT&T Research) 2008-06-16 $\n]"
|
||||
"[-1c?\n@(#)$Id: readonly (AT&T Research/ksh93) 2020-06-28 $\n]"
|
||||
USAGE_LICENSE
|
||||
"[+NAME?readonly - set readonly attribute on variables]"
|
||||
"[+DESCRIPTION?\breadonly\b sets the readonly attribute on each of "
|
||||
|
@ -1368,6 +1368,9 @@ USAGE_LICENSE
|
|||
"values from being changed. If \b=\b\avalue\a is specified, "
|
||||
"the variable \aname\a is set to \avalue\a before the variable "
|
||||
"is made readonly.]"
|
||||
"[+?Unlike \btypeset -r\b, \breadonly\b does not create a function-local "
|
||||
"scope and the given \aname\as are marked globally read-only by "
|
||||
"default.]"
|
||||
"[+?Within a type definition, if the value is not specified, then a "
|
||||
"value must be specified when creating each instance of the type "
|
||||
"and the value is readonly for each instance.]"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue