Only add object to list new objects when it has a custom constructor

This works around the need to take a custom mutex twice and add the
object to a GSList of objects that are currently in construction for the
common case. Only when the constructor is overwritten do we use the
previous behavior and allow things like singleton objects.

The only slightly incompatible change is that previously, it was ok to
call g_object_set() on construct-only properties while the object was
initialized. This will now fail. If that behavior is needed, setting a
custom constructor that just chains up will reenable this functionality.

https://bugzilla.gnome.org/show_bug.cgi?id=557151
This commit is contained in:
Benjamin Otte 2009-10-08 20:01:15 +02:00 committed by Alexander Larsson
parent f0f32a7ef0
commit 2a78adc5e3

View File

@ -116,6 +116,8 @@
#define CLASS_HAS_PROPS_FLAG 0x1
#define CLASS_HAS_PROPS(class) \
((class)->flags & CLASS_HAS_PROPS_FLAG)
#define CLASS_HAS_CUSTOM_CONSTRUCTOR(class) \
((class)->constructor != g_object_constructor)
#define CLASS_HAS_DERIVED_CLASS_FLAG 0x2
#define CLASS_HAS_DERIVED_CLASS(class) \
@ -715,10 +717,13 @@ g_object_init (GObject *object,
g_object_notify_queue_freeze (object, &property_notify_context);
}
/* enter construction list for notify_queue_thaw() and to allow construct-only properties */
G_LOCK (construction_mutex);
construction_objects = g_slist_prepend (construction_objects, object);
G_UNLOCK (construction_mutex);
if (CLASS_HAS_CUSTOM_CONSTRUCTOR (class))
{
/* enter construction list for notify_queue_thaw() and to allow construct-only properties */
G_LOCK (construction_mutex);
construction_objects = g_slist_prepend (construction_objects, object);
G_UNLOCK (construction_mutex);
}
#ifdef G_ENABLE_DEBUG
IF_DEBUG (OBJECTS)
@ -1257,10 +1262,15 @@ g_object_newv (GType object_type,
g_free (cvalues);
did_construction:
/* adjust freeze_count according to g_object_init() and remaining properties */
G_LOCK (construction_mutex);
newly_constructed = slist_maybe_remove (&construction_objects, object);
G_UNLOCK (construction_mutex);
if (CLASS_HAS_CUSTOM_CONSTRUCTOR (class))
{
/* adjust freeze_count according to g_object_init() and remaining properties */
G_LOCK (construction_mutex);
newly_constructed = slist_maybe_remove (&construction_objects, object);
G_UNLOCK (construction_mutex);
}
else
newly_constructed = TRUE;
if (CLASS_HAS_PROPS (class))
{