enable passing of a hint how many pointers we’ll need to anew()
if 0, the default is used
This commit is contained in:
13
aalloc.c
13
aalloc.c
@ -1,6 +1,6 @@
|
|||||||
#include "sh.h"
|
#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 */
|
/* 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 *);
|
static TPtr *check_ptr(void *, PArea, PBlock *, const char *, const char *);
|
||||||
|
|
||||||
PArea
|
PArea
|
||||||
anew(void)
|
anew(size_t hint)
|
||||||
{
|
{
|
||||||
PArea ap;
|
PArea ap;
|
||||||
PBlock bp;
|
PBlock bp;
|
||||||
@ -164,6 +164,9 @@ anew(void)
|
|||||||
AALLOC_ABORT("AALLOC_INITSZ constant too small: %lu < %lu",
|
AALLOC_ABORT("AALLOC_INITSZ constant too small: %lu < %lu",
|
||||||
(unsigned long)AALLOC_INITSZ,
|
(unsigned long)AALLOC_INITSZ,
|
||||||
(unsigned long)sizeof (struct TBlock));
|
(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
|
#endif
|
||||||
|
|
||||||
if (!global_cookie) {
|
if (!global_cookie) {
|
||||||
@ -182,8 +185,12 @@ anew(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safe_muladd(sizeof (void *), hint, 0);
|
||||||
|
if (hint < sizeof (struct TBlock))
|
||||||
|
hint = AALLOC_INITSZ;
|
||||||
|
|
||||||
safe_malloc(ap, sizeof (struct TArea));
|
safe_malloc(ap, sizeof (struct TArea));
|
||||||
safe_malloc(bp, AALLOC_INITSZ);
|
safe_malloc(bp, hint);
|
||||||
/* ensure unaligned cookie */
|
/* ensure unaligned cookie */
|
||||||
#ifdef AALLOC_NO_COOKIES
|
#ifdef AALLOC_NO_COOKIES
|
||||||
bp->cookie = 0;
|
bp->cookie = 0;
|
||||||
|
4
alloc.c
4
alloc.c
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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 {
|
||||||
struct link *prev;
|
struct link *prev;
|
||||||
@ -41,7 +41,7 @@ struct TArea {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PArea
|
PArea
|
||||||
anew(void)
|
anew(size_t hint __unused)
|
||||||
{
|
{
|
||||||
PArea ap;
|
PArea ap;
|
||||||
|
|
||||||
|
4
edit.c
4
edit.c
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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 */
|
/* tty driver characters we are interested in */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -2681,7 +2681,7 @@ x_init_emacs(void)
|
|||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
AEDIT = anew();
|
AEDIT = anew(0);
|
||||||
x_nextcmd = -1;
|
x_nextcmd = -1;
|
||||||
|
|
||||||
x_tab = alloc(X_NTABS, sizeof (*x_tab), AEDIT);
|
x_tab = alloc(X_NTABS, sizeof (*x_tab), AEDIT);
|
||||||
|
10
main.c
10
main.c
@ -13,7 +13,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#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;
|
extern char **environ;
|
||||||
|
|
||||||
@ -91,11 +91,11 @@ main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
kshname = *argv;
|
kshname = *argv;
|
||||||
|
|
||||||
APERM = anew(); /* initialise permanent Area */
|
APERM = anew(0); /* initialise permanent Area */
|
||||||
|
|
||||||
/* set up base environment */
|
/* set up base environment */
|
||||||
env.type = E_NONE;
|
env.type = E_NONE;
|
||||||
env.areap = anew();
|
env.areap = anew(0);
|
||||||
newblock(); /* set up global l->vars and l->funs */
|
newblock(); /* set up global l->vars and l->funs */
|
||||||
|
|
||||||
/* Do this first so output routines (eg, errorf, shellf) can work */
|
/* 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 = alloc(1, sizeof (struct env), ATEMP);
|
||||||
ep->type = type;
|
ep->type = type;
|
||||||
ep->flags = 0;
|
ep->flags = 0;
|
||||||
ep->areap = anew();
|
ep->areap = anew(0);
|
||||||
ep->loc = e->loc;
|
ep->loc = e->loc;
|
||||||
ep->savefd = NULL;
|
ep->savefd = NULL;
|
||||||
ep->oenv = e;
|
ep->oenv = e;
|
||||||
@ -720,7 +720,7 @@ reclaim(bool finish)
|
|||||||
e->temps = NULL;
|
e->temps = NULL;
|
||||||
adelete(&e->areap);
|
adelete(&e->areap);
|
||||||
if (!finish)
|
if (!finish)
|
||||||
e->areap = anew();
|
e->areap = anew(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
4
sh.h
4
sh.h
@ -103,7 +103,7 @@
|
|||||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R36 2008/11/11"
|
#define MKSH_VERSION "R36 2008/11/11"
|
||||||
|
|
||||||
@ -1247,7 +1247,7 @@ EXTERN int histsize; /* history size */
|
|||||||
EXTERN struct timeval j_usrtime, j_systime;
|
EXTERN struct timeval j_usrtime, j_systime;
|
||||||
|
|
||||||
/* alloc.c */
|
/* alloc.c */
|
||||||
PArea anew(void); /* cannot fail */
|
PArea anew(size_t); /* cannot fail */
|
||||||
void adelete(PArea *);
|
void adelete(PArea *);
|
||||||
void *alloc(size_t, size_t, PArea); /* cannot fail */
|
void *alloc(size_t, size_t, PArea); /* cannot fail */
|
||||||
void *aresize(void *, size_t, size_t, PArea);
|
void *aresize(void *, size_t, size_t, PArea);
|
||||||
|
4
var.c
4
var.c
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
* Variables
|
||||||
@ -39,7 +39,7 @@ newblock(void)
|
|||||||
|
|
||||||
l = alloc(1, sizeof (struct block), ATEMP);
|
l = alloc(1, sizeof (struct block), ATEMP);
|
||||||
l->flags = 0;
|
l->flags = 0;
|
||||||
l->areap = anew(); /* TODO: could use e->area */
|
l->areap = anew(0); /* TODO: could use e->area */
|
||||||
if (!e->loc) {
|
if (!e->loc) {
|
||||||
l->argc = 0;
|
l->argc = 0;
|
||||||
l->argv = empty;
|
l->argv = empty;
|
||||||
|
Reference in New Issue
Block a user