Improve av_strerror() documentation
[libav.git] / libavutil / internal.h
CommitLineData
04d7f601
DB
1/*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
b78e7197
DB
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
04d7f601
DB
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
04d7f601 10 *
b78e7197 11 * FFmpeg is distributed in the hope that it will be useful,
04d7f601
DB
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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
b78e7197 17 * License along with FFmpeg; if not, write to the Free Software
04d7f601
DB
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
05020c89 21/**
ba87f080 22 * @file
89c9ff50 23 * common internal API header
05020c89
RD
24 */
25
98790382
SS
26#ifndef AVUTIL_INTERNAL_H
27#define AVUTIL_INTERNAL_H
05020c89 28
318049b8
MR
29#if !defined(DEBUG) && !defined(NDEBUG)
30# define NDEBUG
31#endif
32
ed0fd852 33#include <limits.h>
99545457 34#include <stdint.h>
318049b8
MR
35#include <stddef.h>
36#include <assert.h>
dbef3f46 37#include "config.h"
2ed6f399 38#include "attributes.h"
2f5421d5 39#include "timer.h"
99545457 40
5e4c7ca2 41#ifndef attribute_align_arg
06be9d9d 42#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,2)
5e4c7ca2
RP
43# define attribute_align_arg __attribute__((force_align_arg_pointer))
44#else
45# define attribute_align_arg
46#endif
47#endif
48
33586ee7
MN
49
50/**
49bd8e4b
MR
51 * Mark a variable as used and prevent the compiler from optimizing it away.
52 * This is useful for asm that accesses varibles in ways that the compiler does not
33586ee7
MN
53 * understand
54 */
5403f857 55#ifndef attribute_used
52476c1b 56#if AV_GCC_VERSION_AT_LEAST(3,1)
5403f857
MR
57# define attribute_used __attribute__((used))
58#else
59# define attribute_used
60#endif
61#endif
62
cd107896 63#ifndef INT16_MIN
ee155011 64#define INT16_MIN (-0x7fff - 1)
cd107896
MR
65#endif
66
67#ifndef INT16_MAX
68#define INT16_MAX 0x7fff
69#endif
70
71#ifndef INT32_MIN
ee155011 72#define INT32_MIN (-0x7fffffff - 1)
cd107896
MR
73#endif
74
75#ifndef INT32_MAX
76#define INT32_MAX 0x7fffffff
77#endif
78
79#ifndef UINT32_MAX
80#define UINT32_MAX 0xffffffff
81#endif
82
83#ifndef INT64_MIN
ee155011 84#define INT64_MIN (-0x7fffffffffffffffLL - 1)
cd107896
MR
85#endif
86
87#ifndef INT64_MAX
8da9266c 88#define INT64_MAX INT64_C(9223372036854775807)
cd107896
MR
89#endif
90
91#ifndef UINT64_MAX
8da9266c 92#define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF)
cd107896
MR
93#endif
94
95#ifndef INT_BIT
28499cc8 96# define INT_BIT (CHAR_BIT * sizeof(int))
cd107896
MR
97#endif
98
05020c89 99#ifndef offsetof
ee155011 100# define offsetof(T, F) ((unsigned int)((char *)&((T *)0)->F))
05020c89
RD
101#endif
102
7d9beec7
RP
103/* Use to export labels from asm. */
104#define LABEL_MANGLE(a) EXTERN_PREFIX #a
105
05020c89 106// Use rip-relative addressing if compiling PIC code on x86-64.
b250f9c6 107#if ARCH_X86_64 && defined(PIC)
df22c35d 108# define LOCAL_MANGLE(a) #a "(%%rip)"
edfd6975 109#else
df22c35d 110# define LOCAL_MANGLE(a) #a
635eb0cc 111#endif
05020c89 112
df22c35d
AS
113#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
114
05020c89
RD
115/* debug stuff */
116
05020c89 117/* dprintf macros */
635eb0cc 118#ifdef DEBUG
318c5e05 119# define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
635eb0cc 120#else
318c5e05 121# define dprintf(pctx, ...)
635eb0cc 122#endif
05020c89 123
635eb0cc 124#define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0)
05020c89 125
7e5f82dc
MR
126/* math */
127
b250f9c6 128#if ARCH_X86
05020c89 129#define MASK_ABS(mask, level)\
be449fca 130 __asm__ volatile(\
7e14b808 131 "cltd \n\t"\
05020c89
RD
132 "xorl %1, %0 \n\t"\
133 "subl %1, %0 \n\t"\
134 : "+a" (level), "=&d" (mask)\
135 );
136#else
137#define MASK_ABS(mask, level)\
ee155011
DB
138 mask = level >> 31;\
139 level = (level ^ mask) - mask;
05020c89
RD
140#endif
141
7d685b48 142/* avoid usage of dangerous/inappropriate system functions */
84662c01 143#undef malloc
05020c89 144#define malloc please_use_av_malloc
84662c01 145#undef free
05020c89 146#define free please_use_av_free
84662c01 147#undef realloc
05020c89 148#define realloc please_use_av_realloc
84662c01 149#undef time
05020c89 150#define time time_is_forbidden_due_to_security_issues
84662c01 151#undef rand
9f5da4d1 152#define rand rand_is_forbidden_due_to_state_trashing_use_av_lfg_get
84662c01 153#undef srand
9f5da4d1 154#define srand srand_is_forbidden_due_to_state_trashing_use_av_lfg_init
84662c01 155#undef random
9f5da4d1 156#define random random_is_forbidden_due_to_state_trashing_use_av_lfg_get
84662c01 157#undef sprintf
05020c89 158#define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf
84662c01 159#undef strcat
272605c7 160#define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat
84662c01 161#undef exit
c367d067 162#define exit exit_is_forbidden
6123abad 163#ifndef LIBAVFORMAT_BUILD
84662c01 164#undef printf
b58f29a1 165#define printf please_use_av_log_instead_of_printf
84662c01 166#undef fprintf
b58f29a1 167#define fprintf please_use_av_log_instead_of_fprintf
59ec6991 168#undef puts
b58f29a1 169#define puts please_use_av_log_instead_of_puts
c5a2fe8f
LA
170#undef perror
171#define perror please_use_av_log_instead_of_perror
05020c89
RD
172#endif
173
d31dbec3 174#define FF_ALLOC_OR_GOTO(ctx, p, size, label)\
e48a0966 175{\
ee155011
DB
176 p = av_malloc(size);\
177 if (p == NULL && (size) != 0) {\
d31dbec3
RP
178 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
179 goto label;\
e48a0966
RP
180 }\
181}
182
d31dbec3 183#define FF_ALLOCZ_OR_GOTO(ctx, p, size, label)\
05020c89 184{\
ee155011
DB
185 p = av_mallocz(size);\
186 if (p == NULL && (size) != 0) {\
d31dbec3
RP
187 av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
188 goto label;\
05020c89
RD
189 }\
190}
191
335ee1aa 192#include "libm.h"
7b04b8a0 193
d80a7fe5 194/**
49bd8e4b 195 * Return NULL if CONFIG_SMALL is true, otherwise the argument
bfe3676f 196 * without modification. Used to disable the definition of strings
d80a7fe5
AJ
197 * (for example AVCodec long_names).
198 */
199#if CONFIG_SMALL
200# define NULL_IF_CONFIG_SMALL(x) NULL
201#else
202# define NULL_IF_CONFIG_SMALL(x) x
203#endif
204
33586ee7
MN
205
206/**
207 * Create a non default alias for a function with specified version.
208 * This is needed when symbols are moved from a lib to a dependancy of the lib
209 * because the gnu linker as of 2010 is buggy and fails to dynamicaly link if a symbol
210 * is not found in the lib in which it was during link time with enabled versioning
211 * even if a correctly versioned and matching symbol exists in another lib and
212 * even if it did find that would it not contain an explicit check to fail
213 */
b462d132 214#if HAVE_SYMVER_ASM_LABEL
ccc87908
MR
215# define FF_SYMVER(type, name, args, ver) \
216 type ff_##name args __asm__ (EXTERN_PREFIX #name "@" ver); \
b462d132
MR
217 type ff_##name args
218#elif HAVE_SYMVER_GNU_ASM
ccc87908
MR
219# define FF_SYMVER(type, name, args, ver) \
220 __asm__ (".symver ff_" #name "," EXTERN_PREFIX #name "@" ver); \
221 type ff_##name args; \
b462d132
MR
222 type ff_##name args
223#endif
224
98790382 225#endif /* AVUTIL_INTERNAL_H */