123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #ifndef OBJALLOC_H
- #define OBJALLOC_H
- #include "ansidecl.h"
- struct objalloc
- {
- char *current_ptr;
- unsigned int current_space;
- void *chunks;
- };
- struct objalloc_align { char x; double d; };
- #if defined (__STDC__) && __STDC__
- #ifndef offsetof
- #include <stddef.h>
- #endif
- #endif
- #ifndef offsetof
- #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
- #endif
- #define OBJALLOC_ALIGN offsetof (struct objalloc_align, d)
- extern struct objalloc *objalloc_create (void);
- extern void *_objalloc_alloc (struct objalloc *, unsigned long);
- #if defined (__GNUC__) && defined (__STDC__) && __STDC__
- #if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
- #define __extension__
- #endif
- #define objalloc_alloc(o, l) \
- __extension__ \
- ({ struct objalloc *__o = (o); \
- unsigned long __len = (l); \
- if (__len == 0) \
- __len = 1; \
- __len = (__len + OBJALLOC_ALIGN - 1) &~ (OBJALLOC_ALIGN - 1); \
- (__len != 0 && __len <= __o->current_space \
- ? (__o->current_ptr += __len, \
- __o->current_space -= __len, \
- (void *) (__o->current_ptr - __len)) \
- : _objalloc_alloc (__o, __len)); })
- #else /* ! __GNUC__ */
- #define objalloc_alloc(o, l) _objalloc_alloc ((o), (l))
- #endif /* ! __GNUC__ */
- extern void objalloc_free (struct objalloc *);
- extern void objalloc_free_block (struct objalloc *, void *);
- #endif /* OBJALLOC_H */
|