Commit 3566689a authored by Niels Möller's avatar Niels Möller
Browse files

Some cleanup.

(lsh_space_alloc, lsh_space_free, lsh_space_realloc): Don't use
these wrapper functions in the !DEBUG_ALLOC case, instead, use
xalloc, free and xrealloc directly using some preprocessor
hacks.

Rev: src/xalloc.c:1.37
Rev: src/xalloc.h:1.34
parent 34446bc8
......@@ -37,9 +37,6 @@
#if DEBUG_ALLOC
#define lsh_free debug_free
#define lsh_malloc debug_malloc
/* There are two sets of allocation functions: Low level allocation *
* that can allocate memory for any purpose, and object allocators
* that assume that the allocated object begins with a type field. */
......@@ -49,7 +46,7 @@
/* NOTE: The code breaks horribly if UNIT is of the wrong size. But it
* doesn't matter much if we guess wrong on some platforms, as this
* affects only optionalal debug code. */
* affects only optional debug code. */
#define UNIT unsigned long
......@@ -125,9 +122,18 @@ debug_realloc(void *m, size_t real_size)
return res;
}
}
}
#else /* !DEBUG_ALLOC */
#endif /* DEBUG_ALLOC */
/* Simple hack to make xalloc and xrealloc accessible, under different
official names, to avoid trivial wrapper functions for
lsh_space_(re)alloc. */
#define xalloc lsh_space_alloc
#define xrealloc lsh_space_realloc
#define static
#endif /* !DEBUG_ALLOC */
static void *xalloc(size_t size)
{
......@@ -269,9 +275,7 @@ lsh_object_check_subtype(struct lsh_class *class,
fatal("lsh_object_check_subtype: Type error, expected %z, got %z!\n",
class->name, instance->isa->name);
}
#endif /* DEBUG_ALLOC */
#if DEBUG_ALLOC
void *lsh_space_alloc(size_t size)
{
UNIT *p = xalloc(size + sizeof(UNIT));
......@@ -315,22 +319,4 @@ void *lsh_space_realloc(void *p, size_t size)
return m + 1;
}
}
#else /* !DEBUG_ALLOC */
/* FIXME: Why not use macros for this? */
void *lsh_space_alloc(size_t size)
{
return xalloc(size);
}
void lsh_space_free(const void *p)
{
lsh_free(p);
}
void *lsh_space_realloc(void *p, size_t size)
{
return xrealloc(p, size);
}
#endif /* !DEBUG_ALLOC */
#endif /* DEBUG_ALLOC */
......@@ -30,30 +30,6 @@
/* Allocation */
#if DEBUG_ALLOC
#define lsh_free debug_free
#define lsh_malloc debug_malloc
#define lsh_realloc debug_realloc
void *
debug_malloc(size_t real_size);
void *
debug_realloc(void *m, size_t real_size);
void
debug_free(const void *m);
#else /* !DEBUG_ALLOC */
/* ANSI-C free doesn't allow const pointers to be freed. (That is one
* of the few things that C++ gets right). */
#define lsh_free(p) free((void *) (p))
#define lsh_malloc malloc
#define lsh_realloc realloc
#endif /* !DEBUG_ALLOC */
struct lsh_object *
lsh_var_alloc(struct lsh_class *class,
size_t extra);
......@@ -78,6 +54,18 @@ void *lsh_space_realloc(void *p, size_t size);
void lsh_space_free(const void *p);
#if DEBUG_ALLOC
#define lsh_free debug_free
#define lsh_malloc debug_malloc
#define lsh_realloc debug_realloc
void *
debug_malloc(size_t real_size);
void *
debug_realloc(void *m, size_t real_size);
void
debug_free(const void *m);
struct lsh_object *lsh_object_check(struct lsh_class *class,
struct lsh_object *instance);
......@@ -97,6 +85,14 @@ struct lsh_object *lsh_object_check_subtype(struct lsh_class *class,
#else /* !DEBUG_ALLOC */
/* ANSI-C free doesn't allow const pointers to be freed. (That is one
* of the few things that C++ gets right). */
#define lsh_free(p) free((void *) (p))
#define lsh_malloc malloc
#define lsh_realloc realloc
#define lsh_space_free free
#define CHECK_TYPE(c, o) ((struct lsh_object *)(o))
#define CHECK_SUBTYPE(c, o) ((struct lsh_object *)(o))
......@@ -104,7 +100,6 @@ struct lsh_object *lsh_object_check_subtype(struct lsh_class *class,
struct class *(var) = (struct class *) (o)
#define CAST_SUBTYPE(class, var, o) CAST(class, var, o)
#endif /* !DEBUG_ALLOC */
......
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