Use size_t and void with memory allocation in ego.

alloc.h now needs to #include <stdlib.h> to find type size_t and
function free().
This commit is contained in:
George Koehler 2017-11-14 20:35:18 -05:00
parent 87a2315037
commit 5bbbaf4919
4 changed files with 83 additions and 86 deletions

View file

@ -8,43 +8,38 @@
#include "../share/alloc.h"
#include "cs.h"
occur_p newoccur(l1, l2, b)
line_p l1, l2;
bblock_p b;
occur_p newoccur(line_p l1, line_p l2, bblock_p b)
{
/* Allocate a new struct occur and initialize it. */
register occur_p rop;
occur_p rop;
rop = (occur_p) newcore(sizeof(struct occur));
rop->oc_lfirst = l1; rop->oc_llast = l2; rop->oc_belongs = b;
return rop;
}
oldoccur(ocp)
occur_p ocp;
void oldoccur(occur_p ocp)
{
oldcore((char *) ocp, sizeof(struct occur));
oldcore(ocp, sizeof(struct occur));
}
avail_p newavail()
avail_p newavail(void)
{
return (avail_p) newcore(sizeof(struct avail));
}
oldavail(avp)
avail_p avp;
void oldavail(avail_p avp)
{
oldcore((char *) avp, sizeof(struct avail));
oldcore(avp, sizeof(struct avail));
}
entity_p newentity()
entity_p newentity(void)
{
return (entity_p) newcore(sizeof(struct entity));
}
oldentity(enp)
entity_p enp;
void oldentity(entity_p enp)
{
oldcore((char *) enp, sizeof(struct entity));
oldcore(enp, sizeof(struct entity));
}

View file

@ -3,27 +3,28 @@
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
extern occur_p newoccur(); /* (line_p l1, l2; bblock_p b)
occur_p newoccur(line_p l1, line_p l2, bblock_p b);
/*
* Returns a pointer to a new struct occur
* and initializes it.
*/
extern oldoccur(); /* (occur_p ocp)
void oldoccur(occur_p ocp); /*
* Release the struct occur ocp points to.
*/
extern avail_p newavail(); /* ()
avail_p newavail(void); /*
* Return a pointer to a new struct avail.
*/
extern oldavail(); /* (avail_p avp)
void oldavail(avail_p avp); /*
* Release the struct avail avp points to.
*/
extern entity_p newentity(); /* ()
entity_p newentity(void); /*
* Return a pointer to a new struct entity.
*/
extern oldentity(); /* (entity_p enp)
void ldentity(entity_p enp); /*
* Release the struct entity enp points to.
*/

View file

