Patchwork [2/3] Purge GLib's gboolean, it's a trap for the unwary

login
register
mail settings
Submitter Markus Armbruster
Date Jan. 18, 2013, 4:04 p.m.
Message ID <1358525049-31163-3-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/213692/
State New
Headers show

Comments

Markus Armbruster - Jan. 18, 2013, 4:04 p.m.
Despite its name, gboolean is an alias for int, *not* for _Bool.  If
you forget that, and compare gboolean values to TRUE, you're in
trouble.

Instead of blindly replacing gboolean by int, replace it by int
exactly where that's needed for type-correctness, and by bool
everywhere else.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 async.c                  |  6 +++---
 hw/fw_cfg.c              |  2 +-
 hw/xen_disk.c            |  2 +-
 qapi/opts-visitor.c      |  2 +-
 qapi/qmp-input-visitor.c |  2 +-
 qemu-img.c               |  2 +-
 qga/channel-posix.c      | 13 +++++++------
 qga/channel-win32.c      | 10 +++++-----
 qga/channel.h            |  2 +-
 qga/main.c               |  6 +++---
 10 files changed, 24 insertions(+), 23 deletions(-)

Patch

diff --git a/async.c b/async.c
index 8c4ec5b..1f998e1 100644
--- a/async.c
+++ b/async.c
@@ -117,7 +117,7 @@  void qemu_bh_delete(QEMUBH *bh)
     bh->deleted = 1;
 }
 
-static gboolean
+static int
 aio_ctx_prepare(GSource *source, int *timeout)
 {
     AioContext *ctx = (AioContext *) source;
@@ -141,7 +141,7 @@  aio_ctx_prepare(GSource *source, int *timeout)
     return false;
 }
 
-static gboolean
+static int
 aio_ctx_check(GSource *source)
 {
     AioContext *ctx = (AioContext *) source;
@@ -155,7 +155,7 @@  aio_ctx_check(GSource *source)
     return aio_pending(ctx);
 }
 
