[pygi] Accept 0 as a valid value for flag and enum arguments
- From: Tomeu Vizoso <tomeuv src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [pygi] Accept 0 as a valid value for flag and enum arguments
- Date: Tue, 24 Nov 2009 15:13:48 +0000 (UTC)
commit fc3dca018e85aee34ade79d104ebd8cdd1dd5968
Author: Tomeu Vizoso <tomeu sugarlabs org>
Date: Tue Nov 24 15:52:47 2009 +0100
Accept 0 as a valid value for flag and enum arguments
https://bugzilla.gnome.org/show_bug.cgi?id=602638
gi/pygi-argument.c | 19 ++++++++++++++++++-
tests/libtestgi.c | 6 ++++++
tests/libtestgi.h | 1 +
tests/test_gi.py | 1 +
4 files changed, 26 insertions(+), 1 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 3a9e207..7f66b1f 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -384,8 +384,25 @@ check_number_release:
PyErr_SetString(PyExc_NotImplementedError, "callback marshalling is not supported yet");
break;
case GI_INFO_TYPE_ENUM:
+ retval = _pygi_g_registered_type_info_check_object(
+ (GIRegisteredTypeInfo *)info, TRUE, object);
+ break;
case GI_INFO_TYPE_FLAGS:
- retval = _pygi_g_registered_type_info_check_object((GIRegisteredTypeInfo *)info, TRUE, object);
+ if (PyNumber_Check(object)) {
+ /* Accept 0 as a valid flag value */
+ PyObject *number = PyNumber_Int(object);
+ if (number == NULL)
+ PyErr_Clear();
+ else {
+ long value = PyInt_AsLong(number);
+ if (value == 0)
+ break;
+ else if (value == -1)
+ PyErr_Clear();
+ }
+ }
+ retval = _pygi_g_registered_type_info_check_object(
+ (GIRegisteredTypeInfo *)info, TRUE, object);
break;
case GI_INFO_TYPE_STRUCT:
{
diff --git a/tests/libtestgi.c b/tests/libtestgi.c
index 9b278b8..3677fca 100644
--- a/tests/libtestgi.c
+++ b/tests/libtestgi.c
@@ -2822,6 +2822,12 @@ test_gi_flags_in (TestGIFlags flags_)
g_assert(flags_ == TESTGI_FLAGS_VALUE2);
}
+void
+test_gi_flags_in_zero (TestGIFlags flags)
+{
+ g_assert(flags == 0);
+}
+
/**
* test_gi_flags_in_ptr:
* @flags_: (in) (transfer none):
diff --git a/tests/libtestgi.h b/tests/libtestgi.h
index 538f139..685dcff 100644
--- a/tests/libtestgi.h
+++ b/tests/libtestgi.h
@@ -489,6 +489,7 @@ GType test_gi_flags_get_type (void) G_GNUC_CONST;
TestGIFlags test_gi_flags_return (void);
void test_gi_flags_in (TestGIFlags flags_);
+void test_gi_flags_in_zero (TestGIFlags flags);
void test_gi_flags_in_ptr (TestGIFlags *flags_);
void test_gi_flags_out (TestGIFlags *flags_);
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 6c63bfc..1b0cadb 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1065,6 +1065,7 @@ class TestGFlags(unittest.TestCase):
def test_flags_in(self):
TestGI.flags_in(TestGI.Flags.VALUE2)
+ TestGI.flags_in_zero(Number(0))
self.assertRaises(TypeError, TestGI.flags_in, 1 << 1)
self.assertRaises(TypeError, TestGI.flags_in, 'TestGI.Flags.VALUE2')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]