27 #define _XOPEN_SOURCE 600
47 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
48 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
49 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
50 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
51 #define free AV_JOIN(MALLOC_PREFIX, free)
53 void *malloc(
size_t size);
54 void *memalign(
size_t align,
size_t size);
55 int posix_memalign(
void **ptr,
size_t align,
size_t size);
56 void *realloc(
void *ptr,
size_t size);
61 #define ALIGN (HAVE_AVX ? 32 : 16)
77 #if CONFIG_MEMALIGN_HACK
85 #if CONFIG_MEMALIGN_HACK
86 ptr = malloc(size +
ALIGN);
89 diff = ((~(long)ptr)&(
ALIGN - 1)) + 1;
90 ptr = (
char *)ptr + diff;
91 ((
char *)ptr)[-1] = diff;
92 #elif HAVE_POSIX_MEMALIGN
94 if (posix_memalign(&ptr,
ALIGN, size))
96 #elif HAVE_ALIGNED_MALLOC
97 ptr = _aligned_malloc(size,
ALIGN);
100 ptr = memalign(
ALIGN, size);
102 ptr = memalign(size,
ALIGN);
135 #if CONFIG_MEMORY_POISONING
144 #if CONFIG_MEMALIGN_HACK
152 #if CONFIG_MEMALIGN_HACK
156 diff = ((
char *)ptr)[-1];
158 ptr = realloc((
char *)ptr - diff, size + diff);
160 ptr = (
char *)ptr + diff;
162 #elif HAVE_ALIGNED_MALLOC
163 return _aligned_realloc(ptr, size + !size,
ALIGN);
165 return realloc(ptr, size + !size);
206 if (!size || nmemb >= INT_MAX / size)
215 if (!*ptrptr && nmemb && size)
222 #if CONFIG_MEMALIGN_HACK
224 int v= ((
char *)ptr)[-1];
226 free((
char *)ptr - v);
228 #elif HAVE_ALIGNED_MALLOC
237 void **ptr = (
void **)arg;
246 memset(ptr, 0, size);
261 int len = strlen(s) + 1;
275 memcpy(ptr, p, size);
287 tab = *(intptr_t**)tab_ptr;
288 if ((nb & (nb - 1)) == 0) {
292 if (nb > INT_MAX / (2 *
sizeof(intptr_t)))
296 tab =
av_realloc(tab, nb_alloc *
sizeof(intptr_t));
299 *(intptr_t**)tab_ptr = tab;
301 tab[nb++] = (intptr_t)elem;
313 int nb = *nb_ptr, nb_alloc;
316 if ((nb & (nb - 1)) == 0) {
320 if (nb > INT_MAX / (2 * elem_size))
330 tab_elem_data = tab + nb*elem_size;
332 memcpy(tab_elem_data, elem_data, elem_size);
333 else if (CONFIG_MEMORY_POISONING)
335 return tab_elem_data;
365 uint32_t
a = v << 8 | v >> 16;
366 uint32_t
b = v << 16 | v >> 8;
367 uint32_t
c = v << 24 |
v;
370 uint32_t a = v | v << 24;
371 uint32_t b = v >> 8 | v << 16;
372 uint32_t c = v >> 16 | v << 8;
424 memset(dst, *src, cnt);
425 }
else if (back == 2) {
427 }
else if (back == 3) {
429 }
else if (back == 4) {
434 while (cnt > blocklen) {
435 memcpy(dst, src, blocklen);
440 memcpy(dst, src, cnt);
469 if (min_size < *size)
472 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
489 if (min_size < *size)
491 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);