summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gobject/pygenum.c6
-rw-r--r--gobject/pygflags.c6
-rw-r--r--tests/enum.py3
3 files changed, 13 insertions, 2 deletions
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index c4c974b..80d241a 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -140,8 +140,12 @@ pyg_enum_from_gtype (GType gtype, int value)
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__enum_values__");
retval = PyDict_GetItem(values, PyInt_FromLong(value));
+ if (!retval) {
+ PyErr_Clear();
+ return PyInt_FromLong(value);
+ }
+
Py_INCREF(retval);
-
return retval;
}
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index 381a1dd..526368a 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -168,12 +168,16 @@ pyg_flags_from_gtype (GType gtype, int value)
retval = PyDict_GetItem(values, PyInt_FromLong(value));
if (!retval) {
PyErr_Clear();
-
+
+ return PyInt_FromLong(value);
+#if 0
+ /* This breaks repr */
retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
g_assert(retval != NULL);
((PyIntObject*)retval)->ob_ival = value;
((PyGFlags*)retval)->gtype = gtype;
+#endif
}
Py_INCREF(retval);
diff --git a/tests/enum.py b/tests/enum.py
index 98dbd89..5e55a90 100644
--- a/tests/enum.py
+++ b/tests/enum.py
@@ -72,6 +72,9 @@ class EnumTest(unittest.TestCase):
assert isinstance(klass.__enum_values__, dict)
assert len(klass.__enum_values__) >= 2
+ def testOutofBounds(self):
+ gtk.icon_size_register('fake', 24, 24)
+
class FlagsTest(unittest.TestCase):
def testFlags(self):
assert issubclass(gobject.GFlags, int)