00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef AVUTIL_MEM_H
00027 #define AVUTIL_MEM_H
00028
00029 #include "attributes.h"
00030 #include "error.h"
00031 #include "avutil.h"
00032
00033 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00034 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00035 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
00036 #elif defined(__TI_COMPILER_VERSION__)
00037 #define DECLARE_ALIGNED(n,t,v) \
00038 AV_PRAGMA(DATA_ALIGN(v,n)) \
00039 t __attribute__((aligned(n))) v
00040 #define DECLARE_ASM_CONST(n,t,v) \
00041 AV_PRAGMA(DATA_ALIGN(v,n)) \
00042 static const t __attribute__((aligned(n))) v
00043 #elif defined(__GNUC__)
00044 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00045 #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
00046 #elif defined(_MSC_VER)
00047 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
00048 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
00049 #else
00050 #define DECLARE_ALIGNED(n,t,v) t v
00051 #define DECLARE_ASM_CONST(n,t,v) static const t v
00052 #endif
00053
00054 #if AV_GCC_VERSION_AT_LEAST(3,1)
00055 #define av_malloc_attrib __attribute__((__malloc__))
00056 #else
00057 #define av_malloc_attrib
00058 #endif
00059
00060 #if AV_GCC_VERSION_AT_LEAST(4,3)
00061 #define av_alloc_size(n) __attribute__((alloc_size(n)))
00062 #else
00063 #define av_alloc_size(n)
00064 #endif
00065
00066 #if LIBAVUTIL_VERSION_MAJOR < 51
00067 # define FF_INTERNAL_MEM_TYPE unsigned int
00068 # define FF_INTERNAL_MEM_TYPE_MAX_VALUE UINT_MAX
00069 #else
00070 # define FF_INTERNAL_MEM_TYPE size_t
00071 # define FF_INTERNAL_MEM_TYPE_MAX_VALUE SIZE_MAX
00072 #endif
00073
00082 void *av_malloc(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1);
00083
00096 void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size) av_alloc_size(2);
00097
00106 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00107
00116 void av_free(void *ptr);
00117
00126 void *av_mallocz(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1);
00127
00138 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00139
00146 char *av_strdup(const char *s) av_malloc_attrib;
00147
00155 void av_freep(void *ptr);
00156
00164 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00165
00170 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00171 {
00172 size_t t = a * b;
00173
00174
00175 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00176 return AVERROR(EINVAL);
00177 *r = t;
00178 return 0;
00179 }
00180
00181 #endif