1 /*
2  * allocator.h
3  *
4  * lispreader
5  *
6  * Copyright (C) 2004 Mark Probst
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
24 #ifndef __ALLOCATOR_H__
25 #define __ALLOCATOR_H__
26 
27 #include <stdlib.h>
28 
29 #include <pools.h>
30 
31 typedef struct
32 {
33     void* (*alloc) (void *allocator_data, size_t size);
34     void (*free) (void *allocator_data, void *chunk);
35     void *allocator_data;
36 } allocator_t;
37 
38 extern allocator_t malloc_allocator;
39 
40 void init_pools_allocator (allocator_t *allocator, pools_t *pools);
41 
42 #define allocator_alloc(a,s)      ((a)->alloc((a)->allocator_data, (s)))
43 #define allocator_free(a,c)       ((a)->free((a)->allocator_data, (c)))
44 
45 char* allocator_strdup (allocator_t *allocator, const char *str);
46 
47 #endif
48