xine-lib 1.2.11
attributes.h
Go to the documentation of this file.
1/*
2 * attributes.h
3 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4 * Copyright (C) 2001-2008 xine developers
5 *
6 * This file was originally part of mpeg2dec, a free MPEG-2 video stream
7 * decoder.
8 *
9 * mpeg2dec is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * mpeg2dec is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
22 */
23
24/* use gcc attribs to align critical data structures */
25
26#ifndef ATTRIBUTE_H_
27#define ATTRIBUTE_H_
28
29#ifdef XINE_COMPILE
30# if defined(HAVE_CONFIG_H) && !defined(__XINE_LIB_CONFIG_H__)
31# error config.h not included in source file !
32# endif
33#else
34# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95 )
35# define SUPPORT_ATTRIBUTE_PACKED 1
36# endif
37
38# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 )
39# define SUPPORT_ATTRIBUTE_DEPRECATED 1
40# define SUPPORT_ATTRIBUTE_FORMAT 1
41# define SUPPORT_ATTRIBUTE_FORMAT_ARG 1
42# define SUPPORT_ATTRIBUTE_MALLOC 1
43# define SUPPORT_ATTRIBUTE_UNUSED 1
44# define SUPPORT_ATTRIBUTE_CONST 1
45# define SUPPORT_ATTRIBUTE_WARN_UNUSED_RESULT 1
46# endif
47
48# if __GNUC__ >= 4
49# define SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT 1
50# if defined(__ELF__) && __ELF__
51# define SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED 1
52# endif
53# define SUPPORT_ATTRIBUTE_SENTINEL 1
54# endif
55#endif
56
57#if defined(SUPPORT_ATTRIBUTE_WARN_UNUSED_RESULT)
58# define XINE_USED __attribute__((warn_unused_result))
59#else
60# define XINE_USED
61#endif
62
63#ifdef ATTRIBUTE_ALIGNED_MAX
64#define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
65#else
66#define ATTR_ALIGN(align)
67#endif
68
69/* Export protected only for libxine functions */
70#if defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED)
71# define XINE_PROTECTED __attribute__((__visibility__("protected")))
72#elif defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT)
73# define XINE_PROTECTED __attribute__((__visibility__("default")))
74#else
75# define XINE_PROTECTED
76#endif
77
78#ifdef SUPPORT_ATTRIBUTE_SENTINEL
79# define XINE_SENTINEL __attribute__((__sentinel__))
80#else
81# define XINE_SENTINEL
82#endif
83
84#if defined(SUPPORT_ATTRIBUTE_DEPRECATED) && (!defined(XINE_COMPILE) || defined(DEBUG))
85# define XINE_DEPRECATED __attribute__((__deprecated__))
86#else
87# define XINE_DEPRECATED
88#endif
89
90#if defined(SUPPORT_ATTRIBUTE_DEPRECATED) && (!defined(XINE_LIBRARY_COMPILE)) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5 ))
91# define XINE_PRIVATE_FIELD __attribute__((__deprecated__("this is xine-engine private field")))
92#elif defined(SUPPORT_ATTRIBUTE_DEPRECATED) && (!defined(XINE_LIBRARY_COMPILE))
93# define XINE_PRIVATE_FIELD __attribute__((__deprecated__))
94#else
95# define XINE_PRIVATE_FIELD
96#endif
97
98#ifdef SUPPORT_ATTRIBUTE_WEAK
99# define XINE_WEAK __attribute__((weak))
100#else
101# define XINE_WEAK
102#endif
103
104#ifndef __attr_unused
105# ifdef SUPPORT_ATTRIBUTE_UNUSED
106# define __attr_unused __attribute__((__unused__))
107# else
108# define __attr_unused
109# endif
110#endif
111
112/* Format attributes */
113#ifdef SUPPORT_ATTRIBUTE_FORMAT
114# if defined(__MINGW32__)
115# if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO
116# ifndef __MINGW_PRINTF_FORMAT
117# define __MINGW_PRINTF_FORMAT gnu_printf
118# endif
119# endif
120# ifndef __MINGW_PRINTF_FORMAT
121# define __MINGW_PRINTF_FORMAT __printf__
122# endif
123# define XINE_FORMAT_PRINTF(fmt,var) __attribute__((__format__(__MINGW_PRINTF_FORMAT, fmt, var)))
124# else
125# define XINE_FORMAT_PRINTF(fmt,var) __attribute__((__format__(__printf__, fmt, var)))
126# endif
127# define XINE_FORMAT_SCANF(fmt,var) __attribute__((__format__(__scanf__, fmt, var)))
128#else
129# define XINE_FORMAT_PRINTF(fmt,var)
130# define XINE_FORMAT_SCANF(fmt,var)
131#endif
132#ifdef SUPPORT_ATTRIBUTE_FORMAT_ARG
133# define XINE_FORMAT_PRINTF_ARG(fmt) __attribute__((__format_arg__(fmt)))
134#else
135# define XINE_FORMAT_PRINTF_ARG(fmt)
136#endif
137
138#ifdef SUPPORT_ATTRIBUTE_MALLOC
139# define XINE_MALLOC __attribute__((__malloc__))
140#else
141# define XINE_MALLOC
142#endif
143
144#ifdef SUPPORT_ATTRIBUTE_PACKED
145# define XINE_PACKED __attribute__((__packed__))
146#else
147# define XINE_PACKED
148#endif
149
150#ifdef SUPPORT_ATTRIBUTE_CONST
151# define XINE_CONST __attribute__((__const__))
152#else
153# define XINE_CONST
154#endif
155
156#endif /* ATTRIBUTE_H_ */