1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/* gc.h -- garbage collector interface for es ($Revision: 1.1.1.1 $) */
/* see also es.h for more generally applicable definitions */
/*
* tags
*/
struct Tag {
void *(*copy)(void *);
size_t (*scan)(void *);
#if ASSERTIONS || GCVERBOSE
long magic;
char *typename;
#endif
};
extern Tag StringTag;
#if ASSERTIONS || GCVERBOSE
enum {TAGMAGIC = 0xDefaced};
#define DefineTag(t, storage) \
static void *CONCAT(t,Copy)(void *); \
static size_t CONCAT(t,Scan)(void *); \
storage Tag CONCAT(t,Tag) = { CONCAT(t,Copy), CONCAT(t,Scan), TAGMAGIC, STRING(t) }
#else
#define DefineTag(t, storage) \
static void *CONCAT(t,Copy)(void *); \
static size_t CONCAT(t,Scan)(void *); \
storage Tag CONCAT(t,Tag) = { CONCAT(t,Copy), CONCAT(t,Scan) }
#endif
/*
* allocation
*/
extern void *gcalloc(size_t, Tag *);
typedef struct Buffer Buffer;
struct Buffer {
size_t len;
size_t current;
char str[1];
};
extern Buffer *openbuffer(size_t minsize);
extern Buffer *expandbuffer(Buffer *buf, size_t minsize);
extern Buffer *bufncat(Buffer *buf, const char *s, size_t len);
extern Buffer *bufcat(Buffer *buf, const char *s);
extern Buffer *bufputc(Buffer *buf, char c);
extern char *sealbuffer(Buffer *buf);
extern char *sealcountedbuffer(Buffer *buf);
extern void freebuffer(Buffer *buf);
extern void *forward(void *p);
|