Re: g_string_free
- From: Darin Adler <darin eazel com>
- To: Gtk Developers <gtk-devel-list redhat com>
- Subject: Re: g_string_free
- Date: Mon, 31 Jul 2000 14:53:12 -0700
on 7/31/00 1:18 PM, Michael Meeks at michael@helixcode.com wrote:
> I can think of no better value to return but NULL; either way,
> people can just ignore the return value with no problem as code that
> passes TRUE will undoubtedly do unless they are writing a bug in
> deliberately :-)
I still prefer g_string_free_keep_string to a boolean parameter. But my
personal preferences are beside the point since there are both compatibility
issues and others who strongly disagree. Here's a patch that implements
Michael's requested change plus some related stuff:
Index: garray.c
===================================================================
RCS file: /cvs/gnome/glib/garray.c,v
retrieving revision 1.19
diff -p -u -r1.19 garray.c
--- garray.c 2000/07/26 11:01:59 1.19
+++ garray.c 2000/07/31 21:44:47
@@ -102,16 +102,27 @@ GArray* g_array_sized_new (gboolean zero
return (GArray*) array;
}
-void
+gchar*
g_array_free (GArray *array,
gboolean free_segment)
{
+ gchar* segment;
+
+ g_return_if_fail (array);
+
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_si
return (GPtrArray*) array;
}
-void
+gpointer*
g_ptr_array_free (GPtrArray *array,
gboolean free_segment)
{
+ gpointer* segment;
+
g_return_if_fail (array);
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 (guin
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,
Index: glib.h
===================================================================
RCS file: /cvs/gnome/glib/glib.h,v
retrieving revision 1.185
diff -p -u -r1.185 glib.h
--- glib.h 2000/07/29 20:59:05 1.185
+++ glib.h 2000/07/31 21:44:55
@@ -1925,7 +1925,7 @@ gchar* g_string_chunk_insert_const
*/
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 (gbool
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,8 +2015,8 @@ GArray* g_array_remove_index_fast (GArra
#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,
- gboolean free_seg);
+gpointer* g_ptr_array_free (GPtrArray *array,
+ gboolean free_segment);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
@@ -2036,7 +2036,7 @@ void g_ptr_array_add
(GPtrArray
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,
Index: gstring.c
===================================================================
RCS file: /cvs/gnome/glib/gstring.c,v
retrieving revision 1.17
diff -p -u -r1.17 gstring.c
--- gstring.c 2000/07/26 11:01:59 1.17
+++ gstring.c 2000/07/31 21:44:56
@@ -251,18 +251,29 @@ 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
===================================================================
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]