[glib] Only add object to list new objects when it has a custom constructor
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib] Only add object to list new objects when it has a custom constructor
- Date: Mon, 30 Nov 2009 20:04:13 +0000 (UTC)
commit 2a78adc5e3f5b33e92cc55570397da24e062aa24
Author: Benjamin Otte <otte gnome org>
Date: Thu Oct 8 20:01:15 2009 +0200
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
gobject/gobject.c | 26 ++++++++++++++++++--------
1 files changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index f906d31..58554c3 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -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))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]