[pygobject/gsoc2009: 28/160] Add short/ushort support
- From: Simon van der Linden <svdlinden src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygobject/gsoc2009: 28/160] Add short/ushort support
- Date: Fri, 14 Aug 2009 21:24:26 +0000 (UTC)
commit ebfa51ac93da64b2a3d7dccee0d02304d80bf748
Author: Mark Lee <marklee src gnome org>
Date: Mon Jul 6 11:52:54 2009 +0200
Add short/ushort support
Add short/ushort support to girepository parameters, function return
types, and unit tests.
http://bugzilla.gnome.org/show_bug.cgi?id=586879
girepository/bank-argument.c | 19 +++++++++++++++++++
girepository/bank.c | 2 ++
tests/test_girepository.py | 28 ++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/girepository/bank-argument.c b/girepository/bank-argument.c
index 2e2a926..0c2859e 100644
--- a/girepository/bank-argument.c
+++ b/girepository/bank-argument.c
@@ -50,6 +50,7 @@ pyg_argument_from_pyobject_check(PyObject *object, GITypeInfo *type_info, GError
case GI_TYPE_TAG_INT16:
case GI_TYPE_TAG_INT32:
case GI_TYPE_TAG_INT:
+ case GI_TYPE_TAG_SHORT:
{
long value;
gint value_max, value_min;
@@ -71,6 +72,9 @@ pyg_argument_from_pyobject_check(PyObject *object, GITypeInfo *type_info, GError
} else if (type_tag == GI_TYPE_TAG_INT) {
value_min = G_MININT;
value_max = G_MAXINT;
+ } else if (type_tag == GI_TYPE_TAG_SHORT) {
+ value_min = G_MINSHORT;
+ value_max = G_MAXSHORT;
} else {
g_assert_not_reached();
value_max = 0;
@@ -90,6 +94,7 @@ pyg_argument_from_pyobject_check(PyObject *object, GITypeInfo *type_info, GError
case GI_TYPE_TAG_UINT16:
case GI_TYPE_TAG_UINT32:
case GI_TYPE_TAG_UINT:
+ case GI_TYPE_TAG_USHORT:
{
guint value_max;
@@ -101,6 +106,8 @@ pyg_argument_from_pyobject_check(PyObject *object, GITypeInfo *type_info, GError
value_max = 4294967295;
} else if (type_tag == GI_TYPE_TAG_UINT) {
value_max = G_MAXUINT;
+ } else if (type_tag == GI_TYPE_TAG_USHORT) {
+ value_max = G_MAXUSHORT;
} else {
g_assert_not_reached();
value_max = 0;
@@ -395,6 +402,9 @@ pyg_argument_from_pyobject(PyObject *object, GITypeInfo *type_info)
else
arg.v_pointer = g_strdup(PyString_AsString(object));
break;
+ case GI_TYPE_TAG_USHORT:
+ arg.v_ushort = PyInt_AsLong(object);
+ break;
case GI_TYPE_TAG_UINT8:
arg.v_uint8 = PyInt_AsLong(object);
break;
@@ -415,6 +425,9 @@ pyg_argument_from_pyobject(PyObject *object, GITypeInfo *type_info)
} else
arg.v_uint64 = PyLong_AsUnsignedLongLong(object);
break;
+ case GI_TYPE_TAG_SHORT:
+ arg.v_short = PyInt_AsLong(object);
+ break;
case GI_TYPE_TAG_INT8:
arg.v_int8 = PyInt_AsLong(object);
break;
@@ -767,6 +780,9 @@ pyg_argument_to_pyobject(GArgument *arg, GITypeInfo *type_info)
case GI_TYPE_TAG_BOOLEAN:
obj = PyBool_FromLong(arg->v_boolean);
break;
+ case GI_TYPE_TAG_USHORT:
+ obj = PyInt_FromLong(arg->v_ushort);
+ break;
case GI_TYPE_TAG_UINT8:
obj = PyInt_FromLong(arg->v_uint8);
break;
@@ -782,6 +798,9 @@ pyg_argument_to_pyobject(GArgument *arg, GITypeInfo *type_info)
case GI_TYPE_TAG_UINT64:
obj = PyLong_FromUnsignedLongLong(arg->v_uint64);
break;
+ case GI_TYPE_TAG_SHORT:
+ obj = PyInt_FromLong(arg->v_short);
+ break;
case GI_TYPE_TAG_INT:
obj = PyInt_FromLong(arg->v_int);
break;
diff --git a/girepository/bank.c b/girepository/bank.c
index 78304f1..fb3841d 100644
--- a/girepository/bank.c
+++ b/girepository/bank.c
@@ -114,6 +114,8 @@ register_constants(PyObject *m)
/* FIXME: Removed from metadata format, fix properly by introducing
special-case struct */
/* PyModule_AddIntConstant(m, "TYPE_TAG_GSTRING", GI_TYPE_TAG_GSTRING); */
+ PyModule_AddIntConstant(m, "TYPE_TAG_SHORT", GI_TYPE_TAG_SHORT);
+ PyModule_AddIntConstant(m, "TYPE_TAG_USHORT", GI_TYPE_TAG_USHORT);
PyModule_AddIntConstant(m, "TYPE_TAG_INT", GI_TYPE_TAG_INT);
PyModule_AddIntConstant(m, "TYPE_TAG_UINT", GI_TYPE_TAG_UINT);
PyModule_AddIntConstant(m, "TYPE_TAG_LONG", GI_TYPE_TAG_LONG);
diff --git a/tests/test_girepository.py b/tests/test_girepository.py
index f9eb81f..d489949 100644
--- a/tests/test_girepository.py
+++ b/tests/test_girepository.py
@@ -4,6 +4,7 @@ import unittest
import time
import gobject
+from gobject import constants
import girepository
import GLib
@@ -54,6 +55,21 @@ class TestGIEverything(unittest.TestCase):
self.assertFalse(Everything.test_boolean(0))
self.assertTrue(Everything.test_boolean(2))
+ def testShort(self):
+ self.assertEqual(3, Everything.test_short(3))
+ self.assertEqual(3, Everything.test_short(3L))
+ self.assertEqual(-3, Everything.test_short(-3))
+ self.assertEqual(-3, Everything.test_short(-3L))
+ self.assertEqual(constants.G_MINSHORT, Everything.test_short(constants.G_MINSHORT))
+ self.assertEqual(constants.G_MAXSHORT, Everything.test_short(constants.G_MAXSHORT))
+ self.assertEqual(constants.G_MINSHORT, Everything.test_short(long(constants.G_MINSHORT)))
+ self.assertEqual(constants.G_MAXSHORT, Everything.test_short(long(constants.G_MAXSHORT)))
+ self.assertRaises(TypeError, Everything.test_short, 'a')
+ self.assertRaises(ValueError, Everything.test_short, constants.G_MINSHORT-1)
+ self.assertRaises(ValueError, Everything.test_short, constants.G_MAXSHORT+1)
+ self.assertRaises(ValueError, Everything.test_short, long(constants.G_MINSHORT-1))
+ self.assertRaises(ValueError, Everything.test_short, long(constants.G_MAXSHORT+1))
+
def testInt(self):
self.assertEqual(3, Everything.test_int(3))
self.assertEqual(-3, Everything.test_int(-3))
@@ -109,6 +125,18 @@ class TestGIEverything(unittest.TestCase):
self.assertRaises(ValueError, Everything.test_int64, INT64_MIN-1)
self.assertRaises(ValueError, Everything.test_int64, INT64_MAX+1)
+ def testUShort(self):
+ self.assertEqual(3, Everything.test_ushort(3))
+ self.assertEqual(3, Everything.test_ushort(3L))
+ self.assertEqual(constants.G_MAXUSHORT, Everything.test_ushort(constants.G_MAXUSHORT))
+ self.assertEqual(constants.G_MAXUSHORT, Everything.test_ushort(long(constants.G_MAXUSHORT)))
+ self.assertRaises(TypeError, Everything.test_ushort, 'a')
+ self.assertRaises(ValueError, Everything.test_ushort, -3)
+ self.assertRaises(ValueError, Everything.test_ushort, -3L)
+ self.assertRaises(ValueError, Everything.test_ushort, constants.G_MAXUSHORT+1)
+ self.assertRaises(ValueError, Everything.test_ushort, long(constants.G_MAXUSHORT+1))
+
+
def testUInt(self):
self.assertEqual(3, Everything.test_uint(3))
self.assertEqual(3, Everything.test_uint(3L))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]