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: 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 $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R31 2007/10/14
@(#)MIRBSD KSH R31 2007/10/18
description:
Check version of shell.
category: pdksh
@ -4052,6 +4052,20 @@ stdin:
expected-stdout:
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
description:
Check if bash-style substring expansion works

View File

@ -5,7 +5,7 @@
#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 a POSIX special builtin;
@ -901,8 +901,9 @@ c_typeset(const char **wp)
if (pflag)
shprintf("typeset ");
if ((vp->flag&ARRAY) && any_set)
shprintf("%s[%d]",
vp->name, vp->index);
shprintf("%s[%lu]",
vp->name,
(u_long)vp->index);
else
shprintf("%s", vp->name);
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 $
.\"
.Dd October 14, 2007
.Dd October 18, 2007
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -1029,7 +1029,7 @@ form
where
.Ar expr
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
only; portable maximum is 1023), inclusive.
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 .
.Sh BUGS
This document attempts to describe
.Nm mksh R31b
.Nm mksh R32
and up,
compiled without any options impacting functionality, such as
.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: 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_VERSION "R31 2007/10/14"
#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/18"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
@ -701,7 +701,7 @@ struct tbl { /* table item */
int (*f)(const char **);/* int function */
struct op *t; /* "function" tree */
} val; /* value */
int index; /* index for an array */
uint32_t index; /* index for an array */
union {
int field; /* field with for -L/-R/-Z */
int errno_; /* CEXEC/CTALIAS */

22
var.c
View File

@ -2,7 +2,7 @@
#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
@ -22,7 +22,8 @@ static void unspecial(const char *);
static void getspec(struct tbl *);
static void setspec(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 void rnd_set(long);
@ -116,7 +117,7 @@ initvar(void)
* the basename of the array.
*/
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;
int len;
@ -134,9 +135,8 @@ array_index_calc(const char *n, bool *arrayp, int *valp)
afree(tmp, ATEMP);
n = str_nsave(n, p - n, ATEMP);
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);
*valp = rval;
afree(sub, ATEMP);
}
return n;
@ -152,8 +152,8 @@ global(const char *n)
struct tbl *vp;
int c;
unsigned h;
bool array;
int val;
bool array;
uint32_t val;
/* Check to see if this is an array */
n = array_index_calc(n, &array, &val);
@ -233,8 +233,8 @@ local(const char *n, bool copy)
struct block *l = e->loc;
struct tbl *vp;
unsigned h;
bool array;
int val;
bool array;
uint32_t val;
/* Check to see if this is an array */
n = array_index_calc(n, &array, &val);
@ -1142,7 +1142,7 @@ unsetspec(struct tbl *vp)
* vp, indexed by val.
*/
static struct tbl *
arraysearch(struct tbl *vp, int val)
arraysearch(struct tbl *vp, uint32_t val)
{
struct tbl *prev, *curr, *new;
size_t namelen = strlen(vp->name) + 1;
@ -1219,7 +1219,7 @@ void
set_array(const char *var, int reset, const char **vals)
{
struct tbl *vp, *vq;
int i;
uint32_t i;
/* to get local array, use "typeset foo; set -A foo" */
vp = global(var);