Add g_try_new, g_try_new0, g_try_renew and g_try_malloc0. (#169611, Stefan
authorMatthias Clasen <mclasen@redhat.com>
Tue, 22 Mar 2005 04:09:17 +0000 (04:09 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 22 Mar 2005 04:09:17 +0000 (04:09 +0000)
2005-03-21  Matthias Clasen  <mclasen@redhat.com>

* glib/gmem.h: Add g_try_new, g_try_new0, g_try_renew and
g_try_malloc0.  (#169611, Stefan Kost)

* glib/gmem.c: Implement g_try_malloc0.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/memory.sgml
glib/gmem.c
glib/gmem.h

index 96bd57f..5fc7ac8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,9 @@
 2005-03-21  Matthias Clasen  <mclasen@redhat.com>
 
-       * glib/gmem.h: Add g_try_new, g_try_new0 and 
-       g_try_renew.  (#169611, Stefan Kost)
+       * glib/gmem.h: Add g_try_new, g_try_new0, g_try_renew and
+       g_try_malloc0.  (#169611, Stefan Kost)
+
+       * glib/gmem.c: Implement g_try_malloc0.
 
 2005-03-20  Tor Lillqvist  <tml@novell.com>
 
index 96bd57f..5fc7ac8 100644 (file)
@@ -1,7 +1,9 @@
 2005-03-21  Matthias Clasen  <mclasen@redhat.com>
 
-       * glib/gmem.h: Add g_try_new, g_try_new0 and 
-       g_try_renew.  (#169611, Stefan Kost)
+       * glib/gmem.h: Add g_try_new, g_try_new0, g_try_renew and
+       g_try_malloc0.  (#169611, Stefan Kost)
+
+       * glib/gmem.c: Implement g_try_malloc0.
 
 2005-03-20  Tor Lillqvist  <tml@novell.com>
 
index 96bd57f..5fc7ac8 100644 (file)
@@ -1,7 +1,9 @@
 2005-03-21  Matthias Clasen  <mclasen@redhat.com>
 
-       * glib/gmem.h: Add g_try_new, g_try_new0 and 
-       g_try_renew.  (#169611, Stefan Kost)
+       * glib/gmem.h: Add g_try_new, g_try_new0, g_try_renew and
+       g_try_malloc0.  (#169611, Stefan Kost)
+
+       * glib/gmem.c: Implement g_try_malloc0.
 
 2005-03-20  Tor Lillqvist  <tml@novell.com>
 
index 96bd57f..5fc7ac8 100644 (file)
@@ -1,7 +1,9 @@
 2005-03-21  Matthias Clasen  <mclasen@redhat.com>
 
-       * glib/gmem.h: Add g_try_new, g_try_new0 and 
-       g_try_renew.  (#169611, Stefan Kost)
+       * glib/gmem.h: Add g_try_new, g_try_new0, g_try_renew and
+       g_try_malloc0.  (#169611, Stefan Kost)
+
+       * glib/gmem.c: Implement g_try_malloc0.
 
 2005-03-20  Tor Lillqvist  <tml@novell.com>
 
index 3c5f0e8..1fe143b 100644 (file)
@@ -2,7 +2,7 @@
 
        * glib/glib-sections.txt: 
        * glib/tmpl/memory.sgml: Document g_try_new, g_try_new0 
-       and g_try_renew.
+       and g_try_renew, g_try_malloc0.
 
 2005-03-20  Matthias Clasen  <mclasen@redhat.com>
 
index d0feee0..786e0d9 100644 (file)
@@ -772,6 +772,7 @@ g_malloc
 g_malloc0
 g_realloc
 g_try_malloc
+g_try_malloc0
 g_try_realloc
 
 <SUBSECTION>
index 91836ad..7c5f8f4 100644 (file)
@@ -144,6 +144,17 @@ Contrast with g_malloc(), which aborts the program on failure.
 @Returns: the allocated memory, or %NULL.
 
 
+<!-- ##### FUNCTION g_try_malloc0 ##### -->
+<para>
+Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on 
+failure. Contrast with g_malloc0(), which aborts the program on failure.
+</para>
+
+@n_bytes: number of bytes to allocate.
+@Returns: the allocated memory, or %NULL.
+@Since: 2.8
+
+
 <!-- ##### FUNCTION g_try_realloc ##### -->
 <para>
 Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL
index 86e6d44..f2c6d20 100644 (file)
@@ -197,6 +197,19 @@ g_try_malloc (gulong n_bytes)
 }
 
 gpointer
+g_try_malloc0 (gulong n_bytes)
+{ 
+  gpointer mem;
+
+  mem = g_try_malloc (n_bytes);
+  
+  if (mem)
+    memset (mem, 0, n_bytes);
+
+  return mem;
+}
+
+gpointer
 g_try_realloc (gpointer mem,
               gulong   n_bytes)
 {
index cf21e58..6966b28 100644 (file)
@@ -51,6 +51,7 @@ gpointer g_realloc        (gpointer    mem,
                           gulong        n_bytes);
 void    g_free           (gpointer      mem);
 gpointer g_try_malloc     (gulong       n_bytes) G_GNUC_MALLOC;
+gpointer g_try_malloc0    (gulong       n_bytes) G_GNUC_MALLOC;
 gpointer g_try_realloc    (gpointer     mem,
                           gulong        n_bytes);