Commit 8ba5fec3 authored by Niels Möller's avatar Niels Möller
Browse files

Added alloc_method and marked variables to object headers.

Rev: src/lsh_types.h:1.13
Rev: src/xalloc.c:1.8
parent 3921af09
......@@ -86,11 +86,17 @@ do { \
/* Generic object */
#define LSH_ALLOC_HEAP 0
#define LSH_ALLOC_STATIC 1
#define LSH_ALLOC_STACK 2
#ifdef DEBUG_ALLOC
struct lsh_object
{
int size; /* Zero for objects that are not allocated on the heap. */
char alloc_method;
char marked;
};
struct lsh_string_header
......@@ -98,13 +104,20 @@ struct lsh_string_header
int magic;
};
#define STATIC_HEADER { 0 },
#define STATIC_HEADER { 0, LSH_ALLOC_STATIC, 0 },
#define STACK_HEADER { 0, LSH_ALLOC_STACK, 0 },
#else /* !DEBUG_ALLOC */
struct lsh_object {};
struct lsh_object
{
char alloc_method;
char marked;
};
struct lsh_string_header {};
#define STATIC_HEADER
#define STATIC_HEADER { LSH_ALLOC_STATIC, 0 },
#define STACK_HEADER { LSH_ALLOC_STACK, 0 },
#endif /* !DEBUG_ALLOC */
......
......@@ -111,11 +111,15 @@ void *lsh_object_alloc(size_t size)
#ifdef DEBUG_ALLOC
self->size = size;
#endif
self->alloc_method = LSH_ALLOC_HEAP;
self->marked = 0;
return (void *) self;
};
void lsh_object_free(void *p)
{
if ( ((struct lsh_object *) p)->alloc_method != LSH_ALLOC_HEAP)
fatal("lsh_object_free: Object not allocated on the heap!\n");
lsh_free(p);
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment