[pygobject] Fix OverflowError in source_remove()



commit 126a10f765af3d3a6f08ce5db7ed9f3ef647848f
Author: Martin Pitt <martinpitt gnome org>
Date:   Tue Oct 23 06:12:08 2012 +0200

    Fix OverflowError in source_remove()
    
    GSource IDs are unsigned, so we must use 'I' for parsing then, not 'i'.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684526

 gi/_glib/glibmodule.c |    2 +-
 tests/test_source.py  |   13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/gi/_glib/glibmodule.c b/gi/_glib/glibmodule.c
index 11b97f5..4dea68c 100644
--- a/gi/_glib/glibmodule.c
+++ b/gi/_glib/glibmodule.c
@@ -313,7 +313,7 @@ pyglib_source_remove(PyObject *self, PyObject *args)
 {
     guint tag;
 
-    if (!PyArg_ParseTuple(args, "i:source_remove", &tag))
+    if (!PyArg_ParseTuple(args, "I:source_remove", &tag))
 	return NULL;
 
     return PyBool_FromLong(g_source_remove(tag));
diff --git a/tests/test_source.py b/tests/test_source.py
index ec47d0e..4c8d24b 100644
--- a/tests/test_source.py
+++ b/tests/test_source.py
@@ -2,7 +2,7 @@
 
 import unittest
 
-from gi.repository import GLib
+from gi.repository import GLib, GObject
 
 
 class Idle(GLib.Idle):
@@ -119,6 +119,17 @@ class TestSource(unittest.TestCase):
         s = f()
         self.assertTrue(s.is_destroyed())
 
+    def testRemove(self):
+        s = GLib.idle_add(dir)
+        self.assertEqual(GLib.source_remove(s), True)
+        # s is now removed, should fail now
+        self.assertEqual(GLib.source_remove(s), False)
+
+        # accepts large source IDs (they are unsigned)
+        self.assertEqual(GLib.source_remove(GObject.G_MAXINT32), False)
+        self.assertEqual(GLib.source_remove(GObject.G_MAXINT32 + 1), False)
+        self.assertEqual(GLib.source_remove(GObject.G_MAXUINT32), False)
+
 
 class TestTimeout(unittest.TestCase):
     def test504337(self):



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