[pygobject] properly handle ulongs properties in py3k



commit d5666d99a1c0396b7da0cb14f9f4ff8892da7e2e
Author: John (J5) Palmieri <johnp redhat com>
Date:   Thu Sep 9 17:35:10 2010 -0400

    properly handle ulongs properties in py3k
    
    * If this is a PyLong object pull use AsUnsignedLong
    
    https://bugzilla.gnome.org/show_bug.cgi?id=615872

 gobject/pygtype.c |   31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index 1d8d6e8..df1a868 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -794,20 +794,23 @@ pyg_value_from_pyobject(GValue *value, PyObject *obj)
 	g_value_set_long(value, PYGLIB_PyLong_AsLong(obj));
 	break;
     case G_TYPE_ULONG:
-	{
-	    if (PYGLIB_PyLong_Check(obj)) {
-		glong val;
+#if PY_VERSION_HEX < 0x03000000
+	if (PyInt_Check(obj)) {
+            long val;
 
-		val = PYGLIB_PyLong_AsLong(obj);
-		if (val >= 0)
-		    g_value_set_ulong(value, (gulong)val);
-		else
-		    return -1;
-	    } else {
-		g_value_set_ulong(value, PyLong_AsUnsignedLong(obj));
-	    }
-	}
-	break;
+            val = PYGLIB_PyLong_AsLong(obj);
+            if (val < 0) {
+                PyErr_SetString(PyExc_OverflowError, "negative value not allowed for uint64 property");
+                return -1;
+            }
+            g_value_set_ulong(value, (gulong)val);
+        } else
+#endif
+        if (PyLong_Check(obj))
+	    g_value_set_ulong(value, PyLong_AsUnsignedLong(obj));
+        else
+            return -1;
+        break;
     case G_TYPE_INT64:
 	g_value_set_int64(value, PyLong_AsLongLong(obj));
 	break;



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