ABI bump to R39: adhere to the future POSIX standard regarding -o nounset;

add appropriate regression test (except $_ *is* unset in non-interactive
shells). See the thread at:
http://article.gmane.org/gmane.os.miros.general/8863
This commit is contained in:
tg 2009-07-16 15:06:45 +00:00
parent e42e775d9b
commit b42582689f
4 changed files with 93 additions and 13 deletions

80
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.290 2009/07/06 15:06:23 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.291 2009/07/16 15:06:42 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 R38 2009/07/06
@(#)MIRBSD KSH R39 2009/07/16
description:
Check version of shell.
stdin:
@ -5875,3 +5875,79 @@ expected-stdout:
= 0
foo
---
name: nounset-1
description:
Check that "set -u" matches (future) POSIX requirement
stdin:
(set -u
try() {
local v
eval v=\$$1
if [[ -n $v ]]; then
echo $1=nz
else
echo $1=zf
fi
}
x=y
(echo $x)
echo =1
(echo $y)
echo =2
(try x)
echo =3
(try y)
echo =4
(try 0)
echo =5
(try 2)
echo =6
(try)
echo =7
(echo at=$@)
echo =8
(echo asterisk=$*)
echo =9
(echo $?)
echo =10
(echo $!)
echo =11
(echo $-)
echo =12
#(echo $_)
#echo =13
(echo $#)
echo =14
(mypid=$$; try mypid)
echo =15
) 2>&1 | sed -e 's/^[^]]*]//' -e 's/^[^:]*: *//'
expected-stdout:
y
=1
y: parameter not set
=2
x=nz
=3
y: parameter not set
=4
0=nz
=5
2: parameter not set
=6
1: parameter not set
=7
at=
=8
asterisk=
=9
0
=10
!: parameter not set
=11
ush
=12
0
=14
mypid=nz
=15
---

10
eval.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.60 2009/06/11 12:42:17 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.61 2009/07/16 15:06:43 tg Exp $");
#ifdef MKSH_SMALL
#define MKSH_NOPWNAM
@ -913,6 +913,7 @@ varsub(Expand *xp, const char *sp, const char *word,
int slen;
const char *p;
struct tbl *vp;
bool zero_ok = false;
if (sp[0] == '\0') /* Bad variable name */
return (-1);
@ -921,8 +922,6 @@ varsub(Expand *xp, const char *sp, const char *word,
/* ${#var}, string length or array size */
if (sp[0] == '#' && (c = sp[1]) != '\0') {
int zero_ok = 0;
/* Can't have any modifiers for ${#...} */
if (*word != CSUBST)
return (-1);
@ -934,7 +933,7 @@ varsub(Expand *xp, const char *sp, const char *word,
vp = global(arrayname(sp));
if (vp->flag & (ISSET|ARRAY))
zero_ok = 1;
zero_ok = true;
for (; vp; vp = vp->u.array)
if (vp->flag & ISSET)
n++;
@ -1005,6 +1004,7 @@ varsub(Expand *xp, const char *sp, const char *word,
xp->split = c == '@'; /* $@ */
state = XARG;
}
zero_ok = true; /* POSIX 2009? */
} else {
if ((p = cstrchr(sp, '[')) && (p[1] == '*' || p[1] == '@') &&
p[2] == ']') {
@ -1052,7 +1052,7 @@ varsub(Expand *xp, const char *sp, const char *word,
(((stype&0x80) ? *xp->str=='\0' : xp->str==null) ? /* undef? */
c == '=' || c == '-' || c == '?' : c == '+'))
state = XBASE; /* expand word instead of variable value */
if (Flag(FNOUNSET) && xp->str == null &&
if (Flag(FNOUNSET) && xp->str == null && !zero_ok &&
(ctype(c, C_SUBOP2) || (state != XBASE && c != '+')))
errorf("%s: parameter not set", sp);
return (state);

12
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.173 2009/07/08 10:37:24 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.174 2009/07/16 15:06:44 tg Rel $
.\" $OpenBSD: ksh.1,v 1.129 2009/05/28 06:09:06 jmc Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
@ -48,7 +48,7 @@
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
..
.\"-
.Dd $Mdocdate: July 8 2009 $
.Dd $Mdocdate: July 16 2009 $
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -3551,7 +3551,11 @@ or
.Dq utf8 ,
or if the input begins with a UTF-8 Byte Order Mark.
.It Fl u \*(Ba Ic nounset
Referencing of an unset parameter is treated as an error, unless one of the
Referencing of an unset parameter, other than
.Dq $@
or
.Dq $* ,
is treated as an error, unless one of the
.Ql \- ,
.Ql + ,
or
@ -5651,7 +5655,7 @@ all contributors, such as the Debian and OpenBSD projects.
See the documentation, CVS, and web site for details.
.Sh BUGS
This document attempts to describe
.Nm mksh\ R38
.Nm mksh\ R39
and up,
compiled without any options impacting functionality, such as
.Dv MKSH_SMALL ,

4
sh.h
View File

@ -122,9 +122,9 @@
#define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.312 2009/07/06 15:06:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.313 2009/07/16 15:06:45 tg Exp $");
#endif
#define MKSH_VERSION "R38 2009/07/06"
#define MKSH_VERSION "R39 2009/07/16"
#ifndef MKSH_INCLUDES_ONLY