+Sat Nov 29 14:57:20 2003 Tim Janik <timj@gtk.org>
+
+ * gobject.c: fix g_object_set() whithin _init() implementations
+ not working for construct-only properties.
+ (g_object_init): make the object enter a construct_objects list.
+ (g_object_newv): remove object from construct_objects after creation.
+ (g_object_set_valist):
+ (g_object_set_property): allow construct-only properties for
+ objects which are in construct_objects.
+
Thu Nov 27 17:53:52 2003 Tim Janik <timj@gtk.org>
* gtype.[hc]:
static GParamSpecPool *pspec_pool = NULL;
static GObjectNotifyContext property_notify_context = { 0, };
static gulong gobject_signals[LAST_SIGNAL] = { 0, };
+G_LOCK_DEFINE_STATIC (construct_objects_lock);
+static GSList *construct_objects = NULL;
/* --- functions --- */
/* freeze object's notification queue, g_object_newv() preserves pairedness */
g_object_notify_queue_freeze (object, &property_notify_context);
+
+ /* allow construct-only properties to be set */
+ G_LOCK (construct_objects_lock);
+ construct_objects = g_slist_prepend (construct_objects, object);
+ G_UNLOCK (construct_objects_lock);
#ifdef G_ENABLE_DEBUG
IF_DEBUG (OBJECTS)
return object;
}
+static gboolean
+object_in_construction (GObject *object)
+{
+ gboolean in_construction;
+ G_LOCK (construct_objects_lock);
+ in_construction = g_slist_find (construct_objects, object) != NULL;
+ G_UNLOCK (construct_objects_lock);
+ return in_construction;
+}
+
gpointer
g_object_newv (GType object_type,
guint n_parameters,
/* construct object from construction parameters */
object = class->constructor (object_type, n_total_cparams, cparams);
+ G_LOCK (construct_objects_lock);
+ construct_objects = g_slist_remove (construct_objects, object);
+ G_UNLOCK (construct_objects_lock);
/* free construction values */
g_free (cparams);
/* create object */
object = (GObject*) g_type_create_instance (type);
-
+
/* set construction parameters */
if (n_construct_properties)
{
G_OBJECT_TYPE_NAME (object));
break;
}
- if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
+ if ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) && !object_in_construction (object))
{
g_warning ("%s: construct property \"%s\" for object `%s' can't be set after construction",
G_STRFUNC, pspec->name, G_OBJECT_TYPE_NAME (object));
G_STRFUNC,
pspec->name,
G_OBJECT_TYPE_NAME (object));
- else if (pspec->flags & G_PARAM_CONSTRUCT_ONLY)
+ else if ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) && !object_in_construction (object))
g_warning ("%s: construct property \"%s\" for object `%s' can't be set after construction",
G_STRFUNC, pspec->name, G_OBJECT_TYPE_NAME (object));
else