glib-patch, where do I send it?
- From: Jörgen Sigvardsson <Jorgen Sigvardsson kau se>
- To: gtk-devel-list redhat com
- Subject: glib-patch, where do I send it?
- Date: Mon, 10 Jan 2000 07:44:22 +0000
The patch includes:
* g_array_copy() - I think it speaks for itself
* g_ptr_array_copy()
* g_ptr_array_copy_deep() - Deep copying!
* g_byte_array_copy()
* g_list_copy_deep()
* g_slist_copy_deep()
* GCopyFunc - Used for deep copying
The deep copy functions basically look like this:
Type g_type_copy_deep(Type obj, GCopyFunc copy)
{
Type newObj = g_type_new();
if(copy)
newObj->data = copy(obj->data);
else
newObj->data = obj->data;
return newObj;
}
I check the copy-pointer if it's NULL. This way I can reuse code in the
shallow copy function:
Type g_type_copy(Type obj)
{
return g_type_copy_deep(obj, NULL);
}
or alt.
#define g_type_copy(x) g_type_copy_deep((x), NULL);
copy points to a function that is (of course) user defined and
knows about the current data type and how it can be copied.
The patch is attached and was produced with the command:
cvs diff glib.h garray.c glist.c gslist.c
and was done approximately 12 hours ago (so the diff is against a fairly
new version of glib ;)
Regards, Jorgen.
Index: glib.h
===================================================================
RCS file: /cvs/gnome/glib/glib.h,v
retrieving revision 1.149
diff -r1.149 glib.h
812a813,814
> typedef gpointer (*GCopyFunc) (gpointer data);
>
967a970,971
> GList* g_list_copy_deep (GList *list,
> GCopyFunc copy);
1019a1024,1025
> GSList* g_slist_copy_deep (GSList *list,
> GCopyFunc copy);
1862a1869
> GArray* g_array_copy (GArray* array);
1888a1896,1898
> GPtrArray* g_ptr_array_copy (GPtrArray* array);
> GPtrArray* g_ptr_array_copy_deep (GPtrArray* array,
> GCopyFunc copy);
1908a1919
> GByteArray* g_byte_array_copy (GByteArray* array);
Index: garray.c
===================================================================
RCS file: /cvs/gnome/glib/garray.c,v
retrieving revision 1.14
diff -r1.14 garray.c
96a97,116
> g_array_copy (GArray* _array)
> {
> GRealArray* newArr;
> GRealArray* array = (GRealArray*)_array;
>
> G_LOCK(array_mem_chunk);
> newArr = g_chunk_new( GRealArray, array_mem_chunk );
> G_UNLOCK(array_mem_chunk);
>
> newArr->alloc = array->alloc;
> newArr->len = array->len;
> newArr->elt_size = array->elt_size;
> newArr->zero_terminated = array->zero_terminated;
> newArr->clear = array->clear;
> newArr->data = g_malloc(newArr->alloc);
> memcpy(newArr->data, array->data, newArr->alloc);
> return (GArray*)newArr;
> }
>
> GArray*
270c290
< ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
---
> ptr_array_mem_chunk = g_mem_chunk_new ("ptr array mem chunk",
298a319,363
> _g_ptr_array_copy_with_func (gpointer* dest,
> gpointer* src,
> guint len,
> GCopyFunc copy)
> {
> guint i;
>
> for(i = 0; i < len; i++)
> dest[i] = copy(src[i]);
> }
>
> GPtrArray*
> g_ptr_array_copy (GPtrArray* array)
> {
> return g_ptr_array_copy_deep(array, NULL);
> }
>
> GPtrArray*
> g_ptr_array_copy_deep (GPtrArray* _array,
> GCopyFunc copy)
> {
> GRealPtrArray* newArr;
> GRealPtrArray* array = (GRealPtrArray*)_array;
>
> G_LOCK (ptr_array_mem_chunk);
> newArr = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
> G_UNLOCK (ptr_array_mem_chunk);
>
> newArr->alloc = array->alloc;
> newArr->len = array->len;
> newArr->pdata = g_new0 (gpointer, array->alloc);
>
> if(copy)
> _g_ptr_array_copy_with_func (newArr->pdata,
> array->pdata,
> newArr->len,
> copy);
> else
> memcpy(newArr->pdata, array->pdata, newArr->alloc);
>
> return (GPtrArray*)newArr;
> }
>
>
> static void
446a512,517
> }
>
> GByteArray*
> g_byte_array_copy (GByteArray* array)
> {
> return (GByteArray*)g_array_copy((GArray*)array);
Index: glist.c
===================================================================
RCS file: /cvs/gnome/glib/glist.c,v
retrieving revision 1.14
diff -r1.14 glist.c
347c347,354
< g_list_copy (GList *list)
---
> g_list_copy (GList* list)
> {
> return g_list_copy_deep(list, NULL);
> }
>
> GList*
> g_list_copy_deep (GList* list,
> GCopyFunc copy)
356c363,366
< new_list->data = list->data;
---
> if(copy)
> new_list->data = copy(list->data);
> else
> new_list->data = list->data;
364c374,377
< last->data = list->data;
---
> if(copy)
> last->data = copy(list->data);
> else
> last->data = list->data;
Index: gslist.c
===================================================================
RCS file: /cvs/gnome/glib/gslist.c,v
retrieving revision 1.12
diff -r1.12 gslist.c
353c353,359
< g_slist_copy (GSList *list)
---
> g_slist_copy(GSList* list)
> {
> return g_slist_copy_deep(list, NULL);
> }
>
> GSList*
> g_slist_copy_deep (GSList *list, GCopyFunc copy)
362c368,371
< new_list->data = list->data;
---
> if(copy)
> new_list->data = copy(list->data);
> else
> new_list->data = list->data;
369c378,381
< last->data = list->data;
---
> if(copy)
> last->data = copy(list->data);
> else
> last->data = list->data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]