summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn (J5) Palmieri <johnp@redhat.com>2010-04-16 10:58:09 -0400
committerJohn (J5) Palmieri <johnp@redhat.com>2010-04-16 10:58:09 -0400
commitdedf0c380d1fa551ce9d7fd544b9973202ba1b05 (patch)
treea3d9177e73125a30c21a60ac10c521c7ef3420b5
parentc0ec19f2b96ec62b43365c9c8007a3646a7d7169 (diff)
downloadpygi-dedf0c380d1fa551ce9d7fd544b9973202ba1b05.tar.gz
pygi-dedf0c380d1fa551ce9d7fd544b9973202ba1b05.tar.xz
pygi-dedf0c380d1fa551ce9d7fd544b9973202ba1b05.zip
Fix test cases by decoding to correctly sized type
* Make work on both Python 3.0 and 2.x by using the Long object instead of Int. Since we are decoding to a C type and this code is internal we can assume UnsignedLongLong python type for unsigned values to avoid issues where we were mistakenly decoding large values into a long.
-rw-r--r--gi/pygi-argument.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 8ba42ba..c6b62a0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -686,15 +686,22 @@ _pygi_argument_from_object (PyObject *object,
case GI_TYPE_TAG_LONG:
case GI_TYPE_TAG_SSIZE:
{
+ /* These types will all fit in long on 32 and 64bit archs */
PyObject *int_;
+ long value;
int_ = PyNumber_Long(object);
if (int_ == NULL) {
break;
}
- arg.v_long = PyLong_AsLong(int_);
+ value = PyLong_AsLong(int_);
+ if (value == -1 && PyErr_Occurred()) {
+ Py_DECREF(int_);
+ break;
+ }
+ arg.v_long = value;
Py_DECREF(int_);
break;
@@ -705,6 +712,7 @@ _pygi_argument_from_object (PyObject *object,
case GI_TYPE_TAG_ULONG:
case GI_TYPE_TAG_SIZE:
{
+ /* all of these types fit in a long long type on all archs */
PyObject *number;
guint64 value;
@@ -712,13 +720,13 @@ _pygi_argument_from_object (PyObject *object,
if (number == NULL) {
break;
}
-
- if (PyLong_Check(number)) {
- value = PyLong_AsLong(number);
- } else {
- value = PyLong_AsUnsignedLongLong(number);
+
+ value = PyLong_AsUnsignedLongLong(number);
+ if (value == -1 && PyErr_Occurred()) {
+ Py_DECREF(number);
+ break;
}
-
+
arg.v_uint64 = value;
Py_DECREF(number);