sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
compiler-macros.h
Go to the documentation of this file.
1
/****************************************************************************
2
*
3
* internal/compiler-macros.h
4
*
5
* Compiler-specific macro definitions used internally by FreeType.
6
*
7
* Copyright (C) 2020-2025 by
8
* David Turner, Robert Wilhelm, and Werner Lemberg.
9
*
10
* This file is part of the FreeType project, and may only be used,
11
* modified, and distributed under the terms of the FreeType project
12
* license, LICENSE.TXT. By continuing to use, modify, or distribute
13
* this file you indicate that you have read the license and
14
* understand and accept it fully.
15
*
16
*/
17
22
#ifndef INTERNAL_COMPILER_MACROS_H_
23
#define INTERNAL_COMPILER_MACROS_H_
24
25
#include <
freetype/config/public-macros.h
>
26
27
FT_BEGIN_HEADER
28
29
/* Fix compiler warning with sgi compiler. */
30
#if defined( __sgi ) && !defined( __GNUC__ )
31
# if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 )
32
# pragma set woff 3505
33
# endif
34
#endif
35
36
/* Fix compiler warning with sgi compiler. */
37
#if defined( __sgi ) && !defined( __GNUC__ )
38
# if defined( _COMPILER_VERSION ) && ( _COMPILER_VERSION >= 730 )
39
# pragma set woff 3505
40
# endif
41
#endif
42
43
/* Newer compilers warn for fall-through case statements. */
44
#ifndef FALL_THROUGH
45
# if ( defined( __STDC_VERSION__ ) && __STDC_VERSION__ > 201710L ) || \
46
( defined( __cplusplus ) && __cplusplus > 201402L )
47
# define FALL_THROUGH [[__fallthrough__]]
48
# elif ( defined( __GNUC__ ) && __GNUC__ >= 7 ) || \
49
( defined( __clang__ ) && \
50
( defined( __apple_build_version__ ) \
51
? __apple_build_version__ >= 12000000 \
52
: __clang_major__ >= 10 ) )
53
# define FALL_THROUGH __attribute__(( __fallthrough__ ))
54
# else
55
# define FALL_THROUGH ( (void)0 )
56
# endif
57
#endif
58
59
/*
60
* When defining a macro that expands to a non-trivial C statement, use
61
* FT_BEGIN_STMNT and FT_END_STMNT to enclose the macro's body. This
62
* ensures there are no surprises when the macro is invoked in conditional
63
* branches.
64
*
65
* Example:
66
*
67
* #define LOG( ... ) \
68
* FT_BEGIN_STMNT \
69
* if ( logging_enabled ) \
70
* log( __VA_ARGS__ ); \
71
* FT_END_STMNT
72
*/
73
#define FT_BEGIN_STMNT do {
74
#define FT_END_STMNT } while ( 0 )
75
76
/*
77
* FT_DUMMY_STMNT expands to an empty C statement. Useful for
78
* conditionally defined statement macros.
79
*
80
* Example:
81
*
82
* #ifdef BUILD_CONFIG_LOGGING
83
* #define LOG( ... ) \
84
* FT_BEGIN_STMNT \
85
* if ( logging_enabled ) \
86
* log( __VA_ARGS__ ); \
87
* FT_END_STMNT
88
* #else
89
* # define LOG( ... ) FT_DUMMY_STMNT
90
* #endif
91
*/
92
#define FT_DUMMY_STMNT FT_BEGIN_STMNT FT_END_STMNT
93
94
#ifdef __UINTPTR_TYPE__
95
/*
96
* GCC and Clang both provide a `__UINTPTR_TYPE__` that can be used to
97
* avoid a dependency on `stdint.h`.
98
*/
99
# define FT_UINT_TO_POINTER( x ) (void *)(__UINTPTR_TYPE__)(x)
100
#elif defined( _WIN64 )
101
/* only 64bit Windows uses the LLP64 data model, i.e., */
102
/* 32-bit integers, 64-bit pointers. */
103
# define FT_UINT_TO_POINTER( x ) (void *)(unsigned __int64)(x)
104
#else
105
# define FT_UINT_TO_POINTER( x ) (void *)(unsigned long)(x)
106
#endif
107
108
/*
109
* Use `FT_TYPEOF( type )` to cast a value to `type`. This is useful to
110
* suppress signedness compilation warnings in macros.
111
*
112
* Example:
113
*
114
* #define PAD_( x, n ) ( (x) & ~FT_TYPEOF( x )( (n) - 1 ) )
115
*
116
* (The `typeof` condition is taken from gnulib's `intprops.h` header
117
* file.)
118
*/
119
#if ( ( defined( __GNUC__ ) && __GNUC__ >= 2 ) || \
120
( defined( __IBMC__ ) && __IBMC__ >= 1210 && \
121
defined( __IBM__TYPEOF__ ) ) || \
122
( defined( __SUNPRO_C ) && __SUNPRO_C >= 0x5110 && !__STDC__ ) )
123
#define FT_TYPEOF( type ) ( __typeof__ ( type ) )
124
#else
125
#define FT_TYPEOF( type )
/* empty */
126
#endif
127
128
/*
129
* Mark a function declaration as internal to the library. This ensures
130
* that it will not be exposed by default to client code, and helps
131
* generate smaller and faster code on ELF-based platforms. Place this
132
* before a function declaration.
133
*/
134
135
/* Visual C, MinGW, Cygwin */
136
#if defined( _WIN32 ) || defined( __CYGWIN__ )
137
#define FT_INTERNAL_FUNCTION_ATTRIBUTE
/* empty */
138
139
/* gcc, clang */
140
#elif ( defined( __GNUC__ ) && __GNUC__ >= 4 ) || defined( __clang__ )
141
#define FT_INTERNAL_FUNCTION_ATTRIBUTE \
142
__attribute__(( visibility( "hidden" ) ))
143
144
/* Sun */
145
#elif defined( __SUNPRO_C ) && __SUNPRO_C >= 0x550
146
#define FT_INTERNAL_FUNCTION_ATTRIBUTE __hidden
147
148
#else
149
#define FT_INTERNAL_FUNCTION_ATTRIBUTE
/* empty */
150
#endif
151
152
/*
153
* FreeType supports compilation of its C sources with a C++ compiler (in
154
* C++ mode); this introduces a number of subtle issues.
155
*
156
* The main one is that a C++ function declaration and its definition must
157
* have the same 'linkage'. Because all FreeType headers declare their
158
* functions with C linkage (i.e., within an `extern "C" { ... }` block
159
* due to the magic of FT_BEGIN_HEADER and FT_END_HEADER), their
160
* definition in FreeType sources should also be prefixed with `extern
161
* "C"` when compiled in C++ mode.
162
*
163
* The `FT_FUNCTION_DECLARATION` and `FT_FUNCTION_DEFINITION` macros are
164
* provided to deal with this case, as well as `FT_CALLBACK_DEF` and its
165
* siblings below.
166
*/
167
168
/*
169
* `FT_FUNCTION_DECLARATION( type )` can be used to write a C function
170
* declaration to ensure it will have C linkage when the library is built
171
* with a C++ compiler. The parameter is the function's return type, so a
172
* declaration would look like
173
*
174
* FT_FUNCTION_DECLARATION( int )
175
* foo( int x );
176
*
177
* NOTE: This requires that all uses are inside of `FT_BEGIN_HEADER ...
178
* FT_END_HEADER` blocks, which guarantees that the declarations have C
179
* linkage when the headers are included by C++ sources.
180
*
181
* NOTE: Do not use directly. Use `FT_LOCAL`, `FT_BASE`, and `FT_EXPORT`
182
* instead.
183
*/
184
#define FT_FUNCTION_DECLARATION( x ) extern x
185
186
/*
187
* Same as `FT_FUNCTION_DECLARATION`, but for function definitions instead.
188
*
189
* NOTE: Do not use directly. Use `FT_LOCAL_DEF`, `FT_BASE_DEF`, and
190
* `FT_EXPORT_DEF` instead.
191
*/
192
#ifdef __cplusplus
193
#define FT_FUNCTION_DEFINITION( x ) extern "C" x
194
#else
195
#define FT_FUNCTION_DEFINITION( x ) x
196
#endif
197
198
/*
199
* Use `FT_LOCAL` and `FT_LOCAL_DEF` to declare and define, respectively,
200
* an internal FreeType function that is only used by the sources of a
201
* single `src/module/` directory. This ensures that the functions are
202
* turned into static ones at build time, resulting in smaller and faster
203
* code.
204
*/
205
#ifdef FT_MAKE_OPTION_SINGLE_OBJECT
206
207
#define FT_LOCAL( x ) static x
208
#define FT_LOCAL_DEF( x ) static x
209
210
#else
211
212
#define FT_LOCAL( x ) FT_INTERNAL_FUNCTION_ATTRIBUTE \
213
FT_FUNCTION_DECLARATION( x )
214
#define FT_LOCAL_DEF( x ) FT_FUNCTION_DEFINITION( x )
215
216
#endif
/* FT_MAKE_OPTION_SINGLE_OBJECT */
217
218
/*
219
* Use `FT_LOCAL_ARRAY` and `FT_LOCAL_ARRAY_DEF` to declare and define,
220
* respectively, a constant array that must be accessed from several
221
* sources in the same `src/module/` sub-directory, and which are internal
222
* to the library.
223
*/
224
#define FT_LOCAL_ARRAY( x ) FT_INTERNAL_FUNCTION_ATTRIBUTE \
225
extern const x
226
#define FT_LOCAL_ARRAY_DEF( x ) FT_FUNCTION_DEFINITION( const x )
227
228
/*
229
* `Use FT_BASE` and `FT_BASE_DEF` to declare and define, respectively, an
230
* internal library function that is used by more than a single module.
231
*/
232
#define FT_BASE( x ) FT_INTERNAL_FUNCTION_ATTRIBUTE \
233
FT_FUNCTION_DECLARATION( x )
234
#define FT_BASE_DEF( x ) FT_FUNCTION_DEFINITION( x )
235
236
237
/*
238
* NOTE: Conditionally define `FT_EXPORT_VAR` due to its definition in
239
* `src/smooth/ftgrays.h` to make the header more portable.
240
*/
241
#ifndef FT_EXPORT_VAR
242
#define FT_EXPORT_VAR( x ) FT_FUNCTION_DECLARATION( x )
243
#endif
244
245
/*
246
* When compiling FreeType as a DLL or DSO with hidden visibility,
247
* some systems/compilers need a special attribute in front OR after
248
* the return type of function declarations.
249
*
250
* Two macros are used within the FreeType source code to define
251
* exported library functions: `FT_EXPORT` and `FT_EXPORT_DEF`.
252
*
253
* - `FT_EXPORT( return_type )`
254
*
255
* is used in a function declaration, as in
256
*
257
* ```
258
* FT_EXPORT( FT_Error )
259
* FT_Init_FreeType( FT_Library* alibrary );
260
* ```
261
*
262
* - `FT_EXPORT_DEF( return_type )`
263
*
264
* is used in a function definition, as in
265
*
266
* ```
267
* FT_EXPORT_DEF( FT_Error )
268
* FT_Init_FreeType( FT_Library* alibrary )
269
* {
270
* ... some code ...
271
* return FT_Err_Ok;
272
* }
273
* ```
274
*
275
* You can provide your own implementation of `FT_EXPORT` and
276
* `FT_EXPORT_DEF` here if you want.
277
*
278
* To export a variable, use `FT_EXPORT_VAR`.
279
*/
280
281
/* See `freetype/config/public-macros.h` for the `FT_EXPORT` definition */
282
#define FT_EXPORT_DEF( x ) FT_FUNCTION_DEFINITION( x )
283
284
/*
285
* The following macros are needed to compile the library with a
286
* C++ compiler and with 16bit compilers.
287
*/
288
289
/*
290
* This is special. Within C++, you must specify `extern "C"` for
291
* functions which are used via function pointers, and you also
292
* must do that for structures which contain function pointers to
293
* assure C linkage -- it's not possible to have (local) anonymous
294
* functions which are accessed by (global) function pointers.
295
*
296
*
297
* FT_CALLBACK_DEF is used to _define_ a callback function,
298
* located in the same source code file as the structure that uses
299
* it. FT_COMPARE_DEF, in addition, ensures the `cdecl` calling
300
* convention on x86, required by the C library function `qsort`.
301
*
302
* FT_BASE_CALLBACK and FT_BASE_CALLBACK_DEF are used to declare
303
* and define a callback function, respectively, in a similar way
304
* as FT_BASE and FT_BASE_DEF work.
305
*
306
* FT_CALLBACK_TABLE is used to _declare_ a constant variable that
307
* contains pointers to callback functions.
308
*
309
* FT_CALLBACK_TABLE_DEF is used to _define_ a constant variable
310
* that contains pointers to callback functions.
311
*
312
*
313
* Some 16bit compilers have to redefine these macros to insert
314
* the infamous `_cdecl` or `__fastcall` declarations.
315
*/
316
#ifdef __cplusplus
317
#define FT_CALLBACK_DEF( x ) extern "C" x
318
#else
319
#define FT_CALLBACK_DEF( x ) static x
320
#endif
321
322
#if defined( __GNUC__ ) && defined( __i386__ )
323
#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x ) __attribute__(( cdecl ))
324
#elif defined( _MSC_VER ) && defined( _M_IX86 )
325
#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x ) __cdecl
326
#elif defined( __WATCOMC__ ) && __WATCOMC__ >= 1240
327
#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x ) __watcall
328
#else
329
#define FT_COMPARE_DEF( x ) FT_CALLBACK_DEF( x )
330
#endif
331
332
#define FT_BASE_CALLBACK( x ) FT_FUNCTION_DECLARATION( x )
333
#define FT_BASE_CALLBACK_DEF( x ) FT_FUNCTION_DEFINITION( x )
334
335
#ifndef FT_CALLBACK_TABLE
336
#ifdef __cplusplus
337
#define FT_CALLBACK_TABLE extern "C"
338
#define FT_CALLBACK_TABLE_DEF extern "C"
339
#else
340
#define FT_CALLBACK_TABLE extern
341
#define FT_CALLBACK_TABLE_DEF
/* nothing */
342
#endif
343
#endif
/* FT_CALLBACK_TABLE */
344
345
FT_END_HEADER
346
347
#endif
/* INTERNAL_COMPILER_MACROS_H_ */
public-macros.h
freetype
include
freetype
internal
compiler-macros.h
Generated by
1.18.0