Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
27 /* This file must not include any other glib header file and must thus
28 * not refer to variables from glibconfig.h
31 #ifndef __G_MACROS_H__
32 #define __G_MACROS_H__
34 /* We include stddef.h to get the system's definition of NULL
38 /* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
39 * where this is valid. This allows for warningless compilation of
40 * "long long" types even in the presence of '-ansi -pedantic'.
42 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
43 # define G_GNUC_EXTENSION __extension__
45 # define G_GNUC_EXTENSION
48 /* Provide macros to feature the GCC function attribute.
50 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
52 __attribute__((__pure__))
53 #define G_GNUC_MALLOC \
54 __attribute__((__malloc__))
61 #define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
63 #define G_GNUC_NULL_TERMINATED
66 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
67 #define G_GNUC_PRINTF( format_idx, arg_idx ) \
68 __attribute__((__format__ (__printf__, format_idx, arg_idx)))
69 #define G_GNUC_SCANF( format_idx, arg_idx ) \
70 __attribute__((__format__ (__scanf__, format_idx, arg_idx)))
71 #define G_GNUC_FORMAT( arg_idx ) \
72 __attribute__((__format_arg__ (arg_idx)))
73 #define G_GNUC_NORETURN \
74 __attribute__((__noreturn__))
75 #define G_GNUC_CONST \
76 __attribute__((__const__))
77 #define G_GNUC_UNUSED \
78 __attribute__((__unused__))
79 #define G_GNUC_NO_INSTRUMENT \
80 __attribute__((__no_instrument_function__))
82 #define G_GNUC_PRINTF( format_idx, arg_idx )
83 #define G_GNUC_SCANF( format_idx, arg_idx )
84 #define G_GNUC_FORMAT( arg_idx )
85 #define G_GNUC_NORETURN
88 #define G_GNUC_NO_INSTRUMENT
89 #endif /* !__GNUC__ */
91 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
92 #define G_GNUC_DEPRECATED \
93 __attribute__((__deprecated__))
95 #define G_GNUC_DEPRECATED
98 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
99 #define G_GNUC_WARN_UNUSED_RESULT \
100 __attribute__((warn_unused_result))
102 #define G_GNUC_WARN_UNUSED_RESULT
103 #endif /* __GNUC__ */
105 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
106 * macros, so we can refer to them as strings unconditionally.
107 * usage not-recommended since gcc-3.0
109 #if defined (__GNUC__) && (__GNUC__ < 3)
110 #define G_GNUC_FUNCTION __FUNCTION__
111 #define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
112 #else /* !__GNUC__ */
113 #define G_GNUC_FUNCTION ""
114 #define G_GNUC_PRETTY_FUNCTION ""
115 #endif /* !__GNUC__ */
117 #define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
118 #define G_STRINGIFY_ARG(contents) #contents
120 /* Provide a string identifying the current code position */
121 #if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
122 # define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
124 # define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
127 /* Provide a string identifying the current function, non-concatenatable */
128 #if defined (__GNUC__)
129 # define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
130 #elif defined (G_HAVE_ISO_VARARGS)
131 # define G_STRFUNC ((const char*) (__func__))
133 # define G_STRFUNC ((const char*) ("???"))
136 /* Guard C code in headers, while including them from C++ */
138 # define G_BEGIN_DECLS extern "C" {
139 # define G_END_DECLS }
141 # define G_BEGIN_DECLS
145 /* Provide definitions for some commonly used macros.
146 * Some of them are only provided if they haven't already
147 * been defined. It is assumed that if they are already
148 * defined then the current definition is correct.
153 # else /* !__cplusplus */
154 # define NULL ((void*) 0)
155 # endif /* !__cplusplus */
163 #define TRUE (!FALSE)
167 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
170 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
173 #define ABS(a) (((a) < 0) ? -(a) : (a))
176 #define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
178 /* Count the number of elements in an array. The array must be defined
179 * as such; using this with a dynamically allocated array will give
182 #define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
184 /* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
186 #define GPOINTER_TO_SIZE(p) ((gsize) (p))
187 #define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
189 /* Provide convenience macros for handling structure
190 * fields through their offsets.
192 #define G_STRUCT_OFFSET(struct_type, member) \
193 ((glong) ((guint8*) &((struct_type*) 0)->member))
194 #define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
195 ((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
196 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
197 (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
199 /* Provide simple macro statement wrappers (adapted from Perl):
200 * G_STMT_START { statements; } G_STMT_END;
201 * can be used as a single statement, as in
202 * if (x) G_STMT_START { ... } G_STMT_END; else ...
204 * When GCC is compiling C code in non-ANSI mode, it will use the
205 * compiler __extension__ to wrap the statements wihin `({' and '})' braces.
206 * When compiling on platforms where configure has defined
207 * HAVE_DOWHILE_MACROS, statements will be wrapped with `do' and `while (0)'.
208 * For any other platforms (SunOS4 is known to have this issue), wrap the
209 * statements with `if (1)' and `else (void) 0'.
211 #if !(defined (G_STMT_START) && defined (G_STMT_END))
212 # if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
213 # define G_STMT_START (void) __extension__ (
214 # define G_STMT_END )
215 # else /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
216 # if defined (HAVE_DOWHILE_MACROS)
217 # define G_STMT_START do
218 # define G_STMT_END while (0)
219 # else /* !HAVE_DOWHILE_MACROS */
220 # define G_STMT_START if (1)
221 # define G_STMT_END else (void) 0
222 # endif /* !HAVE_DOWHILE_MACROS */
223 # endif /* !(__GNUC__ && !__STRICT_ANSI__ && !__cplusplus) */
226 /* Allow the app programmer to select whether or not return values
227 * (usually char*) are const or not. Don't try using this feature for
228 * functions with C++ linkage.
230 #ifdef G_DISABLE_CONST_RETURNS
231 #define G_CONST_RETURN
233 #define G_CONST_RETURN const
237 * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
238 * the compiler about the expected result of an expression. Some compilers
239 * can use this information for optimizations.
241 * The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
242 * putting assignments in g_return_if_fail ().
244 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
245 #define _G_BOOLEAN_EXPR(expr) \
247 int _g_boolean_var_; \
249 _g_boolean_var_ = 1; \
251 _g_boolean_var_ = 0; \
254 #define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
255 #define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
257 #define G_LIKELY(expr) (expr)
258 #define G_UNLIKELY(expr) (expr)
261 #endif /* __G_MACROS_H__ */