share structures better, less (void *) casts when we can stay typed
This commit is contained in:
parent
08e1c6a9ea
commit
2a3773b70b
26
lalloc.c
26
lalloc.c
@ -23,7 +23,7 @@
|
|||||||
#include <err.h>
|
#include <err.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.24 2016/02/24 01:44:46 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.25 2016/02/24 02:08:39 tg Exp $");
|
||||||
|
|
||||||
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
|
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
|
||||||
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)
|
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)
|
||||||
@ -33,7 +33,7 @@ __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.24 2016/02/24 01:44:46 tg Exp $");
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static ALLOC_ITEM *findptr(ALLOC_ITEM **, char *, Area *);
|
static struct lalloc_common *findptr(struct lalloc_common **, char *, Area *);
|
||||||
|
|
||||||
#ifndef MKSH_ALLOC_CATCH_UNDERRUNS
|
#ifndef MKSH_ALLOC_CATCH_UNDERRUNS
|
||||||
#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) % ALLOC_SIZE)
|
#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) % ALLOC_SIZE)
|
||||||
@ -45,7 +45,7 @@ static ALLOC_ITEM *findptr(ALLOC_ITEM **, char *, Area *);
|
|||||||
static void
|
static void
|
||||||
free_osimalloc(void *ptr)
|
free_osimalloc(void *ptr)
|
||||||
{
|
{
|
||||||
struct lalloc *lp = ptr;
|
struct lalloc_item *lp = ptr;
|
||||||
|
|
||||||
if (munmap(lp, lp->len))
|
if (munmap(lp, lp->len))
|
||||||
err(1, "free_osimalloc");
|
err(1, "free_osimalloc");
|
||||||
@ -54,7 +54,7 @@ free_osimalloc(void *ptr)
|
|||||||
static void *
|
static void *
|
||||||
remalloc(void *ptr, size_t size)
|
remalloc(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
struct lalloc *lp, *lold = ptr;
|
struct lalloc_item *lp, *lold = ptr;
|
||||||
|
|
||||||
size = (size + 4095) & ~(size_t)4095;
|
size = (size + 4095) & ~(size_t)4095;
|
||||||
|
|
||||||
@ -92,12 +92,12 @@ ainit(Area *ap)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* area pointer is an ALLOC_ITEM, just the head of the list */
|
/* area pointer and items share struct lalloc_common */
|
||||||
ap->next = NULL;
|
ap->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ALLOC_ITEM *
|
static struct lalloc_common *
|
||||||
findptr(ALLOC_ITEM **lpp, char *ptr, Area *ap)
|
findptr(struct lalloc_common **lpp, char *ptr, Area *ap)
|
||||||
{
|
{
|
||||||
void *lp;
|
void *lp;
|
||||||
|
|
||||||
@ -140,11 +140,11 @@ aresize2(void *ptr, size_t fac1, size_t fac2, Area *ap)
|
|||||||
void *
|
void *
|
||||||
aresize(void *ptr, size_t numb, Area *ap)
|
aresize(void *ptr, size_t numb, Area *ap)
|
||||||
{
|
{
|
||||||
ALLOC_ITEM *lp = NULL;
|
struct lalloc_common *lp = NULL;
|
||||||
|
|
||||||
/* resizing (true) or newly allocating? */
|
/* resizing (true) or newly allocating? */
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
ALLOC_ITEM *pp;
|
struct lalloc_common *pp;
|
||||||
|
|
||||||
pp = findptr(&lp, ptr, ap);
|
pp = findptr(&lp, ptr, ap);
|
||||||
pp->next = lp->next;
|
pp->next = lp->next;
|
||||||
@ -157,9 +157,9 @@ aresize(void *ptr, size_t numb, Area *ap)
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
internal_errorf(Toomem, numb);
|
internal_errorf(Toomem, numb);
|
||||||
/* this only works because Area is an ALLOC_ITEM */
|
/* this only works because Area and ALLOC_ITEM share lalloc_common */
|
||||||
lp->next = ap->next;
|
lp->next = ap->next;
|
||||||
ap->next = (void *)lp;
|
ap->next = lp;
|
||||||
/* return user item address */
|
/* return user item address */
|
||||||
return ((char *)lp + ALLOC_SIZE);
|
return ((char *)lp + ALLOC_SIZE);
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ void
|
|||||||
afree(void *ptr, Area *ap)
|
afree(void *ptr, Area *ap)
|
||||||
{
|
{
|
||||||
if (ptr != NULL) {
|
if (ptr != NULL) {
|
||||||
ALLOC_ITEM *lp, *pp;
|
struct lalloc_common *lp, *pp;
|
||||||
|
|
||||||
pp = findptr(&lp, ptr, ap);
|
pp = findptr(&lp, ptr, ap);
|
||||||
/* unhook */
|
/* unhook */
|
||||||
@ -181,7 +181,7 @@ afree(void *ptr, Area *ap)
|
|||||||
void
|
void
|
||||||
afreeall(Area *ap)
|
afreeall(Area *ap)
|
||||||
{
|
{
|
||||||
Area *lp;
|
struct lalloc_common *lp;
|
||||||
|
|
||||||
/* traverse group (linked list) */
|
/* traverse group (linked list) */
|
||||||
while ((lp = ap->next) != NULL) {
|
while ((lp = ap->next) != NULL) {
|
||||||
|
16
sh.h
16
sh.h
@ -175,7 +175,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.761 2016/02/24 01:44:46 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.762 2016/02/24 02:08:39 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R52 2016/02/23"
|
#define MKSH_VERSION "R52 2016/02/23"
|
||||||
|
|
||||||
@ -699,20 +699,20 @@ im_sorry_dave(void)
|
|||||||
|
|
||||||
|
|
||||||
/* 1. internal structure */
|
/* 1. internal structure */
|
||||||
struct lalloc_area {
|
struct lalloc_common {
|
||||||
struct lalloc_area *next;
|
struct lalloc_common *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lalloc {
|
struct lalloc_item {
|
||||||
struct lalloc_area *next;
|
struct lalloc_common *next;
|
||||||
#ifdef MKSH_ALLOC_CATCH_UNDERRUNS
|
#ifdef MKSH_ALLOC_CATCH_UNDERRUNS
|
||||||
size_t len;
|
size_t len;
|
||||||
char dummy[8192 - sizeof(struct lalloc_area *) - sizeof(size_t)];
|
char dummy[8192 - sizeof(struct lalloc_common *) - sizeof(size_t)];
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 2. sizes */
|
/* 2. sizes */
|
||||||
#define ALLOC_ITEM struct lalloc
|
#define ALLOC_ITEM struct lalloc_item
|
||||||
#define ALLOC_SIZE (sizeof(ALLOC_ITEM))
|
#define ALLOC_SIZE (sizeof(ALLOC_ITEM))
|
||||||
#ifndef MKSH_ALLOC_CATCH_UNDERRUNS
|
#ifndef MKSH_ALLOC_CATCH_UNDERRUNS
|
||||||
#define ALLOC_OVERHEAD ALLOC_SIZE
|
#define ALLOC_OVERHEAD ALLOC_SIZE
|
||||||
@ -721,7 +721,7 @@ struct lalloc {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* 3. group structure */
|
/* 3. group structure */
|
||||||
typedef struct lalloc_area Area;
|
typedef struct lalloc_common Area;
|
||||||
|
|
||||||
|
|
||||||
EXTERN Area aperm; /* permanent object space */
|
EXTERN Area aperm; /* permanent object space */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user