enable passing of a hint how many pointers we’ll need to anew()

if 0, the default is used
This commit is contained in:
tg 2008-11-15 07:35:25 +00:00
parent 03acb8ce51
commit 32e1ecf5b3
6 changed files with 23 additions and 16 deletions

View File

@ -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;

View File

@ -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;

4
edit.c
View File

@ -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);

10
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#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

4
sh.h
View File

@ -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);

4
var.c
View File

@ -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;