[pygobject] cairo: Fix GValue converters in case it contains NULL
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] cairo: Fix GValue converters in case it contains NULL
- Date: Sat, 24 Nov 2018 21:07:01 +0000 (UTC)
commit c6ef6bafe795a4a4ac5dd72eb11c433a1e107af1
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Nov 24 21:36:21 2018 +0100
cairo: Fix GValue converters in case it contains NULL
The default values for the cairo boxed types is NULL and the converters
incorrectly returned NULL instead of a None object.
Also add tests for all of them.
gi/pygi-foreign-cairo.c | 10 +++++-----
tests/test_cairo.py | 21 +++++++++++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygi-foreign-cairo.c b/gi/pygi-foreign-cairo.c
index 718f9a0f..c99847bf 100644
--- a/gi/pygi-foreign-cairo.c
+++ b/gi/pygi-foreign-cairo.c
@@ -118,7 +118,7 @@ cairo_context_from_gvalue (const GValue *value)
/* PycairoContext_FromContext steals a ref, so we dup it out of the GValue. */
cairo_t *cr = g_value_dup_boxed (value);
if (!cr) {
- return NULL;
+ Py_RETURN_NONE;
}
return PycairoContext_FromContext (cr, &PycairoContext_Type, NULL);
@@ -203,7 +203,7 @@ cairo_surface_from_gvalue (const GValue *value)
/* PycairoSurface_FromSurface steals a ref, so we dup it out of the GValue. */
cairo_surface_t *surface = g_value_dup_boxed (value);
if (!surface) {
- return NULL;
+ Py_RETURN_NONE;
}
return PycairoSurface_FromSurface (surface, NULL);
@@ -308,7 +308,7 @@ cairo_font_face_from_gvalue (const GValue *value)
{
cairo_font_face_t *font_face = g_value_dup_boxed (value);
if (!font_face) {
- return NULL;
+ Py_RETURN_NONE;
}
return PycairoFontFace_FromFontFace (font_face);
@@ -398,7 +398,7 @@ cairo_scaled_font_from_gvalue (const GValue *value)
/* PycairoScaledFont_FromScaledFont steals a ref, so we dup it out of the GValue. */
cairo_scaled_font_t *scaled_font = g_value_dup_boxed (value);
if (!scaled_font) {
- return NULL;
+ Py_RETURN_NONE;
}
return PycairoScaledFont_FromScaledFont (scaled_font);
@@ -436,7 +436,7 @@ cairo_pattern_from_gvalue (const GValue *value)
/* PycairoPattern_FromPattern steals a ref, so we dup it out of the GValue. */
cairo_pattern_t *pattern = g_value_dup_boxed (value);
if (!pattern) {
- return NULL;
+ Py_RETURN_NONE;
}
return PycairoPattern_FromPattern (pattern, NULL);
diff --git a/tests/test_cairo.py b/tests/test_cairo.py
index 8ccbe15a..f4d0d7c9 100644
--- a/tests/test_cairo.py
+++ b/tests/test_cairo.py
@@ -30,6 +30,27 @@ from gi.repository import GObject, Regress
@unittest.skipUnless(has_cairo, 'built without cairo support')
class Test(unittest.TestCase):
+
+ def test_gvalue_converters(self):
+ surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 10, 10)
+ context = cairo.Context(surface)
+ objects = {
+ 'CairoContext': context,
+ 'CairoSurface': surface,
+ 'CairoFontFace': context.get_font_face(),
+ 'CairoScaledFont': context.get_scaled_font(),
+ 'CairoPattern': context.get_source(),
+ }
+ for type_name, cairo_obj in objects.items():
+ gtype = GObject.type_from_name(type_name)
+ v = GObject.Value()
+ assert v.init(gtype) is None
+ assert v.get_value() is None
+ v.set_value(None)
+ assert v.get_value() is None
+ v.set_value(cairo_obj)
+ assert v.get_value() == cairo_obj
+
def test_cairo_context(self):
context = Regress.test_cairo_context_full_return()
self.assertTrue(isinstance(context, cairo.Context))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]