From ae381d795e178740915defb23a4e54eb7791d8c6 Mon Sep 17 00:00:00 2001
From: Philip Withnall <withnall@endlessm.com>
Date: Sat, 5 Jan 2019 07:51:14 +0000
Subject: [PATCH 438/682] gtask: Ensure to return 1 or 0 from getters rather
 than truthy ints
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Since commit 290bb0dd, where various members of GTask were converted to
a bitfield, some of the getters:
 • g_task_get_check_cancellable()
 • g_task_get_return_on_cancel()
 • g_task_get_completed()
have been returning truthy ints (zero or an arbitrary non-zero integer)
as boolean values, rather than the canonical boolean ints of 1 and 0.

This broke the `yield` statement in Vala, whose generated C code
compares `g_task_get_completed (…) != TRUE`. i.e. Whether the
`completed` field has a value not equal to 1.

Fix this by explicitly converting truthy ints to canonical boolean ints
in all getters.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://gitlab.gnome.org/GNOME/glib/issues/1636
---
 gio/gtask.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gio/gtask.c b/gio/gtask.c
index a2f316d2e..aa98f752c 100644
--- a/gio/gtask.c
+++ b/gio/gtask.c
@@ -1132,7 +1132,8 @@ g_task_get_check_cancellable (GTask *task)
 {
   g_return_val_if_fail (G_IS_TASK (task), FALSE);
 
-  return task->check_cancellable;
+  /* Convert from a bit field to a boolean. */
+  return task->check_cancellable ? TRUE : FALSE;
 }
 
 /**
@@ -1149,7 +1150,8 @@ g_task_get_return_on_cancel (GTask *task)
 {
   g_return_val_if_fail (G_IS_TASK (task), FALSE);
 
-  return task->return_on_cancel;
+  /* Convert from a bit field to a boolean. */
+  return task->return_on_cancel ? TRUE : FALSE;
 }
 
 /**
@@ -1952,7 +1954,8 @@ g_task_get_completed (GTask *task)
 {
   g_return_val_if_fail (G_IS_TASK (task), FALSE);
 
-  return task->completed;
+  /* Convert from a bit field to a boolean. */
+  return task->completed ? TRUE : FALSE;
 }
 
 /**
@@ -2055,7 +2058,7 @@ g_task_get_property (GObject    *object,
   switch ((GTaskProperty) prop_id)
     {
     case PROP_COMPLETED:
-      g_value_set_boolean (value, task->completed);
+      g_value_set_boolean (value, g_task_get_completed (task));
       break;
     }
 }
-- 
2.19.1

