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);
332 else if (CONFIG_MEMORY_POISONING)
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);