@ -17,28 +17,25 @@
#include "alloc.h"
char * myalloc();
void *myalloc(size_t);
#ifdef DEBUG
STATIC unsigned maxuse, curruse;
STATIC size_t maxuse, curruse;
char *newcore(size)
int size;
void *newcore(size_t size)
{
if ((curruse += (unsigned) (size+2)) > maxuse) maxuse = curruse;
if ((curruse += (size+2)) > maxuse) maxuse = curruse;
return myalloc(size);
}
oldcore(p,size)
char *p;
int size;
void oldcore(void *p, size_t size)
{
curruse -= (size+2);
free(p);
}
coreusage()
void coreusage(void)
{
fprintf(stderr,"Maximal core usage (excl. buffers):%u\n",maxuse);
}
@ -115,33 +112,33 @@ int asizetab[] = {
* PART 1
*/
line_p newline(optyp) int optyp; {
register line_p lnp;
register kind=optyp;
line_p newline(byte optyp) {
line_p lnp;
int kind=optyp;
lnp = (line_p) newcore(lsizetab[kind]);
TYPE(lnp) = optyp;
return(lnp);
}
oldline(lnp) register line_p lnp; {
register kind=TYPE(lnp)&BMASK;
void oldline(line_p lnp) {
int kind=TYPE(lnp)&BMASK;
if (kind == OPLIST)
oldargs(ARG(lnp));
oldcore((char *) lnp,lsizetab[kind]);
oldcore(lnp, lsizetab[kind]);
}
arg_p newarg(kind) int kind; {
register arg_p ap;
arg_p newarg(byte kind) {
arg_p ap;
ap = (arg_p) newcore(asizetab[kind]);
ap->a_type = kind;
return(ap);
}
oldargs(ap) register arg_p ap; {
register arg_p next;
void oldargs(arg_p ap) {
arg_p next;
while (ap != (arg_p) 0) {
next = ap->a_next;
@ -155,49 +152,49 @@ oldargs(ap) register arg_p ap; {
oldargb(ap->a_a.a_con.ac_con.ab_next);
break;
}
oldcore((char *) ap,asizetab[ap->a_type]);
oldcore(ap, asizetab[ap->a_type]);
ap = next;
}
}
oldargb(abp) register argb_p abp; {
register argb_p next;
void oldargb(argb_p abp) {
argb_p next;
while (abp != (argb_p) 0) {
next = abp->ab_next;
oldcore((char *) abp,sizeof (argb_t));
oldcore(abp, sizeof (argb_t));
abp = next;
}
}
oldobjects(op) register obj_p op; {
register obj_p next;
void oldobjects(obj_p op) {
obj_p next;
while (op != (obj_p) 0) {
next = op->o_next;
oldcore((char *) op, sizeof(struct obj));
oldcore(op, sizeof(struct obj));
op = next;
}
}
olddblock(dbl) dblock_p dbl; {
void olddblock(dblock_p dbl) {
oldobjects(dbl->d_objlist);
oldargs(dbl->d_values);
oldcore((char *) dbl, sizeof(struct dblock));
oldcore(dbl, sizeof(struct dblock));
}
short **newmap(length) short length; {
short **newmap(short length) {
return((short **) newcore((length+1) * sizeof(short *)));
}
/*ARGSUSED1*/
oldmap(mp,length) short **mp, length; {
oldcore((char *) mp, (length+1) * sizeof(short *));
void oldmap(short **mp, short length) {
oldcore(mp, (length+1) * sizeof(short *));
}
cset newbitvect(n) short n; {
cset newbitvect(short n) {
return((cset) newcore((n-1)*sizeof(int) + sizeof(struct bitvector)));
/* sizeof(struct bitvector) equals to the size of a struct with
* one short, followed by one ALLIGNED int. So the above statement
@ -206,38 +203,39 @@ cset newbitvect(n) short n; {
}
/*ARGSUSED1*/
oldbitvect(s,n) cset s; short n; {
oldcore((char *) s, (n-1)*sizeof(int) + sizeof(struct bitvector));
void oldbitvect(cset s, short n) {
oldcore(s, (n-1)*sizeof(int) + sizeof(struct bitvector));
}
short *newtable(length) short length; {
short *newtable(short length) {
return((short *) newcore((length+1) * sizeof(short)));
}
/*ARGSUSED1*/
oldtable(mp,length) short **mp, length; {
oldcore((char *) mp, (length+1) * sizeof(short));
void oldtable(short **mp, short length) {
oldcore(mp, (length+1) * sizeof(short));
}
cond_p newcondtab(l) int l;
cond_p newcondtab(int l)
{
return (cond_p) newcore(l * (sizeof (struct cond_tab)));
}
oldcondtab(tab) cond_p tab;
void oldcondtab(cond_p tab)
{
int i;
for (i = 0; tab[i].mc_cond != DEFAULT; i++);
oldcore((char *) tab,((i+1) * sizeof (struct cond_tab)));
for (i = 0; tab[i].mc_cond != DEFAULT; i++)
continue;
oldcore(tab, ((i+1) * sizeof (struct cond_tab)));
}
char *myalloc(size) register size; {
register char *p;
void *myalloc(size_t size) {
void *p;
p = calloc((unsigned) size, 1);
if (p == 0)
if (p == NULL)
error("out of memory");
return(p);
}

View file

@ -8,36 +8,39 @@
* C O R E A L L O C A T I O N A N D D E A L L O C A T I O N
*/
#include <stdlib.h>
#ifdef DEBUG
extern char *newcore();
extern oldcore();
void *newcore(size_t);
void oldcore(void *, size_t);
void coreusage(void);
#else
extern char *myalloc();
void *myalloc(size_t);
#define newcore(size) myalloc(size)
#define oldcore(p,size) free((char *)p)
#define oldcore(p,size) free(p)
#endif
#define newstruct(t) ((struct t *) newcore (sizeof (struct t)))
#define oldstruct(t,p) oldcore((char *) p,sizeof (struct t))
#define newstruct(t) ((struct t *) newcore(sizeof (struct t)))
#define oldstruct(t,p) oldcore(p, sizeof (struct t))
extern line_p newline(); /* (byte optype) */
extern arg_p newarg(); /* (byte argtype) */
extern short **newmap(); /* (short length) */
extern cset newbitvect(); /* (short nrbytes) */
extern cond_p newcondtab();
line_p newline(byte optype);
arg_p newarg(byte argtyp);
short **newmap(short length);
cset newbitvect(short nrbytes);
cond_p newcondtab(int length);
extern oldline() ;
extern oldargs() ;
extern oldargb() ;
extern oldobjects() ;
extern olddblock() ;
extern oldmap();
extern oldbitvect(); /* (cset s, short nrbytes) */
extern oldcondtab();
void oldline(line_p);
void oldargs(arg_p);
void oldargb(argb_p);
void oldobjects(obj_p);
void olddblock(dblock_p);
void oldmap(short **mp, short length);
void oldbitvect(cset s, short nrbytes);
void oldcondtab(cond_p);
extern short *newtable();
extern oldtable();
short *newtable(short length);
void oldtable(short **mp, short length);
#define newdblock() (dblock_p) newstruct(dblock)
#define newobject() (obj_p) newstruct(obj)