xine-lib  1.2.9
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 # include "configure.h"
31 #else
32 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95 )
33 # define SUPPORT_ATTRIBUTE_PACKED 1
34 # endif
35 
36 # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 )
37 # define SUPPORT_ATTRIBUTE_DEPRECATED 1
38 # define SUPPORT_ATTRIBUTE_FORMAT 1
39 # define SUPPORT_ATTRIBUTE_FORMAT_ARG 1
40 # define SUPPORT_ATTRIBUTE_MALLOC 1
41 # define SUPPORT_ATTRIBUTE_UNUSED 1
42 # define SUPPORT_ATTRIBUTE_CONST 1
43 # define SUPPORT_ATTRIBUTE_WARN_UNUSED_RESULT 1
44 # endif
45 
46 # if __GNUC__ >= 4
47 # define SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT 1
48 # if defined(__ELF__) && __ELF__
49 # define SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED 1
50 # endif
51 # define SUPPORT_ATTRIBUTE_SENTINEL 1
52 # endif
53 #endif
54 
55 #if defined(SUPPORT_ATTRIBUTE_WARN_UNUSED_RESULT)
56 # define XINE_USED __attribute__((warn_unused_result))
57 #else
58 # define XINE_USED
59 #endif
60 
61 #ifdef ATTRIBUTE_ALIGNED_MAX
62 #define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
63 #else
64 #define ATTR_ALIGN(align)
65 #endif
66 
67 /* Export protected only for libxine functions */
68 #if defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_PROTECTED)
69 # define XINE_PROTECTED __attribute__((__visibility__("protected")))
70 #elif defined(XINE_LIBRARY_COMPILE) && defined(SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT)
71 # define XINE_PROTECTED __attribute__((__visibility__("default")))
72 #else
73 # define XINE_PROTECTED
74 #endif
75 
76 #ifdef SUPPORT_ATTRIBUTE_SENTINEL
77 # define XINE_SENTINEL __attribute__((__sentinel__))
78 #else
79 # define XINE_SENTINEL
80 #endif
81 
82 #if defined(SUPPORT_ATTRIBUTE_DEPRECATED) && (!defined(XINE_COMPILE) || defined(DEBUG))
83 # define XINE_DEPRECATED __attribute__((__deprecated__))
84 #else
85 # define XINE_DEPRECATED
86 #endif
87 
88 #ifdef SUPPORT_ATTRIBUTE_WEAK
89 # define XINE_WEAK __attribute__((weak))
90 #else
91 # define XINE_WEAK
92 #endif
93 
94 #ifndef __attr_unused
95 # ifdef SUPPORT_ATTRIBUTE_UNUSED
96 # define __attr_unused __attribute__((__unused__))
97 # else
98 # define __attr_unused
99 # endif
100 #endif
101 
102 /* Format attributes */
103 #ifdef SUPPORT_ATTRIBUTE_FORMAT
104 # define XINE_FORMAT_PRINTF(fmt,var) __attribute__((__format__(__printf__, fmt, var)))
105 # define XINE_FORMAT_SCANF(fmt,var) __attribute__((__format__(__scanf__, fmt, var)))
106 #else
107 # define XINE_FORMAT_PRINTF(fmt,var)
108 # define XINE_FORMAT_SCANF(fmt,var)
109 #endif
110 #ifdef SUPPORT_ATTRIBUTE_FORMAT_ARG
111 # define XINE_FORMAT_PRINTF_ARG(fmt) __attribute__((__format_arg__(fmt)))
112 #else
113 # define XINE_FORMAT_PRINTF_ARG(fmt)
114 #endif
115 
116 #ifdef SUPPORT_ATTRIBUTE_MALLOC
117 # define XINE_MALLOC __attribute__((__malloc__))
118 #else
119 # define XINE_MALLOC
120 #endif
121 
122 #ifdef SUPPORT_ATTRIBUTE_PACKED
123 # define XINE_PACKED __attribute__((__packed__))
124 #else
125 # define XINE_PACKED
126 #endif
127 
128 #ifdef SUPPORT_ATTRIBUTE_CONST
129 # define XINE_CONST __attribute__((__const__))
130 #else
131 # define XINE_CONST
132 #endif
133 
134 #endif /* ATTRIBUTE_H_ */