Add a DestroyNotify field, and gtk_object_set_data_full() to match.
Tue Feb 10 15:01:44 1998 Owen Taylor <owt1@cornell.edu> * gtk/gtkobject.c gtk/gtkobject.h: Add a DestroyNotify field, and gtk_object_set_data_full() to match. * gtk/gtkobject.c (gtk_object_finalize): ObjectData structures were being added to a free list, then forgotten about. Just rely on GMemChunk instead.
This commit is contained in:
parent
39e26262a5
commit
dd07df15c1
@ -45,6 +45,7 @@ struct _GtkObjectData
|
|||||||
{
|
{
|
||||||
guint id;
|
guint id;
|
||||||
gpointer data;
|
gpointer data;
|
||||||
|
GtkDestroyNotify destroy;
|
||||||
GtkObjectData *next;
|
GtkObjectData *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,7 +69,7 @@ static void gtk_object_get_arg (GtkObject *object,
|
|||||||
guint arg_id);
|
guint arg_id);
|
||||||
static void gtk_object_real_destroy (GtkObject *object);
|
static void gtk_object_real_destroy (GtkObject *object);
|
||||||
static void gtk_object_finalize (GtkObject *object);
|
static void gtk_object_finalize (GtkObject *object);
|
||||||
static void gtk_object_notify_weaks (GtkObject *object);
|
static void gtk_object_notify_weaks (gpointer data);
|
||||||
static void gtk_object_data_init (void);
|
static void gtk_object_data_init (void);
|
||||||
static GtkObjectData* gtk_object_data_new (void);
|
static GtkObjectData* gtk_object_data_new (void);
|
||||||
static void gtk_object_data_destroy (GtkObjectData *odata);
|
static void gtk_object_data_destroy (GtkObjectData *odata);
|
||||||
@ -392,19 +393,14 @@ gtk_object_class_add_user_signal (GtkObjectClass *class,
|
|||||||
static void
|
static void
|
||||||
gtk_object_finalize (GtkObject *object)
|
gtk_object_finalize (GtkObject *object)
|
||||||
{
|
{
|
||||||
GtkObjectData *odata;
|
GtkObjectData *odata, *next;
|
||||||
|
|
||||||
gtk_object_notify_weaks (object);
|
|
||||||
|
|
||||||
if (object->object_data)
|
|
||||||
{
|
|
||||||
odata = object->object_data;
|
odata = object->object_data;
|
||||||
while (odata->next)
|
while (odata)
|
||||||
odata = odata->next;
|
{
|
||||||
|
next = odata->next;
|
||||||
odata->next = object_data_free_list;
|
gtk_object_data_destroy (odata);
|
||||||
object_data_free_list = object->object_data;
|
odata = next;
|
||||||
object->object_data = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (object);
|
g_free (object);
|
||||||
@ -497,7 +493,8 @@ gtk_object_weakref (GtkObject *object,
|
|||||||
weak->next = gtk_object_get_data (object, weakrefs_key);
|
weak->next = gtk_object_get_data (object, weakrefs_key);
|
||||||
weak->notify = notify;
|
weak->notify = notify;
|
||||||
weak->data = data;
|
weak->data = data;
|
||||||
gtk_object_set_data (object, weakrefs_key, weak);
|
gtk_object_set_data_full (object, weakrefs_key, weak,
|
||||||
|
gtk_object_notify_weaks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -517,7 +514,8 @@ gtk_object_weakunref (GtkObject *object,
|
|||||||
if (w->notify == notify && w->data == data)
|
if (w->notify == notify && w->data == data)
|
||||||
{
|
{
|
||||||
if (w == weaks)
|
if (w == weaks)
|
||||||
gtk_object_set_data (object, weakrefs_key, w->next);
|
gtk_object_set_data_full (object, weakrefs_key, w->next,
|
||||||
|
gtk_object_notify_weaks);
|
||||||
else
|
else
|
||||||
*wp = w->next;
|
*wp = w->next;
|
||||||
g_free (w);
|
g_free (w);
|
||||||
@ -527,12 +525,11 @@ gtk_object_weakunref (GtkObject *object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_object_notify_weaks (GtkObject *object)
|
gtk_object_notify_weaks (gpointer data)
|
||||||
{
|
{
|
||||||
GtkWeakRef *w1, *w2;
|
GtkWeakRef *w1, *w2;
|
||||||
|
|
||||||
w1 = gtk_object_get_data (object, weakrefs_key);
|
w1 = (GtkWeakRef *)data;
|
||||||
gtk_object_set_data (object, weakrefs_key, NULL);
|
|
||||||
|
|
||||||
while (w1)
|
while (w1)
|
||||||
{
|
{
|
||||||
@ -952,6 +949,23 @@ void
|
|||||||
gtk_object_set_data (GtkObject *object,
|
gtk_object_set_data (GtkObject *object,
|
||||||
const gchar *key,
|
const gchar *key,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
|
{
|
||||||
|
gtk_object_set_data_full (object, key, data, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************
|
||||||
|
* gtk_object_set_data_full:
|
||||||
|
*
|
||||||
|
* arguments:
|
||||||
|
*
|
||||||
|
* results:
|
||||||
|
*****************************************/
|
||||||
|
|
||||||
|
void
|
||||||
|
gtk_object_set_data_full (GtkObject *object,
|
||||||
|
const gchar *key,
|
||||||
|
gpointer data,
|
||||||
|
GtkDestroyNotify destroy)
|
||||||
{
|
{
|
||||||
GtkObjectData *odata;
|
GtkObjectData *odata;
|
||||||
GtkObjectData *prev;
|
GtkObjectData *prev;
|
||||||
@ -1005,6 +1019,7 @@ gtk_object_set_data (GtkObject *object,
|
|||||||
if (odata->id == *id)
|
if (odata->id == *id)
|
||||||
{
|
{
|
||||||
odata->data = data;
|
odata->data = data;
|
||||||
|
odata->destroy = destroy;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1014,6 +1029,7 @@ gtk_object_set_data (GtkObject *object,
|
|||||||
odata = gtk_object_data_new ();
|
odata = gtk_object_data_new ();
|
||||||
odata->id = *id;
|
odata->id = *id;
|
||||||
odata->data = data;
|
odata->data = data;
|
||||||
|
odata->destroy = destroy;
|
||||||
|
|
||||||
odata->next = object->object_data;
|
odata->next = object->object_data;
|
||||||
object->object_data = odata;
|
object->object_data = odata;
|
||||||
@ -1073,7 +1089,7 @@ gtk_object_remove_data (GtkObject *object,
|
|||||||
g_return_if_fail (GTK_IS_OBJECT (object));
|
g_return_if_fail (GTK_IS_OBJECT (object));
|
||||||
g_return_if_fail (key != NULL);
|
g_return_if_fail (key != NULL);
|
||||||
|
|
||||||
gtk_object_set_data (object, key, NULL);
|
gtk_object_set_data_full (object, key, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************
|
/*****************************************
|
||||||
@ -1091,7 +1107,7 @@ gtk_object_set_user_data (GtkObject *object,
|
|||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
g_return_if_fail (GTK_IS_OBJECT (object));
|
g_return_if_fail (GTK_IS_OBJECT (object));
|
||||||
|
|
||||||
gtk_object_set_data (object, user_data_key, data);
|
gtk_object_set_data_full (object, user_data_key, data, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************
|
/*****************************************
|
||||||
@ -1197,6 +1213,7 @@ gtk_object_data_new ()
|
|||||||
|
|
||||||
odata->id = 0;
|
odata->id = 0;
|
||||||
odata->data = NULL;
|
odata->data = NULL;
|
||||||
|
odata->destroy = NULL;
|
||||||
odata->next = NULL;
|
odata->next = NULL;
|
||||||
|
|
||||||
return odata;
|
return odata;
|
||||||
@ -1215,6 +1232,9 @@ gtk_object_data_destroy (GtkObjectData *odata)
|
|||||||
{
|
{
|
||||||
g_return_if_fail (odata != NULL);
|
g_return_if_fail (odata != NULL);
|
||||||
|
|
||||||
|
if (odata->destroy)
|
||||||
|
odata->destroy (odata);
|
||||||
|
|
||||||
g_mem_chunk_free (object_data_mem_chunk, odata);
|
g_mem_chunk_free (object_data_mem_chunk, odata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,6 +260,14 @@ void gtk_object_set_data (GtkObject *object,
|
|||||||
const gchar *key,
|
const gchar *key,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
|
|
||||||
|
/* Like gtk_object_set_data, but takes an additional argument
|
||||||
|
* which is a function to be called when the data is removed
|
||||||
|
*/
|
||||||
|
void gtk_object_set_data_full (GtkObject *object,
|
||||||
|
const gchar *key,
|
||||||
|
gpointer data,
|
||||||
|
GtkDestroyNotify destroy);
|
||||||
|
|
||||||
/* Get the data associated with "key".
|
/* Get the data associated with "key".
|
||||||
*/
|
*/
|
||||||
gpointer gtk_object_get_data (GtkObject *object,
|
gpointer gtk_object_get_data (GtkObject *object,
|
||||||
|
Loading…
Reference in New Issue
Block a user