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