00001 #pragma once
00002 #ifndef SM_ALLOC_H
00003 #define SM_ALLOC_H
00004
00005 #include <seap-debug.h>
00006
00007 #ifdef __cplusplus
00008 extern "C" {
00009 #endif
00010
00011 #undef __P
00012 #define __P __attribute__ ((unused)) static
00013
00014 #if defined(NDEBUG)
00015 void *sm_alloc (size_t s);
00016 void *sm_calloc (size_t n, size_t s);
00017 void *sm_realloc (void *p, size_t s);
00018 void *sm_reallocf (void *p, size_t s);
00019 int sm_memalign (void **p, size_t a, size_t s);
00020 void sm_free (void *p);
00021 #else
00022 void * __sm_alloc_dbg (size_t s, const char *f, size_t l);
00023 __P void *sm_alloc (size_t s) { return __sm_alloc_dbg (s, __FUNCTION__, 0); }
00024
00025 void * __sm_calloc_dbg (size_t n, size_t s, const char *f, size_t l);
00026 __P void *sm_calloc (size_t n, size_t s) { return __sm_calloc_dbg (n, s, __FUNCTION__, 0); }
00027
00028 void * __sm_realloc_dbg (void *p, size_t s, const char *f, size_t l);
00029 __P void *sm_realloc (void *p, size_t s) { return __sm_realloc_dbg (p, s, __FUNCTION__, 0); }
00030
00031 void * __sm_reallocf_dbg (void *p, size_t s, const char *f, size_t l);
00032 __P void *sm_reallocf (void *p, size_t s) { return __sm_reallocf_dbg (p, s, __FUNCTION__, 0); }
00033
00034 int __sm_memalign_dbg (void **p, size_t a, size_t s, const char *f, size_t l);
00035 __P int __sm_memalign (void **p, size_t a, size_t s) { return __sm_memalign_dbg (p, a, s, __FUNCTION__, 0); }
00036
00037 void __sm_free_dbg (void *p, const char *f, size_t l);
00038 __P void sm_free (void *p) { __sm_free_dbg (p, __FUNCTION__, 0); }
00039
00040 # define sm_alloc(s) __sm_alloc_dbg (s, __PRETTY_FUNCTION__, __LINE__)
00041 # define sm_calloc(n, s) __sm_calloc_dbg (n, s, __PRETTY_FUNCTION__, __LINE__)
00042 # define sm_realloc(p, s) __sm_realloc_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
00043 # define sm_reallocf(p, s) __sm_reallocf_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
00044 # define sm_memalign(p, a, s) __sm_memalign_dbg (p, a, s, __PRETTY_FUNCTION__, __LINE__)
00045 # define sm_free(p) __sm_free_dbg ((void *)(p), __PRETTY_FUNCTION__, __LINE__)
00046 #endif
00047
00048 #define sm_talloc(T) ((T *) sm_alloc(sizeof(T)))
00049 #define sm_valloc(v) ((typeof(v) *) sm_alloc(sizeof v))
00050
00051 #include <assert.h>
00052 #ifndef _A
00053 # define _A(x) assert(x)
00054 #endif
00055
00056 #ifdef __cplusplus
00057 }
00058 #endif
00059
00060 #endif