On Fri, Oct 19, 2012 at 12:06:06PM +0200, Werner Fink wrote:
> On Wed, Jun 06, 2012 at 12:47:17PM +0200, Michal Hlavinka wrote:
> > Hi,
> >
> > we found a regression in ksh. Exporting a variable affects its attributes:
> >
> > $ typeset -Z2 foo=3
> > $ echo $foo
> > 03
> > $ typeset -p foo
> > typeset -Z 2 -R 2 foo=03
> > $ export foo
> > $ echo $foo
> > 3
> > $ typeset -p foo
> > typeset -x -Z 1 -R 1 foo=3
> >
> > last working version is 2009-06-30, first broken version is
> > 2009-09-08. Let me know if you need more information.
> >
> > Michal
>
> A similar report here:
>
> ksh> typeset -Z4 VAR1
> ksh> typeset | grep VAR1
> zerofill 4 rightjust 4 VAR1
> ksh> VAR1=1
> ksh> typeset | grep VAR1
> zerofill 4 rightjust 4 VAR1
> ksh> echo $VAR1
> 0001
> ksh> export VAR1
> ksh> typeset | grep VAR1
> export zerofill 1 rightjust 1 VAR1
> ksh> echo $VAR1
> 1
>
> if exported first the it works
>
> ksh> export VAR2
> ksh> typeset -Z4 VAR2
> ksh> typeset | grep VAR2
> export zerofill 4 rightjust 4 VAR2
> ksh> VAR2=1
> ksh> echo $VAR2
> 0001
>
> Werner
The attached patch for ksh93u should help. The change in unall() is from
current ksh93 tree and required as otherwise the attributes.sh test
will show an error after an unset variable is used again.
Werner
--
"Having a smoking section in a restaurant is like having
a peeing section in a swimming pool." -- Edward Burr
--- src/cmd/ksh93/bltins/typeset.c
+++ src/cmd/ksh93/bltins/typeset.c 2012-10-19 16:56:48.561818559 +0200
@@ -746,6 +746,7 @@
}
if (tp->aflag == '-')
{
+ int oldnum;
if((flag&NV_EXPORT) && (strchr(name,'.') || nv_isvtree(np)))
errormsg(SH_DICT,ERROR_exit(1),e_badexport,name);
#if SHOPT_BSH
@@ -764,6 +765,9 @@
else if(!(flag&NV_LJUST))
newflag &= ~NV_LJUST;
}
+ oldnum = nv_size(np);
+ if (oldnum > 0)
+ tp->argnum = oldnum;
}
else
{
@@ -1222,7 +1226,7 @@
if(shp->subshell)
np=sh_assignok(np,0);
}
- if(!nv_isnull(np))
+ if(!nv_isnull(np) || nv_size(np) || nv_isattr(np,~(NV_MINIMAL|NV_NOFREE)))
_nv_unset(np,0);
if(troot==shp->var_tree && shp->st.real_fun && (dp=shp->var_tree->walk) && dp==shp->st.real_fun->sdict)
nv_delete(np,dp,NV_NOFREE);
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers