Changed the name of vtable alloc, new & free struct members to v* to allow debug...
[profile/ivi/navit.git] / navit / navit / support / glib / gmem.c
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, 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-2000.  See the AUTHORS
22  * file for a list of people on the GLib Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27 /* 
28  * MT safe
29  */
30
31 #include "config.h"
32
33 #include <stdlib.h>
34 #include <string.h>
35 #include <signal.h>
36
37 #include "glib.h"
38 #include "gthreadprivate.h"
39 #include "galias.h"
40
41 #define MEM_PROFILE_TABLE_SIZE 4096
42
43
44 /* notes on macros:
45  * having G_DISABLE_CHECKS defined disables use of glib_mem_profiler_table and
46  * g_mem_profile().
47  * REALLOC_0_WORKS is defined if g_realloc (NULL, x) works.
48  * SANE_MALLOC_PROTOS is defined if the systems malloc() and friends functions
49  * match the corresponding GLib prototypes, keep configure.in and gmem.h in sync here.
50  * g_mem_gc_friendly is TRUE, freed memory should be 0-wiped.
51  */
52
53 /* --- prototypes --- */
54 static gboolean g_mem_initialized = FALSE;
55 static void     g_mem_init_nomessage (void);
56
57
58 /* --- malloc wrappers --- */
59 #ifndef REALLOC_0_WORKS
60 static gpointer
61 standard_realloc (gpointer mem,
62                   gsize    n_bytes)
63 {
64   if (!mem)
65     return malloc (n_bytes);
66   else
67     return realloc (mem, n_bytes);
68 }
69 #endif  /* !REALLOC_0_WORKS */
70
71 #ifdef SANE_MALLOC_PROTOS
72 #  define standard_malloc       malloc
73 #  ifdef REALLOC_0_WORKS
74 #    define standard_realloc    realloc
75 #  endif /* REALLOC_0_WORKS */
76 #  define standard_free         free
77 #  define standard_calloc       calloc
78 #  define standard_try_malloc   malloc
79 #  define standard_try_realloc  realloc
80 #else   /* !SANE_MALLOC_PROTOS */
81 static gpointer
82 standard_malloc (gsize n_bytes)
83 {
84   return malloc (n_bytes);
85 }
86 #  ifdef REALLOC_0_WORKS
87 static gpointer
88 standard_realloc (gpointer mem,
89                   gsize    n_bytes)
90 {
91   return realloc (mem, n_bytes);
92 }
93 #  endif /* REALLOC_0_WORKS */
94 static void
95 standard_free (gpointer mem)
96 {
97   free (mem);
98 }
99 static gpointer
100 standard_calloc (gsize n_blocks,
101                  gsize n_bytes)
102 {
103   return calloc (n_blocks, n_bytes);
104 }
105 #define standard_try_malloc     standard_malloc
106 #define standard_try_realloc    standard_realloc
107 #endif  /* !SANE_MALLOC_PROTOS */
108
109
110 /* --- variables --- */
111 static GMemVTable glib_mem_vtable = {
112   standard_malloc,
113   standard_realloc,
114   standard_free,
115   standard_calloc,
116   standard_try_malloc,
117   standard_try_realloc,
118 };
119
120
121 /* --- functions --- */
122 gpointer
123 g_malloc (gsize n_bytes)
124 {
125   if (G_UNLIKELY (!g_mem_initialized))
126     g_mem_init_nomessage();
127   if (G_LIKELY (n_bytes))
128     {
129       gpointer mem;
130
131       mem = glib_mem_vtable.vmalloc (n_bytes);
132       if (mem)
133         return mem;
134
135 #if NOT_NEEDED_FOR_NAVIT
136       g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
137                G_STRLOC, n_bytes);
138 #endif /* NOT_NEEDED_FOR_NAVIT */
139     }
140
141   return NULL;
142 }
143
144 gpointer
145 g_malloc0 (gsize n_bytes)
146 {
147   if (G_UNLIKELY (!g_mem_initialized))
148     g_mem_init_nomessage();
149   if (G_LIKELY (n_bytes))
150     {
151       gpointer mem;
152
153       mem = glib_mem_vtable.vcalloc (1, n_bytes);
154       if (mem)
155         return mem;
156
157 #if NOT_NEEDED_FOR_NAVIT
158       g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
159                G_STRLOC, n_bytes);
160 #endif /* NOT_NEEDED_FOR_NAVIT */
161     }
162
163   return NULL;
164 }
165
166 gpointer
167 g_realloc (gpointer mem,
168            gsize    n_bytes)
169 {
170   if (G_UNLIKELY (!g_mem_initialized))
171     g_mem_init_nomessage();
172   if (G_LIKELY (n_bytes))
173     {
174       mem = glib_mem_vtable.vrealloc (mem, n_bytes);
175       if (mem)
176         return mem;
177
178 #if NOT_NEEDED_FOR_NAVIT
179       g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes",
180                G_STRLOC, n_bytes);
181 #endif /* NOT_NEEDED_FOR_NAVIT */
182     }
183
184   if (mem)
185     glib_mem_vtable.vfree (mem);
186
187   return NULL;
188 }
189
190 void
191 g_free (gpointer mem)
192 {
193   if (G_UNLIKELY (!g_mem_initialized))
194     g_mem_init_nomessage();
195   if (G_LIKELY (mem))
196     glib_mem_vtable.vfree (mem);
197 }
198
199 gpointer
200 g_try_malloc (gsize n_bytes)
201 {
202   if (G_UNLIKELY (!g_mem_initialized))
203     g_mem_init_nomessage();
204   if (G_LIKELY (n_bytes))
205     return glib_mem_vtable.vtry_malloc (n_bytes);
206   else
207     return NULL;
208 }
209
210 gpointer
211 g_try_malloc0 (gsize n_bytes)
212
213   gpointer mem;
214
215   mem = g_try_malloc (n_bytes);
216   
217   if (mem)
218     memset (mem, 0, n_bytes);
219
220   return mem;
221 }
222
223 gpointer
224 g_try_realloc (gpointer mem,
225                gsize    n_bytes)
226 {
227   if (G_UNLIKELY (!g_mem_initialized))
228     g_mem_init_nomessage();
229   if (G_LIKELY (n_bytes))
230     return glib_mem_vtable.vtry_realloc (mem, n_bytes);
231
232   if (mem)
233     glib_mem_vtable.vfree (mem);
234
235   return NULL;
236 }
237
238 static gpointer
239 fallback_calloc (gsize n_blocks,
240                  gsize n_block_bytes)
241 {
242   gsize l = n_blocks * n_block_bytes;
243   gpointer mem = glib_mem_vtable.vmalloc (l);
244
245   if (mem)
246     memset (mem, 0, l);
247
248   return mem;
249 }
250
251 static gboolean vtable_set = FALSE;
252
253 /**
254  * g_mem_is_system_malloc
255  * 
256  * Checks whether the allocator used by g_malloc() is the system's
257  * malloc implementation. If it returns %TRUE memory allocated with
258  * malloc() can be used interchangeable with memory allocated using g_malloc(). 
259  * This function is useful for avoiding an extra copy of allocated memory returned
260  * by a non-GLib-based API.
261  *
262  * A different allocator can be set using g_mem_set_vtable().
263  *
264  * Return value: if %TRUE, malloc() and g_malloc() can be mixed.
265  **/
266 gboolean
267 g_mem_is_system_malloc (void)
268 {
269   return !vtable_set;
270 }
271
272 void
273 g_mem_set_vtable (GMemVTable *vtable)
274 {
275   if (!vtable_set)
276     {
277       if (vtable->vmalloc && vtable->vrealloc && vtable->vfree)
278         {
279           glib_mem_vtable.vmalloc = vtable->vmalloc;
280           glib_mem_vtable.vrealloc = vtable->vrealloc;
281           glib_mem_vtable.vfree = vtable->vfree;
282           glib_mem_vtable.vcalloc = vtable->vcalloc ? vtable->vcalloc : fallback_calloc;
283           glib_mem_vtable.vtry_malloc = vtable->vtry_malloc ? vtable->vtry_malloc : glib_mem_vtable.vmalloc;
284           glib_mem_vtable.vtry_realloc = vtable->vtry_realloc ? vtable->vtry_realloc : glib_mem_vtable.vrealloc;
285           vtable_set = TRUE;
286         }
287 #if NOT_NEEDED_FOR_NAVIT
288       else
289         g_warning (G_STRLOC ": memory allocation vtable lacks one of malloc(), realloc() or free()");
290 #endif /* NOT_NEEDED_FOR_NAVIT */
291     }
292 #if NOT_NEEDED_FOR_NAVIT
293   else
294     g_warning (G_STRLOC ": memory allocation vtable can only be set once at startup");
295 #endif /* NOT_NEEDED_FOR_NAVIT */
296 }
297
298
299 /* --- memory profiling and checking --- */
300 #ifdef  G_DISABLE_CHECKS
301 GMemVTable *glib_mem_profiler_table = &glib_mem_vtable;
302 void
303 g_mem_profile (void)
304 {
305 }
306 #else   /* !G_DISABLE_CHECKS */
307 typedef enum {
308   PROFILER_FREE         = 0,
309   PROFILER_ALLOC        = 1,
310   PROFILER_RELOC        = 2,
311   PROFILER_ZINIT        = 4
312 } ProfilerJob;
313 static guint *profile_data = NULL;
314 static gsize profile_allocs = 0;
315 static gsize profile_zinit = 0;
316 static gsize profile_frees = 0;
317 static GMutex *gmem_profile_mutex = NULL;
318 #ifdef  G_ENABLE_DEBUG
319 static volatile gsize g_trap_free_size = 0;
320 static volatile gsize g_trap_realloc_size = 0;
321 static volatile gsize g_trap_malloc_size = 0;
322 #endif  /* G_ENABLE_DEBUG */
323
324 #define PROFILE_TABLE(f1,f2,f3)   ( ( ((f3) << 2) | ((f2) << 1) | (f1) ) * (MEM_PROFILE_TABLE_SIZE + 1))
325
326 static void
327 profiler_log (ProfilerJob job,
328               gsize       n_bytes,
329               gboolean    success)
330 {
331   g_mutex_lock (gmem_profile_mutex);
332   if (!profile_data)
333     {
334       profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8, 
335                                       sizeof (profile_data[0]));
336       if (!profile_data)        /* memory system kiddin' me, eh? */
337         {
338           g_mutex_unlock (gmem_profile_mutex);
339           return;
340         }
341     }
342
343   if (n_bytes < MEM_PROFILE_TABLE_SIZE)
344     profile_data[n_bytes + PROFILE_TABLE ((job & PROFILER_ALLOC) != 0,
345                                           (job & PROFILER_RELOC) != 0,
346                                           success != 0)] += 1;
347   else
348     profile_data[MEM_PROFILE_TABLE_SIZE + PROFILE_TABLE ((job & PROFILER_ALLOC) != 0,
349                                                          (job & PROFILER_RELOC) != 0,
350                                                          success != 0)] += 1;
351   if (success)
352     {
353       if (job & PROFILER_ALLOC)
354         {
355           profile_allocs += n_bytes;
356           if (job & PROFILER_ZINIT)
357             profile_zinit += n_bytes;
358         }
359       else
360         profile_frees += n_bytes;
361     }
362   g_mutex_unlock (gmem_profile_mutex);
363 }
364
365 static void
366 profile_print_locked (guint   *local_data,
367                       gboolean success)
368 {
369   gboolean need_header = TRUE;
370   guint i;
371
372   for (i = 0; i <= MEM_PROFILE_TABLE_SIZE; i++)
373     {
374       glong t_malloc = local_data[i + PROFILE_TABLE (1, 0, success)];
375       glong t_realloc = local_data[i + PROFILE_TABLE (1, 1, success)];
376       glong t_free = local_data[i + PROFILE_TABLE (0, 0, success)];
377       glong t_refree = local_data[i + PROFILE_TABLE (0, 1, success)];
378       
379       if (!t_malloc && !t_realloc && !t_free && !t_refree)
380         continue;
381       else if (need_header)
382         {
383           need_header = FALSE;
384           g_print (" blocks of | allocated  | freed      | allocated  | freed      | n_bytes   \n");
385           g_print ("  n_bytes  | n_times by | n_times by | n_times by | n_times by | remaining \n");
386           g_print ("           | malloc()   | free()     | realloc()  | realloc()  |           \n");
387           g_print ("===========|============|============|============|============|===========\n");
388         }
389       if (i < MEM_PROFILE_TABLE_SIZE)
390         g_print ("%10u | %10ld | %10ld | %10ld | %10ld |%+11ld\n",
391                  i, t_malloc, t_free, t_realloc, t_refree,
392                  (t_malloc - t_free + t_realloc - t_refree) * i);
393       else if (i >= MEM_PROFILE_TABLE_SIZE)
394         g_print ("   >%6u | %10ld | %10ld | %10ld | %10ld |        ***\n",
395                  i, t_malloc, t_free, t_realloc, t_refree);
396     }
397   if (need_header)
398     g_print (" --- none ---\n");
399 }
400
401 void
402 g_mem_profile (void)
403 {
404   guint local_data[(MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0])];
405   gsize local_allocs;
406   gsize local_zinit;
407   gsize local_frees;
408
409   if (G_UNLIKELY (!g_mem_initialized))
410     g_mem_init_nomessage();
411
412   g_mutex_lock (gmem_profile_mutex);
413
414   local_allocs = profile_allocs;
415   local_zinit = profile_zinit;
416   local_frees = profile_frees;
417
418   if (!profile_data)
419     {
420       g_mutex_unlock (gmem_profile_mutex);
421       return;
422     }
423
424   memcpy (local_data, profile_data, 
425           (MEM_PROFILE_TABLE_SIZE + 1) * 8 * sizeof (profile_data[0]));
426   
427   g_mutex_unlock (gmem_profile_mutex);
428
429   g_print ("GLib Memory statistics (successful operations):\n");
430   profile_print_locked (local_data, TRUE);
431   g_print ("GLib Memory statistics (failing operations):\n");
432   profile_print_locked (local_data, FALSE);
433   g_print ("Total bytes: allocated=%"G_GSIZE_FORMAT", "
434            "zero-initialized=%"G_GSIZE_FORMAT" (%.2f%%), "
435            "freed=%"G_GSIZE_FORMAT" (%.2f%%), "
436            "remaining=%"G_GSIZE_FORMAT"\n",
437            local_allocs,
438            local_zinit,
439            ((gdouble) local_zinit) / local_allocs * 100.0,
440            local_frees,
441            ((gdouble) local_frees) / local_allocs * 100.0,
442            local_allocs - local_frees);
443 }
444
445 static gpointer
446 profiler_try_malloc (gsize n_bytes)
447 {
448   gsize *p;
449
450 #ifdef  G_ENABLE_DEBUG
451   if (g_trap_malloc_size == n_bytes)
452     G_BREAKPOINT ();
453 #endif  /* G_ENABLE_DEBUG */
454
455   p = standard_malloc (sizeof (gsize) * 2 + n_bytes);
456
457   if (p)
458     {
459       p[0] = 0;         /* free count */
460       p[1] = n_bytes;   /* length */
461       profiler_log (PROFILER_ALLOC, n_bytes, TRUE);
462       p += 2;
463     }
464   else
465     profiler_log (PROFILER_ALLOC, n_bytes, FALSE);
466   
467   return p;
468 }
469
470 static gpointer
471 profiler_malloc (gsize n_bytes)
472 {
473   gpointer mem = profiler_try_malloc (n_bytes);
474
475   if (!mem)
476     g_mem_profile ();
477
478   return mem;
479 }
480
481 static gpointer
482 profiler_calloc (gsize n_blocks,
483                  gsize n_block_bytes)
484 {
485   gsize l = n_blocks * n_block_bytes;
486   gsize *p;
487
488 #ifdef  G_ENABLE_DEBUG
489   if (g_trap_malloc_size == l)
490     G_BREAKPOINT ();
491 #endif  /* G_ENABLE_DEBUG */
492   
493   p = standard_calloc (1, sizeof (gsize) * 2 + l);
494
495   if (p)
496     {
497       p[0] = 0;         /* free count */
498       p[1] = l;         /* length */
499       profiler_log (PROFILER_ALLOC | PROFILER_ZINIT, l, TRUE);
500       p += 2;
501     }
502   else
503     {
504       profiler_log (PROFILER_ALLOC | PROFILER_ZINIT, l, FALSE);
505       g_mem_profile ();
506     }
507
508   return p;
509 }
510
511 static void
512 profiler_free (gpointer mem)
513 {
514   gsize *p = mem;
515
516   p -= 2;
517   if (p[0])     /* free count */
518     {
519       g_warning ("free(%p): memory has been freed %"G_GSIZE_FORMAT" times already",
520                  p + 2, p[0]);
521       profiler_log (PROFILER_FREE,
522                     p[1],       /* length */
523                     FALSE);
524     }
525   else
526     {
527 #ifdef  G_ENABLE_DEBUG
528       if (g_trap_free_size == p[1])
529         G_BREAKPOINT ();
530 #endif  /* G_ENABLE_DEBUG */
531
532       profiler_log (PROFILER_FREE,
533                     p[1],       /* length */
534                     TRUE);
535       memset (p + 2, 0xaa, p[1]);
536
537       /* for all those that miss standard_free (p); in this place, yes,
538        * we do leak all memory when profiling, and that is intentional
539        * to catch double frees. patch submissions are futile.
540        */
541     }
542   p[0] += 1;
543 }
544
545 static gpointer
546 profiler_try_realloc (gpointer mem,
547                       gsize    n_bytes)
548 {
549   gsize *p = mem;
550
551   p -= 2;
552
553 #ifdef  G_ENABLE_DEBUG
554   if (g_trap_realloc_size == n_bytes)
555     G_BREAKPOINT ();
556 #endif  /* G_ENABLE_DEBUG */
557   
558   if (mem && p[0])      /* free count */
559     {
560       g_warning ("realloc(%p, %"G_GSIZE_FORMAT"): "
561                  "memory has been freed %"G_GSIZE_FORMAT" times already",
562                  p + 2, (gsize) n_bytes, p[0]);
563       profiler_log (PROFILER_ALLOC | PROFILER_RELOC, n_bytes, FALSE);
564
565       return NULL;
566     }
567   else
568     {
569       p = standard_realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes);
570
571       if (p)
572         {
573           if (mem)
574             profiler_log (PROFILER_FREE | PROFILER_RELOC, p[1], TRUE);
575           p[0] = 0;
576           p[1] = n_bytes;
577           profiler_log (PROFILER_ALLOC | PROFILER_RELOC, p[1], TRUE);
578           p += 2;
579         }
580       else
581         profiler_log (PROFILER_ALLOC | PROFILER_RELOC, n_bytes, FALSE);
582
583       return p;
584     }
585 }
586
587 static gpointer
588 profiler_realloc (gpointer mem,
589                   gsize    n_bytes)
590 {
591   mem = profiler_try_realloc (mem, n_bytes);
592
593   if (!mem)
594     g_mem_profile ();
595
596   return mem;
597 }
598
599 static GMemVTable profiler_table = {
600   profiler_malloc,
601   profiler_realloc,
602   profiler_free,
603   profiler_calloc,
604   profiler_try_malloc,
605   profiler_try_realloc,
606 };
607 GMemVTable *glib_mem_profiler_table = &profiler_table;
608
609 #endif  /* !G_DISABLE_CHECKS */
610
611 /* --- MemChunks --- */
612 #ifndef G_ALLOC_AND_FREE
613 typedef struct _GAllocator GAllocator;
614 typedef struct _GMemChunk  GMemChunk;
615 #define G_ALLOC_ONLY      1
616 #define G_ALLOC_AND_FREE  2
617 #endif
618
619 struct _GMemChunk {
620   guint alloc_size;           /* the size of an atom */
621 };
622
623 GMemChunk*
624 g_mem_chunk_new (const gchar  *name,
625                  gint          atom_size,
626                  gsize         area_size,
627                  gint          type)
628 {
629   GMemChunk *mem_chunk;
630   g_return_val_if_fail (atom_size > 0, NULL);
631
632   mem_chunk = g_slice_new (GMemChunk);
633   mem_chunk->alloc_size = atom_size;
634   return mem_chunk;
635 }
636
637 void
638 g_mem_chunk_destroy (GMemChunk *mem_chunk)
639 {
640   g_return_if_fail (mem_chunk != NULL);
641   
642   g_slice_free (GMemChunk, mem_chunk);
643 }
644
645 gpointer
646 g_mem_chunk_alloc (GMemChunk *mem_chunk)
647 {
648   g_return_val_if_fail (mem_chunk != NULL, NULL);
649   
650   return g_slice_alloc (mem_chunk->alloc_size);
651 }
652
653 gpointer
654 g_mem_chunk_alloc0 (GMemChunk *mem_chunk)
655 {
656   g_return_val_if_fail (mem_chunk != NULL, NULL);
657   
658   return g_slice_alloc0 (mem_chunk->alloc_size);
659 }
660
661 void
662 g_mem_chunk_free (GMemChunk *mem_chunk,
663                   gpointer   mem)
664 {
665   g_return_if_fail (mem_chunk != NULL);
666   
667   g_slice_free1 (mem_chunk->alloc_size, mem);
668 }
669
670 void    g_mem_chunk_clean       (GMemChunk *mem_chunk)  {}
671 void    g_mem_chunk_reset       (GMemChunk *mem_chunk)  {}
672 void    g_mem_chunk_print       (GMemChunk *mem_chunk)  {}
673 void    g_mem_chunk_info        (void)                  {}
674 void    g_blow_chunks           (void)                  {}
675
676 GAllocator*
677 g_allocator_new (const gchar *name,
678                  guint        n_preallocs)
679 {
680   static struct _GAllocator {
681     gchar      *name;
682     guint16     n_preallocs;
683     guint       is_unused : 1;
684     guint       type : 4;
685     GAllocator *last;
686     GMemChunk  *mem_chunk;
687     gpointer    free_list;
688   } dummy = {
689     "GAllocator is deprecated", 1, TRUE, 0, NULL, NULL, NULL,
690   };
691   /* some (broken) GAllocator uses depend on non-NULL allocators */
692   return (void*) &dummy;
693 }
694
695 void
696 g_allocator_free (GAllocator *allocator)
697 {
698 }
699
700 #ifdef ENABLE_GC_FRIENDLY_DEFAULT
701 gboolean g_mem_gc_friendly = TRUE;
702 #else
703 gboolean g_mem_gc_friendly = FALSE;
704 #endif
705
706 static void
707 g_mem_init_nomessage (void)
708 {
709 #if NOT_NEEDED_FOR_NAVIT
710   gchar buffer[1024];
711   const gchar *val;
712   const GDebugKey keys[] = {
713     { "gc-friendly", 1 },
714   };
715   gint flags;
716   if (g_mem_initialized)
717     return;
718   /* don't use g_malloc/g_message here */
719   val = _g_getenv_nomalloc ("G_DEBUG", buffer);
720   flags = !val ? 0 : g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
721   if (flags & 1)        /* gc-friendly */
722     {
723       g_mem_gc_friendly = TRUE;
724     }
725 #endif /* NOT_NEEDED_FOR_NAVIT */
726   g_mem_initialized = TRUE;
727 }
728
729 void
730 _g_mem_thread_init_noprivate_nomessage (void)
731 {
732   /* we may only create mutexes here, locking/
733    * unlocking a mutex does not yet work.
734    */
735   g_mem_init_nomessage();
736 #ifndef G_DISABLE_CHECKS
737   gmem_profile_mutex = g_mutex_new ();
738 #endif
739 }
740
741 #define __G_MEM_C__
742 #include "galiasdef.c"