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.
22 #include "gvaluecollector.h"
31 #define PARAM_SPEC_PARAM_ID(pspec) (GPOINTER_TO_UINT (g_param_spec_get_qdata ((pspec), quark_param_id)))
34 /* --- prototypes --- */
35 static void g_object_base_class_init (GObjectClass *class);
36 static void g_object_base_class_finalize (GObjectClass *class);
37 static void g_object_do_class_init (GObjectClass *class);
38 static void g_object_do_init (GObject *object);
39 static void g_object_do_queue_param_changed (GObject *object,
41 static void g_object_do_dispatch_param_changed (GObject *object,
43 static void g_object_last_unref (GObject *object);
44 static void g_object_do_shutdown (GObject *object);
45 static void g_object_do_finalize (GObject *object);
46 static void g_value_object_init (GValue *value);
47 static void g_value_object_free_value (GValue *value);
48 static void g_value_object_copy_value (const GValue *src_value,
50 static gpointer g_value_object_peek_pointer (const GValue *value);
51 static gchar* g_value_object_collect_value (GValue *value,
54 GTypeCValue *collect_value);
55 static gchar* g_value_object_lcopy_value (const GValue *value,
58 GTypeCValue *collect_value);
61 /* --- variables --- */
62 static GQuark quark_param_id = 0;
63 static GQuark quark_param_changed_queue = 0;
64 static GQuark quark_closure_array = 0;
65 static GHashTable *param_spec_hash_table = NULL;
68 /* --- functions --- */
71 /* We need an actual method for handling debug keys in GLib.
72 * For now, we'll simply use, as a method
73 * 'extern gboolean glib_debug_objects'
75 gboolean glib_debug_objects = FALSE;
77 static guint debug_objects_count = 0;
78 static GHashTable *debug_objects_ht = NULL;
80 debug_objects_foreach (gpointer key,
84 GObject *object = value;
86 g_message ("[%p] stale %s\tref_count=%u",
88 G_OBJECT_TYPE_NAME (object),
92 debug_objects_atexit (void)
94 if (glib_debug_objects)
98 g_message ("stale GObjects: %u", debug_objects_count);
99 g_hash_table_foreach (debug_objects_ht, debug_objects_foreach, NULL);
103 #endif /* DEBUG_OBJECTS */
106 g_object_type_init (void) /* sync with gtype.c */
108 static gboolean initialized = FALSE;
109 static const GTypeFundamentalInfo finfo = {
110 G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE,
112 static GTypeInfo info = {
113 sizeof (GObjectClass),
114 (GBaseInitFunc) g_object_base_class_init,
115 (GBaseFinalizeFunc) g_object_base_class_finalize,
116 (GClassInitFunc) g_object_do_class_init,
117 NULL /* class_destroy */,
118 NULL /* class_data */,
121 (GInstanceInitFunc) g_object_do_init,
122 NULL, /* value_table */
124 static const GTypeValueTable value_table = {
125 g_value_object_init, /* value_init */
126 g_value_object_free_value, /* value_free */
127 g_value_object_copy_value, /* value_copy */
128 g_value_object_peek_pointer, /* value_peek_pointer */
129 G_VALUE_COLLECT_POINTER, /* collect_type */
130 g_value_object_collect_value, /* collect_value */
131 G_VALUE_COLLECT_POINTER, /* lcopy_type */
132 g_value_object_lcopy_value, /* lcopy_value */
136 g_return_if_fail (initialized == FALSE);
141 info.value_table = &value_table;
142 type = g_type_register_fundamental (G_TYPE_OBJECT, "GObject", &info, &finfo, 0);
143 g_assert (type == G_TYPE_OBJECT);
146 g_atexit (debug_objects_atexit);
147 #endif /* DEBUG_OBJECTS */
151 g_object_base_class_init (GObjectClass *class)
153 /* reset instance specific fields and methods that don't get inherited */
154 class->n_param_specs = 0;
155 class->param_specs = NULL;
156 class->get_param = NULL;
157 class->set_param = NULL;
161 g_object_base_class_finalize (GObjectClass *class)
165 g_message ("finallizing base class of %s", G_OBJECT_CLASS_NAME (class));
167 _g_signals_destroy (G_OBJECT_CLASS_TYPE (class));
169 for (i = 0; i < class->n_param_specs; i++)
171 GParamSpec *pspec = class->param_specs[i];
173 g_param_spec_hash_table_remove (param_spec_hash_table, pspec);
174 g_param_spec_set_qdata (pspec, quark_param_id, NULL);
175 g_param_spec_unref (pspec);
177 class->n_param_specs = 0;
178 g_free (class->param_specs);
179 class->param_specs = NULL;
183 g_object_do_class_init (GObjectClass *class)
185 quark_param_id = g_quark_from_static_string ("glib-object-param-id");
186 quark_param_changed_queue = g_quark_from_static_string ("glib-object-param-changed-queue");
187 quark_closure_array = g_quark_from_static_string ("GObject-closure-array");
188 param_spec_hash_table = g_param_spec_hash_table_new ();
190 class->queue_param_changed = g_object_do_queue_param_changed;
191 class->dispatch_param_changed = g_object_do_dispatch_param_changed;
192 class->shutdown = g_object_do_shutdown;
193 class->finalize = g_object_do_finalize;
197 g_object_class_install_param (GObjectClass *class,
199 GParamSpec *pspec /* 1 ref_count taken over */)
203 g_return_if_fail (G_IS_OBJECT_CLASS (class));
204 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
205 if (pspec->flags & G_PARAM_WRITABLE)
206 g_return_if_fail (class->set_param != NULL);
207 if (pspec->flags & G_PARAM_READABLE)
208 g_return_if_fail (class->get_param != NULL);
209 g_return_if_fail (param_id > 0);
210 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
212 /* expensive paranoia checks ;( */
213 for (i = 0; i < class->n_param_specs; i++)
214 if (PARAM_SPEC_PARAM_ID (class->param_specs[i]) == param_id)
216 g_warning (G_STRLOC ": class `%s' already contains a parameter `%s' with id %u, "
217 "cannot install parameter `%s'",
218 G_OBJECT_CLASS_NAME (class),
219 class->param_specs[i]->name,
224 if (g_object_class_find_param_spec (class, pspec->name))
226 g_warning (G_STRLOC ": class `%s' already contains a parameter named `%s'",
227 G_OBJECT_CLASS_NAME (class),
232 g_param_spec_set_qdata (pspec, quark_param_id, GUINT_TO_POINTER (param_id));
233 g_param_spec_hash_table_insert (param_spec_hash_table, pspec, G_OBJECT_CLASS_TYPE (class));
234 i = class->n_param_specs++;
235 class->param_specs = g_renew (GParamSpec*, class->param_specs, class->n_param_specs);
236 class->param_specs[i] = pspec;
240 g_object_class_find_param_spec (GObjectClass *class,
241 const gchar *param_name)
243 g_return_val_if_fail (G_IS_OBJECT_CLASS (class), NULL);
244 g_return_val_if_fail (param_name != NULL, NULL);
246 return g_param_spec_hash_table_lookup (param_spec_hash_table,
248 G_OBJECT_CLASS_TYPE (class),
253 g_object_do_init (GObject *object)
255 object->ref_count = 1;
256 object->qdata = NULL;
259 if (glib_debug_objects)
261 if (!debug_objects_ht)
262 debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
263 debug_objects_count++;
264 g_hash_table_insert (debug_objects_ht, object, object);
266 #endif /* DEBUG_OBJECTS */
270 g_object_last_unref (GObject *object)
272 g_return_if_fail (object->ref_count > 0);
274 if (object->ref_count == 1) /* may have been re-referenced meanwhile */
275 G_OBJECT_GET_CLASS (object)->shutdown (object);
277 object->ref_count -= 1;
279 if (object->ref_count == 0) /* may have been re-referenced meanwhile */
281 G_OBJECT_GET_CLASS (object)->finalize (object);
282 g_type_free_instance ((GTypeInstance*) object);
287 g_object_do_shutdown (GObject *object)
289 /* this function needs to be always present for unconditional
290 * chaining, we also might add some code here later.
291 * beware though, subclasses may invoke shutdown() arbitrarily.
296 g_object_do_finalize (GObject *object)
298 g_signal_handlers_destroy (object);
299 g_datalist_clear (&object->qdata);
302 if (glib_debug_objects)
304 g_assert (g_hash_table_lookup (debug_objects_ht, object) == object);
306 g_hash_table_remove (debug_objects_ht, object);
307 debug_objects_count--;
309 #endif /* DEBUG_OBJECTS */
313 g_object_new (GType object_type,
314 const gchar *first_param_name,
320 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
322 va_start (var_args, first_param_name);
323 object = g_object_new_valist (object_type, first_param_name, var_args);
330 g_object_new_valist (GType object_type,
331 const gchar *first_param_name,
336 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
338 object = (GObject*) g_type_create_instance (object_type);
339 if (first_param_name)
340 g_object_set_valist (object, first_param_name, var_args);
346 g_object_do_dispatch_param_changed (GObject *object,
349 /* g_message ("NOTIFICATION: parameter `%s' changed on object `%s'",
351 G_OBJECT_TYPE_NAME (object));*/
355 notify_param_changed_handler (gpointer data)
361 /* FIXME: need GDK_THREADS lock */
363 object = G_OBJECT (data);
364 class = G_OBJECT_GET_CLASS (object);
365 slist = g_datalist_id_get_data (&object->qdata, quark_param_changed_queue);
367 /* a reference count is still being held */
369 for (; slist; slist = slist->next)
372 GParamSpec *pspec = slist->data;
375 class->dispatch_param_changed (object, pspec);
378 g_datalist_id_set_data (&object->qdata, quark_param_changed_queue, NULL);
384 g_object_do_queue_param_changed (GObject *object,
387 GSList *slist, *last = NULL;
389 /* if this is a recursive call on this object (i.e. pspecs are queued
390 * for notification, while param_changed notification is currently in
391 * progress), we simply add them to the queue that is currently being
392 * dispatched. otherwise, we later dispatch parameter changed notification
393 * asyncronously from an idle handler untill the queue is completely empty.
396 slist = g_datalist_id_get_data (&object->qdata, quark_param_changed_queue);
397 for (; slist; last = slist, slist = last->next)
398 if (slist->data == pspec)
403 g_object_ref (object);
404 g_idle_add_full (G_NOTIFY_PRIORITY,
405 notify_param_changed_handler,
407 (GDestroyNotify) g_object_unref);
408 g_object_set_qdata_full (object,
409 quark_param_changed_queue,
410 g_slist_prepend (NULL, pspec),
411 (GDestroyNotify) g_slist_free);
414 last->next = g_slist_prepend (NULL, pspec);
418 object_get_param (GObject *object,
421 const gchar *trailer)
425 g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), pspec->owner_type)); /* paranoid */
427 class = g_type_class_peek (pspec->owner_type);
429 class->get_param (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec, trailer);
433 object_set_param (GObject *object,
436 const gchar *trailer)
440 g_return_if_fail (g_type_is_a (G_OBJECT_TYPE (object), pspec->owner_type)); /* paranoid */
442 class = g_type_class_peek (pspec->owner_type);
444 class->set_param (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec, trailer);
446 class->queue_param_changed (object, pspec);
450 g_object_set_valist (GObject *object,
451 const gchar *first_param_name,
456 g_return_if_fail (G_IS_OBJECT (object));
458 g_object_ref (object);
460 name = first_param_name;
464 const gchar *trailer = NULL;
465 GValue value = { 0, };
469 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
471 G_OBJECT_TYPE (object),
476 g_warning ("%s: object class `%s' has no parameter named `%s'",
478 G_OBJECT_TYPE_NAME (object),
482 if (!(pspec->flags & G_PARAM_WRITABLE))
484 g_warning ("%s: parameter `%s' of object class `%s' is not writable",
487 G_OBJECT_TYPE_NAME (object));
491 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
493 G_VALUE_COLLECT (&value, var_args, &error);
496 g_warning ("%s: %s", G_STRLOC, error);
499 /* we purposely leak the value here, it might not be
500 * in a sane state if an error condition occoured
505 object_set_param (object, &value, pspec, trailer);
507 g_value_unset (&value);
509 name = va_arg (var_args, gchar*);
512 g_object_unref (object);
516 g_object_get_valist (GObject *object,
517 const gchar *first_param_name,
522 g_return_if_fail (G_IS_OBJECT (object));
524 g_object_ref (object);
526 name = first_param_name;
530 const gchar *trailer = NULL;
531 GValue value = { 0, };
535 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
537 G_OBJECT_TYPE (object),
542 g_warning ("%s: object class `%s' has no parameter named `%s'",
544 G_OBJECT_TYPE_NAME (object),
548 if (!(pspec->flags & G_PARAM_READABLE))
550 g_warning ("%s: parameter `%s' of object class `%s' is not readable",
553 G_OBJECT_TYPE_NAME (object));
557 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
559 object_get_param (object, &value, pspec, trailer);
561 G_VALUE_LCOPY (&value, var_args, &error);
564 g_warning ("%s: %s", G_STRLOC, error);
567 /* we purposely leak the value here, it might not be
568 * in a sane state if an error condition occoured
573 g_value_unset (&value);
575 name = va_arg (var_args, gchar*);
578 g_object_unref (object);
582 g_object_set (GObject *object,
583 const gchar *first_param_name,
588 g_return_if_fail (G_IS_OBJECT (object));
590 va_start (var_args, first_param_name);
591 g_object_set_valist (object, first_param_name, var_args);
596 g_object_get (GObject *object,
597 const gchar *first_param_name,
602 g_return_if_fail (G_IS_OBJECT (object));
604 va_start (var_args, first_param_name);
605 g_object_get_valist (object, first_param_name, var_args);
610 g_object_set_param (GObject *object,
611 const gchar *param_name,
615 const gchar *trailer;
617 g_return_if_fail (G_IS_OBJECT (object));
618 g_return_if_fail (param_name != NULL);
619 g_return_if_fail (G_IS_VALUE (value));
621 g_object_ref (object);
623 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
625 G_OBJECT_TYPE (object),
629 g_warning ("%s: object class `%s' has no parameter named `%s'",
631 G_OBJECT_TYPE_NAME (object),
635 GValue tmp_value = { 0, };
637 /* provide a copy to work from and convert if necessary */
638 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
640 if (!g_value_convert (value, &tmp_value) ||
641 g_param_value_validate (pspec, &tmp_value))
642 g_warning ("%s: cannot convert `%s' value to parameter `%s' value of type `%s'",
644 G_VALUE_TYPE_NAME (value),
646 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
648 object_set_param (object, &tmp_value, pspec, trailer);
650 g_value_unset (&tmp_value);
653 g_object_unref (object);
657 g_object_get_param (GObject *object,
658 const gchar *param_name,
662 const gchar *trailer;
664 g_return_if_fail (G_IS_OBJECT (object));
665 g_return_if_fail (param_name != NULL);
666 g_return_if_fail (G_IS_VALUE (value));
668 g_object_ref (object);
670 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
672 G_OBJECT_TYPE (object),
676 g_warning ("%s: object class `%s' has no parameter named `%s'",
678 G_OBJECT_TYPE_NAME (object),
682 GValue tmp_value = { 0, };
684 /* provide a copy to work from and later convert if necessary, so
685 * _get_param() implementations need *not* care about freeing values
686 * that might be already set in the parameter to get.
687 * (though, at this point, GValue should exclusively be modified
688 * through the accessor functions anyways)
690 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
692 if (!g_value_types_exchangable (G_VALUE_TYPE (value), G_PARAM_SPEC_VALUE_TYPE (pspec)))
693 g_warning ("%s: can't retrive parameter `%s' value of type `%s' as value of type `%s'",
696 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
697 G_VALUE_TYPE_NAME (value));
700 object_get_param (object, &tmp_value, pspec, trailer);
701 g_value_convert (&tmp_value, value);
702 /* g_value_validate (value, pspec); */
705 g_value_unset (&tmp_value);
708 g_object_unref (object);
712 g_object_queue_param_changed (GObject *object,
713 const gchar *param_name)
717 g_return_if_fail (G_IS_OBJECT (object));
718 g_return_if_fail (param_name != NULL);
720 pspec = g_param_spec_hash_table_lookup (param_spec_hash_table,
722 G_OBJECT_TYPE (object),
725 g_warning ("%s: object class `%s' has no parameter named `%s'",
727 G_OBJECT_TYPE_NAME (object),
730 G_OBJECT_GET_CLASS (object)->queue_param_changed (object, pspec);
734 g_object_ref (GObject *object)
736 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
737 g_return_val_if_fail (object->ref_count > 0, NULL);
739 object->ref_count += 1;
745 g_object_unref (GObject *object)
747 g_return_if_fail (G_IS_OBJECT (object));
748 g_return_if_fail (object->ref_count > 0);
750 if (object->ref_count > 1)
751 object->ref_count -= 1;
753 g_object_last_unref (object);
757 g_object_get_qdata (GObject *object,
760 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
762 return quark ? g_datalist_id_get_data (&object->qdata, quark) : NULL;
766 g_object_set_qdata (GObject *object,
770 g_return_if_fail (G_IS_OBJECT (object));
771 g_return_if_fail (quark > 0);
773 g_datalist_id_set_data (&object->qdata, quark, data);
777 g_object_set_qdata_full (GObject *object,
780 GDestroyNotify destroy)
782 g_return_if_fail (G_IS_OBJECT (object));
783 g_return_if_fail (quark > 0);
785 g_datalist_id_set_data_full (&object->qdata, quark, data, data ? destroy : NULL);
789 g_object_steal_qdata (GObject *object,
792 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
793 g_return_val_if_fail (quark > 0, NULL);
795 return g_datalist_id_remove_no_notify (&object->qdata, quark);
799 g_object_get_data (GObject *object,
802 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
803 g_return_val_if_fail (key != NULL, NULL);
805 return g_object_get_qdata (object,
806 g_quark_try_string (key));
810 g_object_set_data (GObject *object,
814 g_return_if_fail (G_IS_OBJECT (object));
815 g_return_if_fail (key != NULL);
817 g_object_set_qdata (object,
818 g_quark_from_string (key),
823 g_object_set_data_full (GObject *object,
826 GDestroyNotify destroy)
828 g_return_if_fail (G_IS_OBJECT (object));
829 g_return_if_fail (key != NULL);
831 g_object_set_qdata_full (object,
832 g_quark_from_string (key),
838 g_object_steal_data (GObject *object,
841 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
842 g_return_val_if_fail (key != NULL, NULL);
844 return g_object_steal_qdata (object,
845 g_quark_try_string (key));
849 g_value_object_init (GValue *value)
851 value->data[0].v_pointer = NULL;
855 g_value_object_free_value (GValue *value)
857 if (value->data[0].v_pointer)
858 g_object_unref (value->data[0].v_pointer);
862 g_value_object_copy_value (const GValue *src_value,
865 if (src_value->data[0].v_pointer)
866 dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
868 dest_value->data[0].v_pointer = NULL;
872 g_value_object_peek_pointer (const GValue *value)
874 return value->data[0].v_pointer;
878 g_value_object_collect_value (GValue *value,
881 GTypeCValue *collect_value)
883 if (collect_value->v_pointer)
885 GObject *object = collect_value->v_pointer;
887 if (object->g_type_instance.g_class == NULL)
888 return g_strconcat ("invalid unclassed object pointer for value type `",
889 G_VALUE_TYPE_NAME (value),
892 else if (!g_type_is_a (G_OBJECT_TYPE (object), G_VALUE_TYPE (value)))
893 return g_strconcat ("invalid object type `",
894 G_OBJECT_TYPE_NAME (object),
895 "' for value type `",
896 G_VALUE_TYPE_NAME (value),
899 value->data[0].v_pointer = g_object_ref (object);
902 value->data[0].v_pointer = NULL;
909 g_value_object_lcopy_value (const GValue *value,
912 GTypeCValue *collect_value)
914 GObject **object_p = collect_value->v_pointer;
917 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
919 *object_p = value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
926 g_value_set_object (GValue *value,
929 g_return_if_fail (G_IS_VALUE_OBJECT (value));
931 g_return_if_fail (G_IS_OBJECT (v_object));
933 if (value->data[0].v_pointer)
934 g_object_unref (value->data[0].v_pointer);
935 value->data[0].v_pointer = v_object;
936 if (value->data[0].v_pointer)
937 g_object_ref (value->data[0].v_pointer);
941 g_value_get_object (const GValue *value)
943 g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL);
945 return value->data[0].v_pointer;
949 g_value_dup_object (const GValue *value)
951 g_return_val_if_fail (G_IS_VALUE_OBJECT (value), NULL);
953 return value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
959 GClosure *closures[1]; /* flexible array */
963 object_remove_closure (gpointer data,
966 GObject *object = data;
967 CArray *carray = g_object_get_qdata (object, quark_closure_array);
970 for (i = 0; i < carray->n_closures; i++)
971 if (carray->closures[i] == closure)
973 carray->n_closures--;
974 if (i < carray->n_closures)
975 carray->closures[i] = carray->closures[carray->n_closures];
978 g_assert_not_reached ();
982 destroy_closure_array (gpointer data)
984 CArray *carray = data;
985 GObject *object = carray->object;
986 guint i, n = carray->n_closures;
988 for (i = 0; i < n; i++)
990 GClosure *closure = carray->closures[i];
992 /* removing object_remove_closure() upfront is probably faster than
993 * letting it fiddle with quark_closure_array which is empty anyways
995 g_closure_remove_inotify (closure, object, object_remove_closure);
996 g_closure_invalidate (closure);
1002 g_object_watch_closure (GObject *object,
1007 g_return_if_fail (G_IS_OBJECT (object));
1008 g_return_if_fail (closure != NULL);
1009 g_return_if_fail (closure->is_invalid == FALSE);
1010 g_return_if_fail (closure->in_marshal == FALSE);
1011 g_return_if_fail (object->ref_count > 0); /* this doesn't work on finalizing objects */
1013 g_closure_add_inotify (closure, object, object_remove_closure);
1014 g_closure_add_marshal_guards (closure,
1015 object, (GClosureNotify) g_object_ref,
1016 object, (GClosureNotify) g_object_unref);
1017 carray = g_object_steal_qdata (object, quark_closure_array);
1020 carray = g_renew (CArray, NULL, 1);
1021 carray->object = object;
1022 carray->n_closures = 1;
1023 carray->closures[0] = closure;
1024 g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
1028 guint i = carray->n_closures++;
1030 carray = g_realloc (carray, sizeof (*carray) + sizeof (carray->closures[0]) * i);
1031 carray->closures[i] = closure;
1032 g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
1037 g_closure_new_object (guint sizeof_closure,
1042 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1043 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1045 closure = g_closure_new_simple (sizeof_closure, object);
1046 g_object_watch_closure (object, closure);
1052 g_cclosure_new_object (GCallback callback_func,
1055 GObject *object = _object;
1058 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1059 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1060 g_return_val_if_fail (callback_func != NULL, NULL);
1062 closure = g_cclosure_new (callback_func, object, NULL);
1063 g_object_watch_closure (object, closure);
1069 g_cclosure_new_object_swap (GCallback callback_func,
1072 GObject *object = _object;
1075 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1076 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1077 g_return_val_if_fail (callback_func != NULL, NULL);
1079 closure = g_cclosure_new_swap (callback_func, object, NULL);
1080 g_object_watch_closure (object, closure);