ksh: namespaces don't work properly when defined within functions
From https://unix.stackexchange.com/questions/668176/problem-with-ksh-namespaces-defined-inside-functions
$ function f { a=0; namespace x { a=1; }; typeset -p .x a; }; f
namespace x
{
:
}
a=1
Expected:
$ function f { a=0; namespace x { a=1; }; typeset -p .x a; }; f
namespace x
{
a=1
}
a=0
See also:
$ namespace x { a=1; }; .x.b=2; typeset -p .x b
namespace x
{
a=1
}
b=2
Expected:
$ namespace x { a=1; }; .x.b=2; typeset -p .x b
namespace x
{
a=1
b=2
}
I see namespaces were apparently removed in ksh2020, maybe they were deemed non-functional?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 21
Commits related to this issue
- Added @McDutchie 's man function from https://github.com/ksh93/ksh/issues/325#issuecomment-974424976 to $FPATH and put in an autoload line for it as that seems to be the only way to override ksh using... — committed to posguy99/dotfiles by posguy99 3 years ago
- [1.0 release prep] Block namespace defs in ksh functions In 93v-/ksh2020, namespace defs in any function are a syntax error. This commit blocks namespace defs for ksh functions only, at the execution... — committed to ksh93/ksh by McDutchie 3 years ago
I’m working on the new approach now. Removing the old stuff took some doing – you’d think everything is between
SHOPT_NAMESPACE
tags, but no, of course that code had little tentacles in various other places. But that’s done now, and I’ve started working on the new code and I’m making surprisingly quick progress. It’s not quite half working yet, but getting there. It’ll be much smaller, simpler and cleaner than the old way. And it’ll support nesting, because with the new approach, that’s trivial.There will be no hooks into typeset at all. ksh already has the necessary functionality and we don’t need to duplicate it or make it fancier. To print out a namespace ‘foo’ you’ll be able to do
typeset -p "${!.foo.@}"
to get the names starting with.foo.
.With what I have now, variable expansions work, assignments don’t yet. But this already works:
…and that doesn’t even work on any released ksh version, though the manual says/implies it should!
Of course that would still not do anything for the second bug @stephane-chazelas reported at the top. As long as that cannot be fixed, then assigning to namespace variables from outside the namespace (as in
.foo.bar=baz
afternamespace foo
) should be blocked, too.How about this: these things get blocked in the 1.0 branch only, as the next release will be from that. (And I want to have the next release out Real Soon Now™ – even Slackware got so desperate for a new ksh they’ve been packaging our development code in slackware-current!) We’ll leave it alone in the master branch so it can hopefully be fixed sometime.
Not sure ksh2020 souce code is going to be any help in respects to namespaces as its namespace code was diminished. It seems that the ksh93v- authors decided to not allow namespace commands inside function definitions on 2013-05-29–not to say what direction ksh93u+m will go but bringing this knowledge into the light.
However, I skimmed over ksh93v- beta release notes and they made lots of fixes and changes to namespaces. Here are just a few of the entries from https://github.com/att/ast/blob/2016-01-10-beta/src/cmd/ksh93/RELEASE.