1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998, 1999, 2000 Tim Janik and Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include "gvaluecollector.h"
30 #define PARAM_SPEC_PARAM_ID(pspec) (GPOINTER_TO_UINT (g_param_spec_get_qdata ((pspec), quark_param_id)))
33 /* --- prototypes --- */
34 static void g_object_base_class_init (GObjectClass *class);
35 static void g_object_base_class_finalize (GObjectClass *class);
36 static void g_object_do_class_init (GObjectClass *class);
37 static void g_object_do_init (GObject *object);
38 static void g_object_do_queue_param_changed (GObject *object,
40 static void g_object_do_dispatch_param_changed (GObject *object,
42 static void g_object_last_unref (GObject *object);
43 static void g_object_do_shutdown (GObject *object);
44 static void g_object_do_finalize (GObject *object);
45 static void g_value_object_init (GValue *value);
46 static void g_value_object_free_value (GValue *value);
47 static void g_value_object_copy_value (const GValue *src_value,
49 static gpointer g_value_object_peek_pointer (const GValue *value);
50 static gchar* g_value_object_collect_value (GValue *value,
53 GTypeCValue *collect_value);
54 static gchar* g_value_object_lcopy_value (const GValue *value,
57 GTypeCValue *collect_value);
60 /* --- variables --- */
61 static GQuark quark_param_id = 0;
62 static GQuark quark_param_changed_queue = 0;
63 static GQuark quark_closure_array = 0;
64 static GHashTable *param_spec_hash_table = NULL;
67 /* --- functions --- */
70 /* We need an actual method for handling debug keys in GLib.
71 * For now, we'll simply use, as a method
72 * 'extern gboolean glib_debug_objects'
74 gboolean glib_debug_objects = FALSE;
76 static guint debug_objects_count = 0;
77 static GHashTable *debug_objects_ht = NULL;
79 debug_objects_foreach (gpointer key,
83 GObject *object = value;
85 g_message ("[%p] stale %s\tref_count=%u",
87 G_OBJECT_TYPE_NAME (object),
91 debug_objects_atexit (void)
93 if (glib_debug_objects)
97 g_message ("stale GObjects: %u", debug_objects_count);
98 g_hash_table_foreach (debug_objects_ht, debug_objects_foreach, NULL);
102 #endif /* DEBUG_OBJECTS */
105 g_object_type_init (void) /* sync with gtype.c */
107 static gboolean initialized = FALSE;
108 static const GTypeFundamentalInfo finfo = {
109 G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE,
111 static GTypeInfo info = {
112 sizeof (GObjectClass),
113 (GBaseInitFunc) g_object_base_class_init,
114 (GBaseFinalizeFunc) g_object_base_class_finalize,
115 (GClassInitFunc) g_object_do_class_init,
116 NULL /* class_destroy */,
117 NULL /* class_data */,
120 (GInstanceInitFunc) g_object_do_init,
121 NULL, /* value_table */
123 static const GTypeValueTable value_table = {
124 g_value_object_init, /* value_init */
125 g_value_object_free_value, /* value_free */
126 g_value_object_copy_value, /* value_copy */
127 g_value_object_peek_pointer, /* value_peek_pointer */
128 G_VALUE_COLLECT_POINTER, /* collect_type */
129 g_value_object_collect_value, /* collect_value */
130 G_VALUE_COLLECT_POINTER, /* lcopy_type */
131 g_value_object_lcopy_value, /* lcopy_value */
135 g_return_if_fail (initialized == FALSE);
140 info.value_table = &value_table;
141 type = g_type_register_fundamental (G_TYPE_OBJECT, "GObject", &info, &finfo, 0);
142 g_assert (type == G_TYPE_OBJECT);
145 g_atexit (debug_objects_atexit);
146 #endif /* DEBUG_OBJECTS */
150 g_object_base_class_init (GObjectClass *class)
152 /* reset instance specific fields and methods that don't get inherited */
153 class->n_param_specs = 0;
154 class->param_specs = NULL;
155 class->get_param = NULL;
156 class->set_param = NULL;
160 g_object_base_class_finalize (GObjectClass *class)
164 g_message ("finallizing base class of %s", G_OBJECT_CLASS_NAME (class));
166 for (i = 0; i < class->n_param_specs; i++)
168 GParamSpec *pspec = class->param_specs[i];
170 g_param_spec_hash_table_remove (param_spec_hash_table, pspec);
171 g_param_spec_set_qdata (pspec, quark_param_id, NULL);
172 g_param_spec_unref (pspec);
174 class->n_param_specs = 0;
175 g_free (class->param_specs);
176 class->param_specs = NULL;
180 g_object_do_class_init (GObjectClass *class)
182 quark_param_id = g_quark_from_static_string ("glib-object-param-id");
183 quark_param_changed_queue = g_quark_from_static_string ("glib-object-param-changed-queue");
184 quark_closure_array = g_quark_from_static_string ("GObject-closure-array");
185 param_spec_hash_table = g_param_spec_hash_table_new ();
187 class->queue_param_changed = g_object_do_queue_param_changed;
188 class->dispatch_param_changed = g_object_do_dispatch_param_changed;
189 class->shutdown = g_object_do_shutdown;
190 class->finalize = g_object_do_finalize;
194 g_object_class_install_param (GObjectClass *class,
196 GParamSpec *pspec /* 1 ref_count taken over */)
200 g_return_if_fail (G_IS_OBJECT_CLASS (class));
201 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
202 if (pspec->flags & G_PARAM_WRITABLE)
203 g_return_if_fail (class->set_param != NULL);
204 if (pspec->flags & G_PARAM_READABLE)
205 g_return_if_fail (class->get_param != NULL);
206 g_return_if_fail (param_id > 0);
207 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
209 /* expensive paranoia checks ;( */
210 for (i = 0; i < class->n_param_specs; i++)
211 if (PARAM_SPEC_PARAM_ID (class->param_specs[i]) == param_id)
213 g_warning (G_STRLOC ": class `%s' already contains a parameter `%s' with id %u, "
214 "cannot install parameter `%s'",
215 G_OBJECT_CLASS_NAME (class),
216 class->param_specs[i]->name,
221 if (g_object_class_find_param_spec (class, pspec->name))
223 g_warning (G_STRLOC ": class `%s' already contains a parameter named `%s'",
224 G_OBJECT_CLASS_NAME (class),
229 g_param_spec_set_qdata (pspec, quark_param_id, GUINT_TO_POINTER (param_id));
230 g_param_spec_hash_table_insert (param_spec_hash_table, pspec, G_OBJECT_CLASS_TYPE (class));
231 i = class->n_param_specs++;
232 class->param_specs = g_renew (GParamSpec*, class->param_specs, class->n_param_specs);
233 class->param_specs[i] = pspec;
237 g_object_class_find_param_spec (GObjectClass *class,
238 const gchar *param_name)
240 g_return_val_if_fail (G_IS_OBJECT_CLASS (class), NULL);
241 g_return_val_if_fail (param_name != NULL, NULL);
243 return g_param_spec_hash_table_lookup (param_spec_hash_table,
245 G_OBJECT_CLASS_TYPE (class),
250 g_object_do_init (GObject *object)
252 object->ref_count = 1;
253 object->qdata = NULL;
256 if (glib_debug_objects)
258 if (!debug_objects_ht)
259 debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
260 debug_objects_count++;
261 g_hash_table_insert (debug_objects_ht, object, object);
263 #endif /* DEBUG_OBJECTS */
267 g_object_last_unref (GObject *object)
269 g_return_if_fail (object->ref_count > 0);
271 if (object->ref_count == 1) /* may have been re-referenced meanwhile */
272 G_OBJECT_GET_CLASS (object)->shutdown (object);
274 object->ref_count -= 1;
276 if (object->ref_count == 0) /* may have been re-referenced meanwhile */
278 G_OBJECT_GET_CLASS (object)->finalize (object);
279 g_type_free_instance ((GTypeInstance*) object);
284 g_object_do_shutdown (GObject *object)
286 /* this function needs to be always present for unconditional
287 * chaining, we also might add some code here later.
288 * beware though, subclasses may invoke shutdown() arbitrarily.
293 g_object_do_finalize (GObject *object)
295 g_datalist_clear (&object->qdata);
298 if (glib_debug_objects)
300 g_assert (g_hash_table_lookup (debug_objects_ht, object) == object);
302 g_hash_table_remove (debug_objects_ht, object);
303 debug_objects_count--;
305 #endif /* DEBUG_OBJECTS */
309 g_object_new (GType object_type,
310 const gchar *first_param_name,
316 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
318 va_start (var_args, first_param_name);
319 object = g_object_new_valist (object_type, first_param_name, var_args);
326 g_object_new_valist (GType object_type,
327 const gchar *first_param_name,
332 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
334 object = (GObject*) g_type_create_instance (object_type);
335 if (first_param_name)
336 g_object_set_valist (object, first_param_name, var_args);
342 g_object_do_dispatch_param_changed (GObject *object,
345 /* g_message ("NOTIFICATION: parameter `%s' changed on object `%s'",
347 G_OBJECT_TYPE_NAME (object));*/
351 notify_param_changed_handler (gpointer data)
357 /* FIXME: need GDK_THREADS lock */
359 object = G_OBJECT (data);
360 class = G_OBJECT_GET_CLASS (object);
361 slist = g_datalist_id_get_data (&object->qdata, quark_param_changed_queue);
363 /* a reference count is still being held */
365 for (; slist; slist = slist->next)
368 GParamSpec *pspec = slist->data;
371 class->dispatch_param_changed (object, pspec);
374 g_datalist_id_set_data (&object->qdata, quark_param_changed_queue, NULL);
380 g_object_do_queue_param_changed (GObject *object,
383 GSList *slist, *last = NULL;
385 /* if this is a recursive call on this object (i.e. pspecs are queued
386 * for notification, while param_changed notification is currently in
387 * progress), we simply add them to the queue that is currently being
388 * dispatched. otherwise, we later dispatch parameter changed notification
389 * asyncronously from an idle handler untill the queue is completely empty.
392 slist = g_datalist_id_get_data (&object->qdata, quark_param_changed_queue);
393 for (; slist; last = slist, slist = last->next)
394 if (slist->data == pspec)
399 g_object_ref (object);
400 g_idle_add_full (G_NOTIFY_PRIORITY,
401 notify_param_changed_handler,
403 (GDestroyNotify) g_object_unref);
404 g_object_set_qdata_full (object,
405 quark_param_changed_queue,
406 g_slist_prepend (NULL, pspec),
407 (GDestroyNotify) g_slist_free);
410 last->next = g_slist_prepend (NULL, pspec);
414 object_get_param (GObject *object,
417 const gchar *trailer)
421 g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), pspec->owner_type)); /* paranoid */
423 class = g_type_class_peek (pspec->owner_type);
425 class->get_param (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec, trailer);
429 object_set_param (GObject *object,
432 const gchar *trailer)
436 g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), pspec->owner_type)); /* paranoid */
438 class = g_type_class_peek (pspec->owner_type);
440 class->set_param (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec, trailer);
442 class->queue_param_changed (object, pspec);
446 g_object_set_valist (GObject *object,
447 const gchar *first_param_name,
452 g_return_if_fail (G_IS_OBJECT (object));
454 g_object_ref (object);
456 name = first_param_name;
460 const gchar *trailer = NULL;
461 GValue value = { 0, };
465 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
467 G_OBJECT_TYPE (object),
472 g_warning ("%s: object class `%s' has no parameter named `%s'",
474 G_OBJECT_TYPE_NAME (object),
478 if (!(pspec->flags & G_PARAM_WRITABLE))
480 g_warning ("%s: parameter `%s' of object class `%s' is not writable",
483 G_OBJECT_TYPE_NAME (object));
487 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
489 G_VALUE_COLLECT (&value, var_args, &error);
492 g_warning ("%s: %s", G_STRLOC, error);
495 /* we purposely leak the value here, it might not be
496 * in a sane state if an error condition occoured
501 object_set_param (object, &value, pspec, trailer);
503 g_value_unset (&value);
505 name = va_arg (var_args, gchar*);
508 g_object_unref (object);
512 g_object_get_valist (GObject *object,
513 const gchar *first_param_name,
518 g_return_if_fail (G_IS_OBJECT (object));
520 g_object_ref (object);
522 name = first_param_name;
526 const gchar *trailer = NULL;
527 GValue value = { 0, };
531 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
533 G_OBJECT_TYPE (object),
538 g_warning ("%s: object class `%s' has no parameter named `%s'",
540 G_OBJECT_TYPE_NAME (object),
544 if (!(pspec->flags & G_PARAM_READABLE))
546 g_warning ("%s: parameter `%s' of object class `%s' is not readable",
549 G_OBJECT_TYPE_NAME (object));
553 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
555 object_get_param (object, &value, pspec, trailer);
557 G_VALUE_LCOPY (&value, var_args, &error);
560 g_warning ("%s: %s", G_STRLOC, error);
563 /* we purposely leak the value here, it might not be
564 * in a sane state if an error condition occoured
569 g_value_unset (&value);
571 name = va_arg (var_args, gchar*);
574 g_object_unref (object);
578 g_object_set (GObject *object,
579 const gchar *first_param_name,
584 g_return_if_fail (G_IS_OBJECT (object));
586 va_start (var_args, first_param_name);
587 g_object_set_valist (object, first_param_name, var_args);
592 g_object_get (GObject *object,
593 const gchar *first_param_name,
598 g_return_if_fail (G_IS_OBJECT (object));
600 va_start (var_args, first_param_name);
601 g_object_get_valist (object, first_param_name, var_args);
606 g_object_set_param (GObject *object,
607 const gchar *param_name,
611 const gchar *trailer;
613 g_return_if_fail (G_IS_OBJECT (object));
614 g_return_if_fail (param_name != NULL);
615 g_return_if_fail (G_IS_VALUE (value));
617 g_object_ref (object);
619 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
621 G_OBJECT_TYPE (object),
625 g_warning ("%s: object class `%s' has no parameter named `%s'",
627 G_OBJECT_TYPE_NAME (object),
631 GValue tmp_value = { 0, };
633 /* provide a copy to work from and convert if necessary */
634 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
636 if (!g_value_convert (value, &tmp_value) ||
637 g_param_value_validate (pspec, &tmp_value))
638 g_warning ("%s: cannot convert `%s' value to parameter `%s' value of type `%s'",
640 G_VALUE_TYPE_NAME (value),
642 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
644 object_set_param (object, &tmp_value, pspec, trailer);
646 g_value_unset (&tmp_value);
649 g_object_unref (object);
653 g_object_get_param (GObject *object,
654 const gchar *param_name,
658 const gchar *trailer;
660 g_return_if_fail (G_IS_OBJECT (object));
661 g_return_if_fail (param_name != NULL);
662 g_return_if_fail (G_IS_VALUE (value));
664 g_object_ref (object);
666 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
668 G_OBJECT_TYPE (object),
672 g_warning ("%s: object class `%s' has no parameter named `%s'",
674 G_OBJECT_TYPE_NAME (object),
678 GValue tmp_value = { 0, };
680 /* provide a copy to work from and later convert if necessary, so
681 * _get_param() implementations need *not* care about freeing values
682 * that might be already set in the parameter to get.
683 * (though, at this point, GValue should exclusively be modified
684 * through the accessor functions anyways)
686 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
688 if (!g_value_types_exchangable (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec)))
689 g_warning ("%s: can't retrive parameter `%s' value of type `%s' as value of type `%s'",
692 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
693 G_VALUE_TYPE_NAME (value));
696 object_get_param (object, &tmp_value, pspec, trailer);
697 g_value_convert (&tmp_value, value);
698 /* g_value_validate (value, pspec); */
701 g_value_unset (&tmp_value);
704 g_object_unref (object);
708 g_object_queue_param_changed (GObject *object,
709 const gchar *param_name)
713 g_return_if_fail (G_IS_OBJECT (object));
714 g_return_if_fail (param_name != NULL);
716 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
718 G_OBJECT_TYPE (object),
721 g_warning ("%s: object class `%s' has no parameter named `%s'",
723 G_OBJECT_TYPE_NAME (object),
726 G_OBJECT_GET_CLASS (object)->queue_param_changed (object, pspec);
730 g_object_ref (GObject *object)
732 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
733 g_return_val_if_fail (object->ref_count > 0, NULL);
735 object->ref_count += 1;
741 g_object_unref (GObject *object)
743 g_return_if_fail (G_IS_OBJECT (object));
744 g_return_if_fail (object->ref_count > 0);
746 if (object->ref_count > 1)
747 object->ref_count -= 1;
749 g_object_last_unref (object);
753 g_object_get_qdata (GObject *object,
756 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
758 return quark ? g_datalist_id_get_data (&object->qdata, quark) : NULL;
762 g_object_set_qdata (GObject *object,
766 g_return_if_fail (G_IS_OBJECT (object));
767 g_return_if_fail (quark > 0);
769 g_datalist_id_set_data (&object->qdata, quark, data);
773 g_object_set_qdata_full (GObject *object,
776 GDestroyNotify destroy)
778 g_return_if_fail (G_IS_OBJECT (object));
779 g_return_if_fail (quark > 0);
781 g_datalist_id_set_data_full (&object->qdata, quark, data, data ? destroy : NULL);
785 g_object_steal_qdata (GObject *object,
788 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
789 g_return_val_if_fail (quark > 0, NULL);
791 return g_datalist_id_remove_no_notify (&object->qdata, quark);
795 g_value_object_init (GValue *value)
797 value->data[0].v_pointer = NULL;
801 g_value_object_free_value (GValue *value)
803 if (value->data[0].v_pointer)
804 g_object_unref (value->data[0].v_pointer);
808 g_value_object_copy_value (const GValue *src_value,
811 if (src_value->data[0].v_pointer)
812 dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
814 dest_value->data[0].v_pointer = NULL;
818 g_value_object_peek_pointer (const GValue *value)
820 return value->data[0].v_pointer;
824 g_value_object_collect_value (GValue *value,
827 GTypeCValue *collect_value)
829 if (collect_value->v_pointer)
831 GObject *object = collect_value->v_pointer;
833 if (object->g_type_instance.g_class == NULL)
834 return g_strconcat ("invalid unclassed object pointer for value type `",
835 G_VALUE_TYPE_NAME (value),
838 else if (!g_type_is_a (G_OBJECT_TYPE (object), G_VALUE_TYPE (value)))
839 return g_strconcat ("invalid object type `",
840 G_OBJECT_TYPE_NAME (object),
841 "' for value type `",
842 G_VALUE_TYPE_NAME (value),
845 value->data[0].v_pointer = g_object_ref (object);
848 value->data[0].v_pointer = NULL;
855 g_value_object_lcopy_value (const GValue *value,
858 GTypeCValue *collect_value)
860 GObject **object_p = collect_value->v_pointer;
863 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
865 *object_p = value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
872 g_value_set_object (GValue *value,
875 g_return_if_fail (G_IS_VALUE_OBJECT (value));
877 g_return_if_fail (G_IS_OBJECT (v_object));
879 if (value->data[0].v_pointer)
880 g_object_unref (value->data[0].v_pointer);
881 value->data[0].v_pointer = v_object;
882 if (value->data[0].v_pointer)
883 g_object_ref (value->data[0].v_pointer);
887 g_value_get_object (const GValue *value)
889 g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL);
891 return value->data[0].v_pointer;
895 g_value_dup_object (const GValue *value)
897 g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL);
899 return value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
905 GClosure *closures[1]; /* flexible array */
909 object_remove_closure (gpointer data,
912 GObject *object = data;
913 CArray *carray = g_object_get_qdata (object, quark_closure_array);
916 for (i = 0; i < carray->n_closures; i++)
917 if (carray->closures[i] == closure)
919 carray->n_closures--;
920 if (i < carray->n_closures)
921 carray->closures[i] = carray->closures[carray->n_closures];
924 g_assert_not_reached ();
928 destroy_closure_array (gpointer data)
930 CArray *carray = data;
931 GObject *object = carray->object;
932 guint i, n = carray->n_closures;
934 for (i = 0; i < n; i++)
936 GClosure *closure = carray->closures[i];
938 /* removing object_remove_closure() upfront is probably faster than
939 * letting it fiddle with quark_closure_array which is empty anyways
941 g_closure_remove_inotify (closure, object, object_remove_closure);
942 g_closure_invalidate (closure);
948 g_object_watch_closure (GObject *object,
953 g_return_if_fail (G_IS_OBJECT (object));
954 g_return_if_fail (closure != NULL);
955 g_return_if_fail (closure->is_invalid == FALSE);
956 g_return_if_fail (closure->in_marshal == FALSE);
957 g_return_if_fail (object->ref_count > 0); /* this doesn't work on finalizing objects */
959 g_closure_add_inotify (closure, object, object_remove_closure);
960 g_closure_add_marshal_guards (closure,
961 object, (GClosureNotify) g_object_ref,
962 object, (GClosureNotify) g_object_unref);
963 carray = g_object_steal_qdata (object, quark_closure_array);
966 carray = g_renew (CArray, NULL, 1);
967 carray->object = object;
968 carray->n_closures = 1;
969 carray->closures[0] = closure;
970 g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
974 guint i = carray->n_closures++;
976 carray = g_realloc (carray, sizeof (*carray) + sizeof (carray->closures[0]) * i);
977 carray->closures[i] = closure;
978 g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
983 g_closure_new_object (guint sizeof_closure,
988 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
989 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
991 closure = g_closure_new_simple (sizeof_closure, object);
992 g_object_watch_closure (object, closure);
998 g_cclosure_new_object (GCallback callback_func,
1001 GObject *object = _object;
1004 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1005 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1006 g_return_val_if_fail (callback_func != NULL, NULL);
1008 closure = g_cclosure_new (callback_func, object, NULL);
1009 g_object_watch_closure (object, closure);
1015 g_cclosure_new_object_swap (GCallback callback_func,
1018 GObject *object = _object;
1021 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1022 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1023 g_return_val_if_fail (callback_func != NULL, NULL);
1025 closure = g_cclosure_new_swap (callback_func, object, NULL);
1026 g_object_watch_closure (object, closure);