summaryrefslogtreecommitdiff
path: root/magick/common.h
blob: 377d728b08fbb5b9f172459fbf5688a9bca601a3 (plain)
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
  Copyright (C) 2009-2022 GraphicsMagick Group

  This program is covered by multiple licenses, which are described in
  Copyright.txt. You should have received a copy of Copyright.txt with this
  package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.

  Magick API common definitions support.
*/
#ifndef _MAGICK_COMMON_H
#define _MAGICK_COMMON_H

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

/*
 * Borland C++ Builder DLL compilation defines
 */
#if defined(__BORLANDC__) && defined(_DLL)
#  pragma message("BCBMagick lib DLL export interface")
#  define _MAGICKDLL_
#  define _MAGICKLIB_
#  undef BuildMagickModules
#  define SupportMagickModules
#endif

#if defined(MSWINDOWS) && !defined(__CYGWIN__)
#  if defined(_MT) && defined(_DLL) && !defined(_MAGICKDLL_) && !defined(_LIB)
#    define _MAGICKDLL_
#  endif
#  if defined(_MAGICKDLL_)
#    if defined(_VISUALC_)
#      pragma warning( disable: 4273 )  /* Disable the dll linkage warnings */
#    endif
#    if !defined(_MAGICKLIB_)
#      define MagickExport  __declspec(dllimport)
#      if defined(_VISUALC_)
#        pragma message( "Magick lib DLL import interface" )
#      endif
#    else
#      define MagickExport  __declspec(dllexport)
#      if defined(_VISUALC_)
#         pragma message( "Magick lib DLL export interface" )
#      endif
#    endif
#  else
#    define MagickExport
#    if defined(_VISUALC_)
#      pragma message( "Magick lib static interface" )
#    endif
#  endif
#  if defined(_DLL) && !defined(_LIB)
#    define ModuleExport  __declspec(dllexport)
#    if defined(_VISUALC_)
#      pragma message( "Magick module DLL export interface" )
#    endif
#  else
#    define ModuleExport
#    if defined(_VISUALC_)
#      pragma message( "Magick module static interface" )
#    endif
#  endif
#  define MagickGlobal __declspec(thread)
#  if defined(_VISUALC_)
#    pragma warning(disable : 4018)
#    pragma warning(disable : 4244)
#    pragma warning(disable : 4244)
#    pragma warning(disable : 4275) /* non dll-interface class 'foo' used as base for dll-interface class 'bar' */
#    pragma warning(disable : 4800)
#    pragma warning(disable : 4786)
#    pragma warning(disable : 4996) /* function deprecation warnings */
#  endif
#else
#  define MagickExport
#  define ModuleExport
#  define MagickGlobal
#endif

/*
  This size is the default minimum string allocation size (heap or
  stack) for a C string in GraphicsMagick.  The weird size is claimed
  to be based on 2*FILENAME_MAX (not including terminating NULL) on
  some antique system.  Linux has a FILENAME_MAX definition, but it is
  4096 bytes.  Many OSs have path limits of 1024 bytes.

  The FormatString() function assumes that the buffer it is writing to
  has at least this many bytes remaining.
*/
#if !defined(MaxTextExtent)
#  define MaxTextExtent  2053
#endif

#define MagickSignature  0xabacadabUL

#define MagickPassFail unsigned int
#define MagickPass     1
#define MagickFail     0

#define MagickBool     unsigned int
#define MagickTrue     1
#define MagickFalse    0

/*
  Support for __attribute__ was added in GCC 2.0.  It is not supported
  in strict ANSI mode which is indicated by __STRICT_ANSI__ being
  defined.

  http://www.ohse.de/uwe/articles/gcc-attributes.html

  Note that GCC 3.2 on MinGW does not define __GNUC__ or __GNUC_MINOR__.

  Clang/llvm and GCC 5.0 support __has_attribute(attribute) to test if an
  attribute is supported.  Clang/llvm supports __has_builtin(builtin) to test
  if a builtin is supported.  Clang/llvm attempts to support most GCC
  features.

   __SANITIZE_ADDRESS__ is defined by GCC and Clang if -fsanitize=address is
   supplied.

   After incuding valgrind/memcheck.h or valgrind/valgrind.h, the macro
   RUNNING_ON_VALGRIND can be used to test if the program is run under valgrind.
   See http://valgrind.org/docs/manual/manual-core-adv.html.

*/
#if !defined(MAGICK_ATTRIBUTE)
#  if ((!defined(__clang__)) && (!defined(__GNUC__) || (__GNUC__ < 2 || __STRICT_ANSI__)))
#    define MAGICK_ATTRIBUTE(x) /*nothing*/
#  else
#    define MAGICK_ATTRIBUTE(x) __attribute__(x)
#    if ((defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 5)) && !defined(__COVERITY__))
#      define MAGICK_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
#    else
#      define MAGICK_HAS_ATTRIBUTE(attribute) (0)
#    endif
#    if (defined(__clang__) && !defined(__COVERITY__))
#      define MAGICK_CLANG_HAS_BUILTIN(builtin) __has_builtin(builtin)
#    else
#      define MAGICK_CLANG_HAS_BUILTIN(builtin) (0)
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__deprecated__)) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))) /* 3.1+ */
#      define MAGICK_FUNC_DEPRECATED MAGICK_ATTRIBUTE((__deprecated__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__malloc__)) || \
         (__GNUC__ >= 3))  /* 3.0+ */
