GNOME Bugzilla – Bug 656014
Missing GIR annotation/wrapper for pango_layout_get_line_readonly()
Last modified: 2011-08-09 08:44:23 UTC
When running the attached python test snippet I get the following warning: (pango.py:4596): Pango-CRITICAL **: pango_layout_line_unref: assertion `private->ref_count > 0' failed I ran into this problem in custom cell renderer and there I get a segfault, not only the warning. It seems like pango_layout_get_line_readonly() (and _get_line()) need some more wrapping. I looked into the code and one fix might be to simply set (transfer none) in the annotation for _get_line_readonly(). That fixes the issue for me, but it of course has the problem that if layout gets destroyed accessing line.layout causes a segfault. So line.layout would need a manual ref() to ensure its not destroyed while line is around. Thanks, Michael
Here is the example snippet: #!/usr/bin/python from gi.repository import Gtk, GObject def create_layout_and_let_it_go_out_of_scope_again(): widget = Gtk.Button() layout = widget.create_pango_layout("some\nlayout\n") #print layout line = layout.get_line_readonly(0) #print line if __name__ == "__main__": create_layout_and_let_it_go_out_of_scope_again() GObject.timeout_add_seconds(1, Gtk.main_quit) Gtk.main()
Created attachment 193397 [details] [review] patch that works for me (with the caveat outlned about accessing line.layout)
The patch might not be sufficient for your needs, but it is correct in any case, as it does not make a copy of the returned line (which is the very purpose of the _readonly() functions, after all). Also, it documents that you have to ref/unref the retured value yourself if you keep it around for a longer time, so I don't actually think this is a bug? I pushed your patch, thanks!