first step towards mksh R32 ☺

allow array indices in the uint32_t range (0‥4294967295) and map negatives
into that range; adjust manual page and regression tests; to be used RSN ☻
This commit is contained in:
tg
2007-10-18 20:32:33 +00:00
parent d0fc6b07e0
commit 97ba2fabc7
5 changed files with 38 additions and 23 deletions

18
check.t
View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.140 2007/10/14 13:43:40 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.141 2007/10/18 20:32:31 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas 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: 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 $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R31 2007/10/14 @(#)MIRBSD KSH R31 2007/10/18
description: description:
Check version of shell. Check version of shell.
category: pdksh category: pdksh
@ -4052,6 +4052,20 @@ stdin:
expected-stdout: expected-stdout:
5|a|$v|c d|$v|b| 5|a|$v|c d|$v|b|
--- ---
name: arrays-3
description:
Check if array bounds are uint32_t
stdin:
set -A foo a b c
foo[4097]=d
foo[2147483637]=e
print ${foo[*]}
foo[-1]=f
print ${foo[4294967295]} g ${foo[*]}
expected-stdout:
a b c d e
f g a b c d e f
---
name: varexpand-substr-1 name: varexpand-substr-1
description: description:
Check if bash-style substring expansion works Check if bash-style substring expansion works

View File

@ -5,7 +5,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.65 2007/09/09 18:06:40 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.66 2007/10/18 20:32:32 tg Exp $");
/* A leading = means assignments before command are kept; /* A leading = means assignments before command are kept;
* a leading * means a POSIX special builtin; * a leading * means a POSIX special builtin;
@ -901,8 +901,9 @@ c_typeset(const char **wp)
if (pflag) if (pflag)
shprintf("typeset "); shprintf("typeset ");
if ((vp->flag&ARRAY) && any_set) if ((vp->flag&ARRAY) && any_set)
shprintf("%s[%d]", shprintf("%s[%lu]",
vp->name, vp->index); vp->name,
(u_long)vp->index);
else else
shprintf("%s", vp->name); shprintf("%s", vp->name);
if (thing == '-' && (vp->flag&ISSET)) { if (thing == '-' && (vp->flag&ISSET)) {

8
mksh.1
View File

@ -1,7 +1,7 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.102 2007/10/14 13:43:17 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.103 2007/10/18 20:32:32 tg Exp $
.\" $OpenBSD: ksh.1,v 1.120 2007/05/31 20:47:44 otto Exp $ .\" $OpenBSD: ksh.1,v 1.120 2007/05/31 20:47:44 otto Exp $
.\" .\"
.Dd October 14, 2007 .Dd October 18, 2007
.Dt MKSH 1 .Dt MKSH 1
.Os MirBSD .Os MirBSD
.Sh NAME .Sh NAME
@ -1029,7 +1029,7 @@ form
where where
.Ar expr .Ar expr
is an arithmetic expression. is an arithmetic expression.
Array indices are currently limited to the range 0 through 2147483647 (for Array indices are currently limited to the range 0 through 4294967295 (for
.Nm .Nm
only; portable maximum is 1023), inclusive. only; portable maximum is 1023), inclusive.
Parameter substitutions take the form Parameter substitutions take the form
@ -5385,7 +5385,7 @@ and many other persons, and is currently maintained by
.An Thorsten Glaser Aq tg@mirbsd.de . .An Thorsten Glaser Aq tg@mirbsd.de .
.Sh BUGS .Sh BUGS
This document attempts to describe This document attempts to describe
.Nm mksh R31b .Nm mksh R32
and up, and up,
compiled without any options impacting functionality, such as compiled without any options impacting functionality, such as
.Dv MKSH_SMALL , .Dv MKSH_SMALL ,

6
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.177 2007/10/14 13:43:41 tg Exp $" #define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.178 2007/10/18 20:32:33 tg Exp $"
#define MKSH_VERSION "R31 2007/10/14" #define MKSH_VERSION "R31 2007/10/18"
#if HAVE_SYS_PARAM_H #if HAVE_SYS_PARAM_H
#include <sys/param.h> #include <sys/param.h>
@ -701,7 +701,7 @@ struct tbl { /* table item */
int (*f)(const char **);/* int function */ int (*f)(const char **);/* int function */
struct op *t; /* "function" tree */ struct op *t; /* "function" tree */
} val; /* value */ } val; /* value */
int index; /* index for an array */ uint32_t index; /* index for an array */
union { union {
int field; /* field with for -L/-R/-Z */ int field; /* field with for -L/-R/-Z */
int errno_; /* CEXEC/CTALIAS */ int errno_; /* CEXEC/CTALIAS */

18
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.45 2007/09/09 18:06:42 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/var.c,v 1.46 2007/10/18 20:32:33 tg Exp $");
/* /*
* Variables * Variables
@ -22,7 +22,8 @@ static void unspecial(const char *);
static void getspec(struct tbl *); static void getspec(struct tbl *);
static void setspec(struct tbl *); static void setspec(struct tbl *);
static void unsetspec(struct tbl *); static void unsetspec(struct tbl *);
static struct tbl *arraysearch(struct tbl *, int); static struct tbl *arraysearch(struct tbl *, uint32_t);
static const char *array_index_calc(const char *, bool *, uint32_t *);
static int rnd_get(void); static int rnd_get(void);
static void rnd_set(long); static void rnd_set(long);
@ -116,7 +117,7 @@ initvar(void)
* the basename of the array. * the basename of the array.
*/ */
static const char * static const char *
array_index_calc(const char *n, bool *arrayp, int *valp) array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
{ {
const char *p; const char *p;
int len; int len;
@ -134,9 +135,8 @@ array_index_calc(const char *n, bool *arrayp, int *valp)
afree(tmp, ATEMP); afree(tmp, ATEMP);
n = str_nsave(n, p - n, ATEMP); n = str_nsave(n, p - n, ATEMP);
evaluate(sub, &rval, KSH_UNWIND_ERROR, true); evaluate(sub, &rval, KSH_UNWIND_ERROR, true);
if (rval < 0 || rval > 2147483647) if ((long)(*valp = (uint32_t)rval) != rval)
errorf("%s: subscript %ld out of range", n, rval); errorf("%s: subscript %ld out of range", n, rval);
*valp = rval;
afree(sub, ATEMP); afree(sub, ATEMP);
} }
return n; return n;
@ -153,7 +153,7 @@ global(const char *n)
int c; int c;
unsigned h; unsigned h;
bool array; bool array;
int val; uint32_t val;
/* Check to see if this is an array */ /* Check to see if this is an array */
n = array_index_calc(n, &array, &val); n = array_index_calc(n, &array, &val);
@ -234,7 +234,7 @@ local(const char *n, bool copy)
struct tbl *vp; struct tbl *vp;
unsigned h; unsigned h;
bool array; bool array;
int val; uint32_t val;
/* Check to see if this is an array */ /* Check to see if this is an array */
n = array_index_calc(n, &array, &val); n = array_index_calc(n, &array, &val);
@ -1142,7 +1142,7 @@ unsetspec(struct tbl *vp)
* vp, indexed by val. * vp, indexed by val.
*/ */
static struct tbl * static struct tbl *
arraysearch(struct tbl *vp, int val) arraysearch(struct tbl *vp, uint32_t val)
{ {
struct tbl *prev, *curr, *new; struct tbl *prev, *curr, *new;
size_t namelen = strlen(vp->name) + 1; size_t namelen = strlen(vp->name) + 1;
@ -1219,7 +1219,7 @@ void
set_array(const char *var, int reset, const char **vals) set_array(const char *var, int reset, const char **vals)
{ {
struct tbl *vp, *vq; struct tbl *vp, *vq;
int i; uint32_t i;
/* to get local array, use "typeset foo; set -A foo" */ /* to get local array, use "typeset foo; set -A foo" */
vp = global(var); vp = global(var);