lib/ewl_macros.h
Go to the documentation of this file.00001
00002 #ifndef EWL_MACROS_H
00003 #define EWL_MACROS_H
00004
00012 #undef NEW
00013
00017 #define NEW(type, num) calloc(num, sizeof(type))
00018
00019 #undef REALLOC
00020
00025 #define REALLOC(dat, type, num) dat = realloc(dat, sizeof(type) * (num))
00026
00027 #undef FREE
00028
00032 #define FREE(dat) \
00033 do { \
00034 free(dat); dat = NULL; \
00035 } while (0)
00036
00037
00038 #undef IF_FREE
00039
00043 #define IF_FREE(dat) \
00044 do { \
00045 if (dat) FREE(dat); \
00046 } while (0)
00047
00048 #undef IF_FREE_LIST
00049
00053 #define IF_FREE_LIST(list) \
00054 do { \
00055 if (list) { \
00056 ecore_list_destroy(list); \
00057 list = NULL; \
00058 } \
00059 } while (0)
00060
00061 #undef IF_FREE_HASH
00062
00066 #define IF_FREE_HASH(hash) \
00067 do { \
00068 if (hash) { \
00069 ecore_hash_destroy(hash); \
00070 hash = NULL; \
00071 } \
00072 } while (0)
00073
00074 #undef IF_RELEASE
00075
00079 #define IF_RELEASE(item) \
00080 do { \
00081 if (item) { \
00082 ecore_string_release(item); \
00083 item = NULL; \
00084 } \
00085 } while (0)
00086
00087 #undef ZERO
00088
00093 #define ZERO(ptr, type, num) ptr = memset(ptr, 0, sizeof(type) * (num))
00094
00095 #ifndef MIN
00096
00100 #define MIN(x, y) (((x) > (y)) ? (y) : (x))
00101 #endif
00102
00103 #ifndef MAX
00104
00108 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
00109 #endif
00110
00116 #ifdef EWL_ENABLE_DEBUG
00117 # define INTPTR_TO_INT(x) ewl_cast_pointer_to_integer(x)
00118 #else
00119 # define INTPTR_TO_INT(x) ((int)((long int)(x)))
00120 #endif
00121
00126 #define INT_TO_INTPTR(x) ((void *)((long int)(x)))
00127
00133 #ifdef EWL_ENABLE_DEBUG
00134 # define UINTPTR_TO_UINT(x) ((unsigned int) ewl_cast_pointer_to_integer(x))
00135 #else
00136 # define UINTPTR_TO_UINT(x) ((unsigned int)((unsigned long int)(x)))
00137 #endif
00138
00143 #define UINT_TO_UINTPTR(x) ((void *)((unsigned long int)(x)))
00144
00149 #define ARRAY_COUNT(x) (sizeof(x) / sizeof(*(x)))
00150
00155 #endif
00156