]> Pileus Git - ~andy/gtk/blobdiff - gdk/quartz/gdkeventloop-quartz.c
Fix broken quartz build from df3e19b
[~andy/gtk] / gdk / quartz / gdkeventloop-quartz.c
index 4181a5de2498b247508c28433fcd1790f361f3f3..0339bea1744532111adb5f9173775a87adcfe465 100644 (file)
@@ -7,6 +7,7 @@
 #include <unistd.h>
 
 #include "gdkprivate-quartz.h"
+#include <gdk/gdkdisplayprivate.h>
 
 /* 
  * This file implementations integration between the GLib main loop and
@@ -616,14 +617,17 @@ gdk_event_prepare (GSource *source,
 {
   gboolean retval;
 
-  GDK_THREADS_ENTER ();
+  gdk_threads_enter ();
   
   *timeout = -1;
 
-  retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
-           _gdk_quartz_event_loop_check_pending ());
+  if (_gdk_display->event_pause_count > 0)
+    retval = FALSE;
+  else
+    retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
+              _gdk_quartz_event_loop_check_pending ());
 
-  GDK_THREADS_LEAVE ();
+  gdk_threads_leave ();
 
   return retval;
 }
@@ -633,7 +637,27 @@ gdk_event_check (GSource *source)
 {
   gboolean retval;
 
-  GDK_THREADS_ENTER ();
+  gdk_threads_enter ();
+
+  if (_gdk_display->event_pause_count > 0)
+    retval = FALSE;
+  else
+    retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
+              _gdk_quartz_event_loop_check_pending ());
+
+  gdk_threads_leave ();
+
+  return retval;
+}
+
+static gboolean
+gdk_event_dispatch (GSource     *source,
+                   GSourceFunc  callback,
+                   gpointer     user_data)
+{
+  GdkEvent *event;
+
+  gdk_threads_enter ();
 
   /* Refresh the autorelease pool if we're at the base CFRunLoop level
    * (indicated by current_loop_level) and the base g_main_loop level
@@ -650,23 +674,6 @@ gdk_event_check (GSource *source)
       autorelease_pool = [[NSAutoreleasePool alloc] init];
     }
 
-  retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
-           _gdk_quartz_event_loop_check_pending ());
-
-  GDK_THREADS_LEAVE ();
-
-  return retval;
-}
-
-static gboolean
-gdk_event_dispatch (GSource     *source,
-                   GSourceFunc  callback,
-                   gpointer     user_data)
-{
-  GdkEvent *event;
-
-  GDK_THREADS_ENTER ();
-
   _gdk_quartz_display_queue_events (_gdk_display);
 
   event = _gdk_event_unqueue (_gdk_display);
@@ -678,7 +685,7 @@ gdk_event_dispatch (GSource     *source,
       gdk_event_free (event);
     }
 
-  GDK_THREADS_LEAVE ();
+  gdk_threads_leave ();
 
   return TRUE;
 }
@@ -703,6 +710,10 @@ poll_func (GPollFD *ufds,
   NSDate *limit_date;
   gint n_ready;
 
+  static GPollFD *last_ufds;
+
+  last_ufds = ufds;
+
   n_ready = select_thread_start_poll (ufds, nfds, timeout_);
   if (n_ready > 0)
     timeout_ = 0;
@@ -721,7 +732,16 @@ poll_func (GPollFD *ufds,
                                dequeue: YES];
   getting_events--;
 
-  if (n_ready < 0)
+  /* We check if last_ufds did not change since the time this function was
+   * called. It is possible that a recursive main loop (and thus recursive
+   * invocation of this poll function) is triggered while in
+   * nextEventMatchingMask:. If during that time new fds are added,
+   * the cached fds array might be replaced in g_main_context_iterate().
+   * So, we should avoid accessing the old fd array (still pointed at by
+   * ufds) here in that case, since it might have been freed. We avoid this
+   * by not calling the collect stage.
+   */
+  if (last_ufds == ufds && n_ready < 0)
     n_ready = select_thread_collect_poll (ufds, nfds);
       
   if (event &&