[pygobject] GValue.get_value: fix crashes for Variants
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] GValue.get_value: fix crashes for Variants
- Date: Sun, 25 Nov 2018 12:16:45 +0000 (UTC)
commit 62b16247b9230a975d85e749da9f1b199fbc3c84
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sun Nov 25 13:13:38 2018 +0100
GValue.get_value: fix crashes for Variants
g_value_get_variant is transfer-none but was annotated as full which
results in the bindings unreffing it too many times.
Work around the issue by using g_value_dup_variant instead which is
really transfer-full.
gi/overrides/GObject.py | 4 +++-
tests/test_overrides_gobject.py | 7 ++++---
2 files changed, 7 insertions(+), 4 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index e6f5b882..a89ddc7d 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -333,7 +333,9 @@ class Value(GObjectModule.Value):
elif gtype == TYPE_GTYPE:
return self.get_gtype()
elif gtype == TYPE_VARIANT:
- return self.get_variant()
+ # get_variant was missing annotations
+ # https://gitlab.gnome.org/GNOME/glib/merge_requests/492
+ return self.dup_variant()
elif gtype == _gi.TYPE_INVALID:
return None
else:
diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py
index b902564f..37292dbb 100644
--- a/tests/test_overrides_gobject.py
+++ b/tests/test_overrides_gobject.py
@@ -183,13 +183,14 @@ def test_value_variant():
assert v.get_value() is None
variant = GLib.Variant('i', 42)
v.set_value(variant)
-
- # FIXME: triggers an assert
- # assert v.get_value() == variant
+ assert v.get_value() == variant
v.set_value(None)
assert v.get_value() is None
+ with pytest.raises(TypeError):
+ v.set_value(object())
+
def test_value_param():
# FIXME: set_value and get_value trigger a critical
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]