{
guint id;
gpointer data;
+ GtkDestroyNotify destroy;
GtkObjectData *next;
};
guint arg_id);
static void gtk_object_real_destroy (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 GtkObjectData* gtk_object_data_new (void);
static void gtk_object_data_destroy (GtkObjectData *odata);
static void
gtk_object_finalize (GtkObject *object)
{
- GtkObjectData *odata;
-
- gtk_object_notify_weaks (object);
+ GtkObjectData *odata, *next;
- if (object->object_data)
+ odata = object->object_data;
+ while (odata)
{
- odata = object->object_data;
- while (odata->next)
- odata = odata->next;
-
- odata->next = object_data_free_list;
- object_data_free_list = object->object_data;
- object->object_data = NULL;
+ next = odata->next;
+ gtk_object_data_destroy (odata);
+ odata = next;
}
g_free (object);
weak->next = gtk_object_get_data (object, weakrefs_key);
weak->notify = notify;
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
if (w->notify == notify && w->data == data)
{
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
*wp = w->next;
g_free (w);
}
static void
-gtk_object_notify_weaks (GtkObject *object)
+gtk_object_notify_weaks (gpointer data)
{
GtkWeakRef *w1, *w2;
- w1 = gtk_object_get_data (object, weakrefs_key);
- gtk_object_set_data (object, weakrefs_key, NULL);
+ w1 = (GtkWeakRef *)data;
while (w1)
{
*****************************************/
void
-gtk_object_set_data (GtkObject *object,
- const gchar *key,
- gpointer data)
+gtk_object_set_data (GtkObject *object,
+ const gchar *key,
+ 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 *prev;
if (odata->id == *id)
{
odata->data = data;
+ odata->destroy = destroy;
return;
}
odata = gtk_object_data_new ();
odata->id = *id;
odata->data = data;
+ odata->destroy = destroy;
odata->next = object->object_data;
object->object_data = odata;
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (key != NULL);
- gtk_object_set_data (object, key, NULL);
+ gtk_object_set_data_full (object, key, NULL, NULL);
}
/*****************************************
g_return_if_fail (object != NULL);
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);
}
/*****************************************
odata->id = 0;
odata->data = NULL;
+ odata->destroy = NULL;
odata->next = NULL;
return odata;
{
g_return_if_fail (odata != NULL);
+ if (odata->destroy)
+ odata->destroy (odata);
+
g_mem_chunk_free (object_data_mem_chunk, odata);
}