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 #include "config.h"
00029
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif
00033
00034 #define __ATTRIB __attribute__ ((unused)) static
00035
00036 #if !defined(HAVE_POSIX_MEMALIGN)
00037 # if defined (HAVE_MEMALIGN)
00038 extern int posix_memalign (void ** __memptr, size_t __alignment, size_t __size);
00039
00040 # endif
00041 #endif
00042
00043 #if defined(NDEBUG)
00044 void *sm_alloc (size_t s);
00045 void *sm_calloc (size_t n, size_t s);
00046 void *sm_realloc (void *p, size_t s);
00047 void *sm_reallocf (void *p, size_t s);
00048 int sm_memalign (void **p, size_t a, size_t s);
00049 void sm_free (void *p);
00050 #else
00051 void * __sm_alloc_dbg (size_t s, const char *f, size_t l);
00052 __ATTRIB void *sm_alloc (size_t s) { return __sm_alloc_dbg (s, __FUNCTION__, 0); }
00053
00054 void * __sm_calloc_dbg (size_t n, size_t s, const char *f, size_t l);
00055 __ATTRIB void *sm_calloc (size_t n, size_t s) { return __sm_calloc_dbg (n, s, __FUNCTION__, 0); }
00056
00057 void * __sm_realloc_dbg (void *p, size_t s, const char *f, size_t l);
00058 __ATTRIB void *sm_realloc (void *p, size_t s) { return __sm_realloc_dbg (p, s, __FUNCTION__, 0); }
00059
00060 void * __sm_reallocf_dbg (void *p, size_t s, const char *f, size_t l);
00061 __ATTRIB void *sm_reallocf (void *p, size_t s) { return __sm_reallocf_dbg (p, s, __FUNCTION__, 0); }
00062
00063 int __sm_memalign_dbg (void **p, size_t a, size_t s, const char *f, size_t l);
00064 __ATTRIB int __sm_memalign (void **p, size_t a, size_t s) { return __sm_memalign_dbg (p, a, s, __FUNCTION__, 0); }
00065
00066 void __sm_free_dbg (void *p, const char *f, size_t l);
00067 __ATTRIB void sm_free (void *p) { __sm_free_dbg (p, __FUNCTION__, 0); }
00068
00069 # define sm_alloc(s) __sm_alloc_dbg (s, __PRETTY_FUNCTION__, __LINE__)
00070 # define sm_calloc(n, s) __sm_calloc_dbg (n, s, __PRETTY_FUNCTION__, __LINE__)
00071 # define sm_realloc(p, s) __sm_realloc_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
00072 # define sm_reallocf(p, s) __sm_reallocf_dbg ((void *)(p), s, __PRETTY_FUNCTION__, __LINE__)
00073 # define sm_memalign(p, a, s) __sm_memalign_dbg (p, a, s, __PRETTY_FUNCTION__, __LINE__)
00074 # define sm_free(p) __sm_free_dbg ((void *)(p), __PRETTY_FUNCTION__, __LINE__)
00075 #endif
00076
00077 #define sm_talloc(T) ((T *) sm_alloc(sizeof(T)))
00078 #define sm_valloc(v) ((typeof(v) *) sm_alloc(sizeof v))
00079
00080 #include <assert.h>
00081 #ifndef _A
00082 # define _A(x) assert(x)
00083 #endif
00084
00085 #ifdef __cplusplus
00086 }
00087 #endif
00088
00089 #endif