#      define MAGICK_FUNC_MALLOC MAGICK_ATTRIBUTE((__malloc__))
#      if (__GNUC__ >= 11) /* Clang 15 does not support extended malloc attributes */
/* #        warning "Using extended malloc attribute!" */
#        define MAGICK_FUNC_MALLOC_1ARG(deallocator) MAGICK_ATTRIBUTE((__malloc__,__malloc__(deallocator)))
#        define MAGICK_FUNC_MALLOC_2ARG(deallocator, ptrindex) MAGICK_ATTRIBUTE((__malloc__,__malloc__(deallocator,ptrindex)))
#      else
#        define MAGICK_FUNC_MALLOC_1ARG(deallocator) MAGICK_ATTRIBUTE((__malloc__))
#        define MAGICK_FUNC_MALLOC_2ARG(deallocator, ptrindex) MAGICK_ATTRIBUTE((__malloc__))
#      endif
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__nonnull__)) || \
         (((__GNUC__) >= 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))))  /* 3.3+ */
  /* Supports argument syntax like MAGICK_ATTRIBUTE((nonnull (1, 2))) but
     don't know how to support non-GCC fallback. */
#      define MAGICK_FUNC_NONNULL MAGICK_ATTRIBUTE((__nonnull__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__noreturn__)) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))) /* 2.5+ */
#      define MAGICK_FUNC_NORETURN MAGICK_ATTRIBUTE((__noreturn__))
#    endif
  /* clang 3.0 seems to have difficulties with __has_attribute(__const__) but
     clang 3.3 does not.  Just assume that it is supported for clang since
     Linux headers are riddled with it. */
#    if (defined(__clang__) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))) /* 2.5+ */
#      define MAGICK_FUNC_CONST MAGICK_ATTRIBUTE((__const__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__pure__)) || \
         ((__GNUC__) >= 3)) /* 2.96+ */
#      define MAGICK_FUNC_PURE MAGICK_ATTRIBUTE((__pure__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__unused__)) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 7)))) /* 2.7+ */
#      define MAGICK_FUNC_UNUSED MAGICK_ATTRIBUTE((__unused__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__warn_unused_result__)) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))))  /* 3.3+ */
#      define MAGICK_FUNC_WARN_UNUSED_RESULT MAGICK_ATTRIBUTE((__warn_unused_result__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__noinline__)) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))  /* 3.4+ */
#      define MAGICK_FUNC_NOINLINE MAGICK_ATTRIBUTE((__noinline__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__always_inline__)) || \
         (((__GNUC__) > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4))))  /* 3.4+ */
#      define MAGICK_FUNC_ALWAYSINLINE MAGICK_ATTRIBUTE((__always_inline__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__alloc_size__)) || \
         (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))))  /* 4.3+ */
#      define MAGICK_FUNC_ALLOC_SIZE_1ARG(arg_num) MAGICK_ATTRIBUTE((__alloc_size__(arg_num)))
#      define MAGICK_FUNC_ALLOC_SIZE_2ARG(arg_num1,arg_num2) MAGICK_ATTRIBUTE((__alloc_size__(arg_num1,arg_num2)))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__hot__)) || \
         (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))))  /* 4.3+ */
#      define MAGICK_FUNC_HOT MAGICK_ATTRIBUTE((__hot__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__cold__)) || \
         (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))))  /* 4.3+ */
#      define MAGICK_FUNC_COLD MAGICK_ATTRIBUTE((__cold__))
#    endif
#    if ((MAGICK_HAS_ATTRIBUTE(__optimize__)) || \
         (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))))  /* 4.3+ */
#      define MAGICK_OPTIMIZE_FUNC(opt) MAGICK_ATTRIBUTE((__optimize__ (opt)))
#    endif
  /*
    GCC 7 and later support a fallthrough attribute to mark switch statement
    cases which are intended to fall through.  Clang 3.5.0 supports a
    clang::fallthrough statement attribute while Clang 10 supports the same
    attribute as GCC 7.  Some compilers support a FALLTHROUGH (or FALLTHRU)
    pre-processor comment.  C++ 17 supports a standard fallthrough attribute
    of the form "[[fallthrough]]".  See
    https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/,
    https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html,
    https://clang.llvm.org/docs/AttributeReference.html#fallthrough, and
    https://releases.llvm.org/3.7.0/tools/clang/docs/AttributeReference.html#fallthrough-clang-fallthrough

    Usage is to put "MAGICK_FALLTHROUGH;" where a "break;" would go.
  */
#    if ((MAGICK_HAS_ATTRIBUTE(__fallthrough__)) || \
         ((__GNUC__) >= 7))  /* 7+ */