-static gboolean
+static int
 aio_ctx_dispatch(GSource *source, GSourceFunc callback, void *user_data)
 {
     AioContext *ctx = (AioContext *) source;
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index b5d6df9..1ff4b4e 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -66,7 +66,7 @@  struct FWCfgState {
 static char *read_splashfile(char *filename, int *file_sizep, int *file_typep)
 {
     GError *err = NULL;
-    gboolean res;
+    bool res;
     char *content;
     int file_type = -1;
     unsigned int filehead = 0;
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 1037a80..ce2d7c6 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -113,7 +113,7 @@  struct XenBlkDev {
     int                 requests_finished;
 
     /* Persistent grants extension */
-    gboolean            feature_persistent;
+    bool                feature_persistent;
     GTree               *persistent_gnts;
     unsigned int        persistent_gnt_count;
     unsigned int        max_grants;
diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
index 590561a..b4ab204 100644
--- a/qapi/opts-visitor.c
+++ b/qapi/opts-visitor.c
@@ -105,7 +105,7 @@  opts_start_struct(Visitor *v, void **obj, const char *kind,
 }
 
 
-static gboolean
+static int
 ghr_true(void *ign_key, void *ign_value, void *ign_user_data)
 {
     return TRUE;
diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index bac1ed3..8fc76b6 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -88,7 +88,7 @@  static void qmp_input_push(QmpInputVisitor *qiv, QObject *obj, Error **errp)
 }
 
 /** Only for qmp_input_pop. */
-static gboolean always_true(void *key, void *val, void *user_pkey)
+static int always_true(void *key, void *val, void *user_pkey)
 {
     *(const char **)user_pkey = (const char *)key;
     return TRUE;
diff --git a/qemu-img.c b/qemu-img.c
index 7637411..74cf812 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1315,7 +1315,7 @@  static void dump_human_image_info_list(ImageInfoList *list)
     }
 }
 
-static gboolean str_equal_func(const void *a, const void *b)
+static int str_equal_func(const void *a, const void *b)
 {
     return strcmp(a, b) == 0;
 }
diff --git a/qga/channel-posix.c b/qga/channel-posix.c
index 7ce8de0..8a4e2e0 100644
--- a/qga/channel-posix.c
+++ b/qga/channel-posix.c
@@ -25,8 +25,8 @@  struct GAChannel {
 
 static int ga_channel_client_add(GAChannel *c, int fd);
 
-static gboolean ga_channel_listen_accept(GIOChannel *channel,
-                                         GIOCondition condition, void *data)
+static int ga_channel_listen_accept(GIOChannel *channel,
+                                    GIOCondition condition, void *data)
 {
     GAChannel *c = data;
     int ret, client_fd;
@@ -90,11 +90,11 @@  static void ga_channel_client_close(GAChannel *c)
     }
 }
 
-static gboolean ga_channel_client_event(GIOChannel *channel,
-                                        GIOCondition condition, void *data)
+static int ga_channel_client_event(GIOChannel *channel,
+                                   GIOCondition condition, void *data)
 {
     GAChannel *c = data;
-    gboolean client_cont;
+    bool client_cont;
 
     g_assert(c);
     if (c->event_cb) {
@@ -127,7 +127,8 @@  static int ga_channel_client_add(GAChannel *c, int fd)
     return 0;
 }
 
-static gboolean ga_channel_open(GAChannel *c, const char *path, GAChannelMethod method)
+static bool ga_channel_open(GAChannel *c, const char *path,
+                            GAChannelMethod method)
 {
     int ret;
     c->method = method;
diff --git a/qga/channel-win32.c b/qga/channel-win32.c
index e5e375a..f4140fb 100644
--- a/qga/channel-win32.c
+++ b/qga/channel-win32.c
@@ -38,7 +38,7 @@  typedef struct GAWatch {
  * Called by glib prior to polling to set up poll events if polling is needed.
  *
  */
-static gboolean ga_channel_prepare(GSource *source, int *timeout_ms)
+static int ga_channel_prepare(GSource *source, int *timeout_ms)
 {
     GAWatch *watch = (GAWatch *)source;
     GAChannel *c = (GAChannel *)watch->channel;
@@ -95,7 +95,7 @@  out:
 /*
  * Called by glib after an outstanding read request is completed.
  */
-static gboolean ga_channel_check(GSource *source)
+static int ga_channel_check(GSource *source)
 {
     GAWatch *watch = (GAWatch *)source;
     GAChannel *c = (GAChannel *)watch->channel;
@@ -152,13 +152,13 @@  static gboolean ga_channel_check(GSource *source)
 /*
  * Called by glib after either prepare or check routines signal readiness
  */
-static gboolean ga_channel_dispatch(GSource *source, GSourceFunc unused,
+static int ga_channel_dispatch(GSource *source, GSourceFunc unused,
                                     void *user_data)
 {
     GAWatch *watch = (GAWatch *)source;
     GAChannel *c = (GAChannel *)watch->channel;
     GAChannelReadState *rs = &c->rstate;
-    gboolean success;
+    bool success;
 
     g_debug("dispatch");
     success = c->cb(watch->pollfd.revents, c->user_data);
@@ -284,7 +284,7 @@  GIOStatus ga_channel_write_all(GAChannel *c, const char *buf, size_t size)
     return status;
 }
 
-static gboolean ga_channel_open(GAChannel *c, GAChannelMethod method,
+static bool ga_channel_open(GAChannel *c, GAChannelMethod method,
                                 const char *path)
 {
     if (!method == GA_CHANNEL_VIRTIO_SERIAL) {
diff --git a/qga/channel.h b/qga/channel.h
index 494ef91..e2c62db 100644
--- a/qga/channel.h
+++ b/qga/channel.h
@@ -22,7 +22,7 @@  typedef enum {
     GA_CHANNEL_UNIX_LISTEN,
 } GAChannelMethod;
 
-typedef gboolean (*GAChannelCallback)(GIOCondition condition, void *opaque);
+typedef bool (*GAChannelCallback)(GIOCondition condition, void *opaque);
 
 GAChannel *ga_channel_new(GAChannelMethod method, const char *path,
                           GAChannelCallback cb, void *opaque);
diff --git a/qga/main.c b/qga/main.c
index 2c551a6..2a20a96 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -115,7 +115,7 @@  static void quit_handler(int sig)
 }
 
 #ifndef _WIN32
-static gboolean register_signal_handlers(void)
+static bool register_signal_handlers(void)
 {
     struct sigaction sigact;
     int ret;
@@ -594,7 +594,7 @@  static void process_event(JSONMessageParser *parser, QList *tokens)
 }
 
 /* false return signals GAChannel to close the current client connection */
-static gboolean channel_event_cb(GIOCondition condition, void *data)
+static bool channel_event_cb(GIOCondition condition, void *data)
 {
     GAState *s = data;
     char buf[QGA_READ_COUNT_DEFAULT+1];
@@ -636,7 +636,7 @@  static gboolean channel_event_cb(GIOCondition condition, void *data)
     return true;
 }
 
-static gboolean channel_init(GAState *s, const char *method, const char *path)
+static bool channel_init(GAState *s, const char *method, const char *path)
 {
     GAChannelMethod channel_method;