1 /* GObject - GLib Type, Object, Parameter and Signal Library
2 * Copyright (C) 1998-1999, 2000-2001 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.
25 #include "gvaluecollector.h"
27 #include "gparamspecs.h"
28 #include "gvaluetypes.h"
29 #include "gobjectnotifyqueue.c"
34 #define PREALLOC_CPARAMS (8)
38 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
39 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
49 /* --- properties --- */
55 /* --- prototypes --- */
56 static void g_object_base_class_init (GObjectClass *class);
57 static void g_object_base_class_finalize (GObjectClass *class);
58 static void g_object_do_class_init (GObjectClass *class);
59 static void g_object_init (GObject *object);
60 static GObject* g_object_constructor (GType type,
61 guint n_construct_properties,
62 GObjectConstructParam *construct_params);
63 static void g_object_last_unref (GObject *object);
64 static void g_object_real_dispose (GObject *object);
65 static void g_object_finalize (GObject *object);
66 static void g_object_do_set_property (GObject *object,
70 static void g_object_do_get_property (GObject *object,
74 static void g_value_object_init (GValue *value);
75 static void g_value_object_free_value (GValue *value);
76 static void g_value_object_copy_value (const GValue *src_value,
78 static void g_value_object_transform_value (const GValue *src_value,
80 static gpointer g_value_object_peek_pointer (const GValue *value);
81 static gchar* g_value_object_collect_value (GValue *value,
82 guint n_collect_values,
83 GTypeCValue *collect_values,
85 static gchar* g_value_object_lcopy_value (const GValue *value,
86 guint n_collect_values,
87 GTypeCValue *collect_values,
89 static void g_object_dispatch_properties_changed (GObject *object,
92 static inline void object_get_property (GObject *object,
95 static inline void object_set_property (GObject *object,
98 GObjectNotifyQueue *nqueue);
100 static void object_interface_check_properties (gpointer func_data,
104 /* --- variables --- */
105 static GQuark quark_closure_array = 0;
106 static GQuark quark_weak_refs = 0;
107 static GParamSpecPool *pspec_pool = NULL;
108 static GObjectNotifyContext property_notify_context = { 0, };
109 static gulong gobject_signals[LAST_SIGNAL] = { 0, };
112 /* --- functions --- */
113 #ifdef G_ENABLE_DEBUG
114 #define IF_DEBUG(debug_type) if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type)
115 G_LOCK_DEFINE_STATIC (debug_objects);
116 static volatile GObject *g_trap_object_ref = NULL;
117 static guint debug_objects_count = 0;
118 static GHashTable *debug_objects_ht = NULL;
120 debug_objects_foreach (gpointer key,
124 GObject *object = value;
126 g_message ("[%p] stale %s\tref_count=%u",
128 G_OBJECT_TYPE_NAME (object),
132 debug_objects_atexit (void)
136 G_LOCK (debug_objects);
137 g_message ("stale GObjects: %u", debug_objects_count);
138 g_hash_table_foreach (debug_objects_ht, debug_objects_foreach, NULL);
139 G_UNLOCK (debug_objects);
142 #endif /* G_ENABLE_DEBUG */
145 g_object_type_init (void) /* sync with gtype.c */
147 static gboolean initialized = FALSE;
148 static const GTypeFundamentalInfo finfo = {
149 G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE,
151 static GTypeInfo info = {
152 sizeof (GObjectClass),
153 (GBaseInitFunc) g_object_base_class_init,
154 (GBaseFinalizeFunc) g_object_base_class_finalize,
155 (GClassInitFunc) g_object_do_class_init,
156 NULL /* class_destroy */,
157 NULL /* class_data */,
160 (GInstanceInitFunc) g_object_init,
161 NULL, /* value_table */
163 static const GTypeValueTable value_table = {
164 g_value_object_init, /* value_init */
165 g_value_object_free_value, /* value_free */
166 g_value_object_copy_value, /* value_copy */
167 g_value_object_peek_pointer, /* value_peek_pointer */
168 "p", /* collect_format */
169 g_value_object_collect_value, /* collect_value */
170 "p", /* lcopy_format */
171 g_value_object_lcopy_value, /* lcopy_value */
175 g_return_if_fail (initialized == FALSE);
180 info.value_table = &value_table;
181 type = g_type_register_fundamental (G_TYPE_OBJECT, "GObject", &info, &finfo, 0);
182 g_assert (type == G_TYPE_OBJECT);
183 g_value_register_transform_func (G_TYPE_OBJECT, G_TYPE_OBJECT, g_value_object_transform_value);
185 #ifdef G_ENABLE_DEBUG
188 debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
189 g_atexit (debug_objects_atexit);
191 #endif /* G_ENABLE_DEBUG */
195 g_object_base_class_init (GObjectClass *class)
197 GObjectClass *pclass = g_type_class_peek_parent (class);
199 /* reset instance specific fields and methods that don't get inherited */
200 class->construct_properties = pclass ? g_slist_copy (pclass->construct_properties) : NULL;
201 class->get_property = NULL;
202 class->set_property = NULL;
206 g_object_base_class_finalize (GObjectClass *class)
210 _g_signals_destroy (G_OBJECT_CLASS_TYPE (class));
212 g_slist_free (class->construct_properties);
213 class->construct_properties = NULL;
214 list = g_param_spec_pool_list_owned (pspec_pool, G_OBJECT_CLASS_TYPE (class));
215 for (node = list; node; node = node->next)
217 GParamSpec *pspec = node->data;
219 g_param_spec_pool_remove (pspec_pool, pspec);
220 PARAM_SPEC_SET_PARAM_ID (pspec, 0);
221 g_param_spec_unref (pspec);
227 g_object_notify_dispatcher (GObject *object,
231 G_OBJECT_GET_CLASS (object)->dispatch_properties_changed (object, n_pspecs, pspecs);
235 g_object_do_class_init (GObjectClass *class)
237 /* read the comment about typedef struct CArray; on why not to change this quark */
238 quark_closure_array = g_quark_from_static_string ("GObject-closure-array");
240 quark_weak_refs = g_quark_from_static_string ("GObject-weak-references");
241 pspec_pool = g_param_spec_pool_new (TRUE);
242 property_notify_context.quark_notify_queue = g_quark_from_static_string ("GObject-notify-queue");
243 property_notify_context.dispatcher = g_object_notify_dispatcher;
245 class->constructor = g_object_constructor;
246 class->set_property = g_object_do_set_property;
247 class->get_property = g_object_do_get_property;
248 class->dispose = g_object_real_dispose;
249 class->finalize = g_object_finalize;
250 class->dispatch_properties_changed = g_object_dispatch_properties_changed;
251 class->notify = NULL;
253 gobject_signals[NOTIFY] =
254 g_signal_new ("notify",
255 G_TYPE_FROM_CLASS (class),
256 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
257 G_STRUCT_OFFSET (GObjectClass, notify),
259 g_cclosure_marshal_VOID__PARAM,
263 /* Install a check function that we'll use to verify that classes that
264 * implement an interface implement all properties for that interface
266 g_type_add_interface_check (NULL, object_interface_check_properties);
270 install_property_internal (GType g_type,
274 if (g_param_spec_pool_lookup (pspec_pool, pspec->name, g_type, FALSE))
276 g_warning ("When installing property: type `%s' already has a property named `%s'",
277 g_type_name (g_type),
282 g_param_spec_ref (pspec);
283 g_param_spec_sink (pspec);
284 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
285 g_param_spec_pool_insert (pspec_pool, pspec, g_type);
289 g_object_class_install_property (GObjectClass *class,
293 g_return_if_fail (G_IS_OBJECT_CLASS (class));
294 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
295 if (pspec->flags & G_PARAM_WRITABLE)
296 g_return_if_fail (class->set_property != NULL);
297 if (pspec->flags & G_PARAM_READABLE)
298 g_return_if_fail (class->get_property != NULL);
299 g_return_if_fail (property_id > 0);
300 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
301 if (pspec->flags & G_PARAM_CONSTRUCT)
302 g_return_if_fail ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);
303 if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
304 g_return_if_fail (pspec->flags & G_PARAM_WRITABLE);
306 install_property_internal (G_OBJECT_CLASS_TYPE (class), property_id, pspec);
308 if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
309 class->construct_properties = g_slist_prepend (class->construct_properties, pspec);
311 /* for property overrides of construct poperties, we have to get rid
312 * of the overidden inherited construct property
314 pspec = g_param_spec_pool_lookup (pspec_pool, pspec->name, g_type_parent (G_OBJECT_CLASS_TYPE (class)), TRUE);
315 if (pspec && pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
316 class->construct_properties = g_slist_remove (class->construct_properties, pspec);
320 g_object_interface_install_property (gpointer g_iface,
323 GTypeInterface *iface_class = g_iface;
325 g_return_if_fail (G_TYPE_IS_INTERFACE (iface_class->g_type));
326 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
327 g_return_if_fail (!G_IS_PARAM_SPEC_OVERRIDE (pspec)); /* paranoid */
328 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
330 install_property_internal (iface_class->g_type, 0, pspec);
334 g_object_class_find_property (GObjectClass *class,
335 const gchar *property_name)
338 GParamSpec *redirect;
340 g_return_val_if_fail (G_IS_OBJECT_CLASS (class), NULL);
341 g_return_val_if_fail (property_name != NULL, NULL);
343 pspec = g_param_spec_pool_lookup (pspec_pool,
345 G_OBJECT_CLASS_TYPE (class),
349 redirect = g_param_spec_get_redirect_target (pspec);
360 g_object_interface_find_property (gpointer g_iface,
361 const gchar *property_name)
363 GTypeInterface *iface_class = g_iface;
365 g_return_val_if_fail (G_TYPE_IS_INTERFACE (iface_class->g_type), NULL);
366 g_return_val_if_fail (property_name != NULL, NULL);
368 return g_param_spec_pool_lookup (pspec_pool,
375 g_object_class_override_property (GObjectClass *oclass,
379 GParamSpec *overridden = NULL;
383 g_return_if_fail (G_IS_OBJECT_CLASS (oclass));
384 g_return_if_fail (property_id > 0);
385 g_return_if_fail (name != NULL);
387 /* Find the overridden property; first check parent types
389 parent_type = g_type_parent (G_OBJECT_CLASS_TYPE (oclass));
390 if (parent_type != G_TYPE_NONE)
391 overridden = g_param_spec_pool_lookup (pspec_pool,
400 /* Now check interfaces
402 ifaces = g_type_interfaces (G_OBJECT_CLASS_TYPE (oclass), &n_ifaces);
403 while (n_ifaces-- && !overridden)
405 overridden = g_param_spec_pool_lookup (pspec_pool,
416 g_warning ("%s: Can't find property to override for '%s::%s'",
417 G_STRLOC, G_OBJECT_CLASS_NAME (oclass), name);
421 new = g_param_spec_override (name, overridden);
422 g_object_class_install_property (oclass, property_id, new);
425 GParamSpec** /* free result */
426 g_object_class_list_properties (GObjectClass *class,
427 guint *n_properties_p)
432 g_return_val_if_fail (G_IS_OBJECT_CLASS (class), NULL);
434 pspecs = g_param_spec_pool_list (pspec_pool,
435 G_OBJECT_CLASS_TYPE (class),
443 GParamSpec** /* free result */
444 g_object_interface_list_properties (gpointer g_iface,
445 guint *n_properties_p)
447 GTypeInterface *iface_class = g_iface;
451 g_return_val_if_fail (G_TYPE_IS_INTERFACE (iface_class->g_type), NULL);
453 pspecs = g_param_spec_pool_list (pspec_pool,
463 g_object_init (GObject *object)
465 object->ref_count = 1;
466 g_datalist_init (&object->qdata);
468 /* freeze object's notification queue, g_object_newv() preserves pairedness */
469 g_object_notify_queue_freeze (object, &property_notify_context);
471 #ifdef G_ENABLE_DEBUG
474 G_LOCK (debug_objects);
475 debug_objects_count++;
476 g_hash_table_insert (debug_objects_ht, object, object);
477 G_UNLOCK (debug_objects);
479 #endif /* G_ENABLE_DEBUG */
483 g_object_do_set_property (GObject *object,
491 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
497 g_object_do_get_property (GObject *object,
505 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
511 g_object_real_dispose (GObject *object)
515 g_signal_handlers_destroy (object);
516 g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL);
518 /* yes, temporarily altering the ref_count is hackish, but that
519 * enforces people not jerking around with weak_ref notifiers
521 ref_count = object->ref_count;
522 object->ref_count = 0;
523 g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
524 object->ref_count = ref_count;
528 g_object_finalize (GObject *object)
530 g_datalist_clear (&object->qdata);
532 #ifdef G_ENABLE_DEBUG
535 G_LOCK (debug_objects);
536 g_assert (g_hash_table_lookup (debug_objects_ht, object) == object);
537 g_hash_table_remove (debug_objects_ht, object);
538 debug_objects_count--;
539 G_UNLOCK (debug_objects);
541 #endif /* G_ENABLE_DEBUG */
545 g_object_last_unref (GObject *object)
547 g_return_if_fail (object->ref_count > 0);
549 if (object->ref_count == 1) /* may have been re-referenced meanwhile */
550 G_OBJECT_GET_CLASS (object)->dispose (object);
552 #ifdef G_ENABLE_DEBUG
553 if (g_trap_object_ref == object)
555 #endif /* G_ENABLE_DEBUG */
557 object->ref_count -= 1;
559 if (object->ref_count == 0) /* may have been re-referenced meanwhile */
561 g_signal_handlers_destroy (object);
562 g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
563 G_OBJECT_GET_CLASS (object)->finalize (object);
564 #ifdef G_ENABLE_DEBUG
567 /* catch objects not chaining finalize handlers */
568 G_LOCK (debug_objects);
569 g_assert (g_hash_table_lookup (debug_objects_ht, object) == NULL);
570 G_UNLOCK (debug_objects);
572 #endif /* G_ENABLE_DEBUG */
573 g_type_free_instance ((GTypeInstance*) object);
578 g_object_dispatch_properties_changed (GObject *object,
584 for (i = 0; i < n_pspecs; i++)
585 g_signal_emit (object, gobject_signals[NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
589 g_object_run_dispose (GObject *object)
591 g_return_if_fail (G_IS_OBJECT (object));
592 g_return_if_fail (object->ref_count > 0);
594 g_object_ref (object);
595 G_OBJECT_GET_CLASS (object)->dispose (object);
596 g_object_unref (object);
600 g_object_freeze_notify (GObject *object)
602 g_return_if_fail (G_IS_OBJECT (object));
603 if (!object->ref_count)
606 g_object_ref (object);
607 g_object_notify_queue_freeze (object, &property_notify_context);
608 g_object_unref (object);
612 g_object_notify (GObject *object,
613 const gchar *property_name)
617 g_return_if_fail (G_IS_OBJECT (object));
618 g_return_if_fail (property_name != NULL);
619 if (!object->ref_count)
622 g_object_ref (object);
623 /* We don't need to get the redirect target
624 * (by, e.g. calling g_object_class_find_property())
625 * because g_object_notify_queue_add() does that
627 pspec = g_param_spec_pool_lookup (pspec_pool,
629 G_OBJECT_TYPE (object),
633 g_warning ("%s: object class `%s' has no property named `%s'",
635 G_OBJECT_TYPE_NAME (object),
639 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
641 g_object_notify_queue_add (object, nqueue, pspec);
642 g_object_notify_queue_thaw (object, nqueue);
644 g_object_unref (object);
648 g_object_thaw_notify (GObject *object)
650 GObjectNotifyQueue *nqueue;
652 g_return_if_fail (G_IS_OBJECT (object));
653 if (!object->ref_count)
656 g_object_ref (object);
657 nqueue = g_object_notify_queue_from_object (object, &property_notify_context);
658 if (!nqueue || !nqueue->freeze_count)
659 g_warning (G_STRLOC ": property-changed notification for %s(%p) is not frozen",
660 G_OBJECT_TYPE_NAME (object), object);
662 g_object_notify_queue_thaw (object, nqueue);
663 g_object_unref (object);
667 object_get_property (GObject *object,
671 GObjectClass *class = g_type_class_peek (pspec->owner_type);
672 guint param_id = PARAM_SPEC_PARAM_ID (pspec);
673 GParamSpec *redirect;
675 redirect = g_param_spec_get_redirect_target (pspec);
679 class->get_property (object, param_id, value, pspec);
683 object_set_property (GObject *object,
686 GObjectNotifyQueue *nqueue)
688 GValue tmp_value = { 0, };
689 GObjectClass *class = g_type_class_peek (pspec->owner_type);
690 guint param_id = PARAM_SPEC_PARAM_ID (pspec);
691 GParamSpec *redirect;
693 redirect = g_param_spec_get_redirect_target (pspec);
697 /* provide a copy to work from, convert (if necessary) and validate */
698 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
699 if (!g_value_transform (value, &tmp_value))
700 g_warning ("unable to set property `%s' of type `%s' from value of type `%s'",
702 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
703 G_VALUE_TYPE_NAME (value));
704 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
706 gchar *contents = g_strdup_value_contents (value);
708 g_warning ("value \"%s\" of type `%s' is invalid or out of range for property `%s' of type `%s'",
710 G_VALUE_TYPE_NAME (value),
712 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
717 class->set_property (object, param_id, &tmp_value, pspec);
718 g_object_notify_queue_add (object, nqueue, pspec);
720 g_value_unset (&tmp_value);
724 object_interface_check_properties (gpointer func_data,
727 GTypeInterface *iface_class = g_iface;
728 GObjectClass *class = g_type_class_peek (iface_class->g_instance_type);
729 GType iface_type = iface_class->g_type;
733 if (!G_IS_OBJECT_CLASS (class))
736 pspecs = g_param_spec_pool_list (pspec_pool, iface_type, &n);
740 GParamSpec *class_pspec = g_param_spec_pool_lookup (pspec_pool,
742 G_OBJECT_CLASS_TYPE (class),
747 g_critical ("Object class %s doesn't implement property "
748 "'%s' from interface '%s'",
749 g_type_name (G_OBJECT_CLASS_TYPE (class)),
751 g_type_name (iface_type));
756 /* The implementation paramspec must have a less restrictive
757 * type than the interface parameter spec for set() and a
758 * more restrictive type for get(). We just require equality,
759 * rather than doing something more complicated checking
760 * the READABLE and WRITABLE flags. We also simplify here
761 * by only checking the value type, not the G_PARAM_SPEC_TYPE.
764 !g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (pspecs[n]),
765 G_PARAM_SPEC_VALUE_TYPE (class_pspec)))
767 g_critical ("Property '%s' on class '%s' has type '%s' "
768 "which is different from the type '%s', "
769 "of the property on interface '%s'\n",
771 g_type_name (G_OBJECT_CLASS_TYPE (class)),
772 g_type_name (G_PARAM_SPEC_VALUE_TYPE (class_pspec)),
773 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspecs[n])),
774 g_type_name (iface_type));
777 #define SUBSET(a,b,mask) (((a) & ~(b) & (mask)) == 0)
779 /* CONSTRUCT and CONSTRUCT_ONLY add restrictions.
780 * READABLE and WRITABLE remove restrictions. The implementation
781 * paramspec must have less restrictive flags.
784 (!SUBSET (class_pspec->flags,
786 G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY) ||
787 !SUBSET (pspecs[n]->flags,
789 G_PARAM_READABLE | G_PARAM_WRITABLE)))
791 g_critical ("Flags for property '%s' on class '%s' "
792 "are not compatible with the property on"
795 g_type_name (G_OBJECT_CLASS_TYPE (class)),
796 g_type_name (iface_type));
805 g_object_new (GType object_type,
806 const gchar *first_property_name,
812 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
814 va_start (var_args, first_property_name);
815 object = g_object_new_valist (object_type, first_property_name, var_args);
822 g_object_newv (GType object_type,
824 GParameter *parameters)
826 GObjectConstructParam *cparams, *oparams;
827 GObjectNotifyQueue *nqueue;
831 guint n_total_cparams = 0, n_cparams = 0, n_oparams = 0, n_cvalues;
836 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
838 class = g_type_class_ref (object_type);
839 for (slist = class->construct_properties; slist; slist = slist->next)
841 clist = g_list_prepend (clist, slist->data);
842 n_total_cparams += 1;
845 /* collect parameters, sort into construction and normal ones */
846 oparams = g_new (GObjectConstructParam, n_parameters);
847 cparams = g_new (GObjectConstructParam, n_total_cparams);
848 for (i = 0; i < n_parameters; i++)
850 GValue *value = ¶meters[i].value;
851 GParamSpec *pspec = g_param_spec_pool_lookup (pspec_pool,
857 g_warning ("%s: object class `%s' has no property named `%s'",
859 g_type_name (object_type),
863 if (!(pspec->flags & G_PARAM_WRITABLE))
865 g_warning ("%s: property `%s' of object class `%s' is not writable",
868 g_type_name (object_type));
871 if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
873 GList *list = g_list_find (clist, pspec);
877 g_warning (G_STRLOC ": construct property \"%s\" for object `%s' can't be set twice",
878 pspec->name, g_type_name (object_type));
881 cparams[n_cparams].pspec = pspec;
882 cparams[n_cparams].value = value;
887 list->prev->next = list->next;
889 list->next->prev = list->prev;
890 g_list_free_1 (list);
894 oparams[n_oparams].pspec = pspec;
895 oparams[n_oparams].value = value;
900 /* set remaining construction properties to default values */
901 n_cvalues = n_total_cparams - n_cparams;
902 cvalues = g_new (GValue, n_cvalues);
905 GList *tmp = clist->next;
906 GParamSpec *pspec = clist->data;
907 GValue *value = cvalues + n_total_cparams - n_cparams - 1;
910 g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec));
911 g_param_value_set_default (pspec, value);
913 cparams[n_cparams].pspec = pspec;
914 cparams[n_cparams].value = value;
917 g_list_free_1 (clist);
921 /* construct object from construction parameters */
922 object = class->constructor (object_type, n_total_cparams, cparams);
924 /* free construction values */
927 g_value_unset (cvalues + n_cvalues);
930 /* release g_object_init() notification queue freeze_count */
931 nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
932 g_object_notify_queue_thaw (object, nqueue);
934 /* set remaining properties */
935 for (i = 0; i < n_oparams; i++)
936 object_set_property (object, oparams[i].pspec, oparams[i].value, nqueue);
939 g_type_class_unref (class);
941 /* release our own freeze count and handle notifications */
942 g_object_notify_queue_thaw (object, nqueue);
948 g_object_new_valist (GType object_type,
949 const gchar *first_property_name,
956 guint n_params = 0, n_alloced_params = 16;
958 g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
960 if (!first_property_name)
961 return g_object_newv (object_type, 0, NULL);
963 class = g_type_class_ref (object_type);
965 params = g_new (GParameter, n_alloced_params);
966 name = first_property_name;
970 GParamSpec *pspec = g_param_spec_pool_lookup (pspec_pool,
976 g_warning ("%s: object class `%s' has no property named `%s'",
978 g_type_name (object_type),
982 if (n_params >= n_alloced_params)
984 n_alloced_params += 16;
985 params = g_renew (GParameter, params, n_alloced_params);
987 params[n_params].name = name;
988 params[n_params].value.g_type = 0;
989 g_value_init (¶ms[n_params].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
990 G_VALUE_COLLECT (¶ms[n_params].value, var_args, 0, &error);
993 g_warning ("%s: %s", G_STRLOC, error);
996 /* we purposely leak the value here, it might not be
997 * in a sane state if an error condition occoured
1002 name = va_arg (var_args, gchar*);
1005 object = g_object_newv (object_type, n_params, params);
1008 g_value_unset (¶ms[n_params].value);
1011 g_type_class_unref (class);
1017 g_object_constructor (GType type,
1018 guint n_construct_properties,
1019 GObjectConstructParam *construct_params)
1024 object = (GObject*) g_type_create_instance (type);
1026 /* set construction parameters */
1027 if (n_construct_properties)
1029 GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
1031 /* set construct properties */
1032 while (n_construct_properties--)
1034 GValue *value = construct_params->value;
1035 GParamSpec *pspec = construct_params->pspec;
1038 object_set_property (object, pspec, value, nqueue);
1040 g_object_notify_queue_thaw (object, nqueue);
1041 /* the notification queue is still frozen from g_object_init(), so
1042 * we don't need to handle it here, g_object_newv() takes
1051 g_object_set_valist (GObject *object,
1052 const gchar *first_property_name,
1055 GObjectNotifyQueue *nqueue;
1058 g_return_if_fail (G_IS_OBJECT (object));
1060 g_object_ref (object);
1061 nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
1063 name = first_property_name;
1066 GValue value = { 0, };
1068 gchar *error = NULL;
1070 pspec = g_param_spec_pool_lookup (pspec_pool,
1072 G_OBJECT_TYPE (object),
1076 g_warning ("%s: object class `%s' has no property named `%s'",
1078 G_OBJECT_TYPE_NAME (object),
1082 if (!(pspec->flags & G_PARAM_WRITABLE))
1084 g_warning ("%s: property `%s' of object class `%s' is not writable",
1087 G_OBJECT_TYPE_NAME (object));
1091 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1093 G_VALUE_COLLECT (&value, var_args, 0, &error);
1096 g_warning ("%s: %s", G_STRLOC, error);
1099 /* we purposely leak the value here, it might not be
1100 * in a sane state if an error condition occoured
1105 object_set_property (object, pspec, &value, nqueue);
1106 g_value_unset (&value);
1108 name = va_arg (var_args, gchar*);
1111 g_object_notify_queue_thaw (object, nqueue);
1112 g_object_unref (object);
1116 g_object_get_valist (GObject *object,
1117 const gchar *first_property_name,
1122 g_return_if_fail (G_IS_OBJECT (object));
1124 g_object_ref (object);
1126 name = first_property_name;
1130 GValue value = { 0, };
1134 pspec = g_param_spec_pool_lookup (pspec_pool,
1136 G_OBJECT_TYPE (object),
1140 g_warning ("%s: object class `%s' has no property named `%s'",
1142 G_OBJECT_TYPE_NAME (object),
1146 if (!(pspec->flags & G_PARAM_READABLE))
1148 g_warning ("%s: property `%s' of object class `%s' is not readable",
1151 G_OBJECT_TYPE_NAME (object));
1155 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1157 object_get_property (object, pspec, &value);
1159 G_VALUE_LCOPY (&value, var_args, 0, &error);
1162 g_warning ("%s: %s", G_STRLOC, error);
1164 g_value_unset (&value);
1168 g_value_unset (&value);
1170 name = va_arg (var_args, gchar*);
1173 g_object_unref (object);
1177 g_object_set (gpointer _object,
1178 const gchar *first_property_name,
1181 GObject *object = _object;
1184 g_return_if_fail (G_IS_OBJECT (object));
1186 va_start (var_args, first_property_name);
1187 g_object_set_valist (object, first_property_name, var_args);
1192 g_object_get (gpointer _object,
1193 const gchar *first_property_name,
1196 GObject *object = _object;
1199 g_return_if_fail (G_IS_OBJECT (object));
1201 va_start (var_args, first_property_name);
1202 g_object_get_valist (object, first_property_name, var_args);
1207 g_object_set_property (GObject *object,
1208 const gchar *property_name,
1209 const GValue *value)
1211 GObjectNotifyQueue *nqueue;
1214 g_return_if_fail (G_IS_OBJECT (object));
1215 g_return_if_fail (property_name != NULL);
1216 g_return_if_fail (G_IS_VALUE (value));
1218 g_object_ref (object);
1219 nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
1221 pspec = g_param_spec_pool_lookup (pspec_pool,
1223 G_OBJECT_TYPE (object),
1226 g_warning ("%s: object class `%s' has no property named `%s'",
1228 G_OBJECT_TYPE_NAME (object),
1231 object_set_property (object, pspec, value, nqueue);
1233 g_object_notify_queue_thaw (object, nqueue);
1234 g_object_unref (object);
1238 g_object_get_property (GObject *object,
1239 const gchar *property_name,
1244 g_return_if_fail (G_IS_OBJECT (object));
1245 g_return_if_fail (property_name != NULL);
1246 g_return_if_fail (G_IS_VALUE (value));
1248 g_object_ref (object);
1250 pspec = g_param_spec_pool_lookup (pspec_pool,
1252 G_OBJECT_TYPE (object),
1255 g_warning ("%s: object class `%s' has no property named `%s'",
1257 G_OBJECT_TYPE_NAME (object),
1261 GValue *prop_value, tmp_value = { 0, };
1263 /* auto-conversion of the callers value type
1265 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
1267 g_value_reset (value);
1270 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
1272 g_warning ("can't retrieve property `%s' of type `%s' as value of type `%s'",
1274 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
1275 G_VALUE_TYPE_NAME (value));
1276 g_object_unref (object);
1281 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
1282 prop_value = &tmp_value;
1284 object_get_property (object, pspec, prop_value);
1285 if (prop_value != value)
1287 g_value_transform (prop_value, value);
1288 g_value_unset (&tmp_value);
1292 g_object_unref (object);
1296 g_object_connect (gpointer _object,
1297 const gchar *signal_spec,
1300 GObject *object = _object;
1303 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1304 g_return_val_if_fail (object->ref_count > 0, object);
1306 va_start (var_args, signal_spec);
1309 GCallback callback = va_arg (var_args, GCallback);
1310 gpointer data = va_arg (var_args, gpointer);
1313 if (strncmp (signal_spec, "signal::", 8) == 0)
1314 sid = g_signal_connect_data (object, signal_spec + 8,
1315 callback, data, NULL,
1317 else if (strncmp (signal_spec, "object_signal::", 15) == 0)
1318 sid = g_signal_connect_object (object, signal_spec + 15,
1321 else if (strncmp (signal_spec, "swapped_signal::", 16) == 0)
1322 sid = g_signal_connect_data (object, signal_spec + 16,
1323 callback, data, NULL,
1325 else if (strncmp (signal_spec, "swapped_object_signal::", 23) == 0)
1326 sid = g_signal_connect_object (object, signal_spec + 23,
1329 else if (strncmp (signal_spec, "signal_after::", 14) == 0)
1330 sid = g_signal_connect_data (object, signal_spec + 14,
1331 callback, data, NULL,
1333 else if (strncmp (signal_spec, "object_signal_after::", 21) == 0)
1334 sid = g_signal_connect_object (object, signal_spec + 21,
1337 else if (strncmp (signal_spec, "swapped_signal_after::", 22) == 0)
1338 sid = g_signal_connect_data (object, signal_spec + 22,
1339 callback, data, NULL,
1340 G_CONNECT_SWAPPED | G_CONNECT_AFTER);
1341 else if (strncmp (signal_spec, "swapped_object_signal_after::", 29) == 0)
1342 sid = g_signal_connect_object (object, signal_spec + 29,
1344 G_CONNECT_SWAPPED | G_CONNECT_AFTER);
1347 g_warning ("%s: invalid signal spec \"%s\"", G_STRLOC, signal_spec);
1350 signal_spec = va_arg (var_args, gchar*);
1358 g_object_disconnect (gpointer _object,
1359 const gchar *signal_spec,
1362 GObject *object = _object;
1365 g_return_if_fail (G_IS_OBJECT (object));
1366 g_return_if_fail (object->ref_count > 0);
1368 va_start (var_args, signal_spec);
1371 GCallback callback = va_arg (var_args, GCallback);
1372 gpointer data = va_arg (var_args, gpointer);
1373 guint sid = 0, detail = 0, mask = 0;
1375 if (strncmp (signal_spec, "any_signal::", 12) == 0)
1378 mask = G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA;
1380 else if (strcmp (signal_spec, "any_signal") == 0)
1383 mask = G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA;
1387 g_warning ("%s: invalid signal spec \"%s\"", G_STRLOC, signal_spec);
1391 if ((mask & G_SIGNAL_MATCH_ID) &&
1392 !g_signal_parse_name (signal_spec, G_OBJECT_TYPE (object), &sid, &detail, FALSE))
1393 g_warning ("%s: invalid signal name \"%s\"", G_STRLOC, signal_spec);
1394 else if (!g_signal_handlers_disconnect_matched (object, mask | (detail ? G_SIGNAL_MATCH_DETAIL : 0),
1396 NULL, (gpointer)callback, data))
1397 g_warning (G_STRLOC ": signal handler %p(%p) is not connected", callback, data);
1398 signal_spec = va_arg (var_args, gchar*);
1409 } weak_refs[1]; /* flexible array */
1413 weak_refs_notify (gpointer data)
1415 WeakRefStack *wstack = data;
1418 for (i = 0; i < wstack->n_weak_refs; i++)
1419 wstack->weak_refs[i].notify (wstack->weak_refs[i].data, wstack->object);
1424 g_object_weak_ref (GObject *object,
1428 WeakRefStack *wstack;
1431 g_return_if_fail (G_IS_OBJECT (object));
1432 g_return_if_fail (notify != NULL);
1433 g_return_if_fail (object->ref_count >= 1);
1435 wstack = g_datalist_id_remove_no_notify (&object->qdata, quark_weak_refs);
1438 i = wstack->n_weak_refs++;
1439 wstack = g_realloc (wstack, sizeof (*wstack) + sizeof (wstack->weak_refs[0]) * i);
1443 wstack = g_renew (WeakRefStack, NULL, 1);
1444 wstack->object = object;
1445 wstack->n_weak_refs = 1;
1448 wstack->weak_refs[i].notify = notify;
1449 wstack->weak_refs[i].data = data;
1450 g_datalist_id_set_data_full (&object->qdata, quark_weak_refs, wstack, weak_refs_notify);
1454 g_object_weak_unref (GObject *object,
1458 WeakRefStack *wstack;
1459 gboolean found_one = FALSE;
1461 g_return_if_fail (G_IS_OBJECT (object));
1462 g_return_if_fail (notify != NULL);
1464 wstack = g_datalist_id_get_data (&object->qdata, quark_weak_refs);
1469 for (i = 0; i < wstack->n_weak_refs; i++)
1470 if (wstack->weak_refs[i].notify == notify &&
1471 wstack->weak_refs[i].data == data)
1474 wstack->n_weak_refs -= 1;
1475 if (i != wstack->n_weak_refs)
1477 wstack->weak_refs[i].notify = wstack->weak_refs[wstack->n_weak_refs].notify;
1478 wstack->weak_refs[i].data = wstack->weak_refs[wstack->n_weak_refs].data;
1484 g_warning (G_STRLOC ": couldn't find weak ref %p(%p)", notify, data);
1488 g_object_add_weak_pointer (GObject *object,
1489 gpointer *weak_pointer_location)
1491 g_return_if_fail (G_IS_OBJECT (object));
1492 g_return_if_fail (weak_pointer_location != NULL);
1494 g_object_weak_ref (object,
1495 (GWeakNotify) g_nullify_pointer,
1496 weak_pointer_location);
1500 g_object_remove_weak_pointer (GObject *object,
1501 gpointer *weak_pointer_location)
1503 g_return_if_fail (G_IS_OBJECT (object));
1504 g_return_if_fail (weak_pointer_location != NULL);
1506 g_object_weak_unref (object,
1507 (GWeakNotify) g_nullify_pointer,
1508 weak_pointer_location);
1512 g_object_ref (gpointer _object)
1514 GObject *object = _object;
1516 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1517 g_return_val_if_fail (object->ref_count > 0, NULL);
1519 #ifdef G_ENABLE_DEBUG
1520 if (g_trap_object_ref == object)
1522 #endif /* G_ENABLE_DEBUG */
1524 object->ref_count += 1;
1530 g_object_unref (gpointer _object)
1532 GObject *object = _object;
1534 g_return_if_fail (G_IS_OBJECT (object));
1535 g_return_if_fail (object->ref_count > 0);
1537 #ifdef G_ENABLE_DEBUG
1538 if (g_trap_object_ref == object)
1540 #endif /* G_ENABLE_DEBUG */
1542 if (object->ref_count > 1)
1543 object->ref_count -= 1;
1545 g_object_last_unref (object);
1549 g_object_get_qdata (GObject *object,
1552 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1554 return quark ? g_datalist_id_get_data (&object->qdata, quark) : NULL;
1558 g_object_set_qdata (GObject *object,
1562 g_return_if_fail (G_IS_OBJECT (object));
1563 g_return_if_fail (quark > 0);
1565 g_datalist_id_set_data (&object->qdata, quark, data);
1569 g_object_set_qdata_full (GObject *object,
1572 GDestroyNotify destroy)
1574 g_return_if_fail (G_IS_OBJECT (object));
1575 g_return_if_fail (quark > 0);
1577 g_datalist_id_set_data_full (&object->qdata, quark, data,
1578 data ? destroy : (GDestroyNotify) NULL);
1582 g_object_steal_qdata (GObject *object,
1585 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1586 g_return_val_if_fail (quark > 0, NULL);
1588 return g_datalist_id_remove_no_notify (&object->qdata, quark);
1592 g_object_get_data (GObject *object,
1597 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1598 g_return_val_if_fail (key != NULL, NULL);
1600 quark = g_quark_try_string (key);
1602 return quark ? g_datalist_id_get_data (&object->qdata, quark) : NULL;
1606 g_object_set_data (GObject *object,
1610 g_return_if_fail (G_IS_OBJECT (object));
1611 g_return_if_fail (key != NULL);
1613 g_datalist_id_set_data (&object->qdata, g_quark_from_string (key), data);
1617 g_object_set_data_full (GObject *object,
1620 GDestroyNotify destroy)
1622 g_return_if_fail (G_IS_OBJECT (object));
1623 g_return_if_fail (key != NULL);
1625 g_datalist_id_set_data_full (&object->qdata, g_quark_from_string (key), data,
1626 data ? destroy : (GDestroyNotify) NULL);
1630 g_object_steal_data (GObject *object,
1635 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1636 g_return_val_if_fail (key != NULL, NULL);
1638 quark = g_quark_try_string (key);
1640 return quark ? g_datalist_id_remove_no_notify (&object->qdata, quark) : NULL;
1644 g_value_object_init (GValue *value)
1646 value->data[0].v_pointer = NULL;
1650 g_value_object_free_value (GValue *value)
1652 if (value->data[0].v_pointer)
1653 g_object_unref (value->data[0].v_pointer);
1657 g_value_object_copy_value (const GValue *src_value,
1660 if (src_value->data[0].v_pointer)
1661 dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
1663 dest_value->data[0].v_pointer = NULL;
1667 g_value_object_transform_value (const GValue *src_value,
1670 if (src_value->data[0].v_pointer && g_type_is_a (G_OBJECT_TYPE (src_value->data[0].v_pointer), G_VALUE_TYPE (dest_value)))
1671 dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
1673 dest_value->data[0].v_pointer = NULL;
1677 g_value_object_peek_pointer (const GValue *value)
1679 return value->data[0].v_pointer;
1683 g_value_object_collect_value (GValue *value,
1684 guint n_collect_values,
1685 GTypeCValue *collect_values,
1686 guint collect_flags)
1688 if (collect_values[0].v_pointer)
1690 GObject *object = collect_values[0].v_pointer;
1692 if (object->g_type_instance.g_class == NULL)
1693 return g_strconcat ("invalid unclassed object pointer for value type `",
1694 G_VALUE_TYPE_NAME (value),
1697 else if (!g_value_type_compatible (G_OBJECT_TYPE (object), G_VALUE_TYPE (value)))
1698 return g_strconcat ("invalid object type `",
1699 G_OBJECT_TYPE_NAME (object),
1700 "' for value type `",
1701 G_VALUE_TYPE_NAME (value),
1704 /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
1705 value->data[0].v_pointer = g_object_ref (object);
1708 value->data[0].v_pointer = NULL;
1714 g_value_object_lcopy_value (const GValue *value,
1715 guint n_collect_values,
1716 GTypeCValue *collect_values,
1717 guint collect_flags)
1719 GObject **object_p = collect_values[0].v_pointer;
1722 return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
1724 if (!value->data[0].v_pointer)
1726 else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
1727 *object_p = value->data[0].v_pointer;
1729 *object_p = g_object_ref (value->data[0].v_pointer);
1735 g_value_set_object (GValue *value,
1740 g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
1742 old = value->data[0].v_pointer;
1746 g_return_if_fail (G_IS_OBJECT (v_object));
1747 g_return_if_fail (g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value)));
1749 value->data[0].v_pointer = v_object;
1750 g_object_ref (value->data[0].v_pointer);
1753 value->data[0].v_pointer = NULL;
1756 g_object_unref (old);
1760 g_value_set_object_take_ownership (GValue *value,
1763 g_value_take_object (value, v_object);
1767 g_value_take_object (GValue *value,
1770 g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
1772 if (value->data[0].v_pointer)
1774 g_object_unref (value->data[0].v_pointer);
1775 value->data[0].v_pointer = NULL;
1780 g_return_if_fail (G_IS_OBJECT (v_object));
1781 g_return_if_fail (g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value)));
1783 value->data[0].v_pointer = v_object; /* we take over the reference count */
1788 g_value_get_object (const GValue *value)
1790 g_return_val_if_fail (G_VALUE_HOLDS_OBJECT (value), NULL);
1792 return value->data[0].v_pointer;
1796 g_value_dup_object (const GValue *value)
1798 g_return_val_if_fail (G_VALUE_HOLDS_OBJECT (value), NULL);
1800 return value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
1804 g_signal_connect_object (gpointer instance,
1805 const gchar *detailed_signal,
1806 GCallback c_handler,
1808 GConnectFlags connect_flags)
1810 g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
1811 g_return_val_if_fail (detailed_signal != NULL, 0);
1812 g_return_val_if_fail (c_handler != NULL, 0);
1818 g_return_val_if_fail (G_IS_OBJECT (gobject), 0);
1820 closure = ((connect_flags & G_CONNECT_SWAPPED) ? g_cclosure_new_object_swap : g_cclosure_new_object) (c_handler, gobject);
1822 return g_signal_connect_closure (instance, detailed_signal, closure, connect_flags & G_CONNECT_AFTER);
1825 return g_signal_connect_data (instance, detailed_signal, c_handler, NULL, NULL, connect_flags);
1831 GClosure *closures[1]; /* flexible array */
1833 /* don't change this structure without supplying an accessor for
1834 * watched closures, e.g.:
1835 * GSList* g_object_list_watched_closures (GObject *object)
1838 * g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1839 * carray = g_object_get_data (object, "GObject-closure-array");
1842 * GSList *slist = NULL;
1844 * for (i = 0; i < carray->n_closures; i++)
1845 * slist = g_slist_prepend (slist, carray->closures[i]);
1853 object_remove_closure (gpointer data,
1856 GObject *object = data;
1857 CArray *carray = g_object_get_qdata (object, quark_closure_array);
1860 for (i = 0; i < carray->n_closures; i++)
1861 if (carray->closures[i] == closure)
1863 carray->n_closures--;
1864 if (i < carray->n_closures)
1865 carray->closures[i] = carray->closures[carray->n_closures];
1868 g_assert_not_reached ();
1872 destroy_closure_array (gpointer data)
1874 CArray *carray = data;
1875 GObject *object = carray->object;
1876 guint i, n = carray->n_closures;
1878 for (i = 0; i < n; i++)
1880 GClosure *closure = carray->closures[i];
1882 /* removing object_remove_closure() upfront is probably faster than
1883 * letting it fiddle with quark_closure_array which is empty anyways
1885 g_closure_remove_invalidate_notifier (closure, object, object_remove_closure);
1886 g_closure_invalidate (closure);
1892 g_object_watch_closure (GObject *object,
1898 g_return_if_fail (G_IS_OBJECT (object));
1899 g_return_if_fail (closure != NULL);
1900 g_return_if_fail (closure->is_invalid == FALSE);
1901 g_return_if_fail (closure->in_marshal == FALSE);
1902 g_return_if_fail (object->ref_count > 0); /* this doesn't work on finalizing objects */
1904 g_closure_add_invalidate_notifier (closure, object, object_remove_closure);
1905 g_closure_add_marshal_guards (closure,
1906 object, (GClosureNotify) g_object_ref,
1907 object, (GClosureNotify) g_object_unref);
1908 carray = g_datalist_id_remove_no_notify (&object->qdata, quark_closure_array);
1911 carray = g_renew (CArray, NULL, 1);
1912 carray->object = object;
1913 carray->n_closures = 1;
1918 i = carray->n_closures++;
1919 carray = g_realloc (carray, sizeof (*carray) + sizeof (carray->closures[0]) * i);
1921 carray->closures[i] = closure;
1922 g_datalist_id_set_data_full (&object->qdata, quark_closure_array, carray, destroy_closure_array);
1926 g_closure_new_object (guint sizeof_closure,
1931 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1932 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1934 closure = g_closure_new_simple (sizeof_closure, object);
1935 g_object_watch_closure (object, closure);
1941 g_cclosure_new_object (GCallback callback_func,
1946 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1947 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1948 g_return_val_if_fail (callback_func != NULL, NULL);
1950 closure = g_cclosure_new (callback_func, object, NULL);
1951 g_object_watch_closure (object, closure);
1957 g_cclosure_new_object_swap (GCallback callback_func,
1962 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
1963 g_return_val_if_fail (object->ref_count > 0, NULL); /* this doesn't work on finalizing objects */
1964 g_return_val_if_fail (callback_func != NULL, NULL);
1966 closure = g_cclosure_new_swap (callback_func, object, NULL);
1967 g_object_watch_closure (object, closure);