File: cpl_macros.h

package info (click to toggle)
cpl 7.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 14,808 kB
  • sloc: ansic: 132,627; javascript: 6,382; sh: 4,232; makefile: 637
file content (200 lines) | stat: -rw-r--r-- 5,995 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 * This file is part of the ESO Common Pipeline Library
 * Copyright (C) 2001-2017 European Southern Observatory
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * This file must not include any other file than cxmacros.h
 */

#ifndef CPL_MACROS_H
#define CPL_MACROS_H

#include <cxmacros.h>

/*
 * C code guard
 */

#undef CPL_BEGIN_DECLS
#undef CPL_END_DECLS

#define CPL_BEGIN_DECLS  CX_BEGIN_DECLS
#define CPL_END_DECLS    CX_END_DECLS


/*
 * Macro to silence compiler warnings on unused arguments
 * and variables. Active by default, but can be turned off
 * for debug builds using CPL_WITH_UNUSED_WARNINGS.
 */

#ifdef CPL_UNUSED_WARNINGS
#  define CPL_UNUSED(arg)
#else
#  define CPL_UNUSED(arg) (void)(arg)
#endif


/* Needed to concatenate two and three macro arguments */
#define CPL_CONCAT(a,b) a ## _ ## b
#define CPL_CONCAT2X(a,b) CPL_CONCAT(a,b)
#define CPL_CONCAT3X(a,b,c) CPL_CONCAT2X(CPL_CONCAT2X(a,b),c)

#define CPL_XSTRINGIFY(TOSTRING) #TOSTRING
#define CPL_STRINGIFY(TOSTRING) CPL_XSTRINGIFY(TOSTRING)

/*

  (Try to) determine support for the function __attribute__

  These attributes are used in CPL (from the given gcc version)

   2.3  format (used only from gcc 3)
   2.5  const  (used only from gcc 3)
   2.96 pure   (used only from gcc 3)
   3.0  malloc
   3.1  deprecated
   3.3  nonnull
   3.4  warn_unused_result
   4.3  alloc_size

 */

#if defined __GNUC__ && __GNUC__ > 2
   /* gcc 3 or higher */

#  define CPL_ATTR_CONST       __attribute__((const))
#  define CPL_ATTR_PRINTF(A,B) __attribute__((format (printf, A, B)))
#  define CPL_ATTR_PURE        __attribute__((pure))

#  if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 0
     /* gcc 3.1 or higher */
#    define CPL_ATTR_DEPRECATED __attribute__((deprecated))
#  endif

#  if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 2
     /* gcc 3.3 or higher */
#    define CPL_ATTR_NONNULL __attribute__((nonnull))
#    define CPL_HAVE_ATTR_NONNULL
#    define CPL_UNLIKELY(x)     __builtin_expect((x), 0)
#    define CPL_LIKELY(x)       __builtin_expect((x), 1)
#    define CPL_ATTR_NOINLINE   __attribute__((noinline))
#  endif

#  if __GNUC__ > 3 || defined __GNUC_MINOR__ && __GNUC_MINOR__ > 3
     /* gcc 3.4 or higher */
#    define CPL_ATTR_ALLOC   __attribute__((malloc, warn_unused_result))

#    if __GNUC__ > 4 || __GNUC__ == 4 && defined __GNUC_MINOR__ && __GNUC_MINOR__ > 2
       /* gcc 4.3 or higher */

#      define CPL_ATTR_MALLOC                                           \
         __attribute__((malloc, warn_unused_result, alloc_size(1)))
#      define CPL_ATTR_CALLOC                                           \
         __attribute__((malloc, warn_unused_result, alloc_size(1,2)))
#      define CPL_ATTR_REALLOC                                          \
         __attribute__((warn_unused_result, alloc_size(2)))
#    else
       /* gcc 3.4 to 4.2 */
#      define CPL_ATTR_MALLOC  __attribute__((malloc, warn_unused_result))
#      define CPL_ATTR_CALLOC  __attribute__((malloc, warn_unused_result))
#      define CPL_ATTR_REALLOC __attribute__((warn_unused_result))
#    endif

#  else
     /* gcc 3.0 to 3.3 */

#    define CPL_ATTR_ALLOC   __attribute__((malloc))
#    define CPL_ATTR_MALLOC  __attribute__((malloc))
#    define CPL_ATTR_CALLOC  __attribute__((malloc))
#    define CPL_ATTR_REALLOC  /* __attribute__ */
#  endif

#  if __GNUC__ >= 4
#    define CPL_INTERNAL  __attribute__((visibility("hidden")))
#    define CPL_EXPORT    __attribute__((visibility("default")))
#  endif
#endif

#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#define CPL_DIAG_PRAGMA_PUSH_IGN(x)                             \
    _Pragma("GCC diagnostic push")                              \
    _Pragma(CPL_STRINGIFY(GCC diagnostic ignored #x))
#define CPL_DIAG_PRAGMA_PUSH_ERR(x)                             \
    _Pragma("GCC diagnostic push")                              \
    _Pragma(CPL_STRINGIFY(GCC diagnostic error #x))
#define CPL_DIAG_PRAGMA_POP                     \
    _Pragma("GCC diagnostic pop")
#else
#define CPL_DIAG_PRAGMA_PUSH_IGN(x) /* pragma GCC diagnostic ignored */
#define CPL_DIAG_PRAGMA_PUSH_ERR(x) /* pragma GCC diagnostic error   */
#define CPL_DIAG_PRAGMA_POP         /* pragma GCC diagnostic pop     */
#endif


#ifndef CPL_ATTR_ALLOC
#  define CPL_ATTR_ALLOC /* __attribute__ */
#endif

#ifndef CPL_ATTR_CALLOC
#  define CPL_ATTR_CALLOC /*__attribute__ */
#endif

#ifndef CPL_ATTR_CONST
#  define CPL_ATTR_CONST /* __attribute__ */
#endif

#ifndef CPL_ATTR_DEPRECATED
#  define CPL_ATTR_DEPRECATED /* __attribute__ */
#endif

#ifndef CPL_ATTR_PURE
#  define CPL_ATTR_PURE /* __attribute__ */
#endif

#ifndef CPL_ATTR_MALLOC
#  define CPL_ATTR_MALLOC /* __attribute__ */
#endif

#ifndef CPL_ATTR_NONNULL
#  define CPL_ATTR_NONNULL /* __attribute__ */
#endif

#ifndef CPL_ATTR_PRINTF
#  define CPL_ATTR_PRINTF(A,B) /* __attribute__ */
#endif

#ifndef CPL_ATTR_REALLOC
#  define CPL_ATTR_REALLOC /* __attribute__ */
#endif

#ifndef CPL_UNLIKELY
#    define CPL_UNLIKELY(x) (x)
#    define CPL_LIKELY(x)   (x)
#endif

#ifndef CPL_ATTR_NOINLINE
#    define CPL_ATTR_NOINLINE /* __attribute__ */
#endif

#ifndef CPL_INTERNAL
#    define CPL_INTERNAL /* __attribute__ */
#    define CPL_EXPORT   /* __attribute__ */
#endif

#endif /* CPL_MACROS_H */