GObject property validation during object construction



I have a GObject.

struct _MyObject
{
  gchar *foo;
};

I set a string property in my class_init with g_param_spec_string. I
set the property->cset_nth to a string of valid characters
("abc...xyz").

static void
my_object_class_init (MyObjectClass *klass)
{
  GParamSpecString *pspec = g_param_spec_string ("foo", "foo", "foo",
                                                 NULL,
                                                 G_PARAM_READWRITE | 
                                                 G_PARAM_CONSTRUCT);
  pspec->cset_nth = g_strdup ("abcdefghijklmnopqrstuvwxyz-_");

  g_object_class_install_property (object_class, PROP_FOO, pspec);
}

When I create an instance of my object with g_object_new:

MyObject *obj = g_object_new (MY_TYPE_OBJECT,
                              "foo", "invalid string",
                              NULL);

I notice that g_param_value_validate *is* being called, and does return
FALSE, but it's not setting an error; it appears to g_logs a warning
and eventually aborts. Is there any way to make that validation check
non-fatal, so I can handle the error nicely?

Also, this behavior seems contradictory to the GObject documentation on
properties: "the GValue is validated by g_param_value_validate [...] As
such, the g_object_set_property function will return with an error."
g_object_set_property returns void and does not accept a GError.

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]