From 32e1ecf5b38ba55e8f780dda80b1fdb4a661c217 Mon Sep 17 00:00:00 2001 From: tg Date: Sat, 15 Nov 2008 07:35:25 +0000 Subject: [PATCH] =?UTF-8?q?enable=20passing=20of=20a=20hint=20how=20many?= =?UTF-8?q?=20pointers=20we=E2=80=99ll=20need=20to=20anew()=20if=200,=20th?= =?UTF-8?q?e=20default=20is=20used?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aalloc.c | 13 ++++++++++--- alloc.c | 4 ++-- edit.c | 4 ++-- main.c | 10 +++++----- sh.h | 4 ++-- var.c | 4 ++-- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/aalloc.c b/aalloc.c index c371bbb..4d3a063 100644 --- a/aalloc.c +++ b/aalloc.c @@ -1,6 +1,6 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.25 2008/11/12 23:34:02 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/aalloc.c,v 1.26 2008/11/15 07:35:23 tg Exp $"); /* mksh integration of aalloc */ @@ -138,7 +138,7 @@ static PBlock check_bp(PArea, const char *, TCookie); static TPtr *check_ptr(void *, PArea, PBlock *, const char *, const char *); PArea -anew(void) +anew(size_t hint) { PArea ap; PBlock bp; @@ -164,6 +164,9 @@ anew(void) AALLOC_ABORT("AALLOC_INITSZ constant too small: %lu < %lu", (unsigned long)AALLOC_INITSZ, (unsigned long)sizeof (struct TBlock)); + if (hint != (1UL << (ffs(hint) - 1))) + AALLOC_ABORT("anew hint %lu not a power of two or too big", + (unsigned long)hint); #endif if (!global_cookie) { @@ -182,8 +185,12 @@ anew(void) #endif } + safe_muladd(sizeof (void *), hint, 0); + if (hint < sizeof (struct TBlock)) + hint = AALLOC_INITSZ; + safe_malloc(ap, sizeof (struct TArea)); - safe_malloc(bp, AALLOC_INITSZ); + safe_malloc(bp, hint); /* ensure unaligned cookie */ #ifdef AALLOC_NO_COOKIES bp->cookie = 0; diff --git a/alloc.c b/alloc.c index 296d536..095961d 100644 --- a/alloc.c +++ b/alloc.c @@ -29,7 +29,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.11 2008/11/12 00:54:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.12 2008/11/15 07:35:23 tg Exp $"); struct link { struct link *prev; @@ -41,7 +41,7 @@ struct TArea { }; PArea -anew(void) +anew(size_t hint __unused) { PArea ap; diff --git a/edit.c b/edit.c index dbce972..036349e 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.144 2008/11/12 00:54:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.145 2008/11/15 07:35:23 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -2681,7 +2681,7 @@ x_init_emacs(void) { int i, j; - AEDIT = anew(); + AEDIT = anew(0); x_nextcmd = -1; x_tab = alloc(X_NTABS, sizeof (*x_tab), AEDIT); diff --git a/main.c b/main.c index f5a25c5..c8265a5 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.110 2008/11/12 04:55:18 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.111 2008/11/15 07:35:24 tg Exp $"); extern char **environ; @@ -91,11 +91,11 @@ main(int argc, const char *argv[]) } kshname = *argv; - APERM = anew(); /* initialise permanent Area */ + APERM = anew(0); /* initialise permanent Area */ /* set up base environment */ env.type = E_NONE; - env.areap = anew(); + env.areap = anew(0); newblock(); /* set up global l->vars and l->funs */ /* Do this first so output routines (eg, errorf, shellf) can work */ @@ -614,7 +614,7 @@ newenv(int type) ep = alloc(1, sizeof (struct env), ATEMP); ep->type = type; ep->flags = 0; - ep->areap = anew(); + ep->areap = anew(0); ep->loc = e->loc; ep->savefd = NULL; ep->oenv = e; @@ -720,7 +720,7 @@ reclaim(bool finish) e->temps = NULL; adelete(&e->areap); if (!finish) - e->areap = anew(); + e->areap = anew(0); } static void diff --git a/sh.h b/sh.h index 1e71432..b5961cc 100644 --- a/sh.h +++ b/sh.h @@ -103,7 +103,7 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.257 2008/11/12 04:55:19 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.258 2008/11/15 07:35:24 tg Exp $"); #endif #define MKSH_VERSION "R36 2008/11/11" @@ -1247,7 +1247,7 @@ EXTERN int histsize; /* history size */ EXTERN struct timeval j_usrtime, j_systime; /* alloc.c */ -PArea anew(void); /* cannot fail */ +PArea anew(size_t); /* cannot fail */ void adelete(PArea *); void *alloc(size_t, size_t, PArea); /* cannot fail */ void *aresize(void *, size_t, size_t, PArea); diff --git a/var.c b/var.c index 4392b52..4759e50 100644 --- a/var.c +++ b/var.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.60 2008/11/12 00:54:52 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.61 2008/11/15 07:35:25 tg Exp $"); /* * Variables @@ -39,7 +39,7 @@ newblock(void) l = alloc(1, sizeof (struct block), ATEMP); l->flags = 0; - l->areap = anew(); /* TODO: could use e->area */ + l->areap = anew(0); /* TODO: could use e->area */ if (!e->loc) { l->argc = 0; l->argv = empty;