27 #define _XOPEN_SOURCE 600
46 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
47 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
48 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
49 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
50 #define free AV_JOIN(MALLOC_PREFIX, free)
52 void *malloc(
size_t size);
53 void *memalign(
size_t align,
size_t size);
54 int posix_memalign(
void **ptr,
size_t align,
size_t size);
55 void *realloc(
void *ptr,
size_t size);
60 #define ALIGN (HAVE_AVX ? 32 : 16)
76 #if CONFIG_MEMALIGN_HACK
84 #if CONFIG_MEMALIGN_HACK
85 ptr = malloc(size +
ALIGN);
88 diff = ((~(long)ptr)&(
ALIGN - 1)) + 1;
89 ptr = (
char *)ptr + diff;
90 ((
char *)ptr)[-1] = diff;
91 #elif HAVE_POSIX_MEMALIGN
93 if (posix_memalign(&ptr,
ALIGN, size))
95 #elif HAVE_ALIGNED_MALLOC
96 ptr = _aligned_malloc(size,
ALIGN);
99 ptr = memalign(
ALIGN, size);
101 ptr = memalign(size,
ALIGN);
134 #if CONFIG_MEMORY_POISONING
143 #if CONFIG_MEMALIGN_HACK
151 #if CONFIG_MEMALIGN_HACK
155 diff = ((
char *)ptr)[-1];
157 ptr = realloc((
char *)ptr - diff, size + diff);
159 ptr = (
char *)ptr + diff;
161 #elif HAVE_ALIGNED_MALLOC
162 return _aligned_realloc(ptr, size + !size,
ALIGN);
164 return realloc(ptr, size + !size);
205 if (!size || nmemb >= INT_MAX / size)
214 if (!*ptrptr && nmemb && size)
221 #if CONFIG_MEMALIGN_HACK
223 int v= ((
char *)ptr)[-1];
225 free((
char *)ptr - v);
227 #elif HAVE_ALIGNED_MALLOC
236 void **ptr = (
void **)arg;
245 memset(ptr, 0, size);
251 if (size <= 0 || nmemb >= INT_MAX / size)
260 int len = strlen(s) + 1;
274 memcpy(ptr, p, size);
286 tab = *(intptr_t**)tab_ptr;
287 if ((nb & (nb - 1)) == 0) {
291 if (nb > INT_MAX / (2 *
sizeof(intptr_t)))
295 tab =
av_realloc(tab, nb_alloc *
sizeof(intptr_t));
298 *(intptr_t**)tab_ptr = tab;
300 tab[nb++] = (intptr_t)elem;
312 int nb = *nb_ptr, nb_alloc;
315 if ((nb & (nb - 1)) == 0) {
319 if (nb > INT_MAX / (2 * elem_size))
329 tab_elem_data = tab + nb*elem_size;
331 memcpy(tab_elem_data, elem_data, elem_size);
334 return tab_elem_data;
364 uint32_t
a = v << 8 | v >> 16;
365 uint32_t
b = v << 16 | v >> 8;
366 uint32_t
c = v << 24 |
v;
369 uint32_t a = v | v << 24;
370 uint32_t b = v >> 8 | v << 16;
371 uint32_t c = v >> 16 | v << 8;
423 memset(dst, *src, cnt);
424 }
else if (back == 2) {
426 }
else if (back == 3) {
428 }
else if (back == 4) {
433 while (cnt > blocklen) {
434 memcpy(dst, src, blocklen);
439 memcpy(dst, src, cnt);
void * av_memdup(const void *p, size_t size)
Duplicate the buffer p.
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
void av_max_alloc(size_t max)
Set the maximum size that may me allocated in one block.
static void fill16(uint8_t *dst, int len)
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
simple assert() macros that are a bit more flexible than ISO C assert().
static void fill32(uint8_t *dst, int len)
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
void * av_realloc(void *ptr, size_t size) 1(2)
Allocate or reallocate a block of memory.
static int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
const AVS_VideoInfo int align
memory handling functions
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
Allocate or reallocate a block of memory.
#define CONFIG_MEMORY_POISONING
static size_t max_alloc_size
static void fill24(uint8_t *dst, int len)
static struct twinvq_data tab
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...