#      define MAGICK_FALLTHROUGH MAGICK_ATTRIBUTE((__fallthrough__))
#    endif
  /*
    https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer#Introduction

    To ignore certain functions, one can use the no_sanitize_address attribute
    supported by Clang (3.3+) and GCC (4.8+).
  */
#    if ((MAGICK_HAS_ATTRIBUTE(__no_sanitize_address__)) ||       \
         (((__GNUC__) > 4) || ((__GNUC__ == 8) && (__GNUC_MINOR__ >= 0))))  /* 4.8+ */
#      define MAGICK_NO_SANITIZE_ADDRESS MAGICK_ATTRIBUTE((__no_sanitize_address__))
#    endif
#    if ((MAGICK_CLANG_HAS_BUILTIN(__builtin_assume_aligned)) || \
         (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))))  /* 4.7+ */
#      define MAGICK_ASSUME_ALIGNED(exp,align) __builtin_assume_aligned(exp,align)
#    endif
#    if ((MAGICK_CLANG_HAS_BUILTIN(__builtin_assume_aligned)) || \
         (((__GNUC__) > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))))  /* 4.7+ */
#      define MAGICK_ASSUME_ALIGNED_OFFSET(exp,align,offset) __builtin_assume_aligned(exp,align,offset)
#    endif
#  endif
#endif
#if !defined(MAGICK_FUNC_DEPRECATED)
#  define MAGICK_FUNC_DEPRECATED /*nothing*/
#endif
#if !defined(MAGICK_FUNC_MALLOC)
#  define MAGICK_FUNC_MALLOC /*nothing*/
#endif
#if !defined(MAGICK_FUNC_MALLOC_1ARG)
#  define MAGICK_FUNC_MALLOC_1ARG(deallocator) /*nothing*/
#endif
#if !defined(MAGICK_FUNC_MALLOC_2ARG)
#  define MAGICK_FUNC_MALLOC_2ARG(deallocator,ptrindex) /*nothing*/
#endif
#if !defined (MAGICK_FUNC_NONNULL)
#  define MAGICK_FUNC_NONNULL /*nothing*/
#endif
#if !defined (MAGICK_FUNC_NORETURN)
#  define MAGICK_FUNC_NORETURN /*nothing*/
#endif
#if !defined (MAGICK_FUNC_CONST)
#  define MAGICK_FUNC_CONST /*nothing*/
#endif
#if !defined (MAGICK_FUNC_PURE)
#  define MAGICK_FUNC_PURE /*nothing*/
#endif
#if !defined (MAGICK_FUNC_UNUSED)
#  define MAGICK_FUNC_UNUSED /*nothing*/
#endif
#if !defined(MAGICK_FUNC_WARN_UNUSED_RESULT)
#  define MAGICK_FUNC_WARN_UNUSED_RESULT /*nothing*/
#endif
#if !defined(MAGICK_FUNC_NOINLINE)
#  define MAGICK_FUNC_NOINLINE /*nothing*/
#endif
#if !defined(MAGICK_FUNC_ALWAYSINLINE)
#  define MAGICK_FUNC_ALWAYSINLINE /*nothing*/
#endif
#if !defined(MAGICK_FUNC_ALLOC_SIZE_1ARG)
#  define MAGICK_FUNC_ALLOC_SIZE_1ARG(arg_num) /*nothing*/
#endif
#if !defined(MAGICK_FUNC_ALLOC_SIZE_2ARG)
#  define MAGICK_FUNC_ALLOC_SIZE_2ARG(arg_num1,arg_num2) /*nothing*/
#endif
#if !defined(MAGICK_FUNC_HOT)
#  define MAGICK_FUNC_HOT  /*nothing*/
#endif
#if !defined(MAGICK_FUNC_COLD)
#  define MAGICK_FUNC_COLD  /*nothing*/
#endif
#if !defined(MAGICK_OPTIMIZE_FUNC)
#  define MAGICK_OPTIMIZE_FUNC(opt) /*nothing*/
#endif
#if !defined(MAGICK_FALLTHROUGH)
#  define MAGICK_FALLTHROUGH /*nothing*/
#endif
#if !defined(MAGICK_ASSUME_ALIGNED)
#  define MAGICK_ASSUME_ALIGNED(exp,align) (exp)
#endif
#if !defined(MAGICK_ASSUME_ALIGNED_OFFSET)
#  define MAGICK_ASSUME_ALIGNED_OFFSET(exp,align,offset) (exp)
#endif

  /*
    The isnan and isinf macros are defined by c99 but might not always be
    available.  If they (or a substitute) are not available, then define them
    to a false value.
  */
#if defined(isnan)
#define MAGICK_ISNAN(d) isnan(d)
#else
#define MAGICK_ISNAN(d) (0)
#endif
#if defined(isinf)
#define MAGICK_ISINF(d) isinf(d)
#else
#define MAGICK_ISINF(d) (0)
#endif
#if defined(isnormal)
#define MAGICK_ISNORMAL(d) isnormal(d)
#else
#define MAGICK_ISNORMAL(d) (1)
#endif

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif /* _MAGICK_COMMON_H */

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 2
 * fill-column: 78
 * End:
 */