From 43c8d8765fa8338fba9abbaaccaef15fb2e1b05c Mon Sep 17 00:00:00 2001 From: tg Date: Tue, 21 Jun 2011 21:50:26 +0000 Subject: [PATCH] =?UTF-8?q?pretty=20tricky=20thing,=20IBM=E2=80=99s=20curs?= =?UTF-8?q?es=20library=20does=20nameref=20foo=3Dfoo=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 21 +++++++++++++++++++-- sh.h | 4 ++-- var.c | 21 ++++++++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/check.t b/check.t index af256a6..e86122d 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.467 2011/06/12 14:58:43 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.468 2011/06/21 21:50:23 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -25,7 +25,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R40 2011/06/12 + @(#)MIRBSD KSH R40 2011/06/21 description: Check version of shell. stdin: @@ -8755,6 +8755,23 @@ expected-stdout: 2 a . 3 . --- +name: nameref-4 +description: + Ensure we don't run in an infinite loop +time-limit: 3 +stdin: + baz() { + typeset -n foo=foo + foo[0]=bar + } + set -A foo bad + echo sind $foo . + baz + echo blah $foo . +expected-stdout: + sind bad . + blah bar . +--- name: better-parens-1a description: Check support for ((…)) and $((…)) vs (…) and $(…) diff --git a/sh.h b/sh.h index 9980900..fa26ab1 100644 --- a/sh.h +++ b/sh.h @@ -151,9 +151,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.478 2011/06/21 21:11:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.479 2011/06/21 21:50:25 tg Exp $"); #endif -#define MKSH_VERSION "R40 2011/06/12" +#define MKSH_VERSION "R40 2011/06/21" #ifndef MKSH_INCLUDES_ONLY diff --git a/var.c b/var.c index 8b7249e..f7eccf9 100644 --- a/var.c +++ b/var.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.125 2011/06/21 21:11:21 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.126 2011/06/21 21:50:26 tg Exp $"); /*- * Variables @@ -751,6 +751,25 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) tvar[len-3] = '\0'; } + if (set_refflag == SRF_ENABLE) { + const char *qval; + + /* bail out on 'nameref foo+=bar' */ + if (vappend) + errorfz(); + /* find value if variable already exists */ + if ((qval = val) == NULL) { + varsearch(e->loc, &vp, tvar, hash(tvar)); + if (vp != NULL) + qval = str_val(vp); + } + /* silently ignore 'nameref foo=foo' */ + if (qval != NULL && !strcmp(qval, tvar)) { + afree(tvar, ATEMP); + return (&vtemp); + } + } + /* prevent typeset from creating a local PATH/ENV/SHELL */ if (Flag(FRESTRICTED) && (strcmp(tvar, "PATH") == 0 || strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0))