[Xfce4-commits] <thunar:master> Use unsigned integer for idles and timers.

Nick Schermer noreply at xfce.org
Sun Nov 4 10:40:04 CET 2012


Updating branch refs/heads/master
         to 5c79330053c4b84cd8eadb06d54ca28edac4d893 (commit)
       from b73ec63839ecc39bd66afa3b9da7f74bbd8547ab (commit)

commit 5c79330053c4b84cd8eadb06d54ca28edac4d893
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Nov 4 10:23:05 2012 +0100

    Use unsigned integer for idles and timers.
    
    Could technically overflow.

 plugins/thunar-sendto-email/main.c |    2 +-
 thunar/thunar-launcher.c           |    2 +-
 thunar/thunar-location-button.c    |    2 +-
 thunar/thunar-renamer-progress.c   |   13 +++++------
 thunar/thunar-text-renderer.c      |    9 +++----
 thunar/thunar-tree-view.c          |   37 +++++++++++++++--------------------
 thunar/thunar-user.c               |    6 ++--
 thunar/thunar-window.c             |   10 ++++----
 thunarx/thunarx-provider-factory.c |    4 +-
 9 files changed, 39 insertions(+), 46 deletions(-)

diff --git a/plugins/thunar-sendto-email/main.c b/plugins/thunar-sendto-email/main.c
index c6e8f11..eea70f9 100644
--- a/plugins/thunar-sendto-email/main.c
+++ b/plugins/thunar-sendto-email/main.c
@@ -257,7 +257,7 @@ tse_progress (const gchar *working_directory,
   GtkWidget *vbox;
   gboolean   succeed = FALSE;
   GPid       pid;
-  gint       pulse_timer_id;
+  guint      pulse_timer_id;
   gint       watch_id;
   gint       response;
   gint       status;
diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c
index a155fa1..d1f5ead 100644
--- a/thunar/thunar-launcher.c
+++ b/thunar/thunar-launcher.c
@@ -151,7 +151,7 @@ struct _ThunarLauncher
 
   ThunarDeviceMonitor    *device_monitor;
   ThunarSendtoModel      *sendto_model;
-  gint                    sendto_idle_id;
+  guint                   sendto_idle_id;
 };
 
 struct _ThunarLauncherMountData
diff --git a/thunar/thunar-location-button.c b/thunar/thunar-location-button.c
index 37e493e..7f9cd0f 100644
--- a/thunar/thunar-location-button.c
+++ b/thunar/thunar-location-button.c
@@ -137,7 +137,7 @@ struct _ThunarLocationButton
   ThunarFileIconState file_icon_state;
   
   /* enter folders using DnD */
-  gint                enter_timeout_id;
+  guint               enter_timeout_id;
 
   /* drop support for the button */
   GList              *drop_file_list;
diff --git a/thunar/thunar-renamer-progress.c b/thunar/thunar-renamer-progress.c
index 8e3fa39..4e97120 100644
--- a/thunar/thunar-renamer-progress.c
+++ b/thunar/thunar-renamer-progress.c
@@ -57,7 +57,7 @@ struct _ThunarRenamerProgress
   gboolean     pairs_undo;  /* whether we're undoing previous changes */
 
   /* internal main loop for the _rename() method */
-  gint         next_idle_id;
+  guint        next_idle_id;
   GMainLoop   *next_idle_loop;
 };
 
@@ -85,8 +85,6 @@ thunar_renamer_progress_class_init (ThunarRenamerProgressClass *klass)
 static void
 thunar_renamer_progress_init (ThunarRenamerProgress *renamer_progress)
 {
-  renamer_progress->next_idle_id = -1;
-
   gtk_alignment_set (GTK_ALIGNMENT (renamer_progress), 0.5f, 0.5f, 1.0f, 0.0f);
 
   renamer_progress->bar = gtk_progress_bar_new ();
@@ -102,7 +100,7 @@ thunar_renamer_progress_finalize (GObject *object)
   ThunarRenamerProgress *renamer_progress = THUNAR_RENAMER_PROGRESS (object);
 
   /* make sure we're not finalized while the main loop is active */
-  _thunar_assert (renamer_progress->next_idle_id < 0);
+  _thunar_assert (renamer_progress->next_idle_id == 0);
   _thunar_assert (renamer_progress->next_idle_loop == NULL);
 
   /* release the pairs */
@@ -264,7 +262,7 @@ thunar_renamer_progress_next_idle (gpointer user_data)
 static void
 thunar_renamer_progress_next_idle_destroy (gpointer user_data)
 {
-  THUNAR_RENAMER_PROGRESS (user_data)->next_idle_id = -1;
+  THUNAR_RENAMER_PROGRESS (user_data)->next_idle_id = 0;
 }
 
 
@@ -337,7 +335,8 @@ thunar_renamer_progress_run (ThunarRenamerProgress *renamer_progress,
   _thunar_return_if_fail (THUNAR_IS_RENAMER_PROGRESS (renamer_progress));
 
   /* make sure we're not already renaming */
-  if (G_UNLIKELY (renamer_progress->next_idle_id >= 0 || renamer_progress->next_idle_loop != NULL))
+  if (G_UNLIKELY (renamer_progress->next_idle_id != 0
+      || renamer_progress->next_idle_loop != NULL))
     return;
 
   /* take an additional reference on the progress */
@@ -362,7 +361,7 @@ thunar_renamer_progress_run (ThunarRenamerProgress *renamer_progress,
   renamer_progress->next_idle_loop = NULL;
 
   /* be sure to cancel any pending idle source */
-  if (G_UNLIKELY (renamer_progress->next_idle_id >= 0))
+  if (G_UNLIKELY (renamer_progress->next_idle_id != 0))
     g_source_remove (renamer_progress->next_idle_id);
 
   /* release the list of completed items */
diff --git a/thunar/thunar-text-renderer.c b/thunar/thunar-text-renderer.c
index 9972641..ee12286 100644
--- a/thunar/thunar-text-renderer.c
+++ b/thunar/thunar-text-renderer.c
@@ -137,7 +137,7 @@ struct _ThunarTextRenderer
   /* cell editing support */
   GtkWidget      *entry;
   gboolean        entry_menu_active;
-  gint            entry_menu_popdown_timer_id;
+  guint           entry_menu_popdown_timer_id;
 };
 
 
@@ -279,7 +279,6 @@ static void
 thunar_text_renderer_init (ThunarTextRenderer *text_renderer)
 {
   text_renderer->wrap_width = -1;
-  text_renderer->entry_menu_popdown_timer_id = -1;
   text_renderer->alignment = PANGO_ALIGN_LEFT;
 }
 
@@ -794,7 +793,7 @@ thunar_text_renderer_populate_popup (GtkEntry           *entry,
                                      GtkMenu            *menu,
                                      ThunarTextRenderer *text_renderer)
 {
-  if (G_UNLIKELY (text_renderer->entry_menu_popdown_timer_id >= 0))
+  if (G_UNLIKELY (text_renderer->entry_menu_popdown_timer_id != 0))
     g_source_remove (text_renderer->entry_menu_popdown_timer_id);
 
   text_renderer->entry_menu_active = TRUE;
@@ -810,7 +809,7 @@ thunar_text_renderer_popup_unmap (GtkMenu            *menu,
 {
   text_renderer->entry_menu_active = FALSE;
 
-  if (G_LIKELY (text_renderer->entry_menu_popdown_timer_id < 0))
+  if (G_LIKELY (text_renderer->entry_menu_popdown_timer_id == 0))
     {
       text_renderer->entry_menu_popdown_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 500u, thunar_text_renderer_entry_menu_popdown_timer,
                                                                        text_renderer, thunar_text_renderer_entry_menu_popdown_timer_destroy);
@@ -840,7 +839,7 @@ thunar_text_renderer_entry_menu_popdown_timer (gpointer user_data)
 static void
 thunar_text_renderer_entry_menu_popdown_timer_destroy (gpointer user_data)
 {
-  THUNAR_TEXT_RENDERER (user_data)->entry_menu_popdown_timer_id = -1;
+  THUNAR_TEXT_RENDERER (user_data)->entry_menu_popdown_timer_id = 0;
 }
 
 
diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c
index 72428d5..0d87711 100644
--- a/thunar/thunar-tree-view.c
+++ b/thunar/thunar-tree-view.c
@@ -241,13 +241,13 @@ struct _ThunarTreeView
   gulong                  queue_resize_signal_id;
 
   /* set cursor to current directory idle source */
-  gint                    cursor_idle_id;
+  guint                   cursor_idle_id;
 
   /* autoscroll during drag timer source */
-  gint                    drag_scroll_timer_id;
+  guint                   drag_scroll_timer_id;
 
   /* expand drag dest row timer source */
-  gint                    expand_timer_id;
+  guint                   expand_timer_id;
 };
 
 enum
@@ -374,11 +374,6 @@ thunar_tree_view_init (ThunarTreeView *view)
   GtkTreeSelection  *selection;
   GtkCellRenderer   *renderer;
 
-  /* initialize the view internals */
-  view->cursor_idle_id = -1;
-  view->drag_scroll_timer_id = -1;
-  view->expand_timer_id = -1;
-
   /* grab a reference on the provider factory */
   view->provider_factory = thunarx_provider_factory_get_default ();
 
@@ -459,15 +454,15 @@ thunar_tree_view_finalize (GObject *object)
   g_signal_handler_disconnect (G_OBJECT (view->preferences), view->queue_resize_signal_id);
 
   /* be sure to cancel the cursor idle source */
-  if (G_UNLIKELY (view->cursor_idle_id >= 0))
+  if (G_UNLIKELY (view->cursor_idle_id != 0))
     g_source_remove (view->cursor_idle_id);
 
   /* cancel any running autoscroll timer */
-  if (G_LIKELY (view->drag_scroll_timer_id >= 0))
+  if (G_LIKELY (view->drag_scroll_timer_id != 0))
     g_source_remove (view->drag_scroll_timer_id);
 
   /* be sure to cancel the expand timer source */
-  if (G_UNLIKELY (view->expand_timer_id >= 0))
+  if (G_UNLIKELY (view->expand_timer_id != 0))
     g_source_remove (view->expand_timer_id);
 
   /* reset the current-directory property */
@@ -631,7 +626,7 @@ thunar_tree_view_set_current_directory (ThunarNavigator *navigator,
         }
 
       /* schedule an idle source to set the cursor to the current directory */
-      if (G_LIKELY (view->cursor_idle_id < 0))
+      if (G_LIKELY (view->cursor_idle_id == 0))
         view->cursor_idle_id = g_idle_add_full (G_PRIORITY_LOW, thunar_tree_view_cursor_idle, view, thunar_tree_view_cursor_idle_destroy);
 
       /* drop any existing "new-files" closure */
@@ -903,7 +898,7 @@ thunar_tree_view_drag_motion (GtkWidget      *widget,
     }
 
   /* start the drag autoscroll timer if not already running */
-  if (G_UNLIKELY (view->drag_scroll_timer_id < 0))
+  if (G_UNLIKELY (view->drag_scroll_timer_id == 0))
     {
       /* schedule the drag autoscroll timer */
       view->drag_scroll_timer_id = g_timeout_add_full (G_PRIORITY_LOW, 50, thunar_tree_view_drag_scroll_timer,
@@ -923,7 +918,7 @@ thunar_tree_view_drag_leave (GtkWidget      *widget,
   ThunarTreeView *view = THUNAR_TREE_VIEW (widget);
 
   /* cancel any running autoscroll timer */
-  if (G_LIKELY (view->drag_scroll_timer_id >= 0))
+  if (G_LIKELY (view->drag_scroll_timer_id != 0))
     g_source_remove (view->drag_scroll_timer_id);
 
   /* reset the "drop-file" of the icon renderer */
@@ -1036,7 +1031,7 @@ thunar_tree_view_test_expand_row (GtkTreeView *tree_view,
     }
 
   /* cancel the cursor idle source if not expandable */
-  if (!expandable && view->cursor_idle_id >= 0)
+  if (!expandable && view->cursor_idle_id != 0)
     g_source_remove (view->cursor_idle_id);
 
   return !expandable;
@@ -1399,7 +1394,7 @@ thunar_tree_view_get_dest_actions (ThunarTreeView *view,
   ThunarFile   *file = NULL;
 
   /* cancel any previously active expand timer */
-  if (G_LIKELY (view->expand_timer_id >= 0))
+  if (G_LIKELY (view->expand_timer_id != 0))
     g_source_remove (view->expand_timer_id);
 
   /* determine the path for x/y */
@@ -2429,7 +2424,7 @@ thunar_tree_view_cursor_idle (gpointer user_data)
 static void
 thunar_tree_view_cursor_idle_destroy (gpointer user_data)
 {
-  THUNAR_TREE_VIEW (user_data)->cursor_idle_id = -1;
+  THUNAR_TREE_VIEW (user_data)->cursor_idle_id = 0;
 }
 
 
@@ -2479,7 +2474,7 @@ thunar_tree_view_drag_scroll_timer (gpointer user_data)
                * if a path is expanded while scrolling through the view.
                * reschedule it if the drag dest path is still visible.
                */
-              if (G_UNLIKELY (view->expand_timer_id >= 0))
+              if (G_UNLIKELY (view->expand_timer_id != 0))
                 {
                   /* drop the current expand timer source */
                   g_source_remove (view->expand_timer_id);
@@ -2523,7 +2518,7 @@ thunar_tree_view_drag_scroll_timer (gpointer user_data)
 static void
 thunar_tree_view_drag_scroll_timer_destroy (gpointer user_data)
 {
-  THUNAR_TREE_VIEW (user_data)->drag_scroll_timer_id = -1;
+  THUNAR_TREE_VIEW (user_data)->drag_scroll_timer_id = 0;
 }
 
 
@@ -2537,7 +2532,7 @@ thunar_tree_view_expand_timer (gpointer user_data)
   GDK_THREADS_ENTER ();
 
   /* cancel the drag autoscroll timer when expanding a row */
-  if (G_UNLIKELY (view->drag_scroll_timer_id >= 0))
+  if (G_UNLIKELY (view->drag_scroll_timer_id != 0))
     g_source_remove (view->drag_scroll_timer_id);
 
   /* determine the drag dest row */
@@ -2559,7 +2554,7 @@ thunar_tree_view_expand_timer (gpointer user_data)
 static void
 thunar_tree_view_expand_timer_destroy (gpointer user_data)
 {
-  THUNAR_TREE_VIEW (user_data)->expand_timer_id = -1;
+  THUNAR_TREE_VIEW (user_data)->expand_timer_id = 0;
 }
 
 
diff --git a/thunar/thunar-user.c b/thunar/thunar-user.c
index 184e575..059cca9 100644
--- a/thunar/thunar-user.c
+++ b/thunar/thunar-user.c
@@ -484,7 +484,7 @@ struct _ThunarUserManager
   GHashTable *groups;
   GHashTable *users;
 
-  gint        flush_timer_id;
+  guint       flush_timer_id;
 };
 
 
@@ -534,7 +534,7 @@ thunar_user_manager_finalize (GObject *object)
   ThunarUserManager *manager = THUNAR_USER_MANAGER (object);
 
   /* stop the flush timer */
-  if (G_LIKELY (manager->flush_timer_id >= 0))
+  if (G_LIKELY (manager->flush_timer_id != 0))
     g_source_remove (manager->flush_timer_id);
 
   /* destroy the hash tables */
@@ -591,7 +591,7 @@ thunar_user_manager_flush_timer (gpointer user_data)
 static void
 thunar_user_manager_flush_timer_destroy (gpointer user_data)
 {
-  THUNAR_USER_MANAGER (user_data)->flush_timer_id = -1;
+  THUNAR_USER_MANAGER (user_data)->flush_timer_id = 0;
 }
 
 
diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index 8925f92..a2bd3c0 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -318,10 +318,10 @@ struct _ThunarWindow
   ThunarZoomLevel         zoom_level;
 
   /* menu merge idle source */
-  gint                    merge_idle_id;
+  guint                   merge_idle_id;
 
   /* support to remember window geometry */
-  gint                    save_geometry_timer_id;
+  guint                   save_geometry_timer_id;
 
   /* support to toggle side pane using F9,
    * see the toggle_sidepane() function.
@@ -1009,11 +1009,11 @@ thunar_window_dispose (GObject *object)
   ThunarWindow *window = THUNAR_WINDOW (object);
 
   /* destroy the save geometry timer source */
-  if (G_UNLIKELY (window->save_geometry_timer_id > 0))
+  if (G_UNLIKELY (window->save_geometry_timer_id != 0))
     g_source_remove (window->save_geometry_timer_id);
 
   /* destroy the merge idle source */
-  if (G_UNLIKELY (window->merge_idle_id > 0))
+  if (G_UNLIKELY (window->merge_idle_id != 0))
     g_source_remove (window->merge_idle_id);
 
   /* un-merge the custom preferences */
@@ -1367,7 +1367,7 @@ thunar_window_configure_event (GtkWidget         *widget,
   if (widget->allocation.width != event->width || widget->allocation.height != event->height)
     {
       /* drop any previous timer source */
-      if (window->save_geometry_timer_id > 0)
+      if (window->save_geometry_timer_id != 0)
         g_source_remove (window->save_geometry_timer_id);
 
       /* check if we should schedule another save timer */
diff --git a/thunarx/thunarx-provider-factory.c b/thunarx/thunarx-provider-factory.c
index 1b5d2a3..6d14103 100644
--- a/thunarx/thunarx-provider-factory.c
+++ b/thunarx/thunarx-provider-factory.c
@@ -63,7 +63,7 @@ struct _ThunarxProviderFactory
   ThunarxProviderInfo *infos;     /* provider types and cached provider references */
   gint                 n_infos;   /* number of items in the infos array */
 
-  gint                 timer_id;  /* GSource timer to cleanup cached providers */
+  guint                timer_id;  /* GSource timer to cleanup cached providers */
 };
 
 
@@ -101,7 +101,7 @@ thunarx_provider_factory_finalize (GObject *object)
   gint                    n;
 
   /* stop the "provider cache" cleanup timer */
-  if (G_LIKELY (factory->timer_id > 0))
+  if (G_LIKELY (factory->timer_id != 0))
     g_source_remove (factory->timer_id);
 
   /* release provider infos */


More information about the Xfce4-commits mailing list