nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GLIB - Library of useful routines for C programming |
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
||
3 | * |
||
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. |
||
8 | * |
||
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. |
||
13 | * |
||
14 | * You should have received a copy of the GNU Lesser General Public |
||
15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Modified by the GLib Team and others 1997-2000. See the AUTHORS |
||
20 | * file for a list of people on the GLib Team. See the ChangeLog |
||
21 | * files for a list of changes. These files are distributed with |
||
22 | * GLib at ftp://ftp.gtk.org/pub/gtk/. |
||
23 | */ |
||
24 | |||
25 | #ifndef __G_TYPES_H__ |
||
26 | #define __G_TYPES_H__ |
||
27 | |||
28 | #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION) |
||
29 | #error "Only <glib.h> can be included directly." |
||
30 | #endif |
||
31 | |||
32 | #include <glibconfig.h> |
||
33 | #include <glib/gmacros.h> |
||
34 | #include <glib/gversionmacros.h> |
||
35 | #include <time.h> |
||
36 | |||
37 | G_BEGIN_DECLS |
||
38 | |||
39 | /* Provide type definitions for commonly used types. |
||
40 | * These are useful because a "gint8" can be adjusted |
||
41 | * to be 1 byte (8 bits) on all platforms. Similarly and |
||
42 | * more importantly, "gint32" can be adjusted to be |
||
43 | * 4 bytes (32 bits) on all platforms. |
||
44 | */ |
||
45 | |||
46 | typedef char gchar; |
||
47 | typedef short gshort; |
||
48 | typedef long glong; |
||
49 | typedef int gint; |
||
50 | typedef gint gboolean; |
||
51 | |||
52 | typedef unsigned char guchar; |
||
53 | typedef unsigned short gushort; |
||
54 | typedef unsigned long gulong; |
||
55 | typedef unsigned int guint; |
||
56 | |||
57 | typedef float gfloat; |
||
58 | typedef double gdouble; |
||
59 | |||
60 | /* Define min and max constants for the fixed size numerical types */ |
||
61 | #define G_MININT8 ((gint8) -0x80) |
||
62 | #define G_MAXINT8 ((gint8) 0x7f) |
||
63 | #define G_MAXUINT8 ((guint8) 0xff) |
||
64 | |||
65 | #define G_MININT16 ((gint16) -0x8000) |
||
66 | #define G_MAXINT16 ((gint16) 0x7fff) |
||
67 | #define G_MAXUINT16 ((guint16) 0xffff) |
||
68 | |||
69 | #define G_MININT32 ((gint32) -0x80000000) |
||
70 | #define G_MAXINT32 ((gint32) 0x7fffffff) |
||
71 | #define G_MAXUINT32 ((guint32) 0xffffffff) |
||
72 | |||
73 | #define G_MININT64 ((gint64) G_GINT64_CONSTANT(-0x8000000000000000)) |
||
74 | #define G_MAXINT64 G_GINT64_CONSTANT(0x7fffffffffffffff) |
||
75 | #define G_MAXUINT64 G_GUINT64_CONSTANT(0xffffffffffffffff) |
||
76 | |||
77 | typedef void* gpointer; |
||
78 | typedef const void *gconstpointer; |
||
79 | |||
80 | typedef gint (*GCompareFunc) (gconstpointer a, |
||
81 | gconstpointer b); |
||
82 | typedef gint (*GCompareDataFunc) (gconstpointer a, |
||
83 | gconstpointer b, |
||
84 | gpointer user_data); |
||
85 | typedef gboolean (*GEqualFunc) (gconstpointer a, |
||
86 | gconstpointer b); |
||
87 | typedef void (*GDestroyNotify) (gpointer data); |
||
88 | typedef void (*GFunc) (gpointer data, |
||
89 | gpointer user_data); |
||
90 | typedef guint (*GHashFunc) (gconstpointer key); |
||
91 | typedef void (*GHFunc) (gpointer key, |
||
92 | gpointer value, |
||
93 | gpointer user_data); |
||
94 | |||
95 | /** |
||
96 | * GFreeFunc: |
||
97 | * @data: a data pointer |
||
98 | * |
||
99 | * Declares a type of function which takes an arbitrary |
||
100 | * data pointer argument and has no return value. It is |
||
101 | * not currently used in GLib or GTK+. |
||
102 | */ |
||
103 | typedef void (*GFreeFunc) (gpointer data); |
||
104 | |||
105 | /** |
||
106 | * GTranslateFunc: |
||
107 | * @str: the untranslated string |
||
108 | * @data: user data specified when installing the function, e.g. |
||
109 | * in g_option_group_set_translate_func() |
||
110 | * |
||
111 | * The type of functions which are used to translate user-visible |
||
112 | * strings, for <option>--help</option> output. |
||
113 | * |
||
114 | * Returns: a translation of the string for the current locale. |
||
115 | * The returned string is owned by GLib and must not be freed. |
||
116 | */ |
||
117 | typedef const gchar * (*GTranslateFunc) (const gchar *str, |
||
118 | gpointer data); |
||
119 | |||
120 | |||
121 | /* Define some mathematical constants that aren't available |
||
122 | * symbolically in some strict ISO C implementations. |
||
123 | * |
||
124 | * Note that the large number of digits used in these definitions |
||
125 | * doesn't imply that GLib or current computers in general would be |
||
126 | * able to handle floating point numbers with an accuracy like this. |
||
127 | * It's mostly an exercise in futility and future proofing. For |
||
128 | * extended precision floating point support, look somewhere else |
||
129 | * than GLib. |
||
130 | */ |
||
131 | #define G_E 2.7182818284590452353602874713526624977572470937000 |
||
132 | #define G_LN2 0.69314718055994530941723212145817656807550013436026 |
||
133 | #define G_LN10 2.3025850929940456840179914546843642076011014886288 |
||
134 | #define G_PI 3.1415926535897932384626433832795028841971693993751 |
||
135 | #define G_PI_2 1.5707963267948966192313216916397514420985846996876 |
||
136 | #define G_PI_4 0.78539816339744830961566084581987572104929234984378 |
||
137 | #define G_SQRT2 1.4142135623730950488016887242096980785696718753769 |
||
138 | |||
139 | /* Portable endian checks and conversions |
||
140 | * |
||
141 | * glibconfig.h defines G_BYTE_ORDER which expands to one of |
||
142 | * the below macros. |
||
143 | */ |
||
144 | #define G_LITTLE_ENDIAN 1234 |
||
145 | #define G_BIG_ENDIAN 4321 |
||
146 | #define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */ |
||
147 | |||
148 | |||
149 | /* Basic bit swapping functions |
||
150 | */ |
||
151 | #define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \ |
||
152 | (guint16) ((guint16) (val) >> 8) | \ |
||
153 | (guint16) ((guint16) (val) << 8))) |
||
154 | |||
155 | #define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \ |
||
156 | (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \ |
||
157 | (((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \ |
||
158 | (((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \ |
||
159 | (((guint32) (val) & (guint32) 0xff000000U) >> 24))) |
||
160 | |||
161 | #define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \ |
||
162 | (((guint64) (val) & \ |
||
163 | (guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) | \ |
||
164 | (((guint64) (val) & \ |
||
165 | (guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) | \ |
||
166 | (((guint64) (val) & \ |
||
167 | (guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) | \ |
||
168 | (((guint64) (val) & \ |
||
169 | (guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) << 8) | \ |
||
170 | (((guint64) (val) & \ |
||
171 | (guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >> 8) | \ |
||
172 | (((guint64) (val) & \ |
||
173 | (guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) | \ |
||
174 | (((guint64) (val) & \ |
||
175 | (guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) | \ |
||
176 | (((guint64) (val) & \ |
||
177 | (guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56))) |
||
178 | |||
179 | /* Arch specific stuff for speed |
||
180 | */ |
||
181 | #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__) |
||
182 | |||
183 | # if __GNUC__ >= 4 && defined (__GNUC_MINOR__) && __GNUC_MINOR__ >= 3 |
||
184 | # define GUINT32_SWAP_LE_BE(val) ((guint32) __builtin_bswap32 ((gint32) (val))) |
||
185 | # define GUINT64_SWAP_LE_BE(val) ((guint64) __builtin_bswap64 ((gint64) (val))) |
||
186 | # endif |
||
187 | |||
188 | # if defined (__i386__) |
||
189 | # define GUINT16_SWAP_LE_BE_IA32(val) \ |
||
190 | (G_GNUC_EXTENSION \ |
||
191 | ({ guint16 __v, __x = ((guint16) (val)); \ |
||
192 | if (__builtin_constant_p (__x)) \ |
||
193 | __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \ |
||
194 | else \ |
||
195 | __asm__ ("rorw $8, %w0" \ |
||
196 | : "=r" (__v) \ |
||
197 | : "0" (__x) \ |
||
198 | : "cc"); \ |
||
199 | __v; })) |
||
200 | # if !defined (__i486__) && !defined (__i586__) \ |
||
201 | && !defined (__pentium__) && !defined (__i686__) \ |
||
202 | && !defined (__pentiumpro__) && !defined (__pentium4__) |
||
203 | # define GUINT32_SWAP_LE_BE_IA32(val) \ |
||
204 | (G_GNUC_EXTENSION \ |
||
205 | ({ guint32 __v, __x = ((guint32) (val)); \ |
||
206 | if (__builtin_constant_p (__x)) \ |
||
207 | __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ |
||
208 | else \ |
||
209 | __asm__ ("rorw $8, %w0\n\t" \ |
||
210 | "rorl $16, %0\n\t" \ |
||
211 | "rorw $8, %w0" \ |
||
212 | : "=r" (__v) \ |
||
213 | : "0" (__x) \ |
||
214 | : "cc"); \ |
||
215 | __v; })) |
||
216 | # else /* 486 and higher has bswap */ |
||
217 | # define GUINT32_SWAP_LE_BE_IA32(val) \ |
||
218 | (G_GNUC_EXTENSION \ |
||
219 | ({ guint32 __v, __x = ((guint32) (val)); \ |
||
220 | if (__builtin_constant_p (__x)) \ |
||
221 | __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ |
||
222 | else \ |
||
223 | __asm__ ("bswap %0" \ |
||
224 | : "=r" (__v) \ |
||
225 | : "0" (__x)); \ |
||
226 | __v; })) |
||
227 | # endif /* processor specific 32-bit stuff */ |
||
228 | # define GUINT64_SWAP_LE_BE_IA32(val) \ |
||
229 | (G_GNUC_EXTENSION \ |
||
230 | ({ union { guint64 __ll; \ |
||
231 | guint32 __l[2]; } __w, __r; \ |
||
232 | __w.__ll = ((guint64) (val)); \ |
||
233 | if (__builtin_constant_p (__w.__ll)) \ |
||
234 | __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll); \ |
||
235 | else \ |
||
236 | { \ |
||
237 | __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \ |
||
238 | __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \ |
||
239 | } \ |
||
240 | __r.__ll; })) |
||
241 | /* Possibly just use the constant version and let gcc figure it out? */ |
||
242 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val)) |
||
243 | # ifndef GUINT32_SWAP_LE_BE |
||
244 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val)) |
||
245 | # endif |
||
246 | # ifndef GUINT64_SWAP_LE_BE |
||
247 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val)) |
||
248 | # endif |
||
249 | # elif defined (__ia64__) |
||
250 | # define GUINT16_SWAP_LE_BE_IA64(val) \ |
||
251 | (G_GNUC_EXTENSION \ |
||
252 | ({ guint16 __v, __x = ((guint16) (val)); \ |
||
253 | if (__builtin_constant_p (__x)) \ |
||
254 | __v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \ |
||
255 | else \ |
||
256 | __asm__ __volatile__ ("shl %0 = %1, 48 ;;" \ |
||
257 | "mux1 %0 = %0, @rev ;;" \ |
||
258 | : "=r" (__v) \ |
||
259 | : "r" (__x)); \ |
||
260 | __v; })) |
||
261 | # define GUINT32_SWAP_LE_BE_IA64(val) \ |
||
262 | (G_GNUC_EXTENSION \ |
||
263 | ({ guint32 __v, __x = ((guint32) (val)); \ |
||
264 | if (__builtin_constant_p (__x)) \ |
||
265 | __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ |
||
266 | else \ |
||
267 | __asm__ __volatile__ ("shl %0 = %1, 32 ;;" \ |
||
268 | "mux1 %0 = %0, @rev ;;" \ |
||
269 | : "=r" (__v) \ |
||
270 | : "r" (__x)); \ |
||
271 | __v; })) |
||
272 | # define GUINT64_SWAP_LE_BE_IA64(val) \ |
||
273 | (G_GNUC_EXTENSION \ |
||
274 | ({ guint64 __v, __x = ((guint64) (val)); \ |
||
275 | if (__builtin_constant_p (__x)) \ |
||
276 | __v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \ |
||
277 | else \ |
||
278 | __asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \ |
||
279 | : "=r" (__v) \ |
||
280 | : "r" (__x)); \ |
||
281 | __v; })) |
||
282 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA64 (val)) |
||
283 | # ifndef GUINT32_SWAP_LE_BE |
||
284 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA64 (val)) |
||
285 | # endif |
||
286 | # ifndef GUINT64_SWAP_LE_BE |
||
287 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA64 (val)) |
||
288 | # endif |
||
289 | # elif defined (__x86_64__) |
||
290 | # define GUINT32_SWAP_LE_BE_X86_64(val) \ |
||
291 | (G_GNUC_EXTENSION \ |
||
292 | ({ guint32 __v, __x = ((guint32) (val)); \ |
||
293 | if (__builtin_constant_p (__x)) \ |
||
294 | __v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \ |
||
295 | else \ |
||
296 | __asm__ ("bswapl %0" \ |
||
297 | : "=r" (__v) \ |
||
298 | : "0" (__x)); \ |
||
299 | __v; })) |
||
300 | # define GUINT64_SWAP_LE_BE_X86_64(val) \ |
||
301 | (G_GNUC_EXTENSION \ |
||
302 | ({ guint64 __v, __x = ((guint64) (val)); \ |
||
303 | if (__builtin_constant_p (__x)) \ |
||
304 | __v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \ |
||
305 | else \ |
||
306 | __asm__ ("bswapq %0" \ |
||
307 | : "=r" (__v) \ |
||
308 | : "0" (__x)); \ |
||
309 | __v; })) |
||
310 | /* gcc seems to figure out optimal code for this on its own */ |
||
311 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) |
||
312 | # ifndef GUINT32_SWAP_LE_BE |
||
313 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val)) |
||
314 | # endif |
||
315 | # ifndef GUINT64_SWAP_LE_BE |
||
316 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val)) |
||
317 | # endif |
||
318 | # else /* generic gcc */ |
||
319 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) |
||
320 | # ifndef GUINT32_SWAP_LE_BE |
||
321 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) |
||
322 | # endif |
||
323 | # ifndef GUINT64_SWAP_LE_BE |
||
324 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val)) |
||
325 | # endif |
||
326 | # endif |
||
327 | #else /* generic */ |
||
328 | # define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val)) |
||
329 | # define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val)) |
||
330 | # define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val)) |
||
331 | #endif /* generic */ |
||
332 | |||
333 | #define GUINT16_SWAP_LE_PDP(val) ((guint16) (val)) |
||
334 | #define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val)) |
||
335 | #define GUINT32_SWAP_LE_PDP(val) ((guint32) ( \ |
||
336 | (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \ |
||
337 | (((guint32) (val) & (guint32) 0xffff0000U) >> 16))) |
||
338 | #define GUINT32_SWAP_BE_PDP(val) ((guint32) ( \ |
||
339 | (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \ |
||
340 | (((guint32) (val) & (guint32) 0xff00ff00U) >> 8))) |
||
341 | |||
342 | /* The G*_TO_?E() macros are defined in glibconfig.h. |
||
343 | * The transformation is symmetric, so the FROM just maps to the TO. |
||
344 | */ |
||
345 | #define GINT16_FROM_LE(val) (GINT16_TO_LE (val)) |
||
346 | #define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val)) |
||
347 | #define GINT16_FROM_BE(val) (GINT16_TO_BE (val)) |
||
348 | #define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val)) |
||
349 | #define GINT32_FROM_LE(val) (GINT32_TO_LE (val)) |
||
350 | #define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val)) |
||
351 | #define GINT32_FROM_BE(val) (GINT32_TO_BE (val)) |
||
352 | #define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val)) |
||
353 | |||
354 | #define GINT64_FROM_LE(val) (GINT64_TO_LE (val)) |
||
355 | #define GUINT64_FROM_LE(val) (GUINT64_TO_LE (val)) |
||
356 | #define GINT64_FROM_BE(val) (GINT64_TO_BE (val)) |
||
357 | #define GUINT64_FROM_BE(val) (GUINT64_TO_BE (val)) |
||
358 | |||
359 | #define GLONG_FROM_LE(val) (GLONG_TO_LE (val)) |
||
360 | #define GULONG_FROM_LE(val) (GULONG_TO_LE (val)) |
||
361 | #define GLONG_FROM_BE(val) (GLONG_TO_BE (val)) |
||
362 | #define GULONG_FROM_BE(val) (GULONG_TO_BE (val)) |
||
363 | |||
364 | #define GINT_FROM_LE(val) (GINT_TO_LE (val)) |
||
365 | #define GUINT_FROM_LE(val) (GUINT_TO_LE (val)) |
||
366 | #define GINT_FROM_BE(val) (GINT_TO_BE (val)) |
||
367 | #define GUINT_FROM_BE(val) (GUINT_TO_BE (val)) |
||
368 | |||
369 | #define GSIZE_FROM_LE(val) (GSIZE_TO_LE (val)) |
||
370 | #define GSSIZE_FROM_LE(val) (GSSIZE_TO_LE (val)) |
||
371 | #define GSIZE_FROM_BE(val) (GSIZE_TO_BE (val)) |
||
372 | #define GSSIZE_FROM_BE(val) (GSSIZE_TO_BE (val)) |
||
373 | |||
374 | /* Portable versions of host-network order stuff |
||
375 | */ |
||
376 | #define g_ntohl(val) (GUINT32_FROM_BE (val)) |
||
377 | #define g_ntohs(val) (GUINT16_FROM_BE (val)) |
||
378 | #define g_htonl(val) (GUINT32_TO_BE (val)) |
||
379 | #define g_htons(val) (GUINT16_TO_BE (val)) |
||
380 | |||
381 | /* Overflow-checked unsigned integer arithmetic |
||
382 | */ |
||
383 | #ifndef _GLIB_TEST_OVERFLOW_FALLBACK |
||
384 | #if __GNUC__ >= 5 |
||
385 | #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS |
||
386 | #elif __has_builtin(__builtin_uadd_overflow) |
||
387 | #define _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS |
||
388 | #endif |
||
389 | #endif |
||
390 | |||
391 | #define g_uint_checked_add(dest, a, b) \ |
||
392 | _GLIB_CHECKED_ADD_U32(dest, a, b) |
||
393 | #define g_uint_checked_mul(dest, a, b) \ |
||
394 | _GLIB_CHECKED_MUL_U32(dest, a, b) |
||
395 | |||
396 | #define g_uint64_checked_add(dest, a, b) \ |
||
397 | _GLIB_CHECKED_ADD_U64(dest, a, b) |
||
398 | #define g_uint64_checked_mul(dest, a, b) \ |
||
399 | _GLIB_CHECKED_MUL_U64(dest, a, b) |
||
400 | |||
401 | #if GLIB_SIZEOF_SIZE_T == 8 |
||
402 | #define g_size_checked_add(dest, a, b) \ |
||
403 | _GLIB_CHECKED_ADD_U64(dest, a, b) |
||
404 | #define g_size_checked_mul(dest, a, b) \ |
||
405 | _GLIB_CHECKED_MUL_U64(dest, a, b) |
||
406 | #else |
||
407 | #define g_size_checked_add(dest, a, b) \ |
||
408 | _GLIB_CHECKED_ADD_U32(dest, a, b) |
||
409 | #define g_size_checked_mul(dest, a, b) \ |
||
410 | _GLIB_CHECKED_MUL_U32(dest, a, b) |
||
411 | #endif |
||
412 | |||
413 | /* The names of the following inlines are private. Use the macro |
||
414 | * definitions above. |
||
415 | */ |
||
416 | #ifdef _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS |
||
417 | static inline gboolean _GLIB_CHECKED_ADD_U32 (guint32 *dest, guint32 a, guint32 b) { |
||
418 | return !__builtin_uadd_overflow(a, b, dest); } |
||
419 | static inline gboolean _GLIB_CHECKED_MUL_U32 (guint32 *dest, guint32 a, guint32 b) { |
||
420 | return !__builtin_umul_overflow(a, b, dest); } |
||
421 | static inline gboolean _GLIB_CHECKED_ADD_U64 (guint64 *dest, guint64 a, guint64 b) { |
||
422 | G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64)); |
||
423 | return !__builtin_uaddll_overflow(a, b, (unsigned long long *) dest); } |
||
424 | static inline gboolean _GLIB_CHECKED_MUL_U64 (guint64 *dest, guint64 a, guint64 b) { |
||
425 | return !__builtin_umulll_overflow(a, b, (unsigned long long *) dest); } |
||
426 | #else |
||
427 | static inline gboolean _GLIB_CHECKED_ADD_U32 (guint32 *dest, guint32 a, guint32 b) { |
||
428 | *dest = a + b; return *dest >= a; } |
||
429 | static inline gboolean _GLIB_CHECKED_MUL_U32 (guint32 *dest, guint32 a, guint32 b) { |
||
430 | *dest = a * b; return !a || *dest / a == b; } |
||
431 | static inline gboolean _GLIB_CHECKED_ADD_U64 (guint64 *dest, guint64 a, guint64 b) { |
||
432 | *dest = a + b; return *dest >= a; } |
||
433 | static inline gboolean _GLIB_CHECKED_MUL_U64 (guint64 *dest, guint64 a, guint64 b) { |
||
434 | *dest = a * b; return !a || *dest / a == b; } |
||
435 | #endif |
||
436 | |||
437 | /* IEEE Standard 754 Single Precision Storage Format (gfloat): |
||
438 | * |
||
439 | * 31 30 23 22 0 |
||
440 | * +--------+---------------+---------------+ |
||
441 | * | s 1bit | e[30:23] 8bit | f[22:0] 23bit | |
||
442 | * +--------+---------------+---------------+ |
||
443 | * B0------------------->B1------->B2-->B3--> |
||
444 | * |
||
445 | * IEEE Standard 754 Double Precision Storage Format (gdouble): |
||
446 | * |
||
447 | * 63 62 52 51 32 31 0 |
||
448 | * +--------+----------------+----------------+ +---------------+ |
||
449 | * | s 1bit | e[62:52] 11bit | f[51:32] 20bit | | f[31:0] 32bit | |
||
450 | * +--------+----------------+----------------+ +---------------+ |
||
451 | * B0--------------->B1---------->B2--->B3----> B4->B5->B6->B7-> |
||
452 | */ |
||
453 | /* subtract from biased_exponent to form base2 exponent (normal numbers) */ |
||
454 | typedef union _GDoubleIEEE754 GDoubleIEEE754; |
||
455 | typedef union _GFloatIEEE754 GFloatIEEE754; |
||
456 | #define G_IEEE754_FLOAT_BIAS (127) |
||
457 | #define G_IEEE754_DOUBLE_BIAS (1023) |
||
458 | /* multiply with base2 exponent to get base10 exponent (normal numbers) */ |
||
459 | #define G_LOG_2_BASE_10 (0.30102999566398119521) |
||
460 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
||
461 | union _GFloatIEEE754 |
||
462 | { |
||
463 | gfloat v_float; |
||
464 | struct { |
||
465 | guint mantissa : 23; |
||
466 | guint biased_exponent : 8; |
||
467 | guint sign : 1; |
||
468 | } mpn; |
||
469 | }; |
||
470 | union _GDoubleIEEE754 |
||
471 | { |
||
472 | gdouble v_double; |
||
473 | struct { |
||
474 | guint mantissa_low : 32; |
||
475 | guint mantissa_high : 20; |
||
476 | guint biased_exponent : 11; |
||
477 | guint sign : 1; |
||
478 | } mpn; |
||
479 | }; |
||
480 | #elif G_BYTE_ORDER == G_BIG_ENDIAN |
||
481 | union _GFloatIEEE754 |
||
482 | { |
||
483 | gfloat v_float; |
||
484 | struct { |
||
485 | guint sign : 1; |
||
486 | guint biased_exponent : 8; |
||
487 | guint mantissa : 23; |
||
488 | } mpn; |
||
489 | }; |
||
490 | union _GDoubleIEEE754 |
||
491 | { |
||
492 | gdouble v_double; |
||
493 | struct { |
||
494 | guint sign : 1; |
||
495 | guint biased_exponent : 11; |
||
496 | guint mantissa_high : 20; |
||
497 | guint mantissa_low : 32; |
||
498 | } mpn; |
||
499 | }; |
||
500 | #else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */ |
||
501 | #error unknown ENDIAN type |
||
502 | #endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */ |
||
503 | |||
504 | typedef struct _GTimeVal GTimeVal; |
||
505 | |||
506 | struct _GTimeVal |
||
507 | { |
||
508 | glong tv_sec; |
||
509 | glong tv_usec; |
||
510 | }; |
||
511 | |||
512 | G_END_DECLS |
||
513 | |||
514 | /* We prefix variable declarations so they can |
||
515 | * properly get exported in Windows DLLs. |
||
516 | */ |
||
517 | #ifndef GLIB_VAR |
||
518 | # ifdef G_PLATFORM_WIN32 |
||
519 | # ifdef GLIB_STATIC_COMPILATION |
||
520 | # define GLIB_VAR extern |
||
521 | # else /* !GLIB_STATIC_COMPILATION */ |
||
522 | # ifdef GLIB_COMPILATION |
||
523 | # ifdef DLL_EXPORT |
||
524 | # define GLIB_VAR __declspec(dllexport) |
||
525 | # else /* !DLL_EXPORT */ |
||
526 | # define GLIB_VAR extern |
||
527 | # endif /* !DLL_EXPORT */ |
||
528 | # else /* !GLIB_COMPILATION */ |
||
529 | # define GLIB_VAR extern __declspec(dllimport) |
||
530 | # endif /* !GLIB_COMPILATION */ |
||
531 | # endif /* !GLIB_STATIC_COMPILATION */ |
||
532 | # else /* !G_PLATFORM_WIN32 */ |
||
533 | # define GLIB_VAR _GLIB_EXTERN |
||
534 | # endif /* !G_PLATFORM_WIN32 */ |
||
535 | #endif /* GLIB_VAR */ |
||
536 | |||
537 | #endif /* __G_TYPES_H__ */ |