123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700 |
- #ifndef AVUTIL_MEM_H
- #define AVUTIL_MEM_H
- #include <limits.h>
- #include <stdint.h>
- #include "attributes.h"
- #include "error.h"
- #include "avutil.h"
- #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
- #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
- #define DECLARE_ASM_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
- #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
- #elif defined(__DJGPP__)
- #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (FFMIN(n, 16)))) v
- #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
- #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (FFMIN(n, 16)))) v
- #elif defined(__GNUC__) || defined(__clang__)
- #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
- #define DECLARE_ASM_ALIGNED(n,t,v) t av_used __attribute__ ((aligned (n))) v
- #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
- #elif defined(_MSC_VER)
- #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
- #define DECLARE_ASM_ALIGNED(n,t,v) __declspec(align(n)) t v
- #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
- #else
- #define DECLARE_ALIGNED(n,t,v) t v
- #define DECLARE_ASM_ALIGNED(n,t,v) t v
- #define DECLARE_ASM_CONST(n,t,v) static const t v
- #endif
- #if AV_GCC_VERSION_AT_LEAST(3,1)
- #define av_malloc_attrib __attribute__((__malloc__))
- #else
- #define av_malloc_attrib
- #endif
- #if AV_GCC_VERSION_AT_LEAST(4,3)
- #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
- #else
- #define av_alloc_size(...)
- #endif
- void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
- void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
- av_alloc_size(1, 2) void *av_malloc_array(size_t nmemb, size_t size);
- av_alloc_size(1, 2) void *av_mallocz_array(size_t nmemb, size_t size);
- void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
- void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
- av_warn_unused_result
- int av_reallocp(void *ptr, size_t size);
- void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
- av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
- int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
- void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
- void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
- void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
- void av_free(void *ptr);
- void av_freep(void *ptr);
- char *av_strdup(const char *s) av_malloc_attrib;
- char *av_strndup(const char *s, size_t len) av_malloc_attrib;
- void *av_memdup(const void *p, size_t size);
- void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
- void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
- av_warn_unused_result
- int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
- void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
- const uint8_t *elem_data);
- static inline int av_size_mult(size_t a, size_t b, size_t *r)
- {
- size_t t = a * b;
-
- if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
- return AVERROR(EINVAL);
- *r = t;
- return 0;
- }
- void av_max_alloc(size_t max);
- #endif
|