Skip to content

Commit

Permalink
Add proper prototypes for alloc* functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bruceg committed Jun 14, 2010
1 parent 2df3a23 commit 0dd3a0c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
12 changes: 5 additions & 7 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ static aligned realspace[SPACE / ALIGNMENT];
#define space ((char *) realspace)
static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */

/*@null@*//*@out@*/char *alloc(n)
unsigned int n;
/*@null@*//*@out@*/void *alloc(unsigned int n)
{
char *x;
void *x;
n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
if (n <= avail) { avail -= n; return space + avail; }
x = malloc(n);
if (!x) errno = error_nomem;
return x;
}

void alloc_free(x)
char *x;
void alloc_free(void *x)
{
if (x >= space)
if (x < space + SPACE)
if (x >= (void*)space)
if (x < (void*)(space + SPACE))
return; /* XXX: assuming that pointers are flat */
free(x);
}
6 changes: 3 additions & 3 deletions alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#ifndef ALLOC_H
#define ALLOC_H

extern /*@null@*//*@out@*/char *alloc();
extern void alloc_free();
extern int alloc_re();
extern /*@null@*//*@out@*/void *alloc(unsigned int);
extern void alloc_free(void *);
extern int alloc_re(void **,unsigned int,unsigned int);

#endif
7 changes: 2 additions & 5 deletions alloc_re.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
#include "alloc.h"
#include "byte.h"

int alloc_re(x,m,n)
char **x;
unsigned int m;
unsigned int n;
int alloc_re(void **x,unsigned int m,unsigned int n)
{
char *y;
void *y;

y = alloc(n);
if (!y) return 0;
Expand Down
4 changes: 2 additions & 2 deletions gen_allocdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int ta_ready(register ta *x,register unsigned int n) \
i = x->a; \
if (n > i) { \
x->a = base + n + (n >> 3); \
if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
if (alloc_re((void**)&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
x->a = i; return 0; } \
return 1; } \
x->len = 0; \
Expand All @@ -23,7 +23,7 @@ int ta_rplus(register ta *x,register unsigned int n) \
i = x->a; n += x->len; \
if (n > i) { \
x->a = base + n + (n >> 3); \
if (alloc_re(&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
if (alloc_re((void**)&x->field,i * sizeof(type),x->a * sizeof(type))) return 1; \
x->a = i; return 0; } \
return 1; } \
x->len = 0; \
Expand Down

0 comments on commit 0dd3a0c

Please sign in to comment.