split malloc_os and friends further into

• functions called by mksh’s grouping memory allocator
• functions called by mksh code itself

the latter may be changed to call the internal grouping allocator,
if a porter so desires (but if this were recommended, the code in
question would already do so, so…)
This commit is contained in:
tg 2011-03-05 21:48:09 +00:00
parent 0b6afea352
commit f3dbbe3f0c
3 changed files with 18 additions and 13 deletions

View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.173 2011/03/05 21:43:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.174 2011/03/05 21:48:08 tg Exp $");
#if HAVE_KILLPG
/*
@ -3605,7 +3605,7 @@ c_cat(const char **wp)
char *buf, *cp;
#define MKSH_CAT_BUFSIZ 4096
if ((buf = malloc_os(MKSH_CAT_BUFSIZ)) == NULL) {
if ((buf = malloc_osfunc(MKSH_CAT_BUFSIZ)) == NULL) {
bi_errorf(T_oomem, (unsigned long)MKSH_CAT_BUFSIZ);
return (1);
}
@ -3674,7 +3674,7 @@ c_cat(const char **wp)
} while (*wp);
out:
free_osmalloc(buf);
free_osfunc(buf);
return (rv);
}

View File

@ -20,13 +20,13 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.15 2011/03/05 21:43:16 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.16 2011/03/05 21:48:09 tg Exp $");
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)
#define remalloc(p,n) ((p) == NULL ? malloc_os(n) : realloc_os((p), (n)))
#define remalloc(p,n) ((p) == NULL ? malloc_osi(n) : realloc_osi((p), (n)))
#else
#define remalloc(p,n) realloc_os((p), (n))
#define remalloc(p,n) realloc_osi((p), (n))
#endif
#define ALLOC_ISUNALIGNED(p) (((ptrdiff_t)(p)) % ALLOC_SIZE)
@ -113,7 +113,7 @@ afree(void *ptr, Area *ap)
/* unhook */
pp->next = lp->next;
/* now free ALLOC_ITEM */
free_osmalloc(lp);
free_osimalloc(lp);
}
}
@ -127,6 +127,6 @@ afreeall(Area *ap)
/* make next ALLOC_ITEM head of list */
ap->next = lp->next;
/* free old head */
free_osmalloc(lp);
free_osimalloc(lp);
}
}

15
sh.h
View File

@ -154,7 +154,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.434 2011/03/05 21:43:18 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.435 2011/03/05 21:48:09 tg Exp $");
#endif
#define MKSH_VERSION "R39 2011/02/18"
@ -500,10 +500,15 @@ char *ucstrstr(char *, const char *);
/* 0. OS API: where to get memory from and how to free it (grouped) */
/* malloc(3)/realloc(3) -> free(3) */
#define malloc_os(sz) malloc(sz)
#define realloc_os(p,sz) realloc((p), (sz))
#define free_osmalloc(p) free(p)
/* malloc(3)/realloc(3) -> free(3) for use by the memory allocator */
#define malloc_osi(sz) malloc(sz)
#define realloc_osi(p,sz) realloc((p), (sz))
#define free_osimalloc(p) free(p)
/* malloc(3)/realloc(3) -> free(3) for use by mksh code */
#define malloc_osfunc(sz) malloc(sz)
#define realloc_osfunc(p,sz) realloc((p), (sz))
#define free_osfunc(p) free(p)
#if HAVE_MKNOD
/* setmode(3) -> free(3) */