* back out almost all of the memory allocator related changes, as aalloc
was hard to type and hard to fix, galloc is also hard to fix, and some things I learned will probably improve things more but make me use the original form as base (especially for space savings) * let sizeofN die though, remove even more casts * optimise, polish * regen Makefiles * sprinkle a few /* CONSTCOND */ while here
This commit is contained in:
parent
732e10c982
commit
31d1499219
15
Makefile
15
Makefile
@ -1,23 +1,16 @@
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.70 2008/11/17 01:14:57 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.71 2008/12/13 17:02:10 tg Exp $
|
||||
#-
|
||||
# use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROG= mksh
|
||||
.ifdef TEST
|
||||
SRCS= aalloc.c
|
||||
.else
|
||||
SRCS= alloc.c
|
||||
.endif
|
||||
SRCS+= edit.c eval.c exec.c expr.c funcs.c histrap.c \
|
||||
SRCS= alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c \
|
||||
jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c
|
||||
.if !make(test-build)
|
||||
. if ${DEBUGLIBS:L} == "yes"
|
||||
CPPFLAGS+= -DMKSH_AFREE_DEBUG # MirOS development version
|
||||
#CPPFLAGS+= -DAALLOC_TRACK # MirOS development version
|
||||
. endif
|
||||
CPPFLAGS+= -DAALLOC_NO_COOKIES # for now… aalloc cookies are broken
|
||||
CPPFLAGS+= -DMKSH_ASSUME_UTF8 \
|
||||
-DHAVE_ATTRIBUTE=1 -DHAVE_ATTRIBUTE_BOUNDED=1 \
|
||||
-DHAVE_ATTRIBUTE_USED=1 -DHAVE_SYS_PARAM_H=1 \
|
||||
@ -29,8 +22,8 @@ CPPFLAGS+= -DMKSH_ASSUME_UTF8 \
|
||||
-DHAVE_SYS_SIGNAME=1 -DHAVE_SYS_SIGLIST=1 -DHAVE_STRSIGNAL=0 \
|
||||
-DHAVE_ARC4RANDOM=1 -DHAVE_ARC4RANDOM_PUSHB=1 -DHAVE_MKNOD=1 \
|
||||
-DHAVE_MKSTEMP=1 -DHAVE_NICE=1 -DHAVE_REALPATH=1 \
|
||||
-DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=1 \
|
||||
-DHAVE_LANGINFO_CODESET=1 -DHAVE_SETMODE=1 \
|
||||
-DHAVE_REVOKE=1 -DHAVE_SETLOCALE_CTYPE=0 \
|
||||
-DHAVE_LANGINFO_CODESET=0 -DHAVE_SETMODE=1 \
|
||||
-DHAVE_SETRESUGID=1 -DHAVE_SETGROUPS=1 -DHAVE_STRCASESTR=1 \
|
||||
-DHAVE_STRLCPY=1 -DHAVE_ARC4RANDOM_DECL=1 \
|
||||
-DHAVE_ARC4RANDOM_PUSHB_DECL=1 -DHAVE_FLOCK_DECL=1 \
|
||||
|
33
alloc.c
33
alloc.c
@ -29,51 +29,40 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.12 2008/11/15 07:35:23 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.13 2008/12/13 17:02:11 tg Exp $");
|
||||
|
||||
struct link {
|
||||
struct link *prev;
|
||||
struct link *next;
|
||||
};
|
||||
|
||||
struct TArea {
|
||||
struct link *freelist; /* free list */
|
||||
};
|
||||
|
||||
PArea
|
||||
anew(size_t hint __unused)
|
||||
Area *
|
||||
ainit(Area *ap)
|
||||
{
|
||||
PArea ap;
|
||||
|
||||
if ((ap = malloc(sizeof (struct TArea))) == NULL)
|
||||
internal_errorf("unable to allocate memory");
|
||||
ap->freelist = NULL;
|
||||
return (ap);
|
||||
}
|
||||
|
||||
void
|
||||
adelete(PArea *pap)
|
||||
afreeall(Area *ap)
|
||||
{
|
||||
struct link *l, *l2;
|
||||
|
||||
for (l = (*pap)->freelist; l != NULL; l = l2) {
|
||||
for (l = ap->freelist; l != NULL; l = l2) {
|
||||
l2 = l->next;
|
||||
free(l);
|
||||
}
|
||||
free(*pap);
|
||||
*pap = NULL;
|
||||
ap->freelist = NULL;
|
||||
}
|
||||
|
||||
#define L2P(l) ( (void *)(((char *)(l)) + sizeof (struct link)) )
|
||||
#define P2L(p) ( (struct link *)(((ptrdiff_t)(p)) - sizeof (struct link)) )
|
||||
|
||||
void *
|
||||
alloc(size_t nmemb, size_t size, PArea ap)
|
||||
alloc(size_t size, Area *ap)
|
||||
{
|
||||
struct link *l;
|
||||
|
||||
size *= nmemb;
|
||||
|
||||
if ((l = malloc(sizeof (struct link) + size)) == NULL)
|
||||
internal_errorf("unable to allocate memory");
|
||||
l->next = ap->freelist;
|
||||
@ -86,14 +75,12 @@ alloc(size_t nmemb, size_t size, PArea ap)
|
||||
}
|
||||
|
||||
void *
|
||||
aresize(void *ptr, size_t nmemb, size_t size, PArea ap)
|
||||
aresize(void *ptr, size_t size, Area *ap)
|
||||
{
|
||||
struct link *l, *l2, *lprev, *lnext;
|
||||
|
||||
if (ptr == NULL)
|
||||
return (alloc(nmemb, size, ap));
|
||||
|
||||
size *= nmemb;
|
||||
return (alloc(size, ap));
|
||||
|
||||
l = P2L(ptr);
|
||||
lprev = l->prev;
|
||||
@ -112,7 +99,7 @@ aresize(void *ptr, size_t nmemb, size_t size, PArea ap)
|
||||
}
|
||||
|
||||
void
|
||||
afree(void *ptr, PArea ap)
|
||||
afree(void *ptr, Area *ap)
|
||||
{
|
||||
struct link *l;
|
||||
#ifdef MKSH_AFREE_DEBUG
|
||||
|
16
check.t
16
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.251 2008/12/08 13:57:35 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.252 2008/12/13 17:02:11 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 R36 2008/12/04
|
||||
@(#)MIRBSD KSH R36 2008/12/13
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
@ -4483,8 +4483,8 @@ name: utf8bom-3
|
||||
description:
|
||||
Reading the UTF-8 BOM should enable the utf8-mode flag
|
||||
stdin:
|
||||
"$__progname" -c ':; if [[ $(set +o) = *@(-o utf8-mode)@(| *) ]]; then print on; else print off; fi'
|
||||
"$__progname" -c ':; if [[ $(set +o) = *@(-o utf8-mode)@(| *) ]]; then print on; else print off; fi'
|
||||
"$__progname" -c ':; if [[ $- = *U* ]]; then print on; else print off; fi'
|
||||
"$__progname" -c ':; if [[ $- = *U* ]]; then print on; else print off; fi'
|
||||
expected-stdout:
|
||||
off
|
||||
on
|
||||
@ -4495,7 +4495,7 @@ description:
|
||||
category: !os:hpux
|
||||
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
|
||||
stdin:
|
||||
if [[ $(set +o) = *@(-o utf8-mode)@(| *) ]]; then
|
||||
if [[ $- = *U* ]]; then
|
||||
print is set
|
||||
else
|
||||
print is not set
|
||||
@ -4509,7 +4509,7 @@ description:
|
||||
category: os:hpux
|
||||
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
|
||||
stdin:
|
||||
if [[ $(set +o) = *@(-o utf8-mode)@(| *) ]]; then
|
||||
if [[ $- = *U* ]]; then
|
||||
print is set
|
||||
else
|
||||
print is not set
|
||||
@ -4524,7 +4524,7 @@ category: !os:hpux
|
||||
arguments: !-i!
|
||||
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.UTF-8!
|
||||
stdin:
|
||||
if [[ $(set +o) = *@(-o utf8-mode)@(| *) ]]; then
|
||||
if [[ $- = *U* ]]; then
|
||||
print is set
|
||||
else
|
||||
print is not set
|
||||
@ -4541,7 +4541,7 @@ category: os:hpux
|
||||
arguments: !-i!
|
||||
env-setup: !PS1=!PS2=!LC_CTYPE=en_US.utf8!
|
||||
stdin:
|
||||
if [[ $(set +o) = *@(-o utf8-mode)@(| *) ]]; then
|
||||
if [[ $- = *U* ]]; then
|
||||
print is set
|
||||
else
|
||||
print is not set
|
||||
|
@ -1,4 +1,4 @@
|
||||
$MirOS: src/bin/mksh/copyright,v 1.25 2008/11/12 05:00:40 tg Exp $
|
||||
$MirOS: src/bin/mksh/copyright,v 1.26 2008/12/13 17:02:12 tg Exp $
|
||||
|
||||
The MirBSD Korn Shell (mksh) is
|
||||
|
||||
@ -28,5 +28,5 @@ tors. See the documentation, CVS, and web site for details.
|
||||
A number of files that are either always or conditionally included
|
||||
during compilation, depending on the target operating environment,
|
||||
are covered by different (2/3-clause BSD or similar) licences; re-
|
||||
fer to the individual files for details: alloc.c (included by user
|
||||
request) and setmode.c, strlcpy.c (included when required)
|
||||
fer to the individual files for details: alloc.c (always included)
|
||||
and setmode.c, strlcpy.c (included when required)
|
||||
|
27
edit.c
27
edit.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.147 2008/12/04 18:11:04 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.148 2008/12/13 17:02:12 tg Exp $");
|
||||
|
||||
/* tty driver characters we are interested in */
|
||||
typedef struct {
|
||||
@ -400,7 +400,7 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp)
|
||||
int i, path_order = 0;
|
||||
|
||||
info = (struct path_order_info *)
|
||||
alloc(nwords, sizeof (struct path_order_info), ATEMP);
|
||||
alloc(nwords * sizeof (struct path_order_info), ATEMP);
|
||||
for (i = 0; i < nwords; i++) {
|
||||
info[i].word = words[i];
|
||||
info[i].base = x_basename(words[i], NULL);
|
||||
@ -960,7 +960,8 @@ utf_wctomb(char *dst, unsigned int wc)
|
||||
|
||||
/* +++ emacs editing mode +++ */
|
||||
|
||||
static PArea AEDIT; /* area for kill ring and macro defns */
|
||||
static Area aedit;
|
||||
#define AEDIT &aedit /* area for kill ring and macro defns */
|
||||
|
||||
#define MKCTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F) /* ASCII */
|
||||
#define UNCTRL(x) ((x) ^ 0x40) /* ASCII */
|
||||
@ -1071,7 +1072,7 @@ static int x_search(char *, int, int);
|
||||
static int x_match(char *, char *);
|
||||
static void x_redraw(int);
|
||||
static void x_push(int);
|
||||
static char *x_mapin(const char *, PArea);
|
||||
static char *x_mapin(const char *, Area *);
|
||||
static char *x_mapout(int);
|
||||
static void x_mapout2(int, char **);
|
||||
static void x_print(int, int);
|
||||
@ -2517,7 +2518,7 @@ x_error(int c __unused)
|
||||
}
|
||||
|
||||
static char *
|
||||
x_mapin(const char *cp, PArea ap)
|
||||
x_mapin(const char *cp, Area *ap)
|
||||
{
|
||||
char *new, *op;
|
||||
|
||||
@ -2681,10 +2682,10 @@ x_init_emacs(void)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
AEDIT = anew(8);
|
||||
ainit(AEDIT);
|
||||
x_nextcmd = -1;
|
||||
|
||||
x_tab = alloc(X_NTABS, sizeof (*x_tab), AEDIT);
|
||||
x_tab = alloc(X_NTABS * sizeof (*x_tab), AEDIT);
|
||||
for (j = 0; j < X_TABSZ; j++)
|
||||
x_tab[0][j] = XFUNC_insert;
|
||||
for (i = 1; i < X_NTABS; i++)
|
||||
@ -2694,7 +2695,7 @@ x_init_emacs(void)
|
||||
x_tab[x_defbindings[i].xdb_tab][x_defbindings[i].xdb_char]
|
||||
= x_defbindings[i].xdb_func;
|
||||
|
||||
x_atab = alloc(X_NTABS, sizeof (*x_atab), AEDIT);
|
||||
x_atab = alloc(X_NTABS * sizeof (*x_atab), AEDIT);
|
||||
for (i = 1; i < X_NTABS; i++)
|
||||
for (j = 0; j < X_TABSZ; j++)
|
||||
x_atab[i][j] = NULL;
|
||||
@ -3600,8 +3601,8 @@ x_vi(char *buf, size_t len)
|
||||
|
||||
if (!wbuf_len || wbuf_len != x_cols - 3) {
|
||||
wbuf_len = x_cols - 3;
|
||||
wbuf[0] = aresize(wbuf[0], 1, wbuf_len, APERM);
|
||||
wbuf[1] = aresize(wbuf[1], 1, wbuf_len, APERM);
|
||||
wbuf[0] = aresize(wbuf[0], wbuf_len, APERM);
|
||||
wbuf[1] = aresize(wbuf[1], wbuf_len, APERM);
|
||||
}
|
||||
(void)memset(wbuf[0], ' ', wbuf_len);
|
||||
(void)memset(wbuf[1], ' ', wbuf_len);
|
||||
@ -4130,7 +4131,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
nlen = strlen(ap->val.s) + 1;
|
||||
olen = !macro.p ? 2 :
|
||||
macro.len - (macro.p - macro.buf);
|
||||
nbuf = alloc(1, nlen + 1 + olen, APERM);
|
||||
nbuf = alloc(nlen + 1 + olen, APERM);
|
||||
memcpy(nbuf, ap->val.s, nlen);
|
||||
nbuf[nlen++] = cmd[1];
|
||||
if (macro.p) {
|
||||
@ -4777,8 +4778,8 @@ save_edstate(struct edstate *old)
|
||||
{
|
||||
struct edstate *new;
|
||||
|
||||
new = alloc(1, sizeof (struct edstate), APERM);
|
||||
new->cbuf = alloc(1, old->cbufsize, APERM);
|
||||
new = alloc(sizeof (struct edstate), APERM);
|
||||
new->cbuf = alloc(old->cbufsize, APERM);
|
||||
memcpy(new->cbuf, old->cbuf, old->linelen);
|
||||
new->cbufsize = old->cbufsize;
|
||||
new->linelen = old->linelen;
|
||||
|
11
eval.c
11
eval.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.50 2008/11/12 00:54:47 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.51 2008/12/13 17:02:13 tg Exp $");
|
||||
|
||||
#ifdef MKSH_SMALL
|
||||
#define MKSH_NOPWNAM
|
||||
@ -297,8 +297,7 @@ expand(const char *cp, /* input word */
|
||||
if (!st->next) {
|
||||
SubType *newst;
|
||||
|
||||
newst = alloc(1,
|
||||
sizeof (SubType), ATEMP);
|
||||
newst = alloc(sizeof (SubType), ATEMP);
|
||||
newst->next = NULL;
|
||||
newst->prev = st;
|
||||
st->next = newst;
|
||||
@ -590,7 +589,7 @@ expand(const char *cp, /* input word */
|
||||
*/
|
||||
len = strlen(dp) + 1;
|
||||
setstr(st->var,
|
||||
debunk(alloc(1, len, ATEMP),
|
||||
debunk(alloc(len, ATEMP),
|
||||
dp, len), KSH_UNWIND_ERROR);
|
||||
x.str = str_val(st->var);
|
||||
type = XSUB;
|
||||
@ -770,7 +769,7 @@ expand(const char *cp, /* input word */
|
||||
Xlength(ds, dp) == 0) {
|
||||
char *p;
|
||||
|
||||
*(p = alloc(1, 1, ATEMP)) = '\0';
|
||||
*(p = alloc(1, ATEMP)) = '\0';
|
||||
XPput(*wp, p);
|
||||
}
|
||||
type = XSUBMID;
|
||||
@ -1474,7 +1473,7 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
|
||||
l1 = brace_start - start;
|
||||
l2 = (p - 1) - field_start;
|
||||
l3 = end - brace_end;
|
||||
new = alloc(1, l1 + l2 + l3 + 1, ATEMP);
|
||||
new = alloc(l1 + l2 + l3 + 1, ATEMP);
|
||||
memcpy(new, start, l1);
|
||||
memcpy(new + l1, field_start, l2);
|
||||
memcpy(new + l1 + l2, brace_end, l3);
|
||||
|
4
exec.c
4
exec.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.47 2008/11/12 00:55:31 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.48 2008/12/13 17:02:13 tg Exp $");
|
||||
|
||||
static int comexec(struct op *, struct tbl *volatile, const char **,
|
||||
int volatile);
|
||||
@ -72,7 +72,7 @@ execute(struct op *volatile t,
|
||||
flags &= ~XTIME;
|
||||
|
||||
if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) {
|
||||
e->savefd = alloc(NUFILE, sizeof (short), ATEMP);
|
||||
e->savefd = alloc(NUFILE * sizeof (short), ATEMP);
|
||||
/* initialise to not redirected */
|
||||
memset(e->savefd, 0, NUFILE * sizeof (short));
|
||||
}
|
||||
|
4
expr.c
4
expr.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.20 2008/11/12 00:54:48 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.21 2008/12/13 17:02:13 tg Exp $");
|
||||
|
||||
/* The order of these enums is constrained by the order of opinfo[] */
|
||||
enum token {
|
||||
@ -544,7 +544,7 @@ tempvar(void)
|
||||
{
|
||||
struct tbl *vp;
|
||||
|
||||
vp = alloc(1, sizeof (struct tbl), ATEMP);
|
||||
vp = alloc(sizeof (struct tbl), ATEMP);
|
||||
vp->flag = ISSET|INTEGER;
|
||||
vp->type = 0;
|
||||
vp->areap = ATEMP;
|
||||
|
10
funcs.c
10
funcs.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.92 2008/11/12 00:54:48 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.93 2008/12/13 17:02:14 tg Exp $");
|
||||
|
||||
/* A leading = means assignments before command are kept;
|
||||
* a leading * means a POSIX special builtin;
|
||||
@ -202,7 +202,7 @@ c_cd(const char **wp)
|
||||
olen = strlen(wp[0]);
|
||||
nlen = strlen(wp[1]);
|
||||
elen = strlen(current_wd + ilen + olen) + 1;
|
||||
dir = allocd = alloc(1, ilen + nlen + elen, ATEMP);
|
||||
dir = allocd = alloc(ilen + nlen + elen, ATEMP);
|
||||
memcpy(dir, current_wd, ilen);
|
||||
memcpy(dir + ilen, wp[1], nlen);
|
||||
memcpy(dir + ilen + nlen, current_wd + ilen + olen, elen);
|
||||
@ -2111,9 +2111,9 @@ c_set(const char **wp)
|
||||
owp = wp += argi - 1;
|
||||
wp[0] = l->argv[0]; /* save $0 */
|
||||
while (*++wp != NULL)
|
||||
strdupx(*wp, *wp, l->areap);
|
||||
strdupx(*wp, *wp, &l->area);
|
||||
l->argc = wp - owp - 1;
|
||||
l->argv = alloc(l->argc + 2, sizeof (char *), l->areap);
|
||||
l->argv = alloc((l->argc + 2) * sizeof (char *), &l->area);
|
||||
for (wp = l->argv; (*wp++ = *owp++) != NULL; )
|
||||
;
|
||||
}
|
||||
@ -3064,7 +3064,7 @@ c_realpath(const char **wp)
|
||||
else {
|
||||
char *buf;
|
||||
|
||||
if (realpath(*wp, (buf = alloc(1, PATH_MAX, ATEMP))) == NULL) {
|
||||
if (realpath(*wp, (buf = alloc(PATH_MAX, ATEMP))) == NULL) {
|
||||
rv = errno;
|
||||
bi_errorf("%s: %s", *wp, strerror(rv));
|
||||
} else
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.75 2008/11/12 00:54:48 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.76 2008/12/13 17:02:14 tg Exp $");
|
||||
|
||||
/*-
|
||||
* MirOS: This is the default mapping type, and need not be specified.
|
||||
@ -68,7 +68,7 @@ c_fc(const char **wp)
|
||||
sflag++;
|
||||
else {
|
||||
size_t len = strlen(p);
|
||||
editor = alloc(1, len + 4, ATEMP);
|
||||
editor = alloc(len + 4, ATEMP);
|
||||
memcpy(editor, p, len);
|
||||
memcpy(editor + len, " $_", 4);
|
||||
}
|
||||
@ -504,7 +504,7 @@ sethistsize(int n)
|
||||
cursize = n;
|
||||
}
|
||||
|
||||
history = aresize(history, n, sizeof (char *), APERM);
|
||||
history = aresize(history, n * sizeof (char *), APERM);
|
||||
|
||||
histsize = n;
|
||||
histptr = history + cursize;
|
||||
@ -555,7 +555,7 @@ init_histvec(void)
|
||||
{
|
||||
if (history == (char **)NULL) {
|
||||
histsize = HISTORYSIZE;
|
||||
history = alloc(histsize, sizeof (char *), APERM);
|
||||
history = alloc(histsize * sizeof (char *), APERM);
|
||||
histptr = history - 1;
|
||||
}
|
||||
}
|
||||
|
6
jobs.c
6
jobs.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.41 2008/11/30 10:33:38 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.42 2008/12/13 17:02:15 tg Exp $");
|
||||
|
||||
/* Order important! */
|
||||
#define PRUNNING 0
|
||||
@ -1399,7 +1399,7 @@ new_job(void)
|
||||
newj = free_jobs;
|
||||
free_jobs = free_jobs->next;
|
||||
} else
|
||||
newj = alloc(1, sizeof (Job), APERM);
|
||||
newj = alloc(sizeof (Job), APERM);
|
||||
|
||||
/* brute force method */
|
||||
for (i = 1; ; i++) {
|
||||
@ -1426,7 +1426,7 @@ new_proc(void)
|
||||
p = free_procs;
|
||||
free_procs = free_procs->next;
|
||||
} else
|
||||
p = alloc(1, sizeof (Proc), APERM);
|
||||
p = alloc(sizeof (Proc), APERM);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
12
lex.c
12
lex.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.78 2008/12/04 18:11:05 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.79 2008/12/13 17:02:15 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -776,7 +776,7 @@ yylex(int cf)
|
||||
|
||||
dp = Xstring(ws, wp);
|
||||
if ((c == '<' || c == '>' || c == '&') && state == SBASE) {
|
||||
struct ioword *iop = alloc(1, sizeof (struct ioword), ATEMP);
|
||||
struct ioword *iop = alloc(sizeof (struct ioword), ATEMP);
|
||||
|
||||
if (Xlength(ws, wp) == 0)
|
||||
iop->unit = c == '<' ? 0 : 1;
|
||||
@ -1038,11 +1038,11 @@ yyerror(const char *fmt, ...)
|
||||
*/
|
||||
|
||||
Source *
|
||||
pushs(int type, PArea areap)
|
||||
pushs(int type, Area *areap)
|
||||
{
|
||||
Source *s;
|
||||
|
||||
s = alloc(1, sizeof (Source), areap);
|
||||
s = alloc(sizeof (Source), areap);
|
||||
s->type = type;
|
||||
s->str = null;
|
||||
s->start = NULL;
|
||||
@ -1268,7 +1268,7 @@ set_prompt(int to, Source *s)
|
||||
{
|
||||
struct shf *shf;
|
||||
char * volatile ps1;
|
||||
PArea saved_atemp;
|
||||
Area *saved_atemp;
|
||||
|
||||
ps1 = str_val(global("PS1"));
|
||||
shf = shf_sopen(NULL, strlen(ps1) * 2,
|
||||
@ -1525,7 +1525,7 @@ getsc_bn(void)
|
||||
static Lex_state *
|
||||
push_state_(State_info *si, Lex_state *old_end)
|
||||
{
|
||||
Lex_state *new = alloc(STATE_BSIZE, sizeof (Lex_state), ATEMP);
|
||||
Lex_state *new = alloc(STATE_BSIZE * sizeof (Lex_state), ATEMP);
|
||||
|
||||
new[0].ls_info.base = old_end;
|
||||
si->base = &new[0];
|
||||
|
40
main.c
40
main.c
@ -13,7 +13,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.115 2008/12/04 18:11:06 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.116 2008/12/13 17:02:15 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -22,7 +22,7 @@ extern uid_t kshuid;
|
||||
extern gid_t kshgid, kshegid;
|
||||
#endif
|
||||
|
||||
static void reclaim(bool);
|
||||
static void reclaim(void);
|
||||
static void remove_temps(struct temp *);
|
||||
|
||||
static const char initifs[] = "IFS= \t\n";
|
||||
@ -91,11 +91,11 @@ main(int argc, const char *argv[])
|
||||
}
|
||||
kshname = *argv;
|
||||
|
||||
APERM = anew(256); /* initialise permanent Area */
|
||||
ainit(&aperm); /* initialise permanent Area */
|
||||
|
||||
/* set up base environment */
|
||||
env.type = E_NONE;
|
||||
env.areap = anew(32);
|
||||
ainit(&env.area);
|
||||
newblock(); /* set up global l->vars and l->funs */
|
||||
|
||||
/* Do this first so output routines (eg, errorf, shellf) can work */
|
||||
@ -135,7 +135,7 @@ main(int argc, const char *argv[])
|
||||
#else
|
||||
#ifdef _CS_PATH
|
||||
if ((k = confstr(_CS_PATH, NULL, 0)) != (size_t)-1 && k > 0 &&
|
||||
confstr(_CS_PATH, cp = alloc(1, k + 1, APERM), k + 1) == k + 1)
|
||||
confstr(_CS_PATH, cp = alloc(k + 1, APERM), k + 1) == k + 1)
|
||||
def_path = cp;
|
||||
else
|
||||
#endif
|
||||
@ -569,7 +569,7 @@ shell(Source * volatile s, volatile int toplevel)
|
||||
if (t != NULL && t->type != TEOF && interactive && really_exit)
|
||||
really_exit = 0;
|
||||
|
||||
reclaim(false);
|
||||
reclaim();
|
||||
}
|
||||
quitenv(NULL);
|
||||
source = old_source;
|
||||
@ -613,10 +613,10 @@ newenv(int type)
|
||||
{
|
||||
struct env *ep;
|
||||
|
||||
ep = alloc(1, sizeof (struct env), ATEMP);
|
||||
ep = alloc(sizeof (struct env), ATEMP);
|
||||
ep->type = type;
|
||||
ep->flags = 0;
|
||||
ep->areap = anew(16);
|
||||
ainit(&ep->area);
|
||||
ep->loc = e->loc;
|
||||
ep->savefd = NULL;
|
||||
ep->oenv = e;
|
||||
@ -668,12 +668,12 @@ quitenv(struct shf *shf)
|
||||
}
|
||||
if (shf)
|
||||
shf_close(shf);
|
||||
reclaim(true);
|
||||
reclaim();
|
||||
exit(exstat);
|
||||
}
|
||||
if (shf)
|
||||
shf_close(shf);
|
||||
reclaim(true);
|
||||
reclaim();
|
||||
|
||||
e = e->oenv;
|
||||
afree(ep, ATEMP);
|
||||
@ -697,7 +697,7 @@ cleanup_parents_env(void)
|
||||
for (fd = 0; fd < NUFILE; fd++)
|
||||
if (ep->savefd[fd] > 0)
|
||||
close(ep->savefd[fd]);
|
||||
afree(ep->savefd, ep->areap);
|
||||
afree(ep->savefd, &ep->area);
|
||||
ep->savefd = NULL;
|
||||
}
|
||||
}
|
||||
@ -716,13 +716,11 @@ cleanup_proc_env(void)
|
||||
|
||||
/* remove temp files and free ATEMP Area */
|
||||
static void
|
||||
reclaim(bool finish)
|
||||
reclaim(void)
|
||||
{
|
||||
remove_temps(e->temps);
|
||||
e->temps = NULL;
|
||||
adelete(&e->areap);
|
||||
if (!finish)
|
||||
e->areap = anew(16);
|
||||
afreeall(&e->area);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1142,7 +1140,7 @@ coproc_cleanup(int reuse)
|
||||
}
|
||||
|
||||
struct temp *
|
||||
maketemp(PArea ap, Temp_type type, struct temp **tlist)
|
||||
maketemp(Area *ap, Temp_type type, struct temp **tlist)
|
||||
{
|
||||
struct temp *tp;
|
||||
int len;
|
||||
@ -1157,7 +1155,7 @@ maketemp(PArea ap, Temp_type type, struct temp **tlist)
|
||||
pathname = tempnam(dir, "mksh.");
|
||||
len = ((pathname == NULL) ? 0 : strlen(pathname)) + 1;
|
||||
#endif
|
||||
tp = alloc(1, sizeof (struct temp) + len, ap);
|
||||
tp = alloc(sizeof (struct temp) + len, ap);
|
||||
tp->name = (char *)&tp[1];
|
||||
#if !HAVE_MKSTEMP
|
||||
if (pathname == NULL)
|
||||
@ -1200,7 +1198,7 @@ hash(const char *n)
|
||||
}
|
||||
|
||||
void
|
||||
ktinit(struct table *tp, PArea ap, int tsize)
|
||||
ktinit(struct table *tp, Area *ap, int tsize)
|
||||
{
|
||||
tp->areap = ap;
|
||||
tp->tbls = NULL;
|
||||
@ -1217,7 +1215,7 @@ texpand(struct table *tp, int nsize)
|
||||
struct tbl **ntblp, **otblp = tp->tbls;
|
||||
int osize = tp->size;
|
||||
|
||||
ntblp = alloc(nsize, sizeof (struct tbl *), tp->areap);
|
||||
ntblp = alloc(nsize * sizeof (struct tbl *), tp->areap);
|
||||
for (i = 0; i < nsize; i++)
|
||||
ntblp[i] = NULL;
|
||||
tp->size = nsize;
|
||||
@ -1290,7 +1288,7 @@ ktenter(struct table *tp, const char *n, unsigned int h)
|
||||
}
|
||||
/* create new tbl entry */
|
||||
len = strlen(n) + 1;
|
||||
p = alloc(1, offsetof(struct tbl, name[0]) + len, tp->areap);
|
||||
p = alloc(offsetof(struct tbl, name[0]) + len, tp->areap);
|
||||
p->flag = 0;
|
||||
p->type = 0;
|
||||
p->areap = tp->areap;
|
||||
@ -1337,7 +1335,7 @@ ktsort(struct table *tp)
|
||||
size_t i;
|
||||
struct tbl **p, **sp, **dp;
|
||||
|
||||
p = alloc(tp->size + 1, sizeof (struct tbl *), ATEMP);
|
||||
p = alloc((tp->size + 1) * sizeof (struct tbl *), ATEMP);
|
||||
sp = tp->tbls; /* source */
|
||||
dp = p; /* dest */
|
||||
for (i = 0; i < (size_t)tp->size; i++)
|
||||
|
20
misc.c
20
misc.c
@ -6,7 +6,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.92 2008/12/04 18:11:06 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.93 2008/12/13 17:02:16 tg Exp $");
|
||||
|
||||
#undef USE_CHVT
|
||||
#if defined(TIOCSCTTY) && !defined(MKSH_SMALL)
|
||||
@ -70,7 +70,7 @@ Xcheck_grow_(XString *xsp, const char *xp, unsigned int more)
|
||||
const char *old_beg = xsp->beg;
|
||||
|
||||
xsp->len += more > xsp->len ? more : xsp->len;
|
||||
xsp->beg = aresize(xsp->beg, 1, xsp->len + 8, xsp->areap);
|
||||
xsp->beg = aresize(xsp->beg, xsp->len + 8, xsp->areap);
|
||||
xsp->end = xsp->beg + xsp->len;
|
||||
return xsp->beg + (xp - old_beg);
|
||||
}
|
||||
@ -493,7 +493,7 @@ gmatchx(const char *s, const char *p, bool isfile)
|
||||
if (!isfile && !has_globbing(p, pe)) {
|
||||
size_t len = pe - p + 1;
|
||||
char tbuf[64];
|
||||
char *t = len <= sizeof(tbuf) ? tbuf : alloc(1, len, ATEMP);
|
||||
char *t = len <= sizeof(tbuf) ? tbuf : alloc(len, ATEMP);
|
||||
debunk(t, p, len);
|
||||
return !strcmp(t, s);
|
||||
}
|
||||
@ -933,7 +933,7 @@ print_columns(struct shf *shf, int n,
|
||||
char *(*func) (const void *, int, char *, int),
|
||||
const void *arg, int max_width, int prefcol)
|
||||
{
|
||||
char *str = alloc(1, max_width + 1, ATEMP);
|
||||
char *str = alloc(max_width + 1, ATEMP);
|
||||
int i, r, c, rows, cols, nspace;
|
||||
|
||||
/* max_width + 1 for the space. Note that no space
|
||||
@ -1048,8 +1048,8 @@ ksh_get_wd(size_t *dlen)
|
||||
char *ret, *b;
|
||||
size_t len = 1;
|
||||
|
||||
if ((ret = getcwd((b = alloc(1, PATH_MAX + 1, ATEMP)), PATH_MAX)))
|
||||
ret = aresize(b, 1, len = (strlen(b) + 1), ATEMP);
|
||||
if ((ret = getcwd((b = alloc(PATH_MAX + 1, ATEMP)), PATH_MAX)))
|
||||
ret = aresize(b, len = (strlen(b) + 1), ATEMP);
|
||||
else
|
||||
afree(b, ATEMP);
|
||||
|
||||
@ -1229,7 +1229,7 @@ set_current_wd(char *pathl)
|
||||
|
||||
if (len > current_wd_size) {
|
||||
afree(current_wd, APERM);
|
||||
current_wd = alloc(1, current_wd_size = len, APERM);
|
||||
current_wd = alloc(current_wd_size = len, APERM);
|
||||
}
|
||||
memcpy(current_wd, p, len);
|
||||
if (p != pathl && p != null)
|
||||
@ -1426,19 +1426,19 @@ stristr(const char *b, const char *l)
|
||||
|
||||
#ifdef MKSH_SMALL
|
||||
char *
|
||||
strndup_(const char *src, size_t len, PArea ap)
|
||||
strndup_(const char *src, size_t len, Area *ap)
|
||||
{
|
||||
char *dst = NULL;
|
||||
|
||||
if (src != NULL) {
|
||||
dst = alloc(1, ++len, ap);
|
||||
dst = alloc(++len, ap);
|
||||
strlcpy(dst, src, len);
|
||||
}
|
||||
return (dst);
|
||||
}
|
||||
|
||||
char *
|
||||
strdup_(const char *src, PArea ap)
|
||||
strdup_(const char *src, Area *ap)
|
||||
{
|
||||
return (src == NULL ? NULL : strndup_(src, strlen(src), ap));
|
||||
}
|
||||
|
117
sh.h
117
sh.h
@ -103,9 +103,9 @@
|
||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.265 2008/12/04 18:11:08 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.266 2008/12/13 17:02:16 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R36 2008/12/04"
|
||||
#define MKSH_VERSION "R36 2008/12/13"
|
||||
|
||||
#ifndef MKSH_INCLUDES_ONLY
|
||||
|
||||
@ -130,7 +130,10 @@ typedef int bool;
|
||||
/* extra macros */
|
||||
|
||||
#ifndef timerclear
|
||||
#define timerclear(tvp) do { (tvp)->tv_sec = (tvp)->tv_usec = 0; } while (0)
|
||||
#define timerclear(tvp) \
|
||||
do { \
|
||||
(tvp)->tv_sec = (tvp)->tv_usec = 0; \
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#endif
|
||||
#ifndef timeradd
|
||||
#define timeradd(tvp, uvp, vvp) \
|
||||
@ -141,7 +144,7 @@ typedef int bool;
|
||||
(vvp)->tv_sec++; \
|
||||
(vvp)->tv_usec -= 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#endif
|
||||
#ifndef timersub
|
||||
#define timersub(tvp, uvp, vvp) \
|
||||
@ -152,7 +155,7 @@ typedef int bool;
|
||||
(vvp)->tv_sec--; \
|
||||
(vvp)->tv_usec += 1000000; \
|
||||
} \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#endif
|
||||
|
||||
#define ksh_isdigit(c) (((c) >= '0') && ((c) <= '9'))
|
||||
@ -363,7 +366,7 @@ char *ucstrstr(char *, const char *);
|
||||
\
|
||||
if (strdup_src != NULL) { \
|
||||
size_t strdup_len = strlen(strdup_src) + 1; \
|
||||
strdup_dst = alloc(1, strdup_len, (ap)); \
|
||||
strdup_dst = alloc(strdup_len, (ap)); \
|
||||
strlcpy(strdup_dst, strdup_src, strdup_len); \
|
||||
} \
|
||||
(d) = strdup_dst; \
|
||||
@ -374,7 +377,7 @@ char *ucstrstr(char *, const char *);
|
||||
\
|
||||
if (strdup_src != NULL) { \
|
||||
size_t strdup_len = (n) + 1; \
|
||||
strdup_dst = alloc(1, strdup_len, (ap)); \
|
||||
strdup_dst = alloc(strdup_len, (ap)); \
|
||||
strlcpy(strdup_dst, strdup_src, strdup_len); \
|
||||
} \
|
||||
(d) = strdup_dst; \
|
||||
@ -389,15 +392,22 @@ char *ucstrstr(char *, const char *);
|
||||
#define MKSH_NOVI
|
||||
#endif
|
||||
|
||||
typedef struct TArea *PArea;
|
||||
EXTERN PArea APERM; /* permanent object space */
|
||||
#define ATEMP e->areap
|
||||
/*
|
||||
* Area-based allocation built on malloc/free
|
||||
*/
|
||||
typedef struct Area {
|
||||
struct link *freelist; /* free list */
|
||||
} Area;
|
||||
|
||||
EXTERN Area aperm; /* permanent object space */
|
||||
#define APERM &aperm
|
||||
#define ATEMP &e->area
|
||||
|
||||
/*
|
||||
* parsing & execution environment
|
||||
*/
|
||||
extern struct env {
|
||||
PArea areap; /* temporary allocation area */
|
||||
Area area; /* temporary allocation area */
|
||||
struct block *loc; /* local variables and functions */
|
||||
short *savefd; /* original redirected fds */
|
||||
struct env *oenv; /* link to previous environment */
|
||||
@ -746,13 +756,13 @@ struct shf {
|
||||
int fd; /* file descriptor */
|
||||
int errno_; /* saved value of errno after error */
|
||||
int bsize; /* actual size of buf */
|
||||
PArea areap; /* area shf/buf were allocated in */
|
||||
Area *areap; /* area shf/buf were allocated in */
|
||||
};
|
||||
|
||||
extern struct shf shf_iob[];
|
||||
|
||||
struct table {
|
||||
PArea areap; /* area to allocate entries */
|
||||
Area *areap; /* area to allocate entries */
|
||||
struct tbl **tbls; /* hashed table items */
|
||||
short size, nfree; /* hash size (always 2^^n), free entries */
|
||||
};
|
||||
@ -761,7 +771,7 @@ struct tbl { /* table item */
|
||||
Tflag flag; /* flags */
|
||||
int type; /* command type (see below), base (if INTEGER),
|
||||
* or offset from val.s of value (if EXPORT) */
|
||||
PArea areap; /* area to allocate from */
|
||||
Area *areap; /* area to allocate from */
|
||||
union {
|
||||
char *s; /* string */
|
||||
long i; /* integer */
|
||||
@ -853,7 +863,7 @@ struct arg_info {
|
||||
* activation record for function blocks
|
||||
*/
|
||||
struct block {
|
||||
PArea areap; /* area to allocate things */
|
||||
Area area; /* area to allocate things */
|
||||
const char **argv;
|
||||
int argc;
|
||||
int flags; /* see BF_* */
|
||||
@ -1057,7 +1067,7 @@ struct ioword {
|
||||
typedef struct XString {
|
||||
char *end, *beg; /* end, begin of string */
|
||||
size_t len; /* length */
|
||||
PArea areap; /* area to allocate/free from */
|
||||
Area *areap; /* area to allocate/free from */
|
||||
} XString;
|
||||
|
||||
typedef char *XStringP;
|
||||
@ -1066,23 +1076,23 @@ typedef char *XStringP;
|
||||
#define XinitN(xs, length, area) do { \
|
||||
(xs).len = (length); \
|
||||
(xs).areap = (area); \
|
||||
(xs).beg = alloc(1, (xs).len + X_EXTRA, (xs).areap); \
|
||||
(xs).beg = alloc((xs).len + X_EXTRA, (xs).areap); \
|
||||
(xs).end = (xs).beg + (xs).len; \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
#define Xinit(xs, xp, length, area) do { \
|
||||
XinitN((xs), (length), (area)); \
|
||||
(xp) = (xs).beg; \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
/* stuff char into string */
|
||||
#define Xput(xs, xp, c) (*xp++ = (c))
|
||||
|
||||
/* check if there are at least n bytes left */
|
||||
#define XcheckN(xs, xp, n) do { \
|
||||
int more = ((xp) + (n)) - (xs).end; \
|
||||
size_t more = ((xp) + (n)) - (xs).end; \
|
||||
if (more > 0) \
|
||||
(xp) = Xcheck_grow_(&(xs), (xp), more); \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
/* check for overflow, expand string */
|
||||
#define Xcheck(xs, xp) XcheckN((xs), (xp), 1)
|
||||
@ -1091,16 +1101,16 @@ typedef char *XStringP;
|
||||
#define Xfree(xs, xp) afree((xs).beg, (xs).areap)
|
||||
|
||||
/* close, return string */
|
||||
#define Xclose(xs, xp) aresize((void*)(xs).beg, 1, \
|
||||
(size_t)((xp) - (xs).beg), (xs).areap)
|
||||
#define Xclose(xs, xp) aresize((xs).beg, (xp) - (xs).beg, (xs).areap)
|
||||
|
||||
/* begin of string */
|
||||
#define Xstring(xs, xp) ((xs).beg)
|
||||
|
||||
#define Xnleft(xs, xp) ((xs).end - (xp)) /* may be less than 0 */
|
||||
#define Xlength(xs, xp) ((xp) - (xs).beg)
|
||||
#define Xsize(xs, xp) ((xs).end - (xs).beg)
|
||||
#define Xsavepos(xs, xp) ((xp) - (xs).beg)
|
||||
#define Xrestpos(xs, xp, n) ((xs).beg + (n))
|
||||
#define Xnleft(xs, xp) ((xs).end - (xp)) /* may be less than 0 */
|
||||
#define Xlength(xs, xp) ((xp) - (xs).beg)
|
||||
#define Xsize(xs, xp) ((xs).end - (xs).beg)
|
||||
#define Xsavepos(xs, xp) ((xp) - (xs).beg)
|
||||
#define Xrestpos(xs, xp, n) ((xs).beg + (n))
|
||||
|
||||
char *Xcheck_grow_(XString *, const char *, unsigned int);
|
||||
|
||||
@ -1115,28 +1125,25 @@ typedef struct XPtrV {
|
||||
|
||||
#define XPinit(x, n) do { \
|
||||
void **vp__; \
|
||||
vp__ = alloc((n), sizeof (void *), ATEMP); \
|
||||
vp__ = alloc((n) * sizeof (void *), ATEMP); \
|
||||
(x).cur = (x).beg = vp__; \
|
||||
(x).end = vp__ + (n); \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
#define XPput(x, p) do { \
|
||||
if ((x).cur >= (x).end) { \
|
||||
size_t n = XPsize(x); \
|
||||
(x).beg = aresize((void*)(x).beg, \
|
||||
n * 2, sizeof (void *), ATEMP); \
|
||||
(x).beg = aresize((x).beg, \
|
||||
n * 2 * sizeof (void *), ATEMP); \
|
||||
(x).cur = (x).beg + n; \
|
||||
(x).end = (x).cur + n; \
|
||||
} \
|
||||
*(x).cur++ = (p); \
|
||||
} while (0)
|
||||
} while (/* CONSTCOND */ 0)
|
||||
|
||||
#define XPptrv(x) ((x).beg)
|
||||
#define XPsize(x) ((x).cur - (x).beg)
|
||||
|
||||
#define XPclose(x) aresize((void*)(x).beg, \
|
||||
XPsize(x), sizeof (void *), ATEMP)
|
||||
|
||||
#define XPclose(x) aresize((x).beg, XPsize(x) * sizeof (void *), ATEMP)
|
||||
#define XPfree(x) afree((x).beg, ATEMP)
|
||||
|
||||
#define IDENT 64
|
||||
@ -1156,7 +1163,7 @@ struct source {
|
||||
int errline; /* line the error occurred on (0 if not set) */
|
||||
const char *file; /* input file name */
|
||||
int flags; /* SF_* */
|
||||
PArea areap;
|
||||
Area *areap;
|
||||
XString xs; /* input buffer */
|
||||
Source *next; /* stacked source */
|
||||
char ugbuf[2]; /* buffer for ungetsc() (SREREAD) and
|
||||
@ -1250,17 +1257,11 @@ EXTERN int histsize; /* history size */
|
||||
EXTERN struct timeval j_usrtime, j_systime;
|
||||
|
||||
/* alloc.c */
|
||||
#ifdef AALLOC_STATS
|
||||
#define AALLOC_STRINGIFY(x) __STRING(x)
|
||||
#define anew(hint) anewEx((hint), __FILE__ ":" AALLOC_STRINGIFY(__LINE__))
|
||||
PArea anewEx(size_t, const char *); /* cannot fail */
|
||||
#else
|
||||
PArea anew(size_t); /* cannot fail */
|
||||
#endif
|
||||
void adelete(PArea *);
|
||||
void *alloc(size_t, size_t, PArea); /* cannot fail */
|
||||
void *aresize(void *, size_t, size_t, PArea);
|
||||
void afree(void *, PArea); /* can take NULL */
|
||||
Area *ainit(Area *);
|
||||
void afreeall(Area *);
|
||||
void *alloc(size_t, Area *); /* cannot fail */
|
||||
void *aresize(void *, size_t, Area *);
|
||||
void afree(void *, Area *); /* can take NULL */
|
||||
/* edit.c */
|
||||
void x_init(void);
|
||||
int x_read(char *, size_t);
|
||||
@ -1391,7 +1392,7 @@ int yylex(int);
|
||||
void yyerror(const char *, ...)
|
||||
__attribute__((noreturn))
|
||||
__attribute__((format (printf, 1, 2)));
|
||||
Source *pushs(int, PArea);
|
||||
Source *pushs(int, Area *);
|
||||
void set_prompt(int, Source *);
|
||||
void pprompt(const char *, int);
|
||||
int promptlen(const char *);
|
||||
@ -1440,12 +1441,12 @@ void coproc_readw_close(int);
|
||||
void coproc_write_close(int);
|
||||
int coproc_getfd(int, const char **);
|
||||
void coproc_cleanup(int);
|
||||
struct temp *maketemp(PArea, Temp_type, struct temp **);
|
||||
struct temp *maketemp(Area *, Temp_type, struct temp **);
|
||||
unsigned int hash(const char *);
|
||||
void ktinit(struct table *, PArea, int);
|
||||
void ktinit(struct table *, Area *, int);
|
||||
struct tbl *ktsearch(struct table *, const char *, unsigned int);
|
||||
struct tbl *ktenter(struct table *, const char *, unsigned int);
|
||||
#define ktdelete(p) do { p->flag = 0; } while (0)
|
||||
#define ktdelete(p) do { p->flag = 0; } while (/* CONSTCOND */ 0)
|
||||
void ktwalk(struct tstate *, struct table *);
|
||||
struct tbl *ktnext(struct tstate *);
|
||||
struct tbl **ktsort(struct table *);
|
||||
@ -1478,8 +1479,8 @@ void simplify_path(char *);
|
||||
char *get_phys_path(const char *);
|
||||
void set_current_wd(char *);
|
||||
#ifdef MKSH_SMALL
|
||||
char *strdup_(const char *, PArea);
|
||||
char *strndup_(const char *, size_t, PArea);
|
||||
char *strdup_(const char *, Area *);
|
||||
char *strndup_(const char *, size_t, Area *);
|
||||
#endif
|
||||
/* shf.c */
|
||||
struct shf *shf_open(const char *, int, int, int);
|
||||
@ -1512,11 +1513,11 @@ struct op *compile(Source *);
|
||||
/* tree.c */
|
||||
int fptreef(struct shf *, int, const char *, ...);
|
||||
char *snptreef(char *, int, const char *, ...);
|
||||
struct op *tcopy(struct op *, PArea);
|
||||
char *wdcopy(const char *, PArea);
|
||||
struct op *tcopy(struct op *, Area *);
|
||||
char *wdcopy(const char *, Area *);
|
||||
const char *wdscan(const char *, int);
|
||||
char *wdstrip(const char *, bool, bool);
|
||||
void tfree(struct op *, PArea);
|
||||
void tfree(struct op *, Area *);
|
||||
/* var.c */
|
||||
void newblock(void);
|
||||
void popblock(void);
|
||||
|
14
shf.c
14
shf.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.23 2008/11/12 00:54:51 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.24 2008/12/13 17:02:17 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@ -29,7 +29,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
||||
int fd;
|
||||
|
||||
/* Done before open so if alloca fails, fd won't be lost. */
|
||||
shf = alloc(1, sizeof (struct shf) + bsize, ATEMP);
|
||||
shf = alloc(sizeof (struct shf) + bsize, ATEMP);
|
||||
shf->areap = ATEMP;
|
||||
shf->buf = (unsigned char *)&shf[1];
|
||||
shf->bsize = bsize;
|
||||
@ -92,12 +92,12 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
|
||||
|
||||
if (shf) {
|
||||
if (bsize) {
|
||||
shf->buf = alloc(1, bsize, ATEMP);
|
||||
shf->buf = alloc(bsize, ATEMP);
|
||||
sflags |= SHF_ALLOCB;
|
||||
} else
|
||||
shf->buf = NULL;
|
||||
} else {
|
||||
shf = alloc(1, sizeof (struct shf) + bsize, ATEMP);
|
||||
shf = alloc(sizeof (struct shf) + bsize, ATEMP);
|
||||
shf->buf = (unsigned char *)&shf[1];
|
||||
sflags |= SHF_ALLOCS;
|
||||
}
|
||||
@ -180,7 +180,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
||||
internal_errorf("shf_sopen: flags 0x%x", sflags);
|
||||
|
||||
if (!shf) {
|
||||
shf = alloc(1, sizeof (struct shf), ATEMP);
|
||||
shf = alloc(sizeof (struct shf), ATEMP);
|
||||
sflags |= SHF_ALLOCS;
|
||||
}
|
||||
shf->areap = ATEMP;
|
||||
@ -188,7 +188,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
||||
if (bsize <= 0)
|
||||
bsize = 64;
|
||||
sflags |= SHF_ALLOCB;
|
||||
buf = alloc(1, bsize, shf->areap);
|
||||
buf = alloc(bsize, shf->areap);
|
||||
}
|
||||
shf->fd = -1;
|
||||
shf->buf = shf->rp = shf->wp = (unsigned char *)buf;
|
||||
@ -323,7 +323,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
||||
!(shf->flags & SHF_ALLOCB))
|
||||
return EOF;
|
||||
/* allocate more space for buffer */
|
||||
nbuf = aresize(shf->buf, 2, shf->wbsize, shf->areap);
|
||||
nbuf = aresize(shf->buf, 2 * shf->wbsize, shf->areap);
|
||||
shf->rp = nbuf + (shf->rp - shf->buf);
|
||||
shf->wp = nbuf + (shf->wp - shf->buf);
|
||||
shf->rbsize += shf->wbsize;
|
||||
|
20
syn.c
20
syn.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.31 2008/12/02 13:20:40 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.32 2008/12/13 17:02:17 tg Exp $");
|
||||
|
||||
struct nesting_state {
|
||||
int start_token; /* token than began nesting (eg, FOR) */
|
||||
@ -172,8 +172,8 @@ synio(int cf)
|
||||
if (iop->flag & IOBASH) {
|
||||
char *cp;
|
||||
|
||||
nextiop = alloc(1, sizeof (*iop), ATEMP);
|
||||
nextiop->name = cp = alloc(5, 1, ATEMP);
|
||||
nextiop = alloc(sizeof (*iop), ATEMP);
|
||||
nextiop->name = cp = alloc(5, ATEMP);
|
||||
|
||||
if (iop->unit > 9) {
|
||||
*cp++ = CHAR;
|
||||
@ -214,7 +214,7 @@ get_command(int cf)
|
||||
XPtrV args, vars;
|
||||
struct nesting_state old_nesting;
|
||||
|
||||
iops = alloc(NUFILE + 1, sizeof (struct ioword *), ATEMP);
|
||||
iops = alloc((NUFILE + 1) * sizeof (struct ioword *), ATEMP);
|
||||
XPinit(args, 16);
|
||||
XPinit(vars, 16);
|
||||
|
||||
@ -421,7 +421,7 @@ get_command(int cf)
|
||||
syniocf &= ~(KEYWORD|ALIAS);
|
||||
t = pipeline(0);
|
||||
if (t) {
|
||||
t->str = alloc(1, 2, ATEMP);
|
||||
t->str = alloc(2, ATEMP);
|
||||
t->str[0] = '\0'; /* TF_* flags */
|
||||
t->str[1] = '\0';
|
||||
}
|
||||
@ -445,7 +445,7 @@ get_command(int cf)
|
||||
t->ioact = NULL;
|
||||
} else {
|
||||
iops[iopn++] = NULL;
|
||||
iops = aresize(iops, iopn, sizeof (struct ioword *), ATEMP);
|
||||
iops = aresize(iops, iopn * sizeof (struct ioword *), ATEMP);
|
||||
t->ioact = iops;
|
||||
}
|
||||
|
||||
@ -620,13 +620,13 @@ function_body(char *name,
|
||||
* be used as input), we pretend there is a colon here.
|
||||
*/
|
||||
t->left = newtp(TCOM);
|
||||
t->left->args = alloc(2, sizeof (char *), ATEMP);
|
||||
t->left->args[0] = tv = alloc(3, sizeof (char), ATEMP);
|
||||
t->left->args = alloc(2 * sizeof (char *), ATEMP);
|
||||
t->left->args[0] = tv = alloc(3, ATEMP);
|
||||
tv[0] = CHAR;
|
||||
tv[1] = ':';
|
||||
tv[2] = EOS;
|
||||
t->left->args[1] = NULL;
|
||||
t->left->vars = alloc(1, sizeof (char *), ATEMP);
|
||||
t->left->vars = alloc(sizeof (char *), ATEMP);
|
||||
t->left->vars[0] = NULL;
|
||||
t->left->lineno = 1;
|
||||
}
|
||||
@ -803,7 +803,7 @@ newtp(int type)
|
||||
{
|
||||
struct op *t;
|
||||
|
||||
t = alloc(1, sizeof (struct op), ATEMP);
|
||||
t = alloc(sizeof (struct op), ATEMP);
|
||||
t->type = type;
|
||||
t->u.evalflags = 0;
|
||||
t->args = NULL;
|
||||
|
28
tree.c
28
tree.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.23 2008/11/12 00:54:51 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.24 2008/12/13 17:02:17 tg Exp $");
|
||||
|
||||
#define INDENT 4
|
||||
|
||||
@ -12,8 +12,8 @@ static void pioact(struct shf *, int, struct ioword *);
|
||||
static void tputC(int, struct shf *);
|
||||
static void tputS(char *, struct shf *);
|
||||
static void vfptreef(struct shf *, int, const char *, va_list);
|
||||
static struct ioword **iocopy(struct ioword **, PArea);
|
||||
static void iofree(struct ioword **, PArea);
|
||||
static struct ioword **iocopy(struct ioword **, Area *);
|
||||
static void iofree(struct ioword **, Area *);
|
||||
|
||||
/*
|
||||
* print a command tree
|
||||
@ -412,7 +412,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
* copy tree (for function definition)
|
||||
*/
|
||||
struct op *
|
||||
tcopy(struct op *t, PArea ap)
|
||||
tcopy(struct op *t, Area *ap)
|
||||
{
|
||||
struct op *r;
|
||||
const char **tw;
|
||||
@ -421,7 +421,7 @@ tcopy(struct op *t, PArea ap)
|
||||
if (t == NULL)
|
||||
return NULL;
|
||||
|
||||
r = alloc(1, sizeof (struct op), ap);
|
||||
r = alloc(sizeof (struct op), ap);
|
||||
|
||||
r->type = t->type;
|
||||
r->u.evalflags = t->u.evalflags;
|
||||
@ -436,7 +436,7 @@ tcopy(struct op *t, PArea ap)
|
||||
else {
|
||||
for (tw = (const char **)t->vars; *tw++ != NULL; )
|
||||
;
|
||||
rw = r->vars = alloc((tw - (const char **)t->vars + 1),
|
||||
rw = r->vars = alloc((tw - (const char **)t->vars + 1) *
|
||||
sizeof (*tw), ap);
|
||||
for (tw = (const char **)t->vars; *tw != NULL; )
|
||||
*rw++ = wdcopy(*tw++, ap);
|
||||
@ -448,7 +448,7 @@ tcopy(struct op *t, PArea ap)
|
||||
else {
|
||||
for (tw = t->args; *tw++ != NULL; )
|
||||
;
|
||||
r->args = (const char **)(rw = alloc((tw - t->args + 1),
|
||||
r->args = (const char **)(rw = alloc((tw - t->args + 1) *
|
||||
sizeof (*tw), ap));
|
||||
for (tw = t->args; *tw != NULL; )
|
||||
*rw++ = wdcopy(*tw++, ap);
|
||||
@ -465,10 +465,10 @@ tcopy(struct op *t, PArea ap)
|
||||
}
|
||||
|
||||
char *
|
||||
wdcopy(const char *wp, PArea ap)
|
||||
wdcopy(const char *wp, Area *ap)
|
||||
{
|
||||
size_t len = wdscan(wp, EOS) - wp;
|
||||
return memcpy(alloc(1, len, ap), wp, len);
|
||||
return memcpy(alloc(len, ap), wp, len);
|
||||
}
|
||||
|
||||
/* return the position of prefix c in wp plus 1 */
|
||||
@ -611,20 +611,20 @@ wdstrip(const char *wp, bool keepq, bool make_magic)
|
||||
}
|
||||
|
||||
static struct ioword **
|
||||
iocopy(struct ioword **iow, PArea ap)
|
||||
iocopy(struct ioword **iow, Area *ap)
|
||||
{
|
||||
struct ioword **ior;
|
||||
int i;
|
||||
|
||||
for (ior = iow; *ior++ != NULL; )
|
||||
;
|
||||
ior = alloc((ior - iow + 1), sizeof (struct ioword *), ap);
|
||||
ior = alloc((ior - iow + 1) * sizeof (struct ioword *), ap);
|
||||
|
||||
for (i = 0; iow[i] != NULL; i++) {
|
||||
struct ioword *p, *q;
|
||||
|
||||
p = iow[i];
|
||||
q = alloc(1, sizeof (struct ioword), ap);
|
||||
q = alloc(sizeof (struct ioword), ap);
|
||||
ior[i] = q;
|
||||
*q = *p;
|
||||
if (p->name != NULL)
|
||||
@ -643,7 +643,7 @@ iocopy(struct ioword **iow, PArea ap)
|
||||
* free tree (for function definition)
|
||||
*/
|
||||
void
|
||||
tfree(struct op *t, PArea ap)
|
||||
tfree(struct op *t, Area *ap)
|
||||
{
|
||||
char **w;
|
||||
|
||||
@ -678,7 +678,7 @@ tfree(struct op *t, PArea ap)
|
||||
}
|
||||
|
||||
static void
|
||||
iofree(struct ioword **iow, PArea ap)
|
||||
iofree(struct ioword **iow, Area *ap)
|
||||
{
|
||||
struct ioword **iop;
|
||||
struct ioword *p;
|
||||
|
18
var.c
18
var.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.64 2008/12/04 18:11:08 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.65 2008/12/13 17:02:18 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -37,9 +37,9 @@ newblock(void)
|
||||
struct block *l;
|
||||
static const char *empty[] = { null };
|
||||
|
||||
l = alloc(1, sizeof (struct block), ATEMP);
|
||||
l = alloc(sizeof (struct block), ATEMP);
|
||||
l->flags = 0;
|
||||
l->areap = anew(Flag(FTALKING) ? 1024 : 64);
|
||||
ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */
|
||||
if (!e->loc) {
|
||||
l->argc = 0;
|
||||
l->argv = empty;
|
||||
@ -48,8 +48,8 @@ newblock(void)
|
||||
l->argv = e->loc->argv;
|
||||
}
|
||||
l->exit = l->error = NULL;
|
||||
ktinit(&l->vars, l->areap, 0);
|
||||
ktinit(&l->funs, l->areap, 0);
|
||||
ktinit(&l->vars, &l->area, 0);
|
||||
ktinit(&l->funs, &l->area, 0);
|
||||
l->next = e->loc;
|
||||
e->loc = l;
|
||||
}
|
||||
@ -74,7 +74,7 @@ popblock(void)
|
||||
}
|
||||
if (l->flags & BF_DOGETOPTS)
|
||||
user_opt = l->getopts_state;
|
||||
adelete(&l->areap);
|
||||
afreeall(&l->area);
|
||||
afree(l, ATEMP);
|
||||
}
|
||||
|
||||
@ -523,7 +523,7 @@ formatstr(struct tbl *vp, const char *s)
|
||||
} else
|
||||
nlen = olen;
|
||||
|
||||
p = alloc(1, (psiz = nlen * /* MB_LEN_MAX */ 3 + 1), ATEMP);
|
||||
p = alloc((psiz = nlen * /* MB_LEN_MAX */ 3 + 1), ATEMP);
|
||||
if (vp->flag & (RJUST|LJUST)) {
|
||||
int slen = olen, i = 0;
|
||||
|
||||
@ -595,7 +595,7 @@ export(struct tbl *vp, const char *val)
|
||||
int vallen = strlen(val) + 1;
|
||||
|
||||
vp->flag |= ALLOC;
|
||||
xp = alloc(1, namelen + 1 + vallen, vp->areap);
|
||||
xp = alloc(namelen + 1 + vallen, vp->areap);
|
||||
memcpy(vp->val.s = xp, vp->name, namelen);
|
||||
xp += namelen;
|
||||
*xp++ = '=';
|
||||
@ -1212,7 +1212,7 @@ arraysearch(struct tbl *vp, uint32_t val)
|
||||
else
|
||||
new = curr;
|
||||
} else
|
||||
new = alloc(1, sizeof (struct tbl) + namelen, vp->areap);
|
||||
new = alloc(sizeof (struct tbl) + namelen, vp->areap);
|
||||
strlcpy(new->name, vp->name, namelen);
|
||||
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
||||
new->type = vp->type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user