pygobject r1054 - in trunk: . gobject tests



Author: gjc
Date: Sun Apr  5 14:39:35 2009
New Revision: 1054
URL: http://svn.gnome.org/viewvc/pygobject?rev=1054&view=rev

Log:
Bug 577999 â converting a negative long Python value to a GUINT64 GValue doesn't error out as it should

Modified:
   trunk/ChangeLog
   trunk/gobject/pygtype.c
   trunk/tests/test_properties.py

Modified: trunk/gobject/pygtype.c
==============================================================================
--- trunk/gobject/pygtype.c	(original)
+++ trunk/gobject/pygtype.c	Sun Apr  5 14:39:35 2009
@@ -716,11 +716,6 @@
 	break;
     case G_TYPE_INT:
 	g_value_set_int(value, _PyLong_AsLong(obj));
-	if (PyErr_Occurred()) {
-	    g_value_unset(value);
-	    PyErr_Clear();
-	    return -1;
-	}
 	break;
     case G_TYPE_UINT:
 	{
@@ -734,21 +729,11 @@
 		    return -1;
 	    } else {
 		g_value_set_uint(value, PyLong_AsUnsignedLong(obj));
-		if (PyErr_Occurred()) {
-		    g_value_unset(value);
-		    PyErr_Clear();
-		    return -1;
-		}
 	    }
 	}
 	break;
     case G_TYPE_LONG:
 	g_value_set_long(value, _PyLong_AsLong(obj));
-	if (PyErr_Occurred()) {
-	    g_value_unset(value);
-	    PyErr_Clear();
-	    return -1;
-	}
 	break;
     case G_TYPE_ULONG:
 	{
@@ -762,26 +747,24 @@
 		    return -1;
 	    } else {
 		g_value_set_ulong(value, PyLong_AsUnsignedLong(obj));
-		if (PyErr_Occurred()) {
-		    g_value_unset(value);
-		    PyErr_Clear();
-		    return -1;
-		}
 	    }
 	}
 	break;
     case G_TYPE_INT64:
 	g_value_set_int64(value, PyLong_AsLongLong(obj));
-	if (PyErr_Occurred()) {
-	    g_value_unset(value);
-	    PyErr_Clear();
-	    return -1;
-	}
 	break;
     case G_TYPE_UINT64:
-        if (_PyLong_Check(obj))
-            g_value_set_uint64(value, _PyLong_AsLong(obj));
-        else if (PyLong_Check(obj))
+#if PY_VERSION_HEX < 0x03000000
+        if (PyInt_Check(obj)) {
+            long v = PyInt_AsLong(obj);
+            if (v < 0) {
+                PyErr_SetString(PyExc_OverflowError, "negative value not allowed for uint64 property");
+                return -1;
+            }
+            g_value_set_uint64(value, v);
+        } else
+#endif
+        if (PyLong_Check(obj))
             g_value_set_uint64(value, PyLong_AsUnsignedLongLong(obj));
         else
             return -1;
@@ -808,19 +791,9 @@
 	break;
     case G_TYPE_FLOAT:
 	g_value_set_float(value, PyFloat_AsDouble(obj));
-	if (PyErr_Occurred()) {
-	    g_value_unset(value);
-	    PyErr_Clear();
-	    return -1;
-	}
 	break;
     case G_TYPE_DOUBLE:
 	g_value_set_double(value, PyFloat_AsDouble(obj));
-	if (PyErr_Occurred()) {
-	    g_value_unset(value);
-	    PyErr_Clear();
-	    return -1;
-	}
 	break;
     case G_TYPE_STRING:
 	if (obj == Py_None)
@@ -915,6 +888,11 @@
 	    break;
 	}
     }
+    if (PyErr_Occurred()) {
+        g_value_unset(value);
+        PyErr_Clear();
+        return -1;
+    }
     return 0;
 }
 

Modified: trunk/tests/test_properties.py
==============================================================================
--- trunk/tests/test_properties.py	(original)
+++ trunk/tests/test_properties.py	Sun Apr  5 14:39:35 2009
@@ -85,6 +85,9 @@
         obj.props.uint64 = 1
         self.assertEqual(obj.props.uint64, 1L)
 
+        self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1L)
+        self.assertRaises((TypeError, OverflowError), obj.set_property, "uint64", -1)
+
     def testUInt64DefaultValue(self):
         try:
             class TimeControl(GObject):



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