[Vala] Pango.Attribute questions
- From: pHilipp Zabel <philipp zabel gmail com>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] Pango.Attribute questions
- Date: Fri, 6 Nov 2009 14:40:30 +0100
Hi,
I'm a bit confused about how Pango.Attribute is supposed to work,
probable because I don't understand ownership issues of [Compact]
classes properly.
I want to set some Pango attributes on a Gtk.CellRendererText, so I tried this:
1: Pango.AttrList attr_list = new Pango.AttrList ();
2: Pango.Attribute attr_color = Pango.attr_foreground_new (color.red,
color.green, color.blue);
3: Pango.Attribute attr_scale = Pango.attr_scale_new (Pango.Scale.SMALL);
4: attr_list.insert (attr_color);
5: attr_list.insert (attr_scale);
6: renderer.attributes = attr_list;
Vala complains with an "error: duplicating Attribute instance, use
unowned variable or explicitly invoke copy method" in lines 2, 3, 4
and 5.
It works when I change the code to look like this:
1: Pango.AttrList attr_list = new Pango.AttrList ();
2: unowned Pango.Attribute attr_color = Pango.attr_foreground_new
(color.red, color.green, color.blue);
3: unowned Pango.Attribute attr_scale = Pango.attr_scale_new
(Pango.Scale.SMALL);
4: attr_list.insert (attr_color.copy ());
5: attr_list.insert (attr_scale.copy ());
6: renderer.attributes = attr_list;
This compiles to the following C code:
1: attr_list = pango_attr_list_new ();
2: attr_color = pango_attr_foreground_new (color.red, color.green, color.blue);
3: attr_scale = pango_attr_scale_new (PANGO_SCALE_SMALL);
4: pango_attr_list_insert (attr_list, pango_attribute_copy (attr_color));
5: pango_attr_list_insert (attr_list, pango_attribute_copy (attr_scale));
6: g_object_set (renderer, "attributes", attr_list, NULL);
Am I not leaking memory for attr_color and attr_scale due to the copy
and the fact that pango_attribute_destroy is never called on either of
them after the copies are made?
I'd expect the correct C code to look something like this:
1: attr_list = pango_attr_list_new ();
2: attr_color = pango_attr_foreground_new (color.red, color.green, color.blue);
3: attr_scale = pango_attr_scale_new (PANGO_SCALE_SMALL);
4: pango_attr_list_insert (attr_list, attr_color);
5: pango_attr_list_insert (attr_list, attr_scale);
6: g_object_set (renderer, "attributes", attr_list, NULL);
regards
Philipp
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]