| 9 |
|
#define FBSIZE 72 /* size of malloc call */ |
| 10 |
|
|
| 11 |
|
|
| 12 |
– |
|
| 13 |
– |
|
| 14 |
– |
|
| 12 |
|
#include "meta.h" |
| 13 |
|
|
| 14 |
|
|
| 18 |
– |
|
| 19 |
– |
|
| 20 |
– |
|
| 15 |
|
extern int maxalloc; /* number of prims to allocate */ |
| 22 |
– |
|
| 16 |
|
int nalloc = 0; /* number allocated so far */ |
| 17 |
|
|
| 25 |
– |
|
| 26 |
– |
|
| 18 |
|
static PLIST freelist = {NULL, NULL}; |
| 19 |
|
|
| 20 |
|
|
| 21 |
+ |
static int morefree(void); |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
PRIMITIVE * |
| 25 |
< |
palloc() /* allocate a primitive */ |
| 25 |
> |
palloc(void) /* allocate a primitive */ |
| 26 |
|
|
| 27 |
|
{ |
| 28 |
< |
register PRIMITIVE *p; |
| 28 |
> |
register PRIMITIVE *p; |
| 29 |
|
|
| 30 |
< |
if (maxalloc > 0 && nalloc >= maxalloc) |
| 31 |
< |
return(NULL); |
| 30 |
> |
if (maxalloc > 0 && nalloc >= maxalloc) |
| 31 |
> |
return(NULL); |
| 32 |
|
|
| 33 |
< |
if ((p = pop(&freelist)) == NULL) |
| 34 |
< |
if (morefree()) |
| 35 |
< |
p = pop(&freelist); |
| 36 |
< |
else { |
| 37 |
< |
sprintf(errmsg, "out of memory in palloc (nalloc = %d)", nalloc); |
| 38 |
< |
error(SYSTEM, errmsg); |
| 39 |
< |
} |
| 33 |
> |
if ((p = pop(&freelist)) == NULL) { |
| 34 |
> |
if (morefree()) |
| 35 |
> |
p = pop(&freelist); |
| 36 |
> |
else { |
| 37 |
> |
sprintf(errmsg, "out of memory in palloc (nalloc = %d)", nalloc); |
| 38 |
> |
error(SYSTEM, errmsg); |
| 39 |
> |
} |
| 40 |
> |
} |
| 41 |
|
|
| 42 |
< |
nalloc++; |
| 43 |
< |
return(p); |
| 44 |
< |
} |
| 42 |
> |
nalloc++; |
| 43 |
> |
return(p); |
| 44 |
> |
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
< |
|
| 49 |
< |
|
| 50 |
< |
pfree(p) /* free a primitive */ |
| 51 |
< |
|
| 59 |
< |
register PRIMITIVE *p; |
| 60 |
< |
|
| 48 |
> |
void |
| 49 |
> |
pfree( /* free a primitive */ |
| 50 |
> |
register PRIMITIVE *p |
| 51 |
> |
) |
| 52 |
|
{ |
| 53 |
|
|
| 54 |
|
if (p->args != NULL) { |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
< |
|
| 66 |
< |
plfree(pl) /* free a primitive list */ |
| 67 |
< |
|
| 68 |
< |
register PLIST *pl; |
| 78 |
< |
|
| 65 |
> |
void |
| 66 |
> |
plfree( /* free a primitive list */ |
| 67 |
> |
register PLIST *pl |
| 68 |
> |
) |
| 69 |
|
{ |
| 70 |
|
register PRIMITIVE *p; |
| 71 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 97 |
– |
|
| 98 |
– |
|
| 87 |
|
static int |
| 88 |
< |
morefree() /* get more free space */ |
| 88 |
> |
morefree(void) /* get more free space */ |
| 89 |
|
|
| 90 |
|
{ |
| 91 |
|
register PRIMITIVE *p; |