diff --git a/configure.ac b/configure.ac
index 0066dbf..957e958 100644
a
|
b
|
dnl Keep this check close to the beginning, so that the users |
25 | 25 | dnl without any glib won't have their time wasted by other checks. |
26 | 26 | dnl |
27 | 27 | |
| 28 | AC_DEFINE(WITH_GLIB, 1, [Use Glib functions]) |
| 29 | |
| 30 | dnl TODO: make option --with-glib like this: |
| 31 | dnl |
| 32 | dnl AC_ARG_WITH(glib, |
| 33 | dnl [AS_HELP_STRING([--with-glib], [Use glib (default is yes)])], |
| 34 | dnl [with_glib=$enableval], |
| 35 | dnl [with_glib=yes]) |
| 36 | dnl |
| 37 | dnl if test x${with_glib} = xyes; then |
| 38 | dnl dnl some checking stuff |
| 39 | dnl AC_DEFINE(WITH_GLIB, 1, [Use Glib functions]) |
| 40 | dnl fi |
| 41 | |
| 42 | |
28 | 43 | AC_ARG_WITH(glib12, |
29 | 44 | [ --with-glib12 Force using glib 1.2.x [[no]]]) |
30 | 45 | |
diff --git a/mhl/memory.h b/mhl/memory.h
index b006177..20db6c0 100644
a
|
b
|
|
1 | 1 | #ifndef __MHL_MEM |
2 | 2 | #define __MHL_MEM |
3 | 3 | |
| 4 | #if defined _AIX && !defined REGEX_MALLOC |
| 5 | #pragma alloca |
| 6 | #endif |
| 7 | |
| 8 | #include <config.h> |
4 | 9 | #include <memory.h> |
5 | 10 | #include <stdlib.h> |
6 | 11 | |
7 | | /* allocate a chunk of stack memory, uninitialized */ |
8 | | #define mhl_mem_alloc_u(sz) (malloc(sz)) |
| 12 | #ifdef __GNUC__ |
| 13 | # define alloca __builtin_alloca |
| 14 | #else |
| 15 | # ifdef _MSC_VER |
| 16 | # include <malloc.h> |
| 17 | # define alloca _alloca |
| 18 | # else |
| 19 | # if HAVE_ALLOCA_H |
| 20 | # include <alloca.h> |
| 21 | # else |
| 22 | # ifdef _AIX |
| 23 | #pragma alloca |
| 24 | # else |
| 25 | # ifndef alloca /* predefined by HP cc +Olibcalls */ |
| 26 | char *alloca (); |
| 27 | # endif |
| 28 | # endif |
| 29 | # endif |
| 30 | # endif |
| 31 | #endif |
| 32 | |
| 33 | #ifndef HAVE_ALLOCA |
| 34 | # include <stdlib.h> |
| 35 | # if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H) |
| 36 | # include <malloc.h> |
| 37 | # endif |
| 38 | # define alloca malloc |
| 39 | #endif |
| 40 | |
| 41 | #ifdef WITH_GLIB |
| 42 | # include <glib.h> |
| 43 | |
| 44 | # if GLIB_MAJOR_VERSION >= 2 |
| 45 | /* allocate a chunk of stack memory, uninitialized */ |
| 46 | # define mhl_mem_alloc_u(sz) (g_try_malloc(sz)) |
| 47 | |
| 48 | /* allocate a chunk of stack memory, zeroed */ |
| 49 | # define mhl_mem_alloc_z(sz) (g_try_malloc0(sz)) |
| 50 | |
| 51 | /* re-alloc memory chunk */ |
| 52 | # define mhl_mem_realloc(ptr,sz) (g_try_realloc(ptr,sz)) |
| 53 | |
| 54 | # else |
| 55 | |
| 56 | /* allocate a chunk of stack memory, uninitialized */ |
| 57 | # define mhl_mem_alloc_u(sz) (g_malloc(sz)) |
| 58 | |
| 59 | /* allocate a chunk of stack memory, zeroed */ |
| 60 | # define mhl_mem_alloc_z(sz) (g_malloc0(sz)) |
9 | 61 | |
10 | | /* allocate a chunk of stack memory, zeroed */ |
11 | | #define mhl_mem_alloc_z(sz) (calloc(1,sz)) |
| 62 | /* re-alloc memory chunk */ |
| 63 | # define mhl_mem_realloc(ptr,sz) (g_realloc(ptr,sz)) |
| 64 | |
| 65 | # endif |
| 66 | |
| 67 | /* allocate a chunk on stack - automatically free'd on function exit */ |
| 68 | # define mhl_stack_alloc(sz) (g_alloca(sz)) |
| 69 | |
| 70 | #else |
| 71 | |
| 72 | /* allocate a chunk of stack memory, uninitialized */ |
| 73 | # define mhl_mem_alloc_u(sz) (malloc(sz)) |
| 74 | |
| 75 | /* allocate a chunk of stack memory, zeroed */ |
| 76 | # define mhl_mem_alloc_z(sz) (calloc(1,sz)) |
| 77 | |
| 78 | /* re-alloc memory chunk */ |
| 79 | # define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz)) |
| 80 | |
| 81 | /* allocate a chunk on stack - automatically free'd on function exit */ |
| 82 | # define mhl_stack_alloc(sz) (alloca(sz)) |
| 83 | |
| 84 | #endif |
12 | 85 | |
13 | 86 | /* free a chunk of memory from stack, passing NULL does no harm */ |
14 | 87 | static inline void mhl_mem_free(void* ptr) |
15 | 88 | { |
16 | | if (ptr) free(ptr); |
| 89 | if (ptr) |
| 90 | #ifdef WITH_GLIB |
| 91 | g_free(ptr); |
| 92 | #else |
| 93 | free(ptr); |
| 94 | #endif |
17 | 95 | } |
18 | 96 | |
19 | 97 | /* free an ptr and NULL it */ |
20 | 98 | #define MHL_PTR_FREE(ptr) do { mhl_mem_free(ptr); (ptr) = NULL; } while (0); |
21 | 99 | |
22 | | /* allocate a chunk on stack - automatically free'd on function exit */ |
23 | | #define mhl_stack_alloc(sz) (alloca(sz)) |
24 | | |
25 | | /* re-alloc memory chunk */ |
26 | | #define mhl_mem_realloc(ptr,sz) (realloc(ptr,sz)) |
27 | | |
28 | 100 | #endif |