Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 521958
Collapse All | Expand All

(-)a/configure.ac (+41 lines)
Lines 590-595 AS_IF([test x$glib_native_win32 != xyes && test x$ac_cv_sizeof_long_long = x8], Link Here
590
590
591
AC_C_CONST
591
AC_C_CONST
592
592
593
dnl ok, here we try to check whether the systems prototypes for
594
dnl malloc and friends actually match the prototypes provided
595
dnl by gmem.h (keep in sync). i currently only know how to check
596
dnl this reliably with gcc (-Werror), improvements for other
597
dnl compilers are apprechiated.
598
SANE_MALLOC_PROTOS=no
599
AC_MSG_CHECKING([if malloc() and friends prototypes are gmem.h compatible])
600
glib_save_CFLAGS=$CFLAGS
601
AS_IF([test "x$GCC" = "xyes"], [
602
  CFLAGS="$CFLAGS -Werror"
603
  AC_TRY_COMPILE([#include <stdlib.h>], [
604
    void* (*my_calloc_p)  (size_t, size_t) = calloc;
605
    void* (*my_malloc_p)  (size_t)         = malloc;
606
    void  (*my_free_p)    (void*)          = free;
607
    void* (*my_realloc_p) (void*, size_t)  = realloc;
608
    my_calloc_p = 0;
609
    my_malloc_p = 0;
610
    my_free_p = 0;
611
    my_realloc_p = 0;
612
  ],
613
    AC_DEFINE(SANE_MALLOC_PROTOS, 1, 
614
      [Define if you have correct malloc prototypes])
615
    SANE_MALLOC_PROTOS=yes)
616
])
617
AC_MSG_RESULT($SANE_MALLOC_PROTOS)
618
CFLAGS=$glib_save_CFLAGS
619
593
dnl
620
dnl
594
dnl check in which direction the stack grows
621
dnl check in which direction the stack grows
595
dnl
622
dnl
Lines 1240-1245 AS_IF([test "$gtk_ok" = "yes"], [ Link Here
1240
    fi
1267
    fi
1241
])
1268
])
1242
1269
1270
dnl *** check for sane realloc() ***
1271
AC_CACHE_CHECK([whether realloc (NULL,) will work],glib_cv_sane_realloc,[
1272
        AC_TRY_RUN([#include <stdlib.h>
1273
        int main() {
1274
          return realloc (0, sizeof (int)) == 0;
1275
        }],
1276
        [glib_cv_sane_realloc=yes],
1277
        [glib_cv_sane_realloc=no],
1278
	[glib_cv_sane_realloc=yes])
1279
])
1280
AS_IF([test x$glib_cv_sane_realloc = xyes], [
1281
  AC_DEFINE(REALLOC_0_WORKS,1,[whether realloc (NULL,) works])
1282
])
1283
1243
dnl Check for nl_langinfo and CODESET
1284
dnl Check for nl_langinfo and CODESET
1244
AC_LANG_SAVE
1285
AC_LANG_SAVE
1245
AC_LANG_C
1286
AC_LANG_C
(-)a/glib/gmem.c (-11 / +66 lines)
Lines 46-62 Link Here
46
/* notes on macros:
46
/* notes on macros:
47
 * having G_DISABLE_CHECKS defined disables use of glib_mem_profiler_table and
47
 * having G_DISABLE_CHECKS defined disables use of glib_mem_profiler_table and
48
 * g_mem_profile().
48
 * g_mem_profile().
49
 * If g_mem_gc_friendly is TRUE, freed memory should be 0-wiped.
49
 * REALLOC_0_WORKS is defined if g_realloc (NULL, x) works.
50
 * SANE_MALLOC_PROTOS is defined if the systems malloc() and friends functions
51
 * match the corresponding GLib prototypes, keep configure.ac and gmem.h in sync here.
52
 * g_mem_gc_friendly is TRUE, freed memory should be 0-wiped.
50
 */
53
 */
51
54
55
/* --- malloc wrappers --- */
56
#ifndef	REALLOC_0_WORKS
57
static gpointer
58
standard_realloc (gpointer mem,
59
		  gsize    n_bytes)
60
{
61
  if (!mem)
62
    return malloc (n_bytes);
63
  else
64
    return realloc (mem, n_bytes);
65
}
66
#endif	/* !REALLOC_0_WORKS */
67
68
#ifdef SANE_MALLOC_PROTOS
69
#  define standard_malloc	malloc
70
#  ifdef REALLOC_0_WORKS
71
#    define standard_realloc	realloc
72
#  endif /* REALLOC_0_WORKS */
73
#  define standard_free		free
74
#  define standard_calloc	calloc
75
#  define standard_try_malloc	malloc
76
#  define standard_try_realloc	realloc
77
#else	/* !SANE_MALLOC_PROTOS */
78
static gpointer
79
standard_malloc (gsize n_bytes)
80
{
81
  return malloc (n_bytes);
82
}
83
#  ifdef REALLOC_0_WORKS
84
static gpointer
85
standard_realloc (gpointer mem,
86
		  gsize    n_bytes)
87
{
88
  return realloc (mem, n_bytes);
89
}
90
#  endif /* REALLOC_0_WORKS */
91
static void
92
standard_free (gpointer mem)
93
{
94
  free (mem);
95
}
96
static gpointer
97
standard_calloc (gsize n_blocks,
98
		 gsize n_bytes)
99
{
100
  return calloc (n_blocks, n_bytes);
101
}
102
#define	standard_try_malloc	standard_malloc
103
#define	standard_try_realloc	standard_realloc
104
#endif	/* !SANE_MALLOC_PROTOS */
105
106
52
/* --- variables --- */
107
/* --- variables --- */
53
static GMemVTable glib_mem_vtable = {
108
static GMemVTable glib_mem_vtable = {
54
  malloc,
109
  standard_malloc,
55
  realloc,
110
  standard_realloc,
56
  free,
111
  standard_free,
57
  calloc,
112
  standard_calloc,
58
  malloc,
113
  standard_try_malloc,
59
  realloc,
114
  standard_try_realloc,
60
};
115
};
61
116
62
/**
117
/**
Lines 566-573 profiler_log (ProfilerJob job, Link Here
566
  g_mutex_lock (&gmem_profile_mutex);
621
  g_mutex_lock (&gmem_profile_mutex);
567
  if (!profile_data)
622
  if (!profile_data)
568
    {
623
    {
569
      profile_data = calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8, 
624
      profile_data = standard_calloc ((MEM_PROFILE_TABLE_SIZE + 1) * 8, 
570
                             sizeof (profile_data[0]));
625
                                      sizeof (profile_data[0]));
571
      if (!profile_data)	/* memory system kiddin' me, eh? */
626
      if (!profile_data)	/* memory system kiddin' me, eh? */
572
	{
627
	{
573
	  g_mutex_unlock (&gmem_profile_mutex);
628
	  g_mutex_unlock (&gmem_profile_mutex);
Lines 766-772 profiler_free (gpointer mem) Link Here
766
		    TRUE);
821
		    TRUE);
767
      memset (p + 2, 0xaa, p[1]);
822
      memset (p + 2, 0xaa, p[1]);
768
823
769
      /* for all those that miss free (p); in this place, yes,
824
      /* for all those that miss standard_free (p); in this place, yes,
770
       * we do leak all memory when profiling, and that is intentional
825
       * we do leak all memory when profiling, and that is intentional
771
       * to catch double frees. patch submissions are futile.
826
       * to catch double frees. patch submissions are futile.
772
       */
827
       */
Lines 793-799 profiler_try_realloc (gpointer mem, Link Here
793
    }
848
    }
794
  else
849
  else
795
    {
850
    {
796
      p = realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes);
851
      p = standard_realloc (mem ? p : NULL, sizeof (gsize) * 2 + n_bytes);
797
852
798
      if (p)
853
      if (p)
799
	{
854
	{

Return to bug 521958