}
/*
- * Implements allocator_t's free_pointer allocate.
+ * Implements allocator_t's free_pointer function.
* See #allocator_s.free_pointer for description.
*/
static void free_pointer(allocator_t *allocator, void * pointer)
}
/*
- * Implements allocator_t's reallocate allocate.
+ * Implements allocator_t's reallocate function.
* See #allocator_s.reallocate for description.
*/
static void * reallocate(allocator_t *allocator, void * old, size_t bytes, char * file,int line)
return new_space;
}
+/*
+ * Implements allocator_t's clone_bytes function.
+ * See #allocator_s.clone_bytes for description.
+ */
static void * clone_bytes(allocator_t *allocator,void * to_clone, size_t bytes, char * file, int line)
{
private_allocator_t *this = (private_allocator_t *) allocator;
{
return NULL;
}
+
void *new_space = this->allocate_special(this,bytes,file,line,TRUE);
mutex: PTHREAD_MUTEX_INITIALIZER
};
+allocator_t *global_allocator = &(allocator.public);
+#else /* !LEAK_DETECTION */
+
+
+chunk_t allocator_alloc_as_chunk(size_t bytes)
+{
+ chunk_t new_chunk;
+ new_chunk.ptr = malloc(bytes);
+ new_chunk.len = (new_chunk.ptr == NULL) ? 0 : bytes;
+ return new_chunk;
+
+}
+
+void * allocator_clone_bytes(void * pointer, size_t size)
+{
+ void *data;
+ data = malloc(size);
+ if (data == NULL){ return NULL;}
+ memcpy(data,pointer,size);
+ return (data);
+}
+
+
+void allocator_free_chunk(chunk_t chunk)
+{
+ free(chunk.ptr);
+}
+
+
+#endif /* LEAK_DETECTION */
-allocator_t *global_allocator = &(allocator.public);
-#endif
#include <stdlib.h>
#include <stddef.h>
+#include <string.h>
#include "types.h"
#define report_memory_leaks(void) (global_allocator->report_memory_leaks(global_allocator))
#else
#define allocator_alloc(bytes) (malloc(bytes))
- #define allocator_alloc_as_chunk(bytes){\
- chunk_t new_chunk; \
- new_chunk.ptr = malloc(bytes); \
- new_chunk.len = (new_chunk.ptr == NULL) ? 0 : bytes; \
- return new_chunk; \
- }
+
+ chunk_t allocator_alloc_as_chunk(size_t bytes);
+
#define allocator_realloc(old,bytes) (realloc(old,bytes))
#define allocator_free(pointer) (free(pointer))
- #define allocator_clone_bytes(pointer,size){\
- void *new_data = malloc(size)\
- if (new_data == NULL) return NULL; \
- memcpy(new_data,pointer,size)\
- return new_data; \
- }
- #define allocator_free_chunk(chunk){ \
- free(chunk.ptr); \
- chunk.ptr = NULL; \
- chunk.len = 0; \
- }
+ void * allocator_clone_bytes(void * pointer, size_t size);
+ void allocator_free_chunk(chunk_t chunk);
#define report_memory_leaks(void) {}
#endif