mirror of
https://github.com/tildeclub/ex-vi.git
synced 2026-06-19 18:39:25 +00:00
* A new version of mapmalloc.c that is derived from Unix 7th Edition code
has been introduced.
This commit is contained in:
39
malloc.c
39
malloc.c
@@ -36,7 +36,7 @@
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @(#)malloc.c 1.17 (gritter) 11/26/04
|
||||
* @(#)malloc.c 1.18 (gritter) 2/18/05
|
||||
*/
|
||||
|
||||
#ifdef VMUNIX
|
||||
@@ -71,12 +71,18 @@ extern nl_catd catd;
|
||||
|
||||
#ifdef debug
|
||||
#define ASSERT(p) if(!(p))botch("p");else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
int
|
||||
botch(char *s)
|
||||
{
|
||||
printf("assertion botched: %s\n",s);
|
||||
const char msg[] = "assertion botched\n";
|
||||
write(2, msg, sizeof msg - 1);
|
||||
/*printf("assertion botched: %s\n",s);*/
|
||||
abort();
|
||||
}
|
||||
static int allock(void);
|
||||
#else
|
||||
#define ASSERT(p)
|
||||
#endif
|
||||
@@ -110,7 +116,7 @@ botch(char *s)
|
||||
#define NALIGN 1
|
||||
#define WORD sizeof (union store)
|
||||
#define BLOCK 1024 /* a multiple of WORD*/
|
||||
#define BUSY 1
|
||||
#define BUSY ((intptr_t)1)
|
||||
#ifdef NULL
|
||||
#undef NULL
|
||||
#endif
|
||||
@@ -142,7 +148,7 @@ poolsbrk(intptr_t inc)
|
||||
error(catgets(catd, 1, 241,
|
||||
"No memory pool"));
|
||||
if (inc == 0)
|
||||
return pool;
|
||||
return pool + ps;
|
||||
os = ps;
|
||||
ns = ps + inc;
|
||||
if (ns >= POOL)
|
||||
@@ -152,12 +158,12 @@ poolsbrk(intptr_t inc)
|
||||
return pool + os;
|
||||
}
|
||||
|
||||
char *
|
||||
void *
|
||||
malloc(size_t nbytes)
|
||||
{
|
||||
register union store *p, *q;
|
||||
register nw;
|
||||
static temp; /*coroutines assume no auto*/
|
||||
register int nw;
|
||||
static int temp; /*coroutines assume no auto*/
|
||||
|
||||
if(allocs[0].ptr==0) { /*first time*/
|
||||
allocs[0].ptr = setbusy(&allocs[1]);
|
||||
@@ -220,11 +226,13 @@ found:
|
||||
|
||||
/* freeing strategy tuned for LIFO allocation
|
||||
*/
|
||||
int
|
||||
free(register char *ap)
|
||||
void
|
||||
free(register void *ap)
|
||||
{
|
||||
register union store *p = (union store *)ap;
|
||||
|
||||
if (ap == NULL)
|
||||
return;
|
||||
ASSERT(p>clearbusy(allocs[1].ptr)&&p<=alloct);
|
||||
ASSERT(allock());
|
||||
allocp = --p;
|
||||
@@ -239,9 +247,10 @@ free(register char *ap)
|
||||
* returns new location, or 0 on failure
|
||||
*/
|
||||
|
||||
char *
|
||||
realloc(register union store *p, size_t nbytes)
|
||||
void *
|
||||
realloc(void *ap, size_t nbytes)
|
||||
{
|
||||
register union store *p = ap;
|
||||
register union store *q;
|
||||
union store *s, *t;
|
||||
register size_t nw;
|
||||
@@ -295,12 +304,12 @@ allock(void)
|
||||
*/
|
||||
#define CHARPERINT (sizeof(INT)/sizeof(char))
|
||||
|
||||
char *
|
||||
void *
|
||||
calloc(size_t num, size_t size)
|
||||
{
|
||||
register char *mp;
|
||||
register INT *q;
|
||||
register m;
|
||||
register int m;
|
||||
|
||||
num *= size;
|
||||
mp = malloc(num);
|
||||
@@ -313,14 +322,14 @@ calloc(size_t num, size_t size)
|
||||
return(mp);
|
||||
}
|
||||
|
||||
#ifdef notdef
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
void
|
||||
cfree(char *p, size_t num, size_t size)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
#ifdef notdef
|
||||
/*
|
||||
* Just in case ...
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user