GObject properties and g_value_set_string()



Hi all,

Currently, I do my properties like following:

http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/lib/ags_turtle.c?h=2.1.x#n175
http://git.savannah.nongnu.org/cgit/gsequencer.git/tree/ags/lib/ags_turtle.c?h=2.1.x#n218

Is it ok to do g_strdup() and pass it to g_value_set_string()?
Or does g_value_set_string() duplicate the string for me?

Does the following make any sense?

g_value_set_string(value, g_strdup(turtle->filename));

This sample code is from GLib-2.0 API Reference Manual:

================================

gint intval;
gchar *strval;
GObject *objval;

g_object_get (my_object,
              "int-property", &intval,
              "str-property", &strval,
              "obj-property", &objval,
              NULL);

// Do something with intval, strval, objval

g_free (strval);
g_object_unref (objval);

================================

Since I have to free the string, I just wonder if I need to g_strdup() it.

bests,
Joël


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