[pygobject/pygobject-2-28] Fix crash in Gtk.TextIter overrides



commit e114c3de09d7d95942b308f704a6ca20244dad9d
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Thu Jul 7 13:39:19 2011 +0200

    Fix crash in Gtk.TextIter overrides
    
    With commit 17cd0fb3 Gtk.TextIter.{forward,backward}_search() returns undefined
    pointers when the search was unsuccessful. Actually check the "success" return
    value; if it is False return None, just like PyGTK used to.
    
    Thanks to Michael Vogt for discovering this and writing the test case!
    
    Test case:
    
    -------------- 8< -----------------
    from gi.repository import Gtk
    
    win = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
    textview = Gtk.TextView()
    buffer = textview.get_buffer()
    buffer.set_text("hello world")
    win.add(textview)
    
    win.show_all()
    
    iter = buffer.get_start_iter()
    end = buffer.get_end_iter()
    ret = iter.forward_search("foo",
                              Gtk.TextSearchFlags.VISIBLE_ONLY,
    			                            end)
    print "this is my return value"
    print ret
    print "now I crash"
    print ret[0].get_offset()
    
    Gtk.main()
    -------------- 8< -----------------

 gi/overrides/Gtk.py |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index b7dd7d7..007e155 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -631,12 +631,18 @@ class TextIter(Gtk.TextIter):
     def forward_search(self, string, flags, limit):
         success, match_start, match_end = super(TextIter, self).forward_search(string,
             flags, limit)
-        return (match_start, match_end,)
+        if success:
+            return (match_start, match_end)
+        else:
+            return None
 
     def backward_search(self, string, flags, limit):
         success, match_start, match_end = super(TextIter, self).backward_search(string,
             flags, limit)
-        return (match_start, match_end,)
+        if success:
+            return (match_start, match_end)
+        else:
+            return None
 
     def begins_tag(self, tag=None):
         return super(TextIter, self).begins_tag(tag)



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