2 * Copyright (c) 2002 Fabrice Bellard
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVUTIL_MEM_INTERNAL_H
22 #define AVUTIL_MEM_INTERNAL_H
31 // Some broken preprocessors need a second expansion
32 // to be forced to tokenize __VA_ARGS__
35 #define LOCAL_ALIGNED_A(a, t, v, s, o, ...) \
36 uint8_t la_##v[sizeof(t s o) + (a)]; \
37 t (*v) o = (void *)FFALIGN((uintptr_t)la_##v, a)
39 #define LOCAL_ALIGNED_D(a, t, v, s, o, ...) \
40 DECLARE_ALIGNED(a, t, la_##v) s o; \
43 #define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
45 #if HAVE_LOCAL_ALIGNED
46 # define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
48 # define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_A(4, t, v, __VA_ARGS__,,))
51 #if HAVE_LOCAL_ALIGNED
52 # define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
54 # define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_A(8, t, v, __VA_ARGS__,,))
57 #if HAVE_LOCAL_ALIGNED
58 # define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
60 # define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_A(16, t, v, __VA_ARGS__,,))
63 #if HAVE_LOCAL_ALIGNED
64 # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
66 # define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_A(32, t, v, __VA_ARGS__,,))
69 static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
73 memcpy(&val, ptr, sizeof(val));
74 if (min_size <= *size) {
75 av_assert0(val || !min_size);
78 min_size = FFMAX(min_size + min_size / 16 + 32, min_size);
80 val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
81 memcpy(ptr, &val, sizeof(val));
87 #endif /* AVUTIL_MEM_INTERNAL_H */