mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 11:42:21 +00:00
Fix nested functions ignoring prefixed variable assignments (#37)
This commit fixes the bug described in att/ast#32. The fix and following explanation is from att/ast#467: While copying variables from function's local scope to a new scope, variable attributes were not copied. Such variables were not marked to be exported in the new function. For e.g. function f2 { env | grep -i "^foo"; } function f1 { env | grep -i "^foo"; f2; } foo=bar f1 prints 'foo=bar' only once, but it should print be twice. src/cmd/ksh93/sh/xec.c: - When variables from the local scope of a function are copied into the scope of a nested function, the attributes of the variables need to be copied as well. src/cmd/ksh93/tests/functions.sh: - Add regression tests from ksh2020 to check environment variables passed to functions.
This commit is contained in:
parent
e0b326ae15
commit
c1994b87f1
3 changed files with 15 additions and 0 deletions
4
NEWS
4
NEWS
|
@ -14,6 +14,10 @@ Any uppercase BUG_* names are modernish shell bug IDs.
|
||||||
- Fixed a bug that caused the kill and stop commands to segfault when given
|
- Fixed a bug that caused the kill and stop commands to segfault when given
|
||||||
a non-existent job.
|
a non-existent job.
|
||||||
|
|
||||||
|
- Nested functions no longer ignore variable assignments that were prefixed
|
||||||
|
to their parent function, i.e. 'VAR=foo func' will now set $VAR to 'foo'
|
||||||
|
in the scope of any nested function 'func' runs.
|
||||||
|
|
||||||
2020-06-20:
|
2020-06-20:
|
||||||
|
|
||||||
- Fixed a bug that caused setting the following variables as readonly in
|
- Fixed a bug that caused setting the following variables as readonly in
|
||||||
|
|
|
@ -3249,7 +3249,10 @@ static void local_exports(register Namval_t *np, void *data)
|
||||||
if(nv_isarray(np))
|
if(nv_isarray(np))
|
||||||
nv_putsub(np,NIL(char*),0);
|
nv_putsub(np,NIL(char*),0);
|
||||||
if((cp = nv_getval(np)) && (mp = nv_search(nv_name(np), shp->var_tree, NV_ADD|HASH_NOSCOPE)) && nv_isnull(mp))
|
if((cp = nv_getval(np)) && (mp = nv_search(nv_name(np), shp->var_tree, NV_ADD|HASH_NOSCOPE)) && nv_isnull(mp))
|
||||||
|
{
|
||||||
nv_putval(mp, cp, 0);
|
nv_putval(mp, cp, 0);
|
||||||
|
mp->nvflag = np->nvflag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1258,5 +1258,13 @@ $SHELL -c 'PATH=/dev/null; fn() { unset -f fn; true; }; fn; fn' 2> /dev/null
|
||||||
$SHELL -c 'PATH=/dev/null; function fn { unset -f fn; true; }; fn; fn' 2> /dev/null
|
$SHELL -c 'PATH=/dev/null; function fn { unset -f fn; true; }; fn; fn' 2> /dev/null
|
||||||
[[ $? != 127 ]] && err_exit 'unset of ksh function fails when it is still running'
|
[[ $? != 127 ]] && err_exit 'unset of ksh function fails when it is still running'
|
||||||
|
|
||||||
|
# ======
|
||||||
|
# Check if environment variables passed while invoking a function are exported
|
||||||
|
# https://github.com/att/ast/issues/32
|
||||||
|
unset foo
|
||||||
|
function f2 { env | grep -q "^foo" || err_exit "Environment variable is not propogated from caller function"; }
|
||||||
|
function f1 { f2; env | grep -q "^foo" || err_exit "Environment variable is not passed to a function"; }
|
||||||
|
foo=bar f1
|
||||||
|
|
||||||
# ======
|
# ======
|
||||||
exit $((Errors<125?Errors:125))
|
exit $((Errors<125?Errors:125))
|
||||||
|
|
Loading…
Reference in a new issue