From 4010a5acb2be1747e60a0e844a508dbf0f55a149 Mon Sep 17 00:00:00 2001 From: Darin Adler Date: Thu, 17 Aug 2000 21:37:18 +0000 Subject: [PATCH] Return the data left behind. Return the data left behind. * glib.h: * garray.c: (g_array_free), (g_ptr_array_free), (g_byte_array_free): Return the data left behind. * gstring.c: (g_string_free): Return the data left behind. Changed the free calls that leave data behind so they return a pointer to the left-behind data, NULL if told not to leave anything behind. This makes these calls easier to use correctly, without any incompatible API change for callers that don't know about the return value. Of course, it would be even clearer if the free calls weren't dual-purpose in the first place. --- ChangeLog | 15 +++++++++++++++ ChangeLog.pre-2-0 | 15 +++++++++++++++ ChangeLog.pre-2-10 | 15 +++++++++++++++ ChangeLog.pre-2-12 | 15 +++++++++++++++ ChangeLog.pre-2-2 | 15 +++++++++++++++ ChangeLog.pre-2-4 | 15 +++++++++++++++ ChangeLog.pre-2-6 | 15 +++++++++++++++ ChangeLog.pre-2-8 | 15 +++++++++++++++ garray.c | 34 +++++++++++++++++++++++++++------- glib.h | 8 ++++---- glib/garray.c | 34 +++++++++++++++++++++++++++------- glib/glib.h | 8 ++++---- glib/gstring.c | 13 +++++++++++-- gstring.c | 13 +++++++++++-- 14 files changed, 204 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5b9fa608..843ac4ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5b9fa608..843ac4ae 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,18 @@ +2000-08-17 Darin Adler + + * glib.h: + * garray.c: (g_array_free), (g_ptr_array_free), + (g_byte_array_free): Return the data left behind. + * gstring.c: (g_string_free): Return the data left behind. + + Changed the free calls that leave data behind so they + return a pointer to the left-behind data, NULL if told not + to leave anything behind. This makes these calls easier + to use correctly, without any incompatible API change for + callers that don't know about the return value. Of course, + it would be even clearer if the free calls weren't dual-purpose + in the first place. + 2000-08-12 Tor Lillqvist * giowin32.c: Some indentation and spacing fixes. Add some more diff --git a/garray.c b/garray.c index 13dac564..285e4fed 100644 --- a/garray.c +++ b/garray.c @@ -102,16 +102,27 @@ GArray* g_array_sized_new (gboolean zero_terminated, return (GArray*) array; } -void +gchar* g_array_free (GArray *array, gboolean free_segment) { + gchar* segment; + + g_return_val_if_fail (array, NULL); + if (free_segment) - g_free (array->data); + { + g_free (array->data); + segment = NULL; + } + else + segment = array->data; G_LOCK (array_mem_chunk); g_mem_chunk_free (array_mem_chunk, array); G_UNLOCK (array_mem_chunk); + + return segment; } GArray* @@ -335,18 +346,27 @@ g_ptr_array_sized_new (guint reserved_size) return (GPtrArray*) array; } -void +gpointer* g_ptr_array_free (GPtrArray *array, gboolean free_segment) { - g_return_if_fail (array); + gpointer* segment; + + g_return_val_if_fail (array, NULL); if (free_segment) - g_free (array->pdata); + { + g_free (array->pdata); + segment = NULL; + } + else + segment = array->pdata; G_LOCK (ptr_array_mem_chunk); g_mem_chunk_free (ptr_array_mem_chunk, array); G_UNLOCK (ptr_array_mem_chunk); + + return segment; } static void @@ -520,10 +540,10 @@ GByteArray* g_byte_array_sized_new (guint reserved_size) return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, reserved_size); } -void g_byte_array_free (GByteArray *array, +guint8* g_byte_array_free (GByteArray *array, gboolean free_segment) { - g_array_free ((GArray*) array, free_segment); + return (guint8*) g_array_free ((GArray*) array, free_segment); } GByteArray* g_byte_array_append (GByteArray *array, diff --git a/glib.h b/glib.h index 4ebe6626..72ccbfba 100644 --- a/glib.h +++ b/glib.h @@ -1925,7 +1925,7 @@ gchar* g_string_chunk_insert_const (GStringChunk *chunk, */ GString* g_string_new (const gchar *init); GString* g_string_sized_new (guint dfl_size); -void g_string_free (GString *string, +gchar* g_string_free (GString *string, gboolean free_segment); gboolean g_string_equal (const GString *v, const GString *v2); @@ -1988,7 +1988,7 @@ GArray* g_array_sized_new (gboolean zero_terminated, gboolean clear, guint element_size, guint reserved_size); -void g_array_free (GArray *array, +gchar* g_array_free (GArray *array, gboolean free_segment); GArray* g_array_append_vals (GArray *array, gconstpointer data, @@ -2015,7 +2015,7 @@ GArray* g_array_remove_index_fast (GArray *array, #define g_ptr_array_index(array,index) (array->pdata)[index] GPtrArray* g_ptr_array_new (void); GPtrArray* g_ptr_array_sized_new (guint reserved_size); -void g_ptr_array_free (GPtrArray *array, +gpointer* g_ptr_array_free (GPtrArray *array, gboolean free_seg); void g_ptr_array_set_size (GPtrArray *array, gint length); @@ -2036,7 +2036,7 @@ void g_ptr_array_add (GPtrArray *array, GByteArray* g_byte_array_new (void); GByteArray* g_byte_array_sized_new (guint reserved_size); -void g_byte_array_free (GByteArray *array, +guint8* g_byte_array_free (GByteArray *array, gboolean free_segment); GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, diff --git a/glib/garray.c b/glib/garray.c index 13dac564..285e4fed 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -102,16 +102,27 @@ GArray* g_array_sized_new (gboolean zero_terminated, return (GArray*) array; } -void +gchar* g_array_free (GArray *array, gboolean free_segment) { + gchar* segment; + + g_return_val_if_fail (array, NULL); + if (free_segment) - g_free (array->data); + { + g_free (array->data); + segment = NULL; + } + else + segment = array->data; G_LOCK (array_mem_chunk); g_mem_chunk_free (array_mem_chunk, array); G_UNLOCK (array_mem_chunk); + + return segment; } GArray* @@ -335,18 +346,27 @@ g_ptr_array_sized_new (guint reserved_size) return (GPtrArray*) array; } -void +gpointer* g_ptr_array_free (GPtrArray *array, gboolean free_segment) { - g_return_if_fail (array); + gpointer* segment; + + g_return_val_if_fail (array, NULL); if (free_segment) - g_free (array->pdata); + { + g_free (array->pdata); + segment = NULL; + } + else + segment = array->pdata; G_LOCK (ptr_array_mem_chunk); g_mem_chunk_free (ptr_array_mem_chunk, array); G_UNLOCK (ptr_array_mem_chunk); + + return segment; } static void @@ -520,10 +540,10 @@ GByteArray* g_byte_array_sized_new (guint reserved_size) return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, reserved_size); } -void g_byte_array_free (GByteArray *array, +guint8* g_byte_array_free (GByteArray *array, gboolean free_segment) { - g_array_free ((GArray*) array, free_segment); + return (guint8*) g_array_free ((GArray*) array, free_segment); } GByteArray* g_byte_array_append (GByteArray *array, diff --git a/glib/glib.h b/glib/glib.h index 4ebe6626..72ccbfba 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -1925,7 +1925,7 @@ gchar* g_string_chunk_insert_const (GStringChunk *chunk, */ GString* g_string_new (const gchar *init); GString* g_string_sized_new (guint dfl_size); -void g_string_free (GString *string, +gchar* g_string_free (GString *string, gboolean free_segment); gboolean g_string_equal (const GString *v, const GString *v2); @@ -1988,7 +1988,7 @@ GArray* g_array_sized_new (gboolean zero_terminated, gboolean clear, guint element_size, guint reserved_size); -void g_array_free (GArray *array, +gchar* g_array_free (GArray *array, gboolean free_segment); GArray* g_array_append_vals (GArray *array, gconstpointer data, @@ -2015,7 +2015,7 @@ GArray* g_array_remove_index_fast (GArray *array, #define g_ptr_array_index(array,index) (array->pdata)[index] GPtrArray* g_ptr_array_new (void); GPtrArray* g_ptr_array_sized_new (guint reserved_size); -void g_ptr_array_free (GPtrArray *array, +gpointer* g_ptr_array_free (GPtrArray *array, gboolean free_seg); void g_ptr_array_set_size (GPtrArray *array, gint length); @@ -2036,7 +2036,7 @@ void g_ptr_array_add (GPtrArray *array, GByteArray* g_byte_array_new (void); GByteArray* g_byte_array_sized_new (guint reserved_size); -void g_byte_array_free (GByteArray *array, +guint8* g_byte_array_free (GByteArray *array, gboolean free_segment); GByteArray* g_byte_array_append (GByteArray *array, const guint8 *data, diff --git a/glib/gstring.c b/glib/gstring.c index 4f2ce7d1..ee380504 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -251,18 +251,27 @@ g_string_new (const gchar *init) return string; } -void +gchar* g_string_free (GString *string, gboolean free_segment) { + gchar *segment; + g_return_if_fail (string != NULL); if (free_segment) - g_free (string->str); + { + g_free (string->str); + segment = NULL; + } + else + segment = string->str; G_LOCK (string_mem_chunk); g_mem_chunk_free (string_mem_chunk, string); G_UNLOCK (string_mem_chunk); + + return segment; } gboolean diff --git a/gstring.c b/gstring.c index 4f2ce7d1..ee380504 100644 --- a/gstring.c +++ b/gstring.c @@ -251,18 +251,27 @@ g_string_new (const gchar *init) return string; } -void +gchar* g_string_free (GString *string, gboolean free_segment) { + gchar *segment; + g_return_if_fail (string != NULL); if (free_segment) - g_free (string->str); + { + g_free (string->str); + segment = NULL; + } + else + segment = string->str; G_LOCK (string_mem_chunk); g_mem_chunk_free (string_mem_chunk, string); G_UNLOCK (string_mem_chunk); + + return segment; } gboolean -- 2.34.1