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 "../share/alloc.h"
#include "cs.h" #include "cs.h"
occur_p newoccur(l1, l2, b) occur_p newoccur(line_p l1, line_p l2, bblock_p b)
line_p l1, l2;
bblock_p b;
{ {
/* Allocate a new struct occur and initialize it. */ /* Allocate a new struct occur and initialize it. */
register occur_p rop; occur_p rop;
rop = (occur_p) newcore(sizeof(struct occur)); rop = (occur_p) newcore(sizeof(struct occur));
rop->oc_lfirst = l1; rop->oc_llast = l2; rop->oc_belongs = b; rop->oc_lfirst = l1; rop->oc_llast = l2; rop->oc_belongs = b;
return rop; return rop;
} }
oldoccur(ocp) void oldoccur(occur_p ocp)
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)); return (avail_p) newcore(sizeof(struct avail));
} }
oldavail(avp) void oldavail(avail_p avp)
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)); return (entity_p) newcore(sizeof(struct entity));
} }
oldentity(enp) void oldentity(entity_p enp)
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. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright". * 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 * Returns a pointer to a new struct occur
* and initializes it. * and initializes it.
*/ */
extern oldoccur(); /* (occur_p ocp) void oldoccur(occur_p ocp); /*
* Release the struct occur ocp points to. * Release the struct occur ocp points to.
*/ */
extern avail_p newavail(); /* () avail_p newavail(void); /*
* Return a pointer to a new struct avail. * 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. * Release the struct avail avp points to.
*/ */
extern entity_p newentity(); /* () entity_p newentity(void); /*
* Return a pointer to a new struct entity. * 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. * Release the struct entity enp points to.
*/ */

View file

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