From 213e90aa188006f164ce292782c1594624a40c70 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 22 Mar 2005 04:09:17 +0000 Subject: [PATCH] Add g_try_new, g_try_new0, g_try_renew and g_try_malloc0. (#169611, Stefan 2005-03-21 Matthias Clasen * 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 | 6 ++++-- ChangeLog.pre-2-10 | 6 ++++-- ChangeLog.pre-2-12 | 6 ++++-- ChangeLog.pre-2-8 | 6 ++++-- docs/reference/ChangeLog | 2 +- docs/reference/glib/glib-sections.txt | 1 + docs/reference/glib/tmpl/memory.sgml | 11 +++++++++++ glib/gmem.c | 13 +++++++++++++ glib/gmem.h | 1 + 9 files changed, 43 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96bd57f..5fc7ac8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,9 @@ 2005-03-21 Matthias Clasen - * 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 diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 96bd57f..5fc7ac8 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,7 +1,9 @@ 2005-03-21 Matthias Clasen - * 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 diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 96bd57f..5fc7ac8 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,7 +1,9 @@ 2005-03-21 Matthias Clasen - * 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 diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 96bd57f..5fc7ac8 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,7 +1,9 @@ 2005-03-21 Matthias Clasen - * 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 diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 3c5f0e8..1fe143b 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -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 diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index d0feee0..786e0d9 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -772,6 +772,7 @@ g_malloc g_malloc0 g_realloc g_try_malloc +g_try_malloc0 g_try_realloc diff --git a/docs/reference/glib/tmpl/memory.sgml b/docs/reference/glib/tmpl/memory.sgml index 91836ad..7c5f8f4 100644 --- a/docs/reference/glib/tmpl/memory.sgml +++ b/docs/reference/glib/tmpl/memory.sgml @@ -144,6 +144,17 @@ Contrast with g_malloc(), which aborts the program on failure. @Returns: the allocated memory, or %NULL. + + +Attempts to allocate @n_bytes, initialized to 0's, and returns %NULL on +failure. Contrast with g_malloc0(), which aborts the program on failure. + + +@n_bytes: number of bytes to allocate. +@Returns: the allocated memory, or %NULL. +@Since: 2.8 + + Attempts to realloc @mem to a new size, @n_bytes, and returns %NULL diff --git a/glib/gmem.c b/glib/gmem.c index 86e6d44..f2c6d20 100644 --- a/glib/gmem.c +++ b/glib/gmem.c @@ -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) { diff --git a/glib/gmem.h b/glib/gmem.h index cf21e58..6966b28 100644 --- a/glib/gmem.h +++ b/glib/gmem.h @@ -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); -- 2.7.4