Added stack, queue ADTs and related tests.
[platform/upstream/glib.git] / glib.h
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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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.
18  */
19
20 /*
21  * Modified by the GLib Team and others 1997-1999.  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/. 
25  */
26
27 #ifndef __G_LIB_H__
28 #define __G_LIB_H__
29
30 /* system specific config file glibconfig.h provides definitions for
31  * the extrema of many of the standard types. These are:
32  *
33  *  G_MINSHORT, G_MAXSHORT
34  *  G_MININT, G_MAXINT
35  *  G_MINLONG, G_MAXLONG
36  *  G_MINFLOAT, G_MAXFLOAT
37  *  G_MINDOUBLE, G_MAXDOUBLE
38  *
39  * It also provides the following typedefs:
40  *
41  *  gint8, guint8
42  *  gint16, guint16
43  *  gint32, guint32
44  *  gint64, guint64
45  *
46  * It defines the G_BYTE_ORDER symbol to one of G_*_ENDIAN (see later in
47  * this file). 
48  *
49  * And it provides a way to store and retrieve a `gint' in/from a `gpointer'.
50  * This is useful to pass an integer instead of a pointer to a callback.
51  *
52  *  GINT_TO_POINTER(i), GUINT_TO_POINTER(i)
53  *  GPOINTER_TO_INT(p), GPOINTER_TO_UINT(p)
54  *
55  * Finally, it provide the following wrappers to STDC functions:
56  *
57  *  g_ATEXIT
58  *    To register hooks which are executed on exit().
59  *    Usually a wrapper for STDC atexit.
60  *
61  *  void *g_memmove(void *dest, const void *src, guint count);
62  *    A wrapper for STDC memmove, or an implementation, if memmove doesn't
63  *    exist.  The prototype looks like the above, give or take a const,
64  *    or size_t.
65  */
66 #include <glibconfig.h>
67
68 /* include varargs functions for assertment macros
69  */
70 #include <stdarg.h>
71
72 /* optionally feature DMALLOC memory allocation debugger
73  */
74 #ifdef USE_DMALLOC
75 #include "dmalloc.h"
76 #endif
77
78
79 #ifdef NATIVE_WIN32
80
81 /* On native Win32, directory separator is the backslash, and search path
82  * separator is the semicolon.
83  */
84 #define G_DIR_SEPARATOR '\\'
85 #define G_DIR_SEPARATOR_S "\\"
86 #define G_SEARCHPATH_SEPARATOR ';'
87 #define G_SEARCHPATH_SEPARATOR_S ";"
88
89 #else  /* !NATIVE_WIN32 */
90
91 /* Unix */
92
93 #define G_DIR_SEPARATOR '/'
94 #define G_DIR_SEPARATOR_S "/"
95 #define G_SEARCHPATH_SEPARATOR ':'
96 #define G_SEARCHPATH_SEPARATOR_S ":"
97
98 #endif /* !NATIVE_WIN32 */
99
100 #ifdef __cplusplus
101 extern "C" {
102 #endif /* __cplusplus */
103
104
105 /* Provide definitions for some commonly used macros.
106  *  Some of them are only provided if they haven't already
107  *  been defined. It is assumed that if they are already
108  *  defined then the current definition is correct.
109  */
110 #ifndef NULL
111 #define NULL    ((void*) 0)
112 #endif
113
114 #ifndef FALSE
115 #define FALSE   (0)
116 #endif
117
118 #ifndef TRUE
119 #define TRUE    (!FALSE)
120 #endif
121
122 #undef  MAX
123 #define MAX(a, b)  (((a) > (b)) ? (a) : (b))
124
125 #undef  MIN
126 #define MIN(a, b)  (((a) < (b)) ? (a) : (b))
127
128 #undef  ABS
129 #define ABS(a)     (((a) < 0) ? -(a) : (a))
130
131 #undef  CLAMP
132 #define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
133
134
135 /* Define G_VA_COPY() to do the right thing for copying va_list variables.
136  * glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
137  */
138 #if !defined (G_VA_COPY)
139 #  if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
140 #  define G_VA_COPY(ap1, ap2)     (*(ap1) = *(ap2))
141 #  elif defined (G_VA_COPY_AS_ARRAY)
142 #  define G_VA_COPY(ap1, ap2)     g_memmove ((ap1), (ap2), sizeof (va_list))
143 #  else /* va_list is a pointer */
144 #  define G_VA_COPY(ap1, ap2)     ((ap1) = (ap2))
145 #  endif /* va_list is a pointer */
146 #endif /* !G_VA_COPY */
147
148
149 /* Provide convenience macros for handling structure
150  * fields through their offsets.
151  */
152 #define G_STRUCT_OFFSET(struct_type, member)    \
153     ((gulong) ((gchar*) &((struct_type*) 0)->member))
154 #define G_STRUCT_MEMBER_P(struct_p, struct_offset)   \
155     ((gpointer) ((gchar*) (struct_p) + (gulong) (struct_offset)))
156 #define G_STRUCT_MEMBER(member_type, struct_p, struct_offset)   \
157     (*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
158
159
160 /* inlining hassle. for compilers that don't allow the `inline' keyword,
161  * mostly because of strict ANSI C compliance or dumbness, we try to fall
162  * back to either `__inline__' or `__inline'.
163  * we define G_CAN_INLINE, if the compiler seems to be actually
164  * *capable* to do function inlining, in which case inline function bodys
165  * do make sense. we also define G_INLINE_FUNC to properly export the
166  * function prototypes if no inlining can be performed.
167  * we special case most of the stuff, so inline functions can have a normal
168  * implementation by defining G_INLINE_FUNC to extern and G_CAN_INLINE to 1.
169  */
170 #ifndef G_INLINE_FUNC
171 #  define G_CAN_INLINE 1
172 #endif
173 #ifdef G_HAVE_INLINE
174 #  if defined (__GNUC__) && defined (__STRICT_ANSI__)
175 #    undef inline
176 #    define inline __inline__
177 #  endif
178 #else /* !G_HAVE_INLINE */
179 #  undef inline
180 #  if defined (G_HAVE___INLINE__)
181 #    define inline __inline__
182 #  else /* !inline && !__inline__ */
183 #    if defined (G_HAVE___INLINE)
184 #      define inline __inline
185 #    else /* !inline && !__inline__ && !__inline */
186 #      define inline /* don't inline, then */
187 #      ifndef G_INLINE_FUNC
188 #        undef G_CAN_INLINE
189 #      endif
190 #    endif
191 #  endif
192 #endif
193 #ifndef G_INLINE_FUNC
194 #  ifdef __GNUC__
195 #    ifdef __OPTIMIZE__
196 #      define G_INLINE_FUNC extern inline
197 #    else
198 #      undef G_CAN_INLINE
199 #      define G_INLINE_FUNC extern
200 #    endif
201 #  else /* !__GNUC__ */
202 #    ifdef G_CAN_INLINE
203 #      define G_INLINE_FUNC static inline
204 #    else
205 #      define G_INLINE_FUNC extern
206 #    endif
207 #  endif /* !__GNUC__ */
208 #endif /* !G_INLINE_FUNC */
209
210
211 /* Provide simple macro statement wrappers (adapted from Perl):
212  *  G_STMT_START { statements; } G_STMT_END;
213  *  can be used as a single statement, as in
214  *  if (x) G_STMT_START { ... } G_STMT_END; else ...
215  *
216  *  For gcc we will wrap the statements within `({' and `})' braces.
217  *  For SunOS they will be wrapped within `if (1)' and `else (void) 0',
218  *  and otherwise within `do' and `while (0)'.
219  */
220 #if !(defined (G_STMT_START) && defined (G_STMT_END))
221 #  if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus)
222 #    define G_STMT_START        (void)(
223 #    define G_STMT_END          )
224 #  else
225 #    if (defined (sun) || defined (__sun__))
226 #      define G_STMT_START      if (1)
227 #      define G_STMT_END        else (void)0
228 #    else
229 #      define G_STMT_START      do
230 #      define G_STMT_END        while (0)
231 #    endif
232 #  endif
233 #endif
234
235
236 /* Provide macros to feature the GCC function attribute.
237  */
238 #if     __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
239 #define G_GNUC_PRINTF( format_idx, arg_idx )    \
240   __attribute__((format (printf, format_idx, arg_idx)))
241 #define G_GNUC_SCANF( format_idx, arg_idx )     \
242   __attribute__((format (scanf, format_idx, arg_idx)))
243 #define G_GNUC_FORMAT( arg_idx )                \
244   __attribute__((format_arg (arg_idx)))
245 #define G_GNUC_NORETURN                         \
246   __attribute__((noreturn))
247 #define G_GNUC_CONST                            \
248   __attribute__((const))
249 #define G_GNUC_UNUSED                           \
250   __attribute__((unused))
251 #else   /* !__GNUC__ */
252 #define G_GNUC_PRINTF( format_idx, arg_idx )
253 #define G_GNUC_SCANF( format_idx, arg_idx )
254 #define G_GNUC_FORMAT( arg_idx )
255 #define G_GNUC_NORETURN
256 #define G_GNUC_CONST
257 #define G_GNUC_UNUSED
258 #endif  /* !__GNUC__ */
259
260
261 /* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
262  * macros, so we can refer to them as strings unconditionally.
263  */
264 #ifdef  __GNUC__
265 #define G_GNUC_FUNCTION         (__FUNCTION__)
266 #define G_GNUC_PRETTY_FUNCTION  (__PRETTY_FUNCTION__)
267 #else   /* !__GNUC__ */
268 #define G_GNUC_FUNCTION         ("")
269 #define G_GNUC_PRETTY_FUNCTION  ("")
270 #endif  /* !__GNUC__ */
271
272 /* we try to provide a usefull equivalent for ATEXIT if it is
273  * not defined, but use is actually abandoned. people should
274  * use g_atexit() instead.
275  */
276 #ifndef ATEXIT
277 # define ATEXIT(proc)   g_ATEXIT(proc)
278 #else
279 # define G_NATIVE_ATEXIT
280 #endif /* ATEXIT */
281
282 /* Hacker macro to place breakpoints for elected machines.
283  * Actual use is strongly deprecated of course ;)
284  */
285 #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
286 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
287 #elif defined (__alpha__) && defined (__GNUC__) && __GNUC__ >= 2
288 #define G_BREAKPOINT()          G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
289 #else   /* !__i386__ && !__alpha__ */
290 #define G_BREAKPOINT()
291 #endif  /* __i386__ */
292
293
294 /* Provide macros for easily allocating memory. The macros
295  *  will cast the allocated memory to the specified type
296  *  in order to avoid compiler warnings. (Makes the code neater).
297  */
298
299 #ifdef __DMALLOC_H__
300 #  define g_new(type, count)            (ALLOC (type, count))
301 #  define g_new0(type, count)           (CALLOC (type, count))
302 #  define g_renew(type, mem, count)     (REALLOC (mem, type, count))
303 #else /* __DMALLOC_H__ */
304 #  define g_new(type, count)      \
305       ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
306 #  define g_new0(type, count)     \
307       ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
308 #  define g_renew(type, mem, count)       \
309       ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
310 #endif /* __DMALLOC_H__ */
311
312 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
313   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
314                    sizeof (type), \
315                    sizeof (type) * (pre_alloc), \
316                    (alloc_type)) \
317 )
318 #define g_chunk_new(type, chunk)        ( \
319   (type *) g_mem_chunk_alloc (chunk) \
320 )
321 #define g_chunk_new0(type, chunk)       ( \
322   (type *) g_mem_chunk_alloc0 (chunk) \
323 )
324 #define g_chunk_free(mem, mem_chunk)    G_STMT_START { \
325   g_mem_chunk_free ((mem_chunk), (mem)); \
326 } G_STMT_END
327
328
329 #define g_string(x) #x
330
331
332 /* Provide macros for error handling. The "assert" macros will
333  *  exit on failure. The "return" macros will exit the current
334  *  function. Two different definitions are given for the macros
335  *  if G_DISABLE_ASSERT is not defined, in order to support gcc's
336  *  __PRETTY_FUNCTION__ capability.
337  */
338
339 #ifdef G_DISABLE_ASSERT
340
341 #define g_assert(expr)
342 #define g_assert_not_reached()
343
344 #else /* !G_DISABLE_ASSERT */
345
346 #ifdef __GNUC__
347
348 #define g_assert(expr)                  G_STMT_START{           \
349      if (!(expr))                                               \
350        g_log (G_LOG_DOMAIN,                                     \
351               G_LOG_LEVEL_ERROR,                                \
352               "file %s: line %d (%s): assertion failed: (%s)",  \
353               __FILE__,                                         \
354               __LINE__,                                         \
355               __PRETTY_FUNCTION__,                              \
356               #expr);                   }G_STMT_END
357
358 #define g_assert_not_reached()          G_STMT_START{           \
359      g_log (G_LOG_DOMAIN,                                       \
360             G_LOG_LEVEL_ERROR,                                  \
361             "file %s: line %d (%s): should not be reached",     \
362             __FILE__,                                           \
363             __LINE__,                                           \
364             __PRETTY_FUNCTION__);       }G_STMT_END
365
366 #else /* !__GNUC__ */
367
368 #define g_assert(expr)                  G_STMT_START{           \
369      if (!(expr))                                               \
370        g_log (G_LOG_DOMAIN,                                     \
371               G_LOG_LEVEL_ERROR,                                \
372               "file %s: line %d: assertion failed: (%s)",       \
373               __FILE__,                                         \
374               __LINE__,                                         \
375               #expr);                   }G_STMT_END
376
377 #define g_assert_not_reached()          G_STMT_START{   \
378      g_log (G_LOG_DOMAIN,                               \
379             G_LOG_LEVEL_ERROR,                          \
380             "file %s: line %d: should not be reached",  \
381             __FILE__,                                   \
382             __LINE__);          }G_STMT_END
383
384 #endif /* __GNUC__ */
385
386 #endif /* !G_DISABLE_ASSERT */
387
388
389 #ifdef G_DISABLE_CHECKS
390
391 #define g_return_if_fail(expr)
392 #define g_return_val_if_fail(expr,val)
393
394 #else /* !G_DISABLE_CHECKS */
395
396 #ifdef __GNUC__
397
398 #define g_return_if_fail(expr)          G_STMT_START{                   \
399      if (!(expr))                                                       \
400        {                                                                \
401          g_log (G_LOG_DOMAIN,                                           \
402                 G_LOG_LEVEL_CRITICAL,                                   \
403                 "file %s: line %d (%s): assertion `%s' failed.",        \
404                 __FILE__,                                               \
405                 __LINE__,                                               \
406                 __PRETTY_FUNCTION__,                                    \
407                 #expr);                                                 \
408          return;                                                        \
409        };                               }G_STMT_END
410
411 #define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
412      if (!(expr))                                                       \
413        {                                                                \
414          g_log (G_LOG_DOMAIN,                                           \
415                 G_LOG_LEVEL_CRITICAL,                                   \
416                 "file %s: line %d (%s): assertion `%s' failed.",        \
417                 __FILE__,                                               \
418                 __LINE__,                                               \
419                 __PRETTY_FUNCTION__,                                    \
420                 #expr);                                                 \
421          return val;                                                    \
422        };                               }G_STMT_END
423
424 #else /* !__GNUC__ */
425
426 #define g_return_if_fail(expr)          G_STMT_START{           \
427      if (!(expr))                                               \
428        {                                                        \
429          g_log (G_LOG_DOMAIN,                                   \
430                 G_LOG_LEVEL_CRITICAL,                           \
431                 "file %s: line %d: assertion `%s' failed.",     \
432                 __FILE__,                                       \
433                 __LINE__,                                       \
434                 #expr);                                         \
435          return;                                                \
436        };                               }G_STMT_END
437
438 #define g_return_val_if_fail(expr, val) G_STMT_START{           \
439      if (!(expr))                                               \
440        {                                                        \
441          g_log (G_LOG_DOMAIN,                                   \
442                 G_LOG_LEVEL_CRITICAL,                           \
443                 "file %s: line %d: assertion `%s' failed.",     \
444                 __FILE__,                                       \
445                 __LINE__,                                       \
446                 #expr);                                         \
447          return val;                                            \
448        };                               }G_STMT_END
449
450 #endif /* !__GNUC__ */
451
452 #endif /* !G_DISABLE_CHECKS */
453
454
455 /* Provide type definitions for commonly used types.
456  *  These are useful because a "gint8" can be adjusted
457  *  to be 1 byte (8 bits) on all platforms. Similarly and
458  *  more importantly, "gint32" can be adjusted to be
459  *  4 bytes (32 bits) on all platforms.
460  */
461
462 typedef char   gchar;
463 typedef short  gshort;
464 typedef long   glong;
465 typedef int    gint;
466 typedef gint   gboolean;
467
468 typedef unsigned char   guchar;
469 typedef unsigned short  gushort;
470 typedef unsigned long   gulong;
471 typedef unsigned int    guint;
472
473 typedef float   gfloat;
474 typedef double  gdouble;
475
476 /* HAVE_LONG_DOUBLE doesn't work correctly on all platforms.
477  * Since gldouble isn't used anywhere, just disable it for now */
478
479 #if 0
480 #ifdef HAVE_LONG_DOUBLE
481 typedef long double gldouble;
482 #else /* HAVE_LONG_DOUBLE */
483 typedef double gldouble;
484 #endif /* HAVE_LONG_DOUBLE */
485 #endif /* 0 */
486
487 typedef void* gpointer;
488 typedef const void *gconstpointer;
489
490
491 typedef gint32  gssize;
492 typedef guint32 gsize;
493 typedef guint32 GQuark;
494 typedef gint32  GTime;
495
496
497 /* Portable endian checks and conversions
498  *
499  * glibconfig.h defines G_BYTE_ORDER which expands to one of
500  * the below macros.
501  */
502 #define G_LITTLE_ENDIAN 1234
503 #define G_BIG_ENDIAN    4321
504 #define G_PDP_ENDIAN    3412            /* unused, need specific PDP check */   
505
506
507 /* Basic bit swapping functions
508  */
509 #define GUINT16_SWAP_LE_BE_CONSTANT(val)        ((guint16) ( \
510     (((guint16) (val) & (guint16) 0x00ffU) << 8) | \
511     (((guint16) (val) & (guint16) 0xff00U) >> 8)))
512 #define GUINT32_SWAP_LE_BE_CONSTANT(val)        ((guint32) ( \
513     (((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
514     (((guint32) (val) & (guint32) 0x0000ff00U) <<  8) | \
515     (((guint32) (val) & (guint32) 0x00ff0000U) >>  8) | \
516     (((guint32) (val) & (guint32) 0xff000000U) >> 24)))
517
518 /* Intel specific stuff for speed
519  */
520 #if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
521 #  define GUINT16_SWAP_LE_BE_X86(val) \
522      (__extension__                                     \
523       ({ register guint16 __v;                          \
524          if (__builtin_constant_p (val))                \
525            __v = GUINT16_SWAP_LE_BE_CONSTANT (val);     \
526          else                                           \
527            __asm__ __const__ ("rorw $8, %w0"            \
528                               : "=r" (__v)              \
529                               : "0" ((guint16) (val))); \
530         __v; }))
531 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_X86 (val))
532 #  if !defined(__i486__) && !defined(__i586__) \
533       && !defined(__pentium__) && !defined(__i686__) && !defined(__pentiumpro__)
534 #     define GUINT32_SWAP_LE_BE_X86(val) \
535         (__extension__                                          \
536          ({ register guint32 __v;                               \
537             if (__builtin_constant_p (val))                     \
538               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
539           else                                                  \
540             __asm__ __const__ ("rorw $8, %w0\n\t"               \
541                                "rorl $16, %0\n\t"               \
542                                "rorw $8, %w0"                   \
543                                : "=r" (__v)                     \
544                                : "0" ((guint32) (val)));        \
545         __v; }))
546 #  else /* 486 and higher has bswap */
547 #     define GUINT32_SWAP_LE_BE_X86(val) \
548         (__extension__                                          \
549          ({ register guint32 __v;                               \
550             if (__builtin_constant_p (val))                     \
551               __v = GUINT32_SWAP_LE_BE_CONSTANT (val);          \
552           else                                                  \
553             __asm__ __const__ ("bswap %0"                       \
554                                : "=r" (__v)                     \
555                                : "0" ((guint32) (val)));        \
556         __v; }))
557 #  endif /* processor specific 32-bit stuff */
558 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86 (val))
559 #else /* !__i386__ */
560 #  define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
561 #  define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
562 #endif /* __i386__ */
563
564 #ifdef G_HAVE_GINT64
565 #  define GUINT64_SWAP_LE_BE_CONSTANT(val)      ((guint64) ( \
566       (((guint64) (val) &                                               \
567         (guint64) G_GINT64_CONSTANT(0x00000000000000ffU)) << 56) |      \
568       (((guint64) (val) &                                               \
569         (guint64) G_GINT64_CONSTANT(0x000000000000ff00U)) << 40) |      \
570       (((guint64) (val) &                                               \
571         (guint64) G_GINT64_CONSTANT(0x0000000000ff0000U)) << 24) |      \
572       (((guint64) (val) &                                               \
573         (guint64) G_GINT64_CONSTANT(0x00000000ff000000U)) <<  8) |      \
574       (((guint64) (val) &                                               \
575         (guint64) G_GINT64_CONSTANT(0x000000ff00000000U)) >>  8) |      \
576       (((guint64) (val) &                                               \
577         (guint64) G_GINT64_CONSTANT(0x0000ff0000000000U)) >> 24) |      \
578       (((guint64) (val) &                                               \
579         (guint64) G_GINT64_CONSTANT(0x00ff000000000000U)) >> 40) |      \
580       (((guint64) (val) &                                               \
581         (guint64) G_GINT64_CONSTANT(0xff00000000000000U)) >> 56)))
582 #  if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2
583 #    define GUINT64_SWAP_LE_BE_X86(val) \
584         (__extension__                                          \
585          ({ union { guint64 __ll;                               \
586                     guint32 __l[2]; } __r;                      \
587             if (__builtin_constant_p (val))                     \
588               __r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (val);     \
589             else                                                \
590               {                                                 \
591                 union { guint64 __ll;                           \
592                         guint32 __l[2]; } __w;                  \
593                 __w.__ll = ((guint64) val);                     \
594                 __r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]);   \
595                 __r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]);   \
596               }                                                 \
597           __r.__ll; }))
598 #    define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86 (val))
599 #  else /* !__i386__ */
600 #    define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT(val))
601 #  endif
602 #endif
603
604 #define GUINT16_SWAP_LE_PDP(val)        ((guint16) (val))
605 #define GUINT16_SWAP_BE_PDP(val)        (GUINT16_SWAP_LE_BE (val))
606 #define GUINT32_SWAP_LE_PDP(val)        ((guint32) ( \
607     (((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
608     (((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
609 #define GUINT32_SWAP_BE_PDP(val)        ((guint32) ( \
610     (((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
611     (((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
612
613 /* The G*_TO_?E() macros are defined in glibconfig.h.
614  * The transformation is symmetric, so the FROM just maps to the TO.
615  */
616 #define GINT16_FROM_LE(val)     (GINT16_TO_LE (val))
617 #define GUINT16_FROM_LE(val)    (GUINT16_TO_LE (val))
618 #define GINT16_FROM_BE(val)     (GINT16_TO_BE (val))
619 #define GUINT16_FROM_BE(val)    (GUINT16_TO_BE (val))
620 #define GINT32_FROM_LE(val)     (GINT32_TO_LE (val))
621 #define GUINT32_FROM_LE(val)    (GUINT32_TO_LE (val))
622 #define GINT32_FROM_BE(val)     (GINT32_TO_BE (val))
623 #define GUINT32_FROM_BE(val)    (GUINT32_TO_BE (val))
624
625 #ifdef G_HAVE_GINT64
626 #define GINT64_FROM_LE(val)     (GINT64_TO_LE (val))
627 #define GUINT64_FROM_LE(val)    (GUINT64_TO_LE (val))
628 #define GINT64_FROM_BE(val)     (GINT64_TO_BE (val))
629 #define GUINT64_FROM_BE(val)    (GUINT64_TO_BE (val))
630 #endif
631
632 #define GLONG_FROM_LE(val)      (GLONG_TO_LE (val))
633 #define GULONG_FROM_LE(val)     (GULONG_TO_LE (val))
634 #define GLONG_FROM_BE(val)      (GLONG_TO_BE (val))
635 #define GULONG_FROM_BE(val)     (GULONG_TO_BE (val))
636
637 #define GINT_FROM_LE(val)       (GINT_TO_LE (val))
638 #define GUINT_FROM_LE(val)      (GUINT_TO_LE (val))
639 #define GINT_FROM_BE(val)       (GINT_TO_BE (val))
640 #define GUINT_FROM_BE(val)      (GUINT_TO_BE (val))
641
642
643 /* Portable versions of host-network order stuff
644  */
645 #define g_ntohl(val) (GUINT32_FROM_BE (val))
646 #define g_ntohs(val) (GUINT16_FROM_BE (val))
647 #define g_htonl(val) (GUINT32_TO_BE (val))
648 #define g_htons(val) (GUINT16_TO_BE (val))
649
650
651 /* Glib version.
652  * we prefix variable declarations so they can
653  * properly get exported in windows dlls.
654  */
655 #ifdef NATIVE_WIN32
656 #  ifdef GLIB_COMPILATION
657 #    define GUTILS_C_VAR __declspec(dllexport)
658 #  else /* !GLIB_COMPILATION */
659 #    define GUTILS_C_VAR extern __declspec(dllimport)
660 #  endif /* !GLIB_COMPILATION */
661 #else /* !NATIVE_WIN32 */
662 #  define GUTILS_C_VAR extern
663 #endif /* !NATIVE_WIN32 */
664
665 GUTILS_C_VAR const guint glib_major_version;
666 GUTILS_C_VAR const guint glib_minor_version;
667 GUTILS_C_VAR const guint glib_micro_version;
668 GUTILS_C_VAR const guint glib_interface_age;
669 GUTILS_C_VAR const guint glib_binary_age;
670
671
672 /* Forward declarations of glib types.
673  */
674 typedef struct _GAllocator      GAllocator;
675 typedef struct _GArray          GArray;
676 typedef struct _GByteArray      GByteArray;
677 typedef struct _GCache          GCache;
678 typedef struct _GCompletion     GCompletion;
679 typedef struct _GData           GData;
680 typedef struct _GDebugKey       GDebugKey;
681 typedef struct _GHashTable      GHashTable;
682 typedef struct _GHook           GHook;
683 typedef struct _GHookList       GHookList;
684 typedef struct _GList           GList;
685 typedef struct _GMemChunk       GMemChunk;
686 typedef struct _GNode           GNode;
687 typedef struct _GPtrArray       GPtrArray;
688 typedef struct _GQueue          GQueue;
689 typedef struct _GRelation       GRelation;
690 typedef struct _GScanner        GScanner;
691 typedef struct _GScannerConfig  GScannerConfig;
692 typedef struct _GSList          GSList;
693 typedef struct _GStack          GStack;
694 typedef struct _GString         GString;
695 typedef struct _GStringChunk    GStringChunk;
696 typedef struct _GTimer          GTimer;
697 typedef struct _GTree           GTree;
698 typedef struct _GTuples         GTuples;
699 typedef union  _GTokenValue     GTokenValue;
700 typedef struct _GIOChannel      GIOChannel;
701
702 typedef enum
703 {
704   G_TRAVERSE_LEAFS      = 1 << 0,
705   G_TRAVERSE_NON_LEAFS  = 1 << 1,
706   G_TRAVERSE_ALL        = G_TRAVERSE_LEAFS | G_TRAVERSE_NON_LEAFS,
707   G_TRAVERSE_MASK       = 0x03
708 } GTraverseFlags;
709
710 typedef enum
711 {
712   G_IN_ORDER,
713   G_PRE_ORDER,
714   G_POST_ORDER,
715   G_LEVEL_ORDER
716 } GTraverseType;
717
718 /* Log level shift offset for user defined
719  * log levels (0-7 are used by GLib).
720  */
721 #define G_LOG_LEVEL_USER_SHIFT  (8)
722
723 /* Glib log levels and flags.
724  */
725 typedef enum
726 {
727   /* log flags */
728   G_LOG_FLAG_RECURSION          = 1 << 0,
729   G_LOG_FLAG_FATAL              = 1 << 1,
730   
731   /* GLib log levels */
732   G_LOG_LEVEL_ERROR             = 1 << 2,       /* always fatal */
733   G_LOG_LEVEL_CRITICAL          = 1 << 3,
734   G_LOG_LEVEL_WARNING           = 1 << 4,
735   G_LOG_LEVEL_MESSAGE           = 1 << 5,
736   G_LOG_LEVEL_INFO              = 1 << 6,
737   G_LOG_LEVEL_DEBUG             = 1 << 7,
738   
739   G_LOG_LEVEL_MASK              = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
740 } GLogLevelFlags;
741
742 /* GLib log levels that are considered fatal by default */
743 #define G_LOG_FATAL_MASK        (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
744
745
746 typedef gpointer        (*GCacheNewFunc)        (gpointer       key);
747 typedef gpointer        (*GCacheDupFunc)        (gpointer       value);
748 typedef void            (*GCacheDestroyFunc)    (gpointer       value);
749 typedef gint            (*GCompareFunc)         (gconstpointer  a,
750                                                  gconstpointer  b);
751 typedef gchar*          (*GCompletionFunc)      (gpointer);
752 typedef void            (*GDestroyNotify)       (gpointer       data);
753 typedef void            (*GDataForeachFunc)     (GQuark         key_id,
754                                                  gpointer       data,
755                                                  gpointer       user_data);
756 typedef void            (*GFunc)                (gpointer       data,
757                                                  gpointer       user_data);
758 typedef guint           (*GHashFunc)            (gconstpointer  key);
759 typedef void            (*GFreeFunc)            (gpointer       data);
760 typedef void            (*GHFunc)               (gpointer       key,
761                                                  gpointer       value,
762                                                  gpointer       user_data);
763 typedef gboolean        (*GHRFunc)              (gpointer       key,
764                                                  gpointer       value,
765                                                  gpointer       user_data);
766 typedef gint            (*GHookCompareFunc)     (GHook          *new_hook,
767                                                  GHook          *sibling);
768 typedef gboolean        (*GHookFindFunc)        (GHook          *hook,
769                                                  gpointer        data);
770 typedef void            (*GHookMarshaller)      (GHook          *hook,
771                                                  gpointer        data);
772 typedef gboolean        (*GHookCheckMarshaller) (GHook          *hook,
773                                                  gpointer        data);
774 typedef void            (*GHookFunc)            (gpointer        data);
775 typedef gboolean        (*GHookCheckFunc)       (gpointer        data);
776 typedef void            (*GHookFreeFunc)        (GHookList      *hook_list,
777                                                  GHook          *hook);
778 typedef void            (*GLogFunc)             (const gchar   *log_domain,
779                                                  GLogLevelFlags log_level,
780                                                  const gchar   *message,
781                                                  gpointer       user_data);
782 typedef gboolean        (*GNodeTraverseFunc)    (GNode         *node,
783                                                  gpointer       data);
784 typedef void            (*GNodeForeachFunc)     (GNode         *node,
785                                                  gpointer       data);
786 typedef gint            (*GSearchFunc)          (gpointer       key,
787                                                  gpointer       data);
788 typedef void            (*GScannerMsgFunc)      (GScanner      *scanner,
789                                                  gchar         *message,
790                                                  gint           error);
791 typedef gint            (*GTraverseFunc)        (gpointer       key,
792                                                  gpointer       value,
793                                                  gpointer       data);
794 typedef void            (*GVoidFunc)            (void);
795
796
797 struct _GList
798 {
799   gpointer data;
800   GList *next;
801   GList *prev;
802 };
803
804 struct _GSList
805 {
806   gpointer data;
807   GSList *next;
808 };
809
810 struct _GStack
811 {
812   GList *list;
813 };
814
815 struct _GQueue
816 {
817   GList *list;
818   GList *list_end;
819   guint list_size;
820 };
821
822 struct _GString
823 {
824   gchar *str;
825   gint len;
826 };
827
828 struct _GArray
829 {
830   gchar *data;
831   guint len;
832 };
833
834 struct _GByteArray
835 {
836   guint8 *data;
837   guint   len;
838 };
839
840 struct _GPtrArray
841 {
842   gpointer *pdata;
843   guint     len;
844 };
845
846 struct _GTuples
847 {
848   guint len;
849 };
850
851 struct _GDebugKey
852 {
853   gchar *key;
854   guint  value;
855 };
856
857
858 /* Doubly linked lists
859  */
860 void   g_list_push_allocator    (GAllocator     *allocator);
861 void   g_list_pop_allocator     (void);
862 GList* g_list_alloc             (void);
863 void   g_list_free              (GList          *list);
864 void   g_list_free_1            (GList          *list);
865 GList* g_list_append            (GList          *list,
866                                  gpointer        data);
867 GList* g_list_prepend           (GList          *list,
868                                  gpointer        data);
869 GList* g_list_insert            (GList          *list,
870                                  gpointer        data,
871                                  gint            position);
872 GList* g_list_insert_sorted     (GList          *list,
873                                  gpointer        data,
874                                  GCompareFunc    func);
875 GList* g_list_concat            (GList          *list1,
876                                  GList          *list2);
877 GList* g_list_delete            (GList          *list,
878                                  GList          *link);
879 GList* g_list_remove            (GList          *list,
880                                  gpointer        data);
881 GList* g_list_remove_link       (GList          *list,
882                                  GList          *llink);
883 GList* g_list_reverse           (GList          *list);
884 GList* g_list_copy              (GList          *list);
885 GList* g_list_nth               (GList          *list,
886                                  guint           n);
887 GList* g_list_find              (GList          *list,
888                                  gpointer        data);
889 GList* g_list_find_custom       (GList          *list,
890                                  gpointer        data,
891                                  GCompareFunc    func);
892 gint   g_list_position          (GList          *list,
893                                  GList          *llink);
894 gint   g_list_index             (GList          *list,
895                                  gpointer        data);
896 GList* g_list_last              (GList          *list);
897 GList* g_list_first             (GList          *list);
898 guint  g_list_length            (GList          *list);
899 void   g_list_foreach           (GList          *list,
900                                  GFunc           func,
901                                  gpointer        user_data);
902 GList* g_list_sort              (GList          *list,
903                                  GCompareFunc    compare_func);
904 gpointer g_list_nth_data        (GList          *list,
905                                  guint           n);
906 #define g_list_previous(list)   ((list) ? (((GList *)(list))->prev) : NULL)
907 #define g_list_next(list)       ((list) ? (((GList *)(list))->next) : NULL)
908
909
910 /* Singly linked lists
911  */
912 void    g_slist_push_allocator  (GAllocator     *allocator);
913 void    g_slist_pop_allocator   (void);
914 GSList* g_slist_alloc           (void);
915 void    g_slist_free            (GSList         *list);
916 void    g_slist_free_1          (GSList         *list);
917 GSList* g_slist_append          (GSList         *list,
918                                  gpointer        data);
919 GSList* g_slist_prepend         (GSList         *list,
920                                  gpointer        data);
921 GSList* g_slist_insert          (GSList         *list,
922                                  gpointer        data,
923                                  gint            position);
924 GSList* g_slist_insert_sorted   (GSList         *list,
925                                  gpointer        data,
926                                  GCompareFunc    func);
927 GSList* g_slist_concat          (GSList         *list1,
928                                  GSList         *list2);
929 GSList* g_slist_remove          (GSList         *list,
930                                  gpointer        data);
931 GSList* g_slist_remove_link     (GSList         *list,
932                                  GSList         *llink);
933 GSList* g_slist_reverse         (GSList         *list);
934 GSList* g_slist_copy            (GSList         *list);
935 GSList* g_slist_nth             (GSList         *list,
936                                  guint           n);
937 GSList* g_slist_find            (GSList         *list,
938                                  gpointer        data);
939 GSList* g_slist_find_custom     (GSList         *list,
940                                  gpointer        data,
941                                  GCompareFunc    func);
942 gint    g_slist_position        (GSList         *list,
943                                  GSList         *llink);
944 gint    g_slist_index           (GSList         *list,
945                                  gpointer        data);
946 GSList* g_slist_last            (GSList         *list);
947 guint   g_slist_length          (GSList         *list);
948 void    g_slist_foreach         (GSList         *list,
949                                  GFunc           func,
950                                  gpointer        user_data);
951 GSList*  g_slist_sort           (GSList          *list,
952                                  GCompareFunc    compare_func);
953 gpointer g_slist_nth_data       (GSList         *list,
954                                  guint           n);
955 #define g_slist_next(slist)     ((slist) ? (((GSList *)(slist))->next) : NULL)
956
957
958 /* Stacks
959  */
960
961 GStack * g_stack_new    (void);
962 void     g_stack_free   (GStack *stack);
963 gpointer g_stack_pop    (GStack *stack);
964
965 #define g_stack_empty(stack) \
966         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? FALSE : TRUE)
967
968 #define g_stack_peek(stack) \
969         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? \
970                 ((GStack *)(stack))->list->data : NULL)
971
972 #define g_stack_index(stack,ptr) \
973         ((((GStack *)(stack)) && ((GStack *)(stack))->list) ? \
974                 g_list_index (((GStack *)(stack))->list, (ptr)) : -1)
975
976 #define g_stack_push(stack,data) G_STMT_START {                         \
977             if ((GStack *)(stack))                                      \
978               ((GStack *)(stack))->list =                               \
979                   g_list_prepend (((GStack *)(stack))->list, (data));   \
980           } G_STMT_END
981
982
983
984 /* Queues
985  */
986
987 GQueue *        g_queue_new             (void);
988 void            g_queue_free            (GQueue *q);
989 guint           g_queue_get_size        (GQueue *q);
990 void            g_queue_push_front      (GQueue *q, gpointer data);
991 void            g_queue_push_back       (GQueue *q, gpointer data);
992 gpointer        g_queue_pop_front       (GQueue *q);
993 gpointer        g_queue_pop_back        (GQueue *q);
994
995 #define g_queue_empty(queue) \
996         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? FALSE : TRUE)
997
998 #define g_queue_peek_front(queue) \
999         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
1000                 ((GQueue *)(queue))->list->data : NULL)
1001
1002 #define g_queue_peek_back(queue) \
1003         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list_end) ? \
1004                 ((GQueue *)(queue))->list_end->data : NULL)
1005
1006 #define g_queue_index(queue,ptr) \
1007         ((((GQueue *)(queue)) && ((GQueue *)(queue))->list) ? \
1008                 g_list_index (((GQueue *)(queue))->list, (ptr)) : -1)
1009
1010 #define         g_queue_push            g_queue_push_back
1011 #define         g_queue_pop             g_queue_pop_front
1012 #define         g_queue_peek            g_queue_peek_front
1013
1014
1015
1016
1017
1018 /* Hash tables
1019  */
1020 GHashTable* g_hash_table_new            (GHashFunc       hash_func,
1021                                          GCompareFunc    key_compare_func);
1022 void        g_hash_table_destroy        (GHashTable     *hash_table);
1023 void        g_hash_table_insert         (GHashTable     *hash_table,
1024                                          gpointer        key,
1025                                          gpointer        value);
1026 void        g_hash_table_remove         (GHashTable     *hash_table,
1027                                          gconstpointer   key);
1028 gpointer    g_hash_table_lookup         (GHashTable     *hash_table,
1029                                          gconstpointer   key);
1030 gboolean    g_hash_table_lookup_extended(GHashTable     *hash_table,
1031                                          gconstpointer   lookup_key,
1032                                          gpointer       *orig_key,
1033                                          gpointer       *value);
1034 void        g_hash_table_freeze         (GHashTable     *hash_table);
1035 void        g_hash_table_thaw           (GHashTable     *hash_table);
1036 void        g_hash_table_foreach        (GHashTable     *hash_table,
1037                                          GHFunc          func,
1038                                          gpointer        user_data);
1039 guint       g_hash_table_foreach_remove (GHashTable     *hash_table,
1040                                          GHRFunc         func,
1041                                          gpointer        user_data);
1042 guint       g_hash_table_size           (GHashTable     *hash_table);
1043
1044
1045 /* Caches
1046  */
1047 GCache*  g_cache_new           (GCacheNewFunc      value_new_func,
1048                                 GCacheDestroyFunc  value_destroy_func,
1049                                 GCacheDupFunc      key_dup_func,
1050                                 GCacheDestroyFunc  key_destroy_func,
1051                                 GHashFunc          hash_key_func,
1052                                 GHashFunc          hash_value_func,
1053                                 GCompareFunc       key_compare_func);
1054 void     g_cache_destroy       (GCache            *cache);
1055 gpointer g_cache_insert        (GCache            *cache,
1056                                 gpointer           key);
1057 void     g_cache_remove        (GCache            *cache,
1058                                 gpointer           value);
1059 void     g_cache_key_foreach   (GCache            *cache,
1060                                 GHFunc             func,
1061                                 gpointer           user_data);
1062 void     g_cache_value_foreach (GCache            *cache,
1063                                 GHFunc             func,
1064                                 gpointer           user_data);
1065
1066
1067 /* Balanced binary trees
1068  */
1069 GTree*   g_tree_new      (GCompareFunc   key_compare_func);
1070 void     g_tree_destroy  (GTree         *tree);
1071 void     g_tree_insert   (GTree         *tree,
1072                           gpointer       key,
1073                           gpointer       value);
1074 void     g_tree_remove   (GTree         *tree,
1075                           gpointer       key);
1076 gpointer g_tree_lookup   (GTree         *tree,
1077                           gpointer       key);
1078 void     g_tree_traverse (GTree         *tree,
1079                           GTraverseFunc  traverse_func,
1080                           GTraverseType  traverse_type,
1081                           gpointer       data);
1082 gpointer g_tree_search   (GTree         *tree,
1083                           GSearchFunc    search_func,
1084                           gpointer       data);
1085 gint     g_tree_height   (GTree         *tree);
1086 gint     g_tree_nnodes   (GTree         *tree);
1087
1088
1089
1090 /* N-way tree implementation
1091  */
1092 struct _GNode
1093 {
1094   gpointer data;
1095   GNode   *next;
1096   GNode   *prev;
1097   GNode   *parent;
1098   GNode   *children;
1099 };
1100
1101 #define  G_NODE_IS_ROOT(node)   (((GNode*) (node))->parent == NULL && \
1102                                  ((GNode*) (node))->prev == NULL && \
1103                                  ((GNode*) (node))->next == NULL)
1104 #define  G_NODE_IS_LEAF(node)   (((GNode*) (node))->children == NULL)
1105
1106 void     g_node_push_allocator  (GAllocator       *allocator);
1107 void     g_node_pop_allocator   (void);
1108 GNode*   g_node_new             (gpointer          data);
1109 void     g_node_destroy         (GNode            *root);
1110 void     g_node_unlink          (GNode            *node);
1111 GNode*   g_node_insert          (GNode            *parent,
1112                                  gint              position,
1113                                  GNode            *node);
1114 GNode*   g_node_insert_before   (GNode            *parent,
1115                                  GNode            *sibling,
1116                                  GNode            *node);
1117 GNode*   g_node_prepend         (GNode            *parent,
1118                                  GNode            *node);
1119 guint    g_node_n_nodes         (GNode            *root,
1120                                  GTraverseFlags    flags);
1121 GNode*   g_node_get_root        (GNode            *node);
1122 gboolean g_node_is_ancestor     (GNode            *node,
1123                                  GNode            *descendant);
1124 guint    g_node_depth           (GNode            *node);
1125 GNode*   g_node_find            (GNode            *root,
1126                                  GTraverseType     order,
1127                                  GTraverseFlags    flags,
1128                                  gpointer          data);
1129
1130 /* convenience macros */
1131 #define g_node_append(parent, node)                             \
1132      g_node_insert_before ((parent), NULL, (node))
1133 #define g_node_insert_data(parent, position, data)              \
1134      g_node_insert ((parent), (position), g_node_new (data))
1135 #define g_node_insert_data_before(parent, sibling, data)        \
1136      g_node_insert_before ((parent), (sibling), g_node_new (data))
1137 #define g_node_prepend_data(parent, data)                       \
1138      g_node_prepend ((parent), g_node_new (data))
1139 #define g_node_append_data(parent, data)                        \
1140      g_node_insert_before ((parent), NULL, g_node_new (data))
1141
1142 /* traversal function, assumes that `node' is root
1143  * (only traverses `node' and its subtree).
1144  * this function is just a high level interface to
1145  * low level traversal functions, optimized for speed.
1146  */
1147 void     g_node_traverse        (GNode            *root,
1148                                  GTraverseType     order,
1149                                  GTraverseFlags    flags,
1150                                  gint              max_depth,
1151                                  GNodeTraverseFunc func,
1152                                  gpointer          data);
1153
1154 /* return the maximum tree height starting with `node', this is an expensive
1155  * operation, since we need to visit all nodes. this could be shortened by
1156  * adding `guint height' to struct _GNode, but then again, this is not very
1157  * often needed, and would make g_node_insert() more time consuming.
1158  */
1159 guint    g_node_max_height       (GNode *root);
1160
1161 void     g_node_children_foreach (GNode           *node,
1162                                   GTraverseFlags   flags,
1163                                   GNodeForeachFunc func,
1164                                   gpointer         data);
1165 void     g_node_reverse_children (GNode           *node);
1166 guint    g_node_n_children       (GNode           *node);
1167 GNode*   g_node_nth_child        (GNode           *node,
1168                                   guint            n);
1169 GNode*   g_node_last_child       (GNode           *node);
1170 GNode*   g_node_find_child       (GNode           *node,
1171                                   GTraverseFlags   flags,
1172                                   gpointer         data);
1173 gint     g_node_child_position   (GNode           *node,
1174                                   GNode           *child);
1175 gint     g_node_child_index      (GNode           *node,
1176                                   gpointer         data);
1177
1178 GNode*   g_node_first_sibling    (GNode           *node);
1179 GNode*   g_node_last_sibling     (GNode           *node);
1180
1181 #define  g_node_prev_sibling(node)      ((node) ? \
1182                                          ((GNode*) (node))->prev : NULL)
1183 #define  g_node_next_sibling(node)      ((node) ? \
1184                                          ((GNode*) (node))->next : NULL)
1185 #define  g_node_first_child(node)       ((node) ? \
1186                                          ((GNode*) (node))->children : NULL)
1187
1188
1189 /* Callback maintenance functions
1190  */
1191 #define G_HOOK_FLAG_USER_SHIFT  (4)
1192 typedef enum
1193 {
1194   G_HOOK_FLAG_ACTIVE    = 1 << 0,
1195   G_HOOK_FLAG_IN_CALL   = 1 << 1,
1196   G_HOOK_FLAG_MASK      = 0x0f
1197 } GHookFlagMask;
1198
1199 #define G_HOOK_DEFERRED_DESTROY ((GHookFreeFunc) 0x01)
1200
1201 struct _GHookList
1202 {
1203   guint          seq_id;
1204   guint          hook_size;
1205   guint          is_setup : 1;
1206   GHook         *hooks;
1207   GMemChunk     *hook_memchunk;
1208   GHookFreeFunc  hook_free; /* virtual function */
1209   GHookFreeFunc  hook_destroy; /* virtual function */
1210 };
1211
1212 struct _GHook
1213 {
1214   gpointer       data;
1215   GHook         *next;
1216   GHook         *prev;
1217   guint          ref_count;
1218   guint          hook_id;
1219   guint          flags;
1220   gpointer       func;
1221   GDestroyNotify destroy;
1222 };
1223
1224 #define G_HOOK_ACTIVE(hook)             ((((GHook*) hook)->flags & \
1225                                           G_HOOK_FLAG_ACTIVE) != 0)
1226 #define G_HOOK_IN_CALL(hook)            ((((GHook*) hook)->flags & \
1227                                           G_HOOK_FLAG_IN_CALL) != 0)
1228 #define G_HOOK_IS_VALID(hook)           (((GHook*) hook)->hook_id != 0 && \
1229                                          G_HOOK_ACTIVE (hook))
1230 #define G_HOOK_IS_UNLINKED(hook)        (((GHook*) hook)->next == NULL && \
1231                                          ((GHook*) hook)->prev == NULL && \
1232                                          ((GHook*) hook)->hook_id == 0 && \
1233                                          ((GHook*) hook)->ref_count == 0)
1234
1235 void     g_hook_list_init               (GHookList              *hook_list,
1236                                          guint                   hook_size);
1237 void     g_hook_list_clear              (GHookList              *hook_list);
1238 GHook*   g_hook_alloc                   (GHookList              *hook_list);
1239 void     g_hook_free                    (GHookList              *hook_list,
1240                                          GHook                  *hook);
1241 void     g_hook_ref                     (GHookList              *hook_list,
1242                                          GHook                  *hook);
1243 void     g_hook_unref                   (GHookList              *hook_list,
1244                                          GHook                  *hook);
1245 gboolean g_hook_destroy                 (GHookList              *hook_list,
1246                                          guint                   hook_id);
1247 void     g_hook_destroy_link            (GHookList              *hook_list,
1248                                          GHook                  *hook);
1249 void     g_hook_prepend                 (GHookList              *hook_list,
1250                                          GHook                  *hook);
1251 void     g_hook_insert_before           (GHookList              *hook_list,
1252                                          GHook                  *sibling,
1253                                          GHook                  *hook);
1254 void     g_hook_insert_sorted           (GHookList              *hook_list,
1255                                          GHook                  *hook,
1256                                          GHookCompareFunc        func);
1257 GHook*   g_hook_get                     (GHookList              *hook_list,
1258                                          guint                   hook_id);
1259 GHook*   g_hook_find                    (GHookList              *hook_list,
1260                                          gboolean                need_valids,
1261                                          GHookFindFunc           func,
1262                                          gpointer                data);
1263 GHook*   g_hook_find_data               (GHookList              *hook_list,
1264                                          gboolean                need_valids,
1265                                          gpointer                data);
1266 GHook*   g_hook_find_func               (GHookList              *hook_list,
1267                                          gboolean                need_valids,
1268                                          gpointer                func);
1269 GHook*   g_hook_find_func_data          (GHookList              *hook_list,
1270                                          gboolean                need_valids,
1271                                          gpointer                func,
1272                                          gpointer                data);
1273 /* return the first valid hook, and increment its reference count */
1274 GHook*   g_hook_first_valid             (GHookList              *hook_list,
1275                                          gboolean                may_be_in_call);
1276 /* return the next valid hook with incremented reference count, and
1277  * decrement the reference count of the original hook
1278  */
1279 GHook*   g_hook_next_valid              (GHookList              *hook_list,
1280                                          GHook                  *hook,
1281                                          gboolean                may_be_in_call);
1282
1283 /* GHookCompareFunc implementation to insert hooks sorted by their id */
1284 gint     g_hook_compare_ids             (GHook                  *new_hook,
1285                                          GHook                  *sibling);
1286
1287 /* convenience macros */
1288 #define  g_hook_append( hook_list, hook )  \
1289      g_hook_insert_before ((hook_list), NULL, (hook))
1290
1291 /* invoke all valid hooks with the (*GHookFunc) signature.
1292  */
1293 void     g_hook_list_invoke             (GHookList              *hook_list,
1294                                          gboolean                may_recurse);
1295 /* invoke all valid hooks with the (*GHookCheckFunc) signature,
1296  * and destroy the hook if FALSE is returned.
1297  */
1298 void     g_hook_list_invoke_check       (GHookList              *hook_list,
1299                                          gboolean                may_recurse);
1300 /* invoke a marshaller on all valid hooks.
1301  */
1302 void     g_hook_list_marshal            (GHookList              *hook_list,
1303                                          gboolean                may_recurse,
1304                                          GHookMarshaller         marshaller,
1305                                          gpointer                data);
1306 void     g_hook_list_marshal_check      (GHookList              *hook_list,
1307                                          gboolean                may_recurse,
1308                                          GHookCheckMarshaller    marshaller,
1309                                          gpointer                data);
1310
1311
1312 /* Fatal error handlers.
1313  * g_on_error_query() will prompt the user to either
1314  * [E]xit, [H]alt, [P]roceed or show [S]tack trace.
1315  * g_on_error_stack_trace() invokes gdb, which attaches to the current
1316  * process and shows a stack trace.
1317  * These function may cause different actions on non-unix platforms.
1318  * The prg_name arg is required by gdb to find the executable, if it is
1319  * passed as NULL, g_on_error_query() will try g_get_prgname().
1320  */
1321 void g_on_error_query (const gchar *prg_name);
1322 void g_on_error_stack_trace (const gchar *prg_name);
1323
1324
1325 /* Logging mechanism
1326  */
1327 extern          const gchar             *g_log_domain_glib;
1328 guint           g_log_set_handler       (const gchar    *log_domain,
1329                                          GLogLevelFlags  log_levels,
1330                                          GLogFunc        log_func,
1331                                          gpointer        user_data);
1332 void            g_log_remove_handler    (const gchar    *log_domain,
1333                                          guint           handler_id);
1334 void            g_log_default_handler   (const gchar    *log_domain,
1335                                          GLogLevelFlags  log_level,
1336                                          const gchar    *message,
1337                                          gpointer        unused_data);
1338 void            g_log                   (const gchar    *log_domain,
1339                                          GLogLevelFlags  log_level,
1340                                          const gchar    *format,
1341                                          ...) G_GNUC_PRINTF (3, 4);
1342 void            g_logv                  (const gchar    *log_domain,
1343                                          GLogLevelFlags  log_level,
1344                                          const gchar    *format,
1345                                          va_list         args);
1346 GLogLevelFlags  g_log_set_fatal_mask    (const gchar    *log_domain,
1347                                          GLogLevelFlags  fatal_mask);
1348 GLogLevelFlags  g_log_set_always_fatal  (GLogLevelFlags  fatal_mask);
1349 #ifndef G_LOG_DOMAIN
1350 #define G_LOG_DOMAIN    ((gchar*) 0)
1351 #endif  /* G_LOG_DOMAIN */
1352 #ifdef  __GNUC__
1353 #define g_error(format, args...)        g_log (G_LOG_DOMAIN, \
1354                                                G_LOG_LEVEL_ERROR, \
1355                                                format, ##args)
1356 #define g_message(format, args...)      g_log (G_LOG_DOMAIN, \
1357                                                G_LOG_LEVEL_MESSAGE, \
1358                                                format, ##args)
1359 #define g_warning(format, args...)      g_log (G_LOG_DOMAIN, \
1360                                                G_LOG_LEVEL_WARNING, \
1361                                                format, ##args)
1362 #else   /* !__GNUC__ */
1363 static void
1364 g_error (const gchar *format,
1365          ...)
1366 {
1367   va_list args;
1368   va_start (args, format);
1369   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
1370   va_end (args);
1371 }
1372 static void
1373 g_message (const gchar *format,
1374            ...)
1375 {
1376   va_list args;
1377   va_start (args, format);
1378   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
1379   va_end (args);
1380 }
1381 static void
1382 g_warning (const gchar *format,
1383            ...)
1384 {
1385   va_list args;
1386   va_start (args, format);
1387   g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
1388   va_end (args);
1389 }
1390 #endif  /* !__GNUC__ */
1391
1392 typedef void    (*GPrintFunc)           (const gchar    *string);
1393 void            g_print                 (const gchar    *format,
1394                                          ...) G_GNUC_PRINTF (1, 2);
1395 GPrintFunc      g_set_print_handler     (GPrintFunc      func);
1396 void            g_printerr              (const gchar    *format,
1397                                          ...) G_GNUC_PRINTF (1, 2);
1398 GPrintFunc      g_set_printerr_handler  (GPrintFunc      func);
1399
1400 /* deprecated compatibility functions, use g_log_set_handler() instead */
1401 typedef void            (*GErrorFunc)           (const gchar *str);
1402 typedef void            (*GWarningFunc)         (const gchar *str);
1403 GErrorFunc   g_set_error_handler   (GErrorFunc   func);
1404 GWarningFunc g_set_warning_handler (GWarningFunc func);
1405 GPrintFunc   g_set_message_handler (GPrintFunc func);
1406
1407
1408 /* Memory allocation and debugging
1409  */
1410 #ifdef USE_DMALLOC
1411
1412 #define g_malloc(size)       ((gpointer) MALLOC (size))
1413 #define g_malloc0(size)      ((gpointer) CALLOC (char, size))
1414 #define g_realloc(mem,size)  ((gpointer) REALLOC (mem, char, size))
1415 #define g_free(mem)          FREE (mem)
1416
1417 #else /* !USE_DMALLOC */
1418
1419 gpointer g_malloc      (gulong    size);
1420 gpointer g_malloc0     (gulong    size);
1421 gpointer g_realloc     (gpointer  mem,
1422                         gulong    size);
1423 void     g_free        (gpointer  mem);
1424
1425 #endif /* !USE_DMALLOC */
1426
1427 void     g_mem_profile (void);
1428 void     g_mem_check   (gpointer  mem);
1429
1430 /* Generic allocators
1431  */
1432 GAllocator* g_allocator_new   (const gchar  *name,
1433                                guint         n_preallocs);
1434 void        g_allocator_free  (GAllocator   *allocator);
1435
1436 #define G_ALLOCATOR_LIST        (1)
1437 #define G_ALLOCATOR_SLIST       (2)
1438 #define G_ALLOCATOR_NODE        (3)
1439
1440
1441 /* "g_mem_chunk_new" creates a new memory chunk.
1442  * Memory chunks are used to allocate pieces of memory which are
1443  *  always the same size. Lists are a good example of such a data type.
1444  * The memory chunk allocates and frees blocks of memory as needed.
1445  *  Just be sure to call "g_mem_chunk_free" and not "g_free" on data
1446  *  allocated in a mem chunk. ("g_free" will most likely cause a seg
1447  *  fault...somewhere).
1448  *
1449  * Oh yeah, GMemChunk is an opaque data type. (You don't really
1450  *  want to know what's going on inside do you?)
1451  */
1452
1453 /* ALLOC_ONLY MemChunk's can only allocate memory. The free operation
1454  *  is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
1455  *  atom. (They are also useful for lists which use MemChunk to allocate
1456  *  memory but are also part of the MemChunk implementation).
1457  * ALLOC_AND_FREE MemChunk's can allocate and free memory.
1458  */
1459
1460 #define G_ALLOC_ONLY      1
1461 #define G_ALLOC_AND_FREE  2
1462
1463 GMemChunk* g_mem_chunk_new     (gchar     *name,
1464                                 gint       atom_size,
1465                                 gulong     area_size,
1466                                 gint       type);
1467 void       g_mem_chunk_destroy (GMemChunk *mem_chunk);
1468 gpointer   g_mem_chunk_alloc   (GMemChunk *mem_chunk);
1469 gpointer   g_mem_chunk_alloc0  (GMemChunk *mem_chunk);
1470 void       g_mem_chunk_free    (GMemChunk *mem_chunk,
1471                                 gpointer   mem);
1472 void       g_mem_chunk_clean   (GMemChunk *mem_chunk);
1473 void       g_mem_chunk_reset   (GMemChunk *mem_chunk);
1474 void       g_mem_chunk_print   (GMemChunk *mem_chunk);
1475 void       g_mem_chunk_info    (void);
1476
1477 /* Ah yes...we have a "g_blow_chunks" function.
1478  * "g_blow_chunks" simply compresses all the chunks. This operation
1479  *  consists of freeing every memory area that should be freed (but
1480  *  which we haven't gotten around to doing yet). And, no,
1481  *  "g_blow_chunks" doesn't follow the naming scheme, but it is a
1482  *  much better name than "g_mem_chunk_clean_all" or something
1483  *  similar.
1484  */
1485 void g_blow_chunks (void);
1486
1487
1488 /* Timer
1489  */
1490 GTimer* g_timer_new     (void);
1491 void    g_timer_destroy (GTimer  *timer);
1492 void    g_timer_start   (GTimer  *timer);
1493 void    g_timer_stop    (GTimer  *timer);
1494 void    g_timer_reset   (GTimer  *timer);
1495 gdouble g_timer_elapsed (GTimer  *timer,
1496                          gulong  *microseconds);
1497
1498
1499 /* String utility functions that modify a string argument or
1500  * return a constant string that must not be freed.
1501  */
1502 #define  G_STR_DELIMITERS       "_-|> <."
1503 gchar*   g_strdelimit           (gchar       *string,
1504                                  const gchar *delimiters,
1505                                  gchar        new_delimiter);
1506 gdouble  g_strtod               (const gchar *nptr,
1507                                  gchar      **endptr);
1508 gchar*   g_strerror             (gint         errnum);
1509 gchar*   g_strsignal            (gint         signum);
1510 gint     g_strcasecmp           (const gchar *s1,
1511                                  const gchar *s2);
1512 gint     g_strncasecmp          (const gchar *s1,
1513                                  const gchar *s2,
1514                                  guint        n);
1515 void     g_strdown              (gchar       *string);
1516 void     g_strup                (gchar       *string);
1517 void     g_strreverse           (gchar       *string);
1518 /* removes leading spaces */
1519 gchar*   g_strchug              (gchar        *string);
1520 /* removes trailing spaces */
1521 gchar*  g_strchomp              (gchar        *string);
1522 /* removes leading & trailing spaces */
1523 #define g_strstrip( string )    g_strchomp (g_strchug (string))
1524
1525 /* String utility functions that return a newly allocated string which
1526  * ought to be freed from the caller at some point.
1527  */
1528 gchar*   g_strdup               (const gchar *str);
1529 gchar*   g_strdup_printf        (const gchar *format,
1530                                  ...) G_GNUC_PRINTF (1, 2);
1531 gchar*   g_strdup_vprintf       (const gchar *format,
1532                                  va_list      args);
1533 gchar*   g_strndup              (const gchar *str,
1534                                  guint        n);
1535 gchar*   g_strnfill             (guint        length,
1536                                  gchar        fill_char);
1537 gchar*   g_strconcat            (const gchar *string1,
1538                                  ...); /* NULL terminated */
1539 gchar*   g_strjoin              (const gchar  *separator,
1540                                  ...); /* NULL terminated */
1541 gchar*   g_strescape            (gchar        *string);
1542 gpointer g_memdup               (gconstpointer mem,
1543                                  guint         byte_size);
1544
1545 /* NULL terminated string arrays.
1546  * g_strsplit() splits up string into max_tokens tokens at delim and
1547  * returns a newly allocated string array.
1548  * g_strjoinv() concatenates all of str_array's strings, sliding in an
1549  * optional separator, the returned string is newly allocated.
1550  * g_strfreev() frees the array itself and all of its strings.
1551  */
1552 gchar**  g_strsplit             (const gchar  *string,
1553                                  const gchar  *delimiter,
1554                                  gint          max_tokens);
1555 gchar*   g_strjoinv             (const gchar  *separator,
1556                                  gchar       **str_array);
1557 void     g_strfreev             (gchar       **str_array);
1558
1559
1560
1561 /* calculate a string size, guarranteed to fit format + args.
1562  */
1563 guint   g_printf_string_upper_bound (const gchar* format,
1564                                      va_list      args);
1565
1566
1567 /* Retrive static string info
1568  */
1569 gchar*  g_get_user_name         (void);
1570 gchar*  g_get_real_name         (void);
1571 gchar*  g_get_home_dir          (void);
1572 gchar*  g_get_tmp_dir           (void);
1573 gchar*  g_get_prgname           (void);
1574 void    g_set_prgname           (const gchar *prgname);
1575
1576
1577 /* Miscellaneous utility functions
1578  */
1579 guint   g_parse_debug_string    (const gchar *string,
1580                                  GDebugKey   *keys,
1581                                  guint        nkeys);
1582 gint    g_snprintf              (gchar       *string,
1583                                  gulong       n,
1584                                  gchar const *format,
1585                                  ...) G_GNUC_PRINTF (3, 4);
1586 gint    g_vsnprintf             (gchar       *string,
1587                                  gulong       n,
1588                                  gchar const *format,
1589                                  va_list      args);
1590 gchar*  g_basename              (const gchar *file_name);
1591 /* Check if a file name is an absolute path */
1592 gboolean g_path_is_absolute     (const gchar *file_name);
1593 /* In case of absolute paths, skip the root part */
1594 gchar*  g_path_skip_root        (gchar       *file_name);
1595
1596 /* strings are newly allocated with g_malloc() */
1597 gchar*  g_dirname               (const gchar *file_name);
1598 gchar*  g_get_current_dir       (void);
1599 gchar*  g_getenv                (const gchar *variable);
1600
1601
1602 /* we use a GLib function as a replacement for ATEXIT, so
1603  * the programmer is not required to check the return value
1604  * (if there is any in the implementation) and doesn't encounter
1605  * missing include files.
1606  */
1607 void    g_atexit                (GVoidFunc    func);
1608
1609
1610 /* Bit tests
1611  */
1612 G_INLINE_FUNC gint      g_bit_nth_lsf (guint32 mask,
1613                                        gint    nth_bit);
1614 #ifdef  G_CAN_INLINE
1615 G_INLINE_FUNC gint
1616 g_bit_nth_lsf (guint32 mask,
1617                gint    nth_bit)
1618 {
1619   do
1620     {
1621       nth_bit++;
1622       if (mask & (1 << (guint) nth_bit))
1623         return nth_bit;
1624     }
1625   while (nth_bit < 32);
1626   return -1;
1627 }
1628 #endif  /* G_CAN_INLINE */
1629
1630 G_INLINE_FUNC gint      g_bit_nth_msf (guint32 mask,
1631                                        gint    nth_bit);
1632 #ifdef G_CAN_INLINE
1633 G_INLINE_FUNC gint
1634 g_bit_nth_msf (guint32 mask,
1635                gint    nth_bit)
1636 {
1637   if (nth_bit < 0)
1638     nth_bit = 32;
1639   do
1640     {
1641       nth_bit--;
1642       if (mask & (1 << (guint) nth_bit))
1643         return nth_bit;
1644     }
1645   while (nth_bit > 0);
1646   return -1;
1647 }
1648 #endif  /* G_CAN_INLINE */
1649
1650 G_INLINE_FUNC guint     g_bit_storage (guint number);
1651 #ifdef G_CAN_INLINE
1652 G_INLINE_FUNC guint
1653 g_bit_storage (guint number)
1654 {
1655   register guint n_bits = 0;
1656   
1657   do
1658     {
1659       n_bits++;
1660       number >>= 1;
1661     }
1662   while (number);
1663   return n_bits;
1664 }
1665 #endif  /* G_CAN_INLINE */
1666
1667 /* String Chunks
1668  */
1669 GStringChunk* g_string_chunk_new           (gint size);
1670 void          g_string_chunk_free          (GStringChunk *chunk);
1671 gchar*        g_string_chunk_insert        (GStringChunk *chunk,
1672                                             const gchar  *string);
1673 gchar*        g_string_chunk_insert_const  (GStringChunk *chunk,
1674                                             const gchar  *string);
1675
1676
1677 /* Strings
1678  */
1679 GString* g_string_new       (const gchar *init);
1680 GString* g_string_sized_new (guint        dfl_size);
1681 void     g_string_free      (GString     *string,
1682                              gint         free_segment);
1683 GString* g_string_assign    (GString     *lval,
1684                              const gchar *rval);
1685 GString* g_string_truncate  (GString     *string,
1686                              gint         len);
1687 GString* g_string_append    (GString     *string,
1688                              const gchar *val);
1689 GString* g_string_append_c  (GString     *string,
1690                              gchar        c);
1691 GString* g_string_prepend   (GString     *string,
1692                              const gchar *val);
1693 GString* g_string_prepend_c (GString     *string,
1694                              gchar        c);
1695 GString* g_string_insert    (GString     *string,
1696                              gint         pos,
1697                              const gchar *val);
1698 GString* g_string_insert_c  (GString     *string,
1699                              gint         pos,
1700                              gchar        c);
1701 GString* g_string_erase     (GString     *string,
1702                              gint         pos,
1703                              gint         len);
1704 GString* g_string_down      (GString     *string);
1705 GString* g_string_up        (GString     *string);
1706 void     g_string_sprintf   (GString     *string,
1707                              const gchar *format,
1708                              ...) G_GNUC_PRINTF (2, 3);
1709 void     g_string_sprintfa  (GString     *string,
1710                              const gchar *format,
1711                              ...) G_GNUC_PRINTF (2, 3);
1712
1713
1714 /* Resizable arrays, remove fills any cleared spot and shortens the
1715  * array, while preserving the order. remove_fast will distort the
1716  * order by moving the last element to the position of the removed 
1717  */
1718
1719 #define g_array_append_val(a,v)   g_array_append_vals (a, &v, 1)
1720 #define g_array_prepend_val(a,v)  g_array_prepend_vals (a, &v, 1)
1721 #define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &v, 1)
1722 #define g_array_index(a,t,i)      (((t*) (a)->data) [(i)])
1723
1724 GArray* g_array_new               (gboolean         zero_terminated,
1725                                    gboolean         clear,
1726                                    guint            element_size);
1727 void    g_array_free              (GArray          *array,
1728                                    gboolean         free_segment);
1729 GArray* g_array_append_vals       (GArray          *array,
1730                                    gconstpointer    data,
1731                                    guint            len);
1732 GArray* g_array_prepend_vals      (GArray          *array,
1733                                    gconstpointer    data,
1734                                    guint            len);
1735 GArray* g_array_insert_vals       (GArray          *array,
1736                                    guint            index,
1737                                    gconstpointer    data,
1738                                    guint            len);
1739 GArray* g_array_set_size          (GArray          *array,
1740                                    guint            length);
1741 GArray* g_array_remove_index      (GArray          *array,
1742                                    guint            index);
1743 GArray* g_array_remove_index_fast (GArray          *array,
1744                                    guint            index);
1745
1746 /* Resizable pointer array.  This interface is much less complicated
1747  * than the above.  Add appends appends a pointer.  Remove fills any
1748  * cleared spot and shortens the array. remove_fast will again distort
1749  * order.  
1750  */
1751 #define     g_ptr_array_index(array,index) (array->pdata)[index]
1752 GPtrArray*  g_ptr_array_new                (void);
1753 void        g_ptr_array_free               (GPtrArray   *array,
1754                                             gboolean     free_seg);
1755 void        g_ptr_array_set_size           (GPtrArray   *array,
1756                                             gint         length);
1757 gpointer    g_ptr_array_remove_index       (GPtrArray   *array,
1758                                             guint        index);
1759 gpointer    g_ptr_array_remove_index_fast  (GPtrArray   *array,
1760                                             guint        index);
1761 gboolean    g_ptr_array_remove             (GPtrArray   *array,
1762                                             gpointer     data);
1763 gboolean    g_ptr_array_remove_fast        (GPtrArray   *array,
1764                                             gpointer     data);
1765 void        g_ptr_array_add                (GPtrArray   *array,
1766                                             gpointer     data);
1767
1768 /* Byte arrays, an array of guint8.  Implemented as a GArray,
1769  * but type-safe.
1770  */
1771
1772 GByteArray* g_byte_array_new               (void);
1773 void        g_byte_array_free              (GByteArray   *array,
1774                                             gboolean      free_segment);
1775 GByteArray* g_byte_array_append            (GByteArray   *array,
1776                                             const guint8 *data,
1777                                             guint         len);
1778 GByteArray* g_byte_array_prepend           (GByteArray   *array,
1779                                             const guint8 *data,
1780                                             guint         len);
1781 GByteArray* g_byte_array_set_size          (GByteArray   *array,
1782                                             guint         length);
1783 GByteArray* g_byte_array_remove_index      (GByteArray   *array,
1784                                             guint         index);
1785 GByteArray* g_byte_array_remove_index_fast (GByteArray   *array,
1786                                             guint         index);
1787
1788
1789 /* Hash Functions
1790  */
1791 gint  g_str_equal (gconstpointer   v,
1792                    gconstpointer   v2);
1793 guint g_str_hash  (gconstpointer   v);
1794
1795 gint  g_int_equal (gconstpointer   v,
1796                    gconstpointer   v2);
1797 guint g_int_hash  (gconstpointer   v);
1798
1799 /* This "hash" function will just return the key's adress as an
1800  * unsigned integer. Useful for hashing on plain adresses or
1801  * simple integer values.
1802  * passing NULL into g_hash_table_new() as GHashFunc has the
1803  * same effect as passing g_direct_hash().
1804  */
1805 guint g_direct_hash  (gconstpointer v);
1806 gint  g_direct_equal (gconstpointer v,
1807                       gconstpointer v2);
1808
1809
1810 /* Quarks (string<->id association)
1811  */
1812 GQuark    g_quark_try_string            (const gchar    *string);
1813 GQuark    g_quark_from_static_string    (const gchar    *string);
1814 GQuark    g_quark_from_string           (const gchar    *string);
1815 gchar*    g_quark_to_string             (GQuark          quark);
1816
1817
1818 /* Keyed Data List
1819  */
1820 void      g_datalist_init                (GData          **datalist);
1821 void      g_datalist_clear               (GData          **datalist);
1822 gpointer  g_datalist_id_get_data         (GData          **datalist,
1823                                           GQuark           key_id);
1824 void      g_datalist_id_set_data_full    (GData          **datalist,
1825                                           GQuark           key_id,
1826                                           gpointer         data,
1827                                           GDestroyNotify   destroy_func);
1828 void      g_datalist_id_remove_no_notify (GData          **datalist,
1829                                           GQuark           key_id);
1830 void      g_datalist_foreach             (GData          **datalist,
1831                                           GDataForeachFunc func,
1832                                           gpointer         user_data);
1833 #define   g_datalist_id_set_data(dl, q, d)      \
1834      g_datalist_id_set_data_full ((dl), (q), (d), NULL)
1835 #define   g_datalist_id_remove_data(dl, q)      \
1836      g_datalist_id_set_data ((dl), (q), NULL)
1837 #define   g_datalist_get_data(dl, k)            \
1838      (g_datalist_id_get_data ((dl), g_quark_try_string (k)))
1839 #define   g_datalist_set_data_full(dl, k, d, f) \
1840      g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
1841 #define   g_datalist_remove_no_notify(dl, k)    \
1842      g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
1843 #define   g_datalist_set_data(dl, k, d)         \
1844      g_datalist_set_data_full ((dl), (k), (d), NULL)
1845 #define   g_datalist_remove_data(dl, k)         \
1846      g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
1847
1848
1849 /* Location Associated Keyed Data
1850  */
1851 void      g_dataset_destroy             (gconstpointer    dataset_location);
1852 gpointer  g_dataset_id_get_data         (gconstpointer    dataset_location,
1853                                          GQuark           key_id);
1854 void      g_dataset_id_set_data_full    (gconstpointer    dataset_location,
1855                                          GQuark           key_id,
1856                                          gpointer         data,
1857                                          GDestroyNotify   destroy_func);
1858 void      g_dataset_id_remove_no_notify (gconstpointer    dataset_location,
1859                                          GQuark           key_id);
1860 void      g_dataset_foreach             (gconstpointer    dataset_location,
1861                                          GDataForeachFunc func,
1862                                          gpointer         user_data);
1863 #define   g_dataset_id_set_data(l, k, d)        \
1864      g_dataset_id_set_data_full ((l), (k), (d), NULL)
1865 #define   g_dataset_id_remove_data(l, k)        \
1866      g_dataset_id_set_data ((l), (k), NULL)
1867 #define   g_dataset_get_data(l, k)              \
1868      (g_dataset_id_get_data ((l), g_quark_try_string (k)))
1869 #define   g_dataset_set_data_full(l, k, d, f)   \
1870      g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
1871 #define   g_dataset_remove_no_notify(l, k)      \
1872      g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
1873 #define   g_dataset_set_data(l, k, d)           \
1874      g_dataset_set_data_full ((l), (k), (d), NULL)
1875 #define   g_dataset_remove_data(l, k)           \
1876      g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
1877
1878
1879 /* GScanner: Flexible lexical scanner for general purpose.
1880  */
1881
1882 /* Character sets */
1883 #define G_CSET_A_2_Z    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1884 #define G_CSET_a_2_z    "abcdefghijklmnopqrstuvwxyz"
1885 #define G_CSET_LATINC   "\300\301\302\303\304\305\306"\
1886                         "\307\310\311\312\313\314\315\316\317\320"\
1887                         "\321\322\323\324\325\326"\
1888                         "\330\331\332\333\334\335\336"
1889 #define G_CSET_LATINS   "\337\340\341\342\343\344\345\346"\
1890                         "\347\350\351\352\353\354\355\356\357\360"\
1891                         "\361\362\363\364\365\366"\
1892                         "\370\371\372\373\374\375\376\377"
1893
1894 /* Error types */
1895 typedef enum
1896 {
1897   G_ERR_UNKNOWN,
1898   G_ERR_UNEXP_EOF,
1899   G_ERR_UNEXP_EOF_IN_STRING,
1900   G_ERR_UNEXP_EOF_IN_COMMENT,
1901   G_ERR_NON_DIGIT_IN_CONST,
1902   G_ERR_DIGIT_RADIX,
1903   G_ERR_FLOAT_RADIX,
1904   G_ERR_FLOAT_MALFORMED
1905 } GErrorType;
1906
1907 /* Token types */
1908 typedef enum
1909 {
1910   G_TOKEN_EOF                   =   0,
1911   
1912   G_TOKEN_LEFT_PAREN            = '(',
1913   G_TOKEN_RIGHT_PAREN           = ')',
1914   G_TOKEN_LEFT_CURLY            = '{',
1915   G_TOKEN_RIGHT_CURLY           = '}',
1916   G_TOKEN_LEFT_BRACE            = '[',
1917   G_TOKEN_RIGHT_BRACE           = ']',
1918   G_TOKEN_EQUAL_SIGN            = '=',
1919   G_TOKEN_COMMA                 = ',',
1920   
1921   G_TOKEN_NONE                  = 256,
1922   
1923   G_TOKEN_ERROR,
1924   
1925   G_TOKEN_CHAR,
1926   G_TOKEN_BINARY,
1927   G_TOKEN_OCTAL,
1928   G_TOKEN_INT,
1929   G_TOKEN_HEX,
1930   G_TOKEN_FLOAT,
1931   G_TOKEN_STRING,
1932   
1933   G_TOKEN_SYMBOL,
1934   G_TOKEN_IDENTIFIER,
1935   G_TOKEN_IDENTIFIER_NULL,
1936   
1937   G_TOKEN_COMMENT_SINGLE,
1938   G_TOKEN_COMMENT_MULTI,
1939   G_TOKEN_LAST
1940 } GTokenType;
1941
1942 union   _GTokenValue
1943 {
1944   gpointer      v_symbol;
1945   gchar         *v_identifier;
1946   gulong        v_binary;
1947   gulong        v_octal;
1948   gulong        v_int;
1949   gdouble       v_float;
1950   gulong        v_hex;
1951   gchar         *v_string;
1952   gchar         *v_comment;
1953   guchar        v_char;
1954   guint         v_error;
1955 };
1956
1957 struct  _GScannerConfig
1958 {
1959   /* Character sets
1960    */
1961   gchar         *cset_skip_characters;          /* default: " \t\n" */
1962   gchar         *cset_identifier_first;
1963   gchar         *cset_identifier_nth;
1964   gchar         *cpair_comment_single;          /* default: "#\n" */
1965   
1966   /* Should symbol lookup work case sensitive?
1967    */
1968   guint         case_sensitive : 1;
1969   
1970   /* Boolean values to be adjusted "on the fly"
1971    * to configure scanning behaviour.
1972    */
1973   guint         skip_comment_multi : 1;         /* C like comment */
1974   guint         skip_comment_single : 1;        /* single line comment */
1975   guint         scan_comment_multi : 1;         /* scan multi line comments? */
1976   guint         scan_identifier : 1;
1977   guint         scan_identifier_1char : 1;
1978   guint         scan_identifier_NULL : 1;
1979   guint         scan_symbols : 1;
1980   guint         scan_binary : 1;
1981   guint         scan_octal : 1;
1982   guint         scan_float : 1;
1983   guint         scan_hex : 1;                   /* `0x0ff0' */
1984   guint         scan_hex_dollar : 1;            /* `$0ff0' */
1985   guint         scan_string_sq : 1;             /* string: 'anything' */
1986   guint         scan_string_dq : 1;             /* string: "\\-escapes!\n" */
1987   guint         numbers_2_int : 1;              /* bin, octal, hex => int */
1988   guint         int_2_float : 1;                /* int => G_TOKEN_FLOAT? */
1989   guint         identifier_2_string : 1;
1990   guint         char_2_token : 1;               /* return G_TOKEN_CHAR? */
1991   guint         symbol_2_token : 1;
1992   guint         scope_0_fallback : 1;           /* try scope 0 on lookups? */
1993 };
1994
1995 struct  _GScanner
1996 {
1997   /* unused fields */
1998   gpointer              user_data;
1999   guint                 max_parse_errors;
2000   
2001   /* g_scanner_error() increments this field */
2002   guint                 parse_errors;
2003   
2004   /* name of input stream, featured by the default message handler */
2005   const gchar           *input_name;
2006   
2007   /* data pointer for derived structures */
2008   gpointer              derived_data;
2009   
2010   /* link into the scanner configuration */
2011   GScannerConfig        *config;
2012   
2013   /* fields filled in after g_scanner_get_next_token() */
2014   GTokenType            token;
2015   GTokenValue           value;
2016   guint                 line;
2017   guint                 position;
2018   
2019   /* fields filled in after g_scanner_peek_next_token() */
2020   GTokenType            next_token;
2021   GTokenValue           next_value;
2022   guint                 next_line;
2023   guint                 next_position;
2024   
2025   /* to be considered private */
2026   GHashTable            *symbol_table;
2027   gint                  input_fd;
2028   const gchar           *text;
2029   const gchar           *text_end;
2030   gchar                 *buffer;
2031   guint                 scope_id;
2032   
2033   /* handler function for _warn and _error */
2034   GScannerMsgFunc       msg_handler;
2035 };
2036
2037 GScanner*       g_scanner_new                   (GScannerConfig *config_templ);
2038 void            g_scanner_destroy               (GScanner       *scanner);
2039 void            g_scanner_input_file            (GScanner       *scanner,
2040                                                  gint           input_fd);
2041 void            g_scanner_sync_file_offset      (GScanner       *scanner);
2042 void            g_scanner_input_text            (GScanner       *scanner,
2043                                                  const  gchar   *text,
2044                                                  guint          text_len);
2045 GTokenType      g_scanner_get_next_token        (GScanner       *scanner);
2046 GTokenType      g_scanner_peek_next_token       (GScanner       *scanner);
2047 GTokenType      g_scanner_cur_token             (GScanner       *scanner);
2048 GTokenValue     g_scanner_cur_value             (GScanner       *scanner);
2049 guint           g_scanner_cur_line              (GScanner       *scanner);
2050 guint           g_scanner_cur_position          (GScanner       *scanner);
2051 gboolean        g_scanner_eof                   (GScanner       *scanner);
2052 guint           g_scanner_set_scope             (GScanner       *scanner,
2053                                                  guint           scope_id);
2054 void            g_scanner_scope_add_symbol      (GScanner       *scanner,
2055                                                  guint           scope_id,
2056                                                  const gchar    *symbol,
2057                                                  gpointer       value);
2058 void            g_scanner_scope_remove_symbol   (GScanner       *scanner,
2059                                                  guint           scope_id,
2060                                                  const gchar    *symbol);
2061 gpointer        g_scanner_scope_lookup_symbol   (GScanner       *scanner,
2062                                                  guint           scope_id,
2063                                                  const gchar    *symbol);
2064 void            g_scanner_scope_foreach_symbol  (GScanner       *scanner,
2065                                                  guint           scope_id,
2066                                                  GHFunc          func,
2067                                                  gpointer        user_data);
2068 gpointer        g_scanner_lookup_symbol         (GScanner       *scanner,
2069                                                  const gchar    *symbol);
2070 void            g_scanner_freeze_symbol_table   (GScanner       *scanner);
2071 void            g_scanner_thaw_symbol_table     (GScanner       *scanner);
2072 void            g_scanner_unexp_token           (GScanner       *scanner,
2073                                                  GTokenType     expected_token,
2074                                                  const gchar    *identifier_spec,
2075                                                  const gchar    *symbol_spec,
2076                                                  const gchar    *symbol_name,
2077                                                  const gchar    *message,
2078                                                  gint            is_error);
2079 void            g_scanner_error                 (GScanner       *scanner,
2080                                                  const gchar    *format,
2081                                                  ...) G_GNUC_PRINTF (2,3);
2082 void            g_scanner_warn                  (GScanner       *scanner,
2083                                                  const gchar    *format,
2084                                                  ...) G_GNUC_PRINTF (2,3);
2085 gint            g_scanner_stat_mode             (const gchar    *filename);
2086 /* keep downward source compatibility */
2087 #define         g_scanner_add_symbol( scanner, symbol, value )  G_STMT_START { \
2088   g_scanner_scope_add_symbol ((scanner), 0, (symbol), (value)); \
2089 } G_STMT_END
2090 #define         g_scanner_remove_symbol( scanner, symbol )      G_STMT_START { \
2091   g_scanner_scope_remove_symbol ((scanner), 0, (symbol)); \
2092 } G_STMT_END
2093 #define         g_scanner_foreach_symbol( scanner, func, data ) G_STMT_START { \
2094   g_scanner_scope_foreach_symbol ((scanner), 0, (func), (data)); \
2095 } G_STMT_END
2096
2097
2098 /* GCompletion
2099  */
2100
2101 struct _GCompletion
2102 {
2103   GList* items;
2104   GCompletionFunc func;
2105   
2106   gchar* prefix;
2107   GList* cache;
2108 };
2109
2110 GCompletion* g_completion_new          (GCompletionFunc func);
2111 void         g_completion_add_items    (GCompletion*    cmp,
2112                                         GList*          items);
2113 void         g_completion_remove_items (GCompletion*    cmp,
2114                                         GList*          items);
2115 void         g_completion_clear_items  (GCompletion*    cmp);
2116 GList*       g_completion_complete     (GCompletion*    cmp,
2117                                         gchar*          prefix,
2118                                         gchar**         new_prefix);
2119 void         g_completion_free         (GCompletion*    cmp);
2120
2121
2122 /* GDate
2123  *
2124  * Date calculations (not time for now, to be resolved). These are a
2125  * mutant combination of Steffen Beyer's DateCalc routines
2126  * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
2127  * date routines (written for in-house software).  Written by Havoc
2128  * Pennington <hp@pobox.com> 
2129  */
2130
2131 typedef guint16 GDateYear;
2132 typedef guint8  GDateDay;   /* day of the month */
2133 typedef struct _GDate GDate;
2134 /* make struct tm known without having to include time.h */
2135 struct tm;
2136
2137 /* enum used to specify order of appearance in parsed date strings */
2138 typedef enum
2139 {
2140   G_DATE_DAY   = 0,
2141   G_DATE_MONTH = 1,
2142   G_DATE_YEAR  = 2
2143 } GDateDMY;
2144
2145 /* actual week and month values */
2146 typedef enum
2147 {
2148   G_DATE_BAD_WEEKDAY  = 0,
2149   G_DATE_MONDAY       = 1,
2150   G_DATE_TUESDAY      = 2,
2151   G_DATE_WEDNESDAY    = 3,
2152   G_DATE_THURSDAY     = 4,
2153   G_DATE_FRIDAY       = 5,
2154   G_DATE_SATURDAY     = 6,
2155   G_DATE_SUNDAY       = 7
2156 } GDateWeekday;
2157 typedef enum
2158 {
2159   G_DATE_BAD_MONTH = 0,
2160   G_DATE_JANUARY   = 1,
2161   G_DATE_FEBRUARY  = 2,
2162   G_DATE_MARCH     = 3,
2163   G_DATE_APRIL     = 4,
2164   G_DATE_MAY       = 5,
2165   G_DATE_JUNE      = 6,
2166   G_DATE_JULY      = 7,
2167   G_DATE_AUGUST    = 8,
2168   G_DATE_SEPTEMBER = 9,
2169   G_DATE_OCTOBER   = 10,
2170   G_DATE_NOVEMBER  = 11,
2171   G_DATE_DECEMBER  = 12
2172 } GDateMonth;
2173
2174 #define G_DATE_BAD_JULIAN 0U
2175 #define G_DATE_BAD_DAY    0U
2176 #define G_DATE_BAD_YEAR   0U
2177
2178 /* Note: directly manipulating structs is generally a bad idea, but
2179  * in this case it's an *incredibly* bad idea, because all or part
2180  * of this struct can be invalid at any given time. Use the functions,
2181  * or you will get hosed, I promise.
2182  */
2183 struct _GDate
2184
2185   guint julian_days : 32; /* julian days representation - we use a
2186                            *  bitfield hoping that 64 bit platforms
2187                            *  will pack this whole struct in one big
2188                            *  int 
2189                            */
2190
2191   guint julian : 1;    /* julian is valid */
2192   guint dmy    : 1;    /* dmy is valid */
2193
2194   /* DMY representation */
2195   guint day    : 6;  
2196   guint month  : 4; 
2197   guint year   : 16; 
2198 };
2199
2200 /* g_date_new() returns an invalid date, you then have to _set() stuff 
2201  * to get a usable object. You can also allocate a GDate statically,
2202  * then call g_date_clear() to initialize.
2203  */
2204 GDate*       g_date_new                   (void);
2205 GDate*       g_date_new_dmy               (GDateDay     day, 
2206                                            GDateMonth   month, 
2207                                            GDateYear    year);
2208 GDate*       g_date_new_julian            (guint32      julian_day);
2209 void         g_date_free                  (GDate       *date);
2210
2211 /* check g_date_valid() after doing an operation that might fail, like
2212  * _parse.  Almost all g_date operations are undefined on invalid
2213  * dates (the exceptions are the mutators, since you need those to
2214  * return to validity).  
2215  */
2216 gboolean     g_date_valid                 (GDate       *date);
2217 gboolean     g_date_valid_day             (GDateDay     day);
2218 gboolean     g_date_valid_month           (GDateMonth   month);
2219 gboolean     g_date_valid_year            (GDateYear    year);
2220 gboolean     g_date_valid_weekday         (GDateWeekday weekday);
2221 gboolean     g_date_valid_julian          (guint32      julian_date);
2222 gboolean     g_date_valid_dmy             (GDateDay     day,
2223                                            GDateMonth   month,
2224                                            GDateYear    year);
2225
2226 GDateWeekday g_date_weekday               (GDate       *date);
2227 GDateMonth   g_date_month                 (GDate       *date);
2228 GDateYear    g_date_year                  (GDate       *date);
2229 GDateDay     g_date_day                   (GDate       *date);
2230 guint32      g_date_julian                (GDate       *date);
2231 guint        g_date_day_of_year           (GDate       *date);
2232
2233 /* First monday/sunday is the start of week 1; if we haven't reached
2234  * that day, return 0. These are not ISO weeks of the year; that
2235  * routine needs to be added.
2236  * these functions return the number of weeks, starting on the
2237  * corrsponding day
2238  */
2239 guint        g_date_monday_week_of_year   (GDate      *date);
2240 guint        g_date_sunday_week_of_year   (GDate      *date);
2241
2242 /* If you create a static date struct you need to clear it to get it
2243  * in a sane state before use. You can clear a whole array at
2244  * once with the ndates argument.
2245  */
2246 void         g_date_clear                 (GDate       *date, 
2247                                            guint        n_dates);
2248
2249 /* The parse routine is meant for dates typed in by a user, so it
2250  * permits many formats but tries to catch common typos. If your data
2251  * needs to be strictly validated, it is not an appropriate function.
2252  */
2253 void         g_date_set_parse             (GDate       *date,
2254                                            const gchar *str);
2255 void         g_date_set_time              (GDate       *date, 
2256                                            GTime        time);
2257 void         g_date_set_month             (GDate       *date, 
2258                                            GDateMonth   month);
2259 void         g_date_set_day               (GDate       *date, 
2260                                            GDateDay     day);
2261 void         g_date_set_year              (GDate       *date,
2262                                            GDateYear    year);
2263 void         g_date_set_dmy               (GDate       *date,
2264                                            GDateDay     day,
2265                                            GDateMonth   month,
2266                                            GDateYear    y);
2267 void         g_date_set_julian            (GDate       *date,
2268                                            guint32      julian_date);
2269 gboolean     g_date_is_first_of_month     (GDate       *date);
2270 gboolean     g_date_is_last_of_month      (GDate       *date);
2271
2272 /* To go forward by some number of weeks just go forward weeks*7 days */
2273 void         g_date_add_days              (GDate       *date, 
2274                                            guint        n_days);
2275 void         g_date_subtract_days         (GDate       *date, 
2276                                            guint        n_days);
2277
2278 /* If you add/sub months while day > 28, the day might change */
2279 void         g_date_add_months            (GDate       *date,
2280                                            guint        n_months);
2281 void         g_date_subtract_months       (GDate       *date,
2282                                            guint        n_months);
2283
2284 /* If it's feb 29, changing years can move you to the 28th */
2285 void         g_date_add_years             (GDate       *date,
2286                                            guint        n_years);
2287 void         g_date_subtract_years        (GDate       *date,
2288                                            guint        n_years);
2289 gboolean     g_date_is_leap_year          (GDateYear    year);
2290 guint8       g_date_days_in_month         (GDateMonth   month, 
2291                                            GDateYear    year);
2292 guint8       g_date_monday_weeks_in_year  (GDateYear    year);
2293 guint8       g_date_sunday_weeks_in_year  (GDateYear    year);
2294
2295 /* qsort-friendly (with a cast...) */
2296 gint         g_date_compare               (GDate       *lhs,
2297                                            GDate       *rhs);
2298 void         g_date_to_struct_tm          (GDate       *date,
2299                                            struct tm   *tm);
2300
2301 /* Just like strftime() except you can only use date-related formats.
2302  *   Using a time format is undefined.
2303  */
2304 gsize        g_date_strftime              (gchar       *s,
2305                                            gsize        slen,
2306                                            const gchar *format,
2307                                            GDate       *date);
2308
2309
2310 /* GRelation
2311  *
2312  * Indexed Relations.  Imagine a really simple table in a
2313  * database.  Relations are not ordered.  This data type is meant for
2314  * maintaining a N-way mapping.
2315  *
2316  * g_relation_new() creates a relation with FIELDS fields
2317  *
2318  * g_relation_destroy() frees all resources
2319  * g_tuples_destroy() frees the result of g_relation_select()
2320  *
2321  * g_relation_index() indexes relation FIELD with the provided
2322  *   equality and hash functions.  this must be done before any
2323  *   calls to insert are made.
2324  *
2325  * g_relation_insert() inserts a new tuple.  you are expected to
2326  *   provide the right number of fields.
2327  *
2328  * g_relation_delete() deletes all relations with KEY in FIELD
2329  * g_relation_select() returns ...
2330  * g_relation_count() counts ...
2331  */
2332
2333 GRelation* g_relation_new     (gint         fields);
2334 void       g_relation_destroy (GRelation   *relation);
2335 void       g_relation_index   (GRelation   *relation,
2336                                gint         field,
2337                                GHashFunc    hash_func,
2338                                GCompareFunc key_compare_func);
2339 void       g_relation_insert  (GRelation   *relation,
2340                                ...);
2341 gint       g_relation_delete  (GRelation   *relation,
2342                                gconstpointer  key,
2343                                gint         field);
2344 GTuples*   g_relation_select  (GRelation   *relation,
2345                                gconstpointer  key,
2346                                gint         field);
2347 gint       g_relation_count   (GRelation   *relation,
2348                                gconstpointer  key,
2349                                gint         field);
2350 gboolean   g_relation_exists  (GRelation   *relation,
2351                                ...);
2352 void       g_relation_print   (GRelation   *relation);
2353
2354 void       g_tuples_destroy   (GTuples     *tuples);
2355 gpointer   g_tuples_index     (GTuples     *tuples,
2356                                gint         index,
2357                                gint         field);
2358
2359
2360 /* Prime numbers.
2361  */
2362
2363 /* This function returns prime numbers spaced by approximately 1.5-2.0
2364  * and is for use in resizing data structures which prefer
2365  * prime-valued sizes.  The closest spaced prime function returns the
2366  * next largest prime, or the highest it knows about which is about
2367  * MAXINT/4.
2368  */
2369 guint      g_spaced_primes_closest (guint num);
2370
2371
2372 /* GIOChannel
2373  */
2374
2375 typedef struct _GIOFuncs GIOFuncs;
2376 typedef enum
2377 {
2378   G_IO_ERROR_NONE,
2379   G_IO_ERROR_AGAIN,
2380   G_IO_ERROR_INVAL,
2381   G_IO_ERROR_UNKNOWN
2382 } GIOError;
2383 typedef enum
2384 {
2385   G_SEEK_CUR,
2386   G_SEEK_SET,
2387   G_SEEK_END
2388 } GSeekType;
2389 typedef enum
2390 {
2391   G_IO_IN       GLIB_SYSDEF_POLLIN,
2392   G_IO_OUT      GLIB_SYSDEF_POLLOUT,
2393   G_IO_PRI      GLIB_SYSDEF_POLLPRI,
2394   G_IO_ERR      GLIB_SYSDEF_POLLERR,
2395   G_IO_HUP      GLIB_SYSDEF_POLLHUP,
2396   G_IO_NVAL     GLIB_SYSDEF_POLLNVAL
2397 } GIOCondition;
2398
2399 struct _GIOChannel
2400 {
2401   guint channel_flags;
2402   guint ref_count;
2403   GIOFuncs *funcs;
2404 };
2405
2406 typedef gboolean (*GIOFunc) (GIOChannel   *source,
2407                              GIOCondition  condition,
2408                              gpointer      data);
2409 struct _GIOFuncs
2410 {
2411   GIOError (*io_read)   (GIOChannel     *channel, 
2412                          gchar          *buf, 
2413                          guint           count,
2414                          guint          *bytes_read);
2415   GIOError (*io_write)  (GIOChannel     *channel, 
2416                          gchar          *buf, 
2417                          guint           count,
2418                          guint          *bytes_written);
2419   GIOError (*io_seek)   (GIOChannel     *channel, 
2420                          gint            offset, 
2421                          GSeekType       type);
2422   void (*io_close)      (GIOChannel     *channel);
2423   guint (*io_add_watch) (GIOChannel     *channel,
2424                          gint            priority,
2425                          GIOCondition    condition,
2426                          GIOFunc         func,
2427                          gpointer        user_data,
2428                          GDestroyNotify  notify);
2429   void (*io_free)       (GIOChannel     *channel);
2430 };
2431
2432 void        g_io_channel_init   (GIOChannel    *channel);
2433 void        g_io_channel_ref    (GIOChannel    *channel);
2434 void        g_io_channel_unref  (GIOChannel    *channel);
2435 GIOError    g_io_channel_read   (GIOChannel    *channel, 
2436                                  gchar         *buf, 
2437                                  guint          count,
2438                                  guint         *bytes_read);
2439 GIOError  g_io_channel_write    (GIOChannel    *channel, 
2440                                  gchar         *buf, 
2441                                  guint          count,
2442                                  guint         *bytes_written);
2443 GIOError  g_io_channel_seek     (GIOChannel    *channel,
2444                                  gint           offset, 
2445                                  GSeekType      type);
2446 void      g_io_channel_close    (GIOChannel    *channel);
2447 guint     g_io_add_watch_full   (GIOChannel    *channel,
2448                                  gint           priority,
2449                                  GIOCondition   condition,
2450                                  GIOFunc        func,
2451                                  gpointer       user_data,
2452                                  GDestroyNotify notify);
2453 guint    g_io_add_watch         (GIOChannel    *channel,
2454                                  GIOCondition   condition,
2455                                  GIOFunc        func,
2456                                  gpointer       user_data);
2457
2458
2459 /* Main loop
2460  */
2461 typedef struct _GTimeVal        GTimeVal;
2462 typedef struct _GSourceFuncs    GSourceFuncs;
2463 typedef struct _GMainLoop       GMainLoop;      /* Opaque */
2464
2465 struct _GTimeVal
2466 {
2467   glong tv_sec;
2468   glong tv_usec;
2469 };
2470 struct _GSourceFuncs
2471 {
2472   gboolean (*prepare)  (gpointer  source_data, 
2473                         GTimeVal *current_time,
2474                         gint     *timeout);
2475   gboolean (*check)    (gpointer  source_data,
2476                         GTimeVal *current_time);
2477   gboolean (*dispatch) (gpointer  source_data, 
2478                         GTimeVal *current_time,
2479                         gpointer  user_data);
2480   GDestroyNotify destroy;
2481 };
2482
2483 /* Standard priorities */
2484
2485 #define G_PRIORITY_HIGH            -100
2486 #define G_PRIORITY_DEFAULT          0
2487 #define G_PRIORITY_HIGH_IDLE        100
2488 #define G_PRIORITY_DEFAULT_IDLE     200
2489 #define G_PRIORITY_LOW              300
2490
2491 typedef gboolean (*GSourceFunc) (gpointer data);
2492
2493 /* Hooks for adding to the main loop */
2494 guint    g_source_add                        (gint           priority, 
2495                                               gboolean       can_recurse,
2496                                               GSourceFuncs  *funcs,
2497                                               gpointer       source_data, 
2498                                               gpointer       user_data,
2499                                               GDestroyNotify notify);
2500 gboolean g_source_remove                     (guint          tag);
2501 gboolean g_source_remove_by_user_data        (gpointer       user_data);
2502 gboolean g_source_remove_by_source_data      (gpointer       source_data);
2503 gboolean g_source_remove_by_funcs_user_data  (GSourceFuncs  *funcs,
2504                                               gpointer       user_data);
2505
2506 void g_get_current_time             (GTimeVal      *result);
2507
2508 /* Running the main loop */
2509 GMainLoop*      g_main_new              (gboolean        is_running);
2510 void            g_main_run              (GMainLoop      *loop);
2511 void            g_main_quit             (GMainLoop      *loop);
2512 void            g_main_destroy          (GMainLoop      *loop);
2513 gboolean        g_main_is_running       (GMainLoop      *loop);
2514
2515 /* Run a single iteration of the mainloop. If block is FALSE,
2516  * will never block
2517  */
2518 gboolean        g_main_iteration        (gboolean       may_block);
2519
2520 /* See if any events are pending */
2521 gboolean        g_main_pending          (void);
2522
2523 /* Idles and timeouts */
2524 guint           g_timeout_add_full      (gint           priority,
2525                                          guint          interval, 
2526                                          GSourceFunc    function,
2527                                          gpointer       data,
2528                                          GDestroyNotify notify);
2529 guint           g_timeout_add           (guint          interval,
2530                                          GSourceFunc    function,
2531                                          gpointer       data);
2532 guint           g_idle_add              (GSourceFunc    function,
2533                                          gpointer       data);
2534 guint           g_idle_add_full         (gint           priority,
2535                                          GSourceFunc    function,
2536                                          gpointer       data,
2537                                          GDestroyNotify destroy);
2538 gboolean        g_idle_remove_by_data   (gpointer       data);
2539
2540 /* GPollFD
2541  *
2542  * System-specific IO and main loop calls
2543  *
2544  * On Win32, the fd in a GPollFD should be Win32 HANDLE (*not* a file
2545  * descriptor as provided by the C runtime) that can be used by
2546  * MsgWaitForMultipleObjects. This does *not* include file handles
2547  * from CreateFile, SOCKETs, nor pipe handles. (But you can use
2548  * WSAEventSelect to signal events when a SOCKET is readable).
2549  *
2550  * On Win32, fd can also be the special value G_WIN32_MSG_HANDLE to
2551  * indicate polling for messages. These message queue GPollFDs should
2552  * be added with the g_main_poll_win32_msg_add function.
2553  *
2554  * But note that G_WIN32_MSG_HANDLE GPollFDs should not be used by GDK
2555  * (GTK) programs, as GDK itself wants to read messages and convert them
2556  * to GDK events.
2557  *
2558  * So, unless you really know what you are doing, it's best not to try
2559  * to use the main loop polling stuff for your own needs on
2560  * Win32. It's really only written for the GIMP's needs so
2561  * far.
2562  */
2563
2564 typedef struct _GPollFD GPollFD;
2565 typedef gint    (*GPollFunc)    (GPollFD *ufds,
2566                                  guint    nfsd,
2567                                  gint     timeout);
2568 struct _GPollFD
2569 {
2570   gint          fd;
2571   gushort       events;
2572   gushort       revents;
2573 };
2574
2575 void        g_main_add_poll          (GPollFD    *fd,
2576                                       gint        priority);
2577 void        g_main_remove_poll       (GPollFD    *fd);
2578 void        g_main_set_poll_func     (GPollFunc   func);
2579
2580 /* On Unix, IO channels created with this function for any file
2581  * descriptor or socket.
2582  *
2583  * On Win32, use this only for plain files opened with the MSVCRT (the
2584  * Microsoft run-time C library) _open(), including file descriptors
2585  * 0, 1 and 2 (corresponding to stdin, stdout and stderr).
2586  * Actually, don't do even that, this code isn't done yet.
2587  *
2588  * The term file descriptor as used in the context of Win32 refers to
2589  * the emulated Unix-like file descriptors MSVCRT provides.
2590  */
2591 GIOChannel* g_io_channel_unix_new    (int         fd);
2592 gint        g_io_channel_unix_get_fd (GIOChannel *channel);
2593
2594 #ifdef NATIVE_WIN32
2595
2596 GUTILS_C_VAR guint g_pipe_readable_msg;
2597
2598 #define G_WIN32_MSG_HANDLE 19981206
2599
2600 /* This is used to add polling for Windows messages. GDK (GTk+) programs
2601  * should *not* use this. (In fact, I can't think of any program that
2602  * would want to use this, but it's here just for completeness's sake.
2603  */
2604 void        g_main_poll_win32_msg_add(gint        priority,
2605                                       GPollFD    *fd,
2606                                       guint       hwnd);
2607
2608 /* An IO channel for Windows messages for window handle hwnd. */
2609 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
2610
2611 /* An IO channel for an anonymous pipe as returned from the MSVCRT
2612  * _pipe(), with no mechanism for the writer to tell the reader when
2613  * there is data in the pipe.
2614  *
2615  * This is not really implemented yet.
2616  */
2617 GIOChannel *g_io_channel_win32_new_pipe (int fd);
2618
2619 /* An IO channel for a pipe as returned from the MSVCRT _pipe(), with
2620  * Windows user messages used to signal data in the pipe for the
2621  * reader.
2622  *
2623  * fd is the file descriptor. For the write end, peer is the thread id
2624  * of the reader, and peer_fd is his file descriptor for the read end
2625  * of the pipe.
2626  *
2627  * This is used by the GIMP, and works.
2628  */
2629 GIOChannel *g_io_channel_win32_new_pipe_with_wakeups (int   fd,
2630                                                       guint peer,
2631                                                       int   peer_fd);
2632
2633 void        g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
2634                                                      guint       peer,
2635                                                      int         peer_fd);
2636
2637 void        g_io_channel_win32_pipe_readable (int   fd,
2638                                               guint offset);
2639
2640 /* Get the C runtime file descriptor of a channel. */
2641 gint        g_io_channel_win32_get_fd (GIOChannel *channel);
2642
2643 /* An IO channel for a SOCK_STREAM winsock socket. The parameter is
2644  * actually a SOCKET.
2645  */
2646 GIOChannel *g_io_channel_win32_new_stream_socket (int socket);
2647
2648 #endif
2649
2650 /* Windows emulation stubs for common Unix functions
2651  */
2652 #ifdef NATIVE_WIN32
2653 #  define MAXPATHLEN 1024
2654 #  ifdef _MSC_VER
2655 typedef int pid_t;
2656
2657 /* These POSIXish functions are available in the Microsoft C library
2658  * prefixed with underscore (which of course technically speaking is
2659  * the Right Thing, as they are non-ANSI. Not that being non-ANSI
2660  * prevents Microsoft from practically requiring you to include
2661  * <windows.h> every now and then...).
2662  *
2663  * You still need to include the appropriate headers to get the
2664  * prototypes, <io.h> or <direct.h>.
2665  *
2666  * For some functions, we provide emulators in glib, which are prefixed
2667  * with gwin_.
2668  */
2669 #    define getcwd              _getcwd
2670 #    define getpid              _getpid
2671 #    define access              _access
2672 #    define open                _open
2673 #    define read                _read
2674 #    define write               _write
2675 #    define lseek               _lseek
2676 #    define close               _close
2677 #    define pipe(phandles)      _pipe (phandles, 4096, _O_BINARY)
2678 #    define popen               _popen
2679 #    define pclose              _pclose
2680 #    define fdopen              _fdopen
2681 #    define ftruncate(fd, size) gwin_ftruncate (fd, size)
2682 #    define opendir             gwin_opendir
2683 #    define readdir             gwin_readdir
2684 #    define rewinddir           gwin_rewinddir
2685 #    define closedir            gwin_closedir
2686 #    define NAME_MAX 255
2687 struct DIR
2688 {
2689   gchar    *dir_name;
2690   gboolean  just_opened;
2691   guint     find_file_handle;
2692   gpointer  find_file_data;
2693 };
2694 typedef struct DIR DIR;
2695 struct dirent
2696 {
2697   gchar  d_name[NAME_MAX + 1];
2698 };
2699 /* emulation functions */
2700 extern int      gwin_ftruncate  (gint            f,
2701                                  guint           size);
2702 DIR*            gwin_opendir    (const gchar    *dirname);
2703 struct dirent*  gwin_readdir    (DIR            *dir);
2704 void            gwin_rewinddir  (DIR            *dir);
2705 gint            gwin_closedir   (DIR            *dir);
2706 #  endif /* _MSC_VER */
2707 #endif   /* NATIVE_WIN32 */
2708
2709
2710 /* GLib Thread support
2711  */
2712 typedef struct _GMutex          GMutex;
2713 typedef struct _GCond           GCond;
2714 typedef struct _GPrivate        GPrivate;
2715 typedef struct _GStaticPrivate  GStaticPrivate;
2716 typedef struct _GThreadFunctions GThreadFunctions;
2717 struct _GThreadFunctions
2718 {
2719   GMutex*  (*mutex_new)       (void);
2720   void     (*mutex_lock)      (GMutex           *mutex);
2721   gboolean (*mutex_trylock)   (GMutex           *mutex);
2722   void     (*mutex_unlock)    (GMutex           *mutex);
2723   void     (*mutex_free)      (GMutex           *mutex);
2724   GCond*   (*cond_new)        (void);
2725   void     (*cond_signal)     (GCond            *cond);
2726   void     (*cond_broadcast)  (GCond            *cond);
2727   void     (*cond_wait)       (GCond            *cond,
2728                                GMutex           *mutex);
2729   gboolean (*cond_timed_wait) (GCond            *cond,
2730                                GMutex           *mutex, 
2731                                GTimeVal         *end_time);
2732   void      (*cond_free)      (GCond            *cond);
2733   GPrivate* (*private_new)    (GDestroyNotify    destructor);
2734   gpointer  (*private_get)    (GPrivate         *private_key);
2735   void      (*private_set)    (GPrivate         *private_key,
2736                                gpointer          data);
2737 };
2738
2739 GUTILS_C_VAR GThreadFunctions   g_thread_functions_for_glib_use;
2740 GUTILS_C_VAR gboolean           g_thread_use_default_impl;
2741 GUTILS_C_VAR gboolean           g_threads_got_initialized;
2742
2743 /* initializes the mutex/cond/private implementation for glib, might
2744  * only be called once, and must not be called directly or indirectly
2745  * from another glib-function, e.g. as a callback.
2746  */
2747 void    g_thread_init   (GThreadFunctions       *vtable);
2748
2749 /* internal function for fallback static mutex implementation */
2750 GMutex* g_static_mutex_get_mutex_impl   (GMutex **mutex);
2751
2752 /* shorthands for conditional and unconditional function calls */
2753 #define G_THREAD_UF(name, arglist) \
2754     (*g_thread_functions_for_glib_use . name) arglist
2755 #define G_THREAD_CF(name, fail, arg) \
2756     (g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
2757 /* keep in mind, all those mutexes and static mutexes are not 
2758  * recursive in general, don't rely on that
2759  */
2760 #define g_thread_supported()    (g_threads_got_initialized)
2761 #define g_mutex_new()            G_THREAD_UF (mutex_new,      ())
2762 #define g_mutex_lock(mutex)      G_THREAD_CF (mutex_lock,     (void)0, (mutex))
2763 #define g_mutex_trylock(mutex)   G_THREAD_CF (mutex_trylock,  TRUE,    (mutex))
2764 #define g_mutex_unlock(mutex)    G_THREAD_CF (mutex_unlock,   (void)0, (mutex))
2765 #define g_mutex_free(mutex)      G_THREAD_CF (mutex_free,     (void)0, (mutex))
2766 #define g_cond_new()             G_THREAD_UF (cond_new,       ())
2767 #define g_cond_signal(cond)      G_THREAD_CF (cond_signal,    (void)0, (cond))
2768 #define g_cond_broadcast(cond)   G_THREAD_CF (cond_broadcast, (void)0, (cond))
2769 #define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait,      (void)0, (cond, \
2770                                                                         mutex))
2771 #define g_cond_free(cond)        G_THREAD_CF (cond_free,      (void)0, (cond))
2772 #define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
2773                                                               TRUE, \
2774                                                               (cond, mutex, \
2775                                                                abs_time))
2776 #define g_private_new(destructor)         G_THREAD_UF (private_new, (destructor))
2777 #define g_private_get(private_key)        G_THREAD_CF (private_get, \
2778                                                        ((gpointer)private_key), \
2779                                                        (private_key))
2780 #define g_private_set(private_key, value) G_THREAD_CF (private_set, \
2781                                                        (void) (private_key = \
2782                                                         (GPrivate*) (value)), \
2783                                                        (private_key, value))
2784 /* GStaticMutexes can be statically initialized with the value
2785  * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
2786  * much easier, than having to explicitly allocate the mutex before
2787  * use
2788  */
2789 #define g_static_mutex_lock(mutex) \
2790     g_mutex_lock (g_static_mutex_get_mutex (mutex))
2791 #define g_static_mutex_trylock(mutex) \
2792     g_mutex_trylock (g_static_mutex_get_mutex (mutex))
2793 #define g_static_mutex_unlock(mutex) \
2794     g_mutex_unlock (g_static_mutex_get_mutex (mutex)) 
2795 struct _GStaticPrivate
2796 {
2797   guint index;
2798 };
2799 #define G_STATIC_PRIVATE_INIT { 0 }
2800 gpointer g_static_private_get (GStaticPrivate   *private_key);
2801 void     g_static_private_set (GStaticPrivate   *private_key, 
2802                                gpointer          data,
2803                                GDestroyNotify    notify);
2804
2805 /* these are some convenience macros that expand to nothing if GLib
2806  * was configured with --disable-threads. for using StaticMutexes,
2807  * you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
2808  * if you need to export the mutex. With G_LOCK_EXTERN (name) you can
2809  * declare such an globally defined lock. name is a unique identifier
2810  * for the protected varibale or code portion. locking, testing and
2811  * unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
2812  * G_TRYLOCK() respectively.  
2813  */
2814 extern void glib_dummy_decl (void);
2815 #define G_LOCK_NAME(name)               (g__ ## name ## _lock)
2816 #ifdef  G_THREADS_ENABLED
2817 #  define G_LOCK_DEFINE_STATIC(name)    static G_LOCK_DEFINE (name)
2818 #  define G_LOCK_DEFINE(name)           \
2819     GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT 
2820 #  define G_LOCK_EXTERN(name)           extern GStaticMutex G_LOCK_NAME (name)
2821
2822 #  ifdef G_DEBUG_LOCKS
2823 #    define G_LOCK(name)                G_STMT_START{             \
2824         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2825                "file %s: line %d (%s): locking: %s ",             \
2826                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2827                #name);                                            \
2828         g_static_mutex_lock (&G_LOCK_NAME (name));                \
2829      }G_STMT_END
2830 #    define G_UNLOCK(name)              G_STMT_START{             \
2831         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2832                "file %s: line %d (%s): unlocking: %s ",           \
2833                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2834                #name);                                            \
2835        g_static_mutex_unlock (&G_LOCK_NAME (name));               \
2836      }G_STMT_END
2837 #    define G_TRYLOCK(name)             G_STMT_START{             \
2838         g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,                   \
2839                "file %s: line %d (%s): try locking: %s ",         \
2840                __FILE__,        __LINE__, G_GNUC_PRETTY_FUNCTION, \
2841                #name);                                            \
2842      }G_STMT_END,       g_static_mutex_trylock (&G_LOCK_NAME (name))
2843 #  else  /* !G_DEBUG_LOCKS */
2844 #    define G_LOCK(name) g_static_mutex_lock       (&G_LOCK_NAME (name)) 
2845 #    define G_UNLOCK(name) g_static_mutex_unlock   (&G_LOCK_NAME (name))
2846 #    define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
2847 #  endif /* !G_DEBUG_LOCKS */
2848 #else   /* !G_THREADS_ENABLED */
2849 #  define G_LOCK_DEFINE_STATIC(name)    extern void glib_dummy_decl (void)
2850 #  define G_LOCK_DEFINE(name)           extern void glib_dummy_decl (void)
2851 #  define G_LOCK_EXTERN(name)           extern void glib_dummy_decl (void)
2852 #  define G_LOCK(name)
2853 #  define G_UNLOCK(name)
2854 #  define G_TRYLOCK(name)               (FALSE)
2855 #endif  /* !G_THREADS_ENABLED */
2856
2857 #ifdef __cplusplus
2858 }
2859 #endif /* __cplusplus */
2860
2861
2862 #endif /* __G_LIB_H__ */