2009-04-08 Marcus Brinkmann <marcus@g10code.de>
authorMarcus Brinkmann <mb@g10code.com>
Wed, 8 Apr 2009 18:00:03 +0000 (18:00 +0000)
committerMarcus Brinkmann <mb@g10code.com>
Wed, 8 Apr 2009 18:00:03 +0000 (18:00 +0000)
* Makefile.am (EXTRA_DIST): Remove glib-2.9.2 patches and add
patches/glib-2.20.0/01-socket.patch.
* patches/glib-2.12.12/01-socket.patch: New file.
* patches/glib-2.9.2-wk1/01-giowin32.patch,
patches/glib-2.9.2-wk1/02-gspawn-w32.patch,
patches/glib-2.9.2-wk1/03-gspawn-w32-fixup.patch,
patches/glib-2.9.2-wk1/04-gspawn-w32-buffering.patch: Removed.

patches/glib-2.9.2-wk1/01-giowin32.patch [deleted file]
patches/glib-2.9.2-wk1/02-gspawn-w32.patch [deleted file]
patches/glib-2.9.2-wk1/03-gspawn-w32-fixup.patch [deleted file]
patches/glib-2.9.2-wk1/04-gspawn-w32-buffering.patch [deleted file]

diff --git a/patches/glib-2.9.2-wk1/01-giowin32.patch b/patches/glib-2.9.2-wk1/01-giowin32.patch
deleted file mode 100755 (executable)
index e0c00a7..0000000
+++ /dev/null
@@ -1,353 +0,0 @@
-#! /bin/sh
-patch -p1 -f $* < $0
-exit $?
-
-Implement write support for fd I/O channels in glib on W32 targets.
-
-(no changelog yet)
-
-diff -rup glib-2.8.4-old/glib/giowin32.c glib-2.8.4/glib/giowin32.c
---- glib-2.8.4-old/glib/giowin32.c     2005-11-08 09:35:50.000000000 +0100
-+++ glib-2.8.4/glib/giowin32.c 2006-01-03 14:51:04.000000000 +0100
-@@ -90,7 +90,8 @@ struct _GIOWin32Channel {
-   gushort revents;
-   /* Following fields used by fd channels for input */
--  
-+  int direction;
-+
-   /* Data is kept in a circular buffer. To be able to distinguish between
-    * empty and full buffer, we cannot fill it completely, but have to
-    * leave a one character gap.
-@@ -376,6 +377,7 @@ create_events (GIOWin32Channel *channel)
-     }
- }
-+
- static unsigned __stdcall
- read_thread (void *parameter)
- {
-@@ -392,6 +394,7 @@ read_thread (void *parameter)
-            (guint) channel->data_avail_event,
-            (guint) channel->space_avail_event);
-   
-+  channel->direction = 0;
-   channel->buffer = g_malloc (BUFFER_SIZE);
-   channel->rdp = channel->wrp = 0;
-   channel->running = TRUE;
-@@ -437,7 +440,12 @@ read_thread (void *parameter)
-       UNLOCK (channel->mutex);
-       nbytes = read (channel->fd, buffer, nbytes);
--      
-+      //      {
-+      //      DWORD nb;
-+      //      ReadFile (_get_osfhandle (channel->fd), buffer, nbytes, &nb, NULL);
-+      //      nbytes = nb;
-+      //      }
-+
-       LOCK (channel->mutex);
-       channel->revents = G_IO_IN;
-@@ -486,6 +494,124 @@ read_thread (void *parameter)
-   return 0;
- }
-+
-+static unsigned __stdcall
-+write_thread (void *parameter)
-+{
-+  GIOWin32Channel *channel = parameter;
-+  guchar *buffer;
-+  guint nbytes;
-+
-+  g_io_channel_ref ((GIOChannel *)channel);
-+
-+  if (channel->debug)
-+    g_print ("write_thread %#x: start fd:%d, data_avail:%#x space_avail:%#x\n",
-+           channel->thread_id,
-+           channel->fd,
-+           (guint) channel->data_avail_event,
-+           (guint) channel->space_avail_event);
-+  
-+  channel->direction = 1;
-+  channel->buffer = g_malloc (BUFFER_SIZE);
-+  channel->rdp = channel->wrp = 0;
-+  channel->running = TRUE;
-+
-+  SetEvent (channel->space_avail_event);
-+  
-+  LOCK (channel->mutex);
-+  while (channel->running || channel->rdp != channel->wrp)
-+    {
-+      if (channel->debug)
-+      g_print ("write_thread %#x: rdp=%d, wrp=%d\n",
-+               channel->thread_id, channel->rdp, channel->wrp);
-+      if (channel->wrp == channel->rdp)
-+      {
-+        /* Buffer is empty.  */
-+        if (channel->debug)
-+          g_print ("write_thread %#x: resetting space_avail\n",
-+                   channel->thread_id);
-+        ResetEvent (channel->space_avail_event);
-+        if (channel->debug)
-+          g_print ("write_thread %#x: waiting for data\n",
-+                   channel->thread_id);
-+        channel->revents = G_IO_OUT;
-+        SetEvent (channel->data_avail_event);
-+        UNLOCK (channel->mutex);
-+        WaitForSingleObject (channel->space_avail_event, INFINITE);
-+
-+        LOCK (channel->mutex);
-+        if (channel->rdp == channel->wrp)
-+          break;
-+
-+        if (channel->debug)
-+          g_print ("write_thread %#x: rdp=%d, wrp=%d\n",
-+                   channel->thread_id, channel->rdp, channel->wrp);
-+      }
-+      
-+      buffer = channel->buffer + channel->rdp;
-+      if (channel->rdp < channel->wrp)
-+      nbytes = channel->wrp - channel->rdp;
-+      else
-+      nbytes = BUFFER_SIZE - channel->rdp;
-+
-+      if (channel->debug)
-+      g_print ("write_thread %#x: calling write() for %d bytes\n",
-+               channel->thread_id, nbytes);
-+
-+      UNLOCK (channel->mutex);
-+      nbytes = write (channel->fd, buffer, nbytes);
-+      //      {
-+      //      DWORD nb;
-+      //      WriteFile (_get_osfhandle (channel->fd), buffer, nbytes, &nb, NULL);
-+      //      nbytes = nb;
-+      //      }
-+
-+      LOCK (channel->mutex);
-+
-+      if (channel->debug)
-+      g_print ("write_thread %#x: write(%i) returned %d, rdp=%d, wrp=%d\n",
-+               channel->thread_id, channel->fd, nbytes, channel->rdp, channel->wrp);
-+
-+      channel->revents = 0;
-+      if (nbytes > 0)
-+      channel->revents |= G_IO_OUT;
-+      else if (nbytes <= 0)
-+      channel->revents |= G_IO_ERR;
-+
-+      channel->rdp = (channel->rdp + nbytes) % BUFFER_SIZE;
-+
-+      if (nbytes <= 0)
-+      break;
-+
-+      if (channel->debug)
-+      g_print ("write_thread: setting data_avail for thread %#x\n",
-+               channel->thread_id);
-+      SetEvent (channel->data_avail_event);
-+    }
-+  
-+  channel->running = FALSE;
-+  if (channel->needs_close)
-+    {
-+      if (channel->debug)
-+      g_print ("write_thread %#x: channel fd %d needs closing\n",
-+               channel->thread_id, channel->fd);
-+      close (channel->fd);
-+      channel->fd = -1;
-+    }
-+
-+  UNLOCK (channel->mutex);
-+  
-+  g_io_channel_unref ((GIOChannel *)channel);
-+  
-+  /* No need to call _endthreadex(), the actual thread starter routine
-+   * in MSVCRT (see crt/src/threadex.c:_threadstartex) calls
-+   * _endthreadex() for us.
-+   */
-+
-+  return 0;
-+}
-+
-+
- static void
- create_thread (GIOWin32Channel     *channel,
-              GIOCondition         condition,
-@@ -502,6 +628,8 @@ create_thread (GIOWin32Channel     *chan
-     g_warning (G_STRLOC ": Error closing thread handle: %s\n",
-              g_win32_error_message (GetLastError ()));
-+  SetThreadPriority (thread_handle, THREAD_PRIORITY_HIGHEST);
-+
-   WaitForSingleObject (channel->space_avail_event, INFINITE);
- }
-@@ -575,6 +703,79 @@ buffer_read (GIOWin32Channel *channel,
-   return (*bytes_read > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF;
- }
-+static GIOStatus
-+buffer_write (GIOWin32Channel *channel,
-+            const guchar    *dest,
-+            gsize            count,
-+            gsize           *bytes_written,
-+            GError         **err)
-+{
-+  guint nbytes;
-+  guint left = count;
-+  
-+  LOCK (channel->mutex);
-+  if (channel->debug)
-+    g_print ("buffer_write: writing to thread %#x %d bytes, rdp=%d, wrp=%d\n",
-+           channel->thread_id, count, channel->rdp, channel->wrp);
-+  
-+  if ((channel->wrp + 1) % BUFFER_SIZE == channel->rdp)
-+    {
-+      /* Buffer is full */
-+      if (channel->debug)
-+      g_print ("buffer_write: tid %#x: resetting data_avail\n",
-+               channel->thread_id);
-+      ResetEvent (channel->data_avail_event);
-+      if (channel->debug)
-+      g_print ("buffer_write: tid %#x: waiting for space\n",
-+               channel->thread_id);
-+      UNLOCK (channel->mutex);
-+      WaitForSingleObject (channel->data_avail_event, INFINITE);
-+      LOCK (channel->mutex);
-+      if (channel->debug)
-+      g_print ("buffer_write: tid %#x: rdp=%d, wrp=%d\n",
-+               channel->thread_id, channel->rdp, channel->wrp);
-+    }
-+   
-+
-+  /* Always leave at least one byte unused gap to be able to
-+     distinguish between the full and empty condition.  */
-+  nbytes = MIN ((channel->rdp + BUFFER_SIZE - channel->wrp - 1) % BUFFER_SIZE,
-+              BUFFER_SIZE - channel->wrp);
-+
-+  UNLOCK (channel->mutex);
-+  nbytes = MIN (left, nbytes);
-+  if (channel->debug)
-+    g_print ("buffer_write: tid %#x: writing %d bytes\n",
-+           channel->thread_id, nbytes);
-+  memcpy (channel->buffer + channel->wrp, dest, nbytes);
-+  dest += nbytes;
-+  left -= nbytes;
-+  LOCK (channel->mutex);
-+
-+  channel->wrp = (channel->wrp + nbytes) % BUFFER_SIZE;
-+  if (channel->debug)
-+    g_print ("buffer_write: tid %#x: rdp=%d, wrp=%d, setting space_avail\n",
-+           channel->thread_id, channel->rdp, channel->wrp);
-+  SetEvent (channel->space_avail_event);
-+
-+  if ((channel->wrp + 1) % BUFFER_SIZE == channel->rdp)
-+    {
-+      /* Buffer is full */
-+      if (channel->debug)
-+      g_print ("buffer_write: tid %#x: resetting data_avail\n",
-+               channel->thread_id);
-+      ResetEvent (channel->data_avail_event);
-+    }
-+
-+  UNLOCK (channel->mutex);
-+  
-+  /* We have no way to indicate any errors form the actual
-+     write() call in the writer thread. Should we have?  */
-+  *bytes_written = count - left;
-+  return (*bytes_written > 0) ? G_IO_STATUS_NORMAL : G_IO_STATUS_EOF;
-+}
-+
-+
- static gboolean
- g_io_win32_prepare (GSource *source,
-                   gint    *timeout)
-@@ -601,13 +802,27 @@ g_io_win32_prepare (GSource *source,
-                condition_to_string (channel->revents));
-       
-       LOCK (channel->mutex);
--      if (channel->running && channel->wrp == channel->rdp)
-+      if (channel->running)
-       {
--        if (channel->debug)
--          g_print ("g_io_win32_prepare: for thread %#x, setting channel->revents = 0\n",
--                   channel->thread_id);
--        channel->revents = 0;
-+        if (channel->direction == 0 && channel->wrp == channel->rdp)
-+          {
-+            if (channel->debug)
-+              g_print ("g_io_win32_prepare: for thread %#x, setting channel->revents = 0\n",
-+                       channel->thread_id);
-+            channel->revents = 0;
-+          }
-       }
-+      else
-+      {
-+        if (channel->direction == 1
-+            && (channel->wrp + 1) % BUFFER_SIZE == channel->rdp)
-+          {
-+            if (channel->debug)
-+              g_print ("g_io_win32_prepare: for thread %#x, setting channel->revents = %i\n",
-+                       channel->thread_id, 0);
-+            channel->revents = 0;
-+          }
-+      }         
-       UNLOCK (channel->mutex);
-       break;
-@@ -965,6 +1180,12 @@ g_io_win32_fd_write (GIOChannel  *channe
-   GIOWin32Channel *win32_channel = (GIOWin32Channel *)channel;
-   gint result;
-   
-+  if (win32_channel->thread_id)
-+    {
-+      return buffer_write (win32_channel, buf, count, bytes_written, err);
-+    }
-+
-+
-   result = write (win32_channel->fd, buf, count);
-   if (win32_channel->debug)
-     g_print ("g_io_win32_fd_write: fd=%d count=%d => %d\n",
-@@ -1061,7 +1282,10 @@ g_io_win32_fd_close (GIOChannel *channel
-                win32_channel->thread_id, win32_channel->fd);
-       win32_channel->running = FALSE;
-       win32_channel->needs_close = TRUE;
--      SetEvent (win32_channel->data_avail_event);
-+      if (win32_channel->direction == 0)
-+      SetEvent (win32_channel->data_avail_event);
-+      else
-+      SetEvent (win32_channel->space_avail_event);
-     }
-   else
-     {
-@@ -1105,7 +1329,12 @@ g_io_win32_fd_create_watch (GIOChannel  
-   LOCK (win32_channel->mutex);
-   if (win32_channel->thread_id == 0)
--    create_thread (win32_channel, condition, read_thread);
-+    {
-+      if (condition & G_IO_IN)
-+      create_thread (win32_channel, condition, read_thread);
-+      else
-+      create_thread (win32_channel, condition, write_thread);
-+    }
-   g_source_add_poll (source, &watch->pollfd);
-   UNLOCK (win32_channel->mutex);
-@@ -1715,8 +1944,13 @@ g_io_channel_win32_make_pollfd (GIOChann
-       fd->fd = (gint) win32_channel->data_avail_event;
--      if (win32_channel->thread_id == 0 && (condition & G_IO_IN))
--      create_thread (win32_channel, condition, read_thread);
-+      if (win32_channel->thread_id == 0)
-+      {
-+        if (condition & G_IO_IN)
-+          create_thread (win32_channel, condition, read_thread);
-+        else
-+          create_thread (win32_channel, condition, write_thread);
-+      }
-       break;
-     case G_IO_WIN32_SOCKET:
diff --git a/patches/glib-2.9.2-wk1/02-gspawn-w32.patch b/patches/glib-2.9.2-wk1/02-gspawn-w32.patch
deleted file mode 100755 (executable)
index ef09310..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#! /bin/sh
-patch -p1 -f $* < $0
-exit $?
-
-Fix calling of the spawn helper for W32.
-
-2006-01-12  Werner Koch  <wk@g10code.com>
-
-       * glib/gspawn-win32.c (do_spawn_with_pipes): First try to load the
-       helper from the module's directory.
-
-
-diff -upr glib-2.9.2-wk1/glib/gspawn-win32.c glib/glib/gspawn-win32.c
---- glib-2.9.2-wk1/glib/gspawn-win32.c 2005-09-07 12:10:49.000000000 +0200
-+++ glib/glib/gspawn-win32.c   2006-01-13 09:14:48.000000000 +0100
-@@ -632,6 +632,7 @@ do_spawn_with_pipes (gint               
-   GError *conv_error = NULL;
-   gint conv_error_index;
-   gchar *helper_process;
-+  gchar *helper_process_buf = NULL;
-   CONSOLE_CURSOR_INFO cursor_info;
-   
-   SETUP_DEBUG();
-@@ -678,6 +679,23 @@ do_spawn_with_pipes (gint               
-     helper_process = HELPER_PROCESS "-console.exe";
-   else
-     helper_process = HELPER_PROCESS ".exe";
-+
-+  /* We better check whether the helper process is available in the
-+     same directory as this library.  Only if this is not the case we
-+     try it without a path and hope that it can be found n PATH. */
-+  helper_process_buf = g_malloc (MAX_PATH + 50 + strlen (helper_process));
-+  if ( GetModuleFileNameA (0, helper_process_buf, MAX_PATH + 50) )
-+    {
-+      char *p = strrchr (helper_process_buf, '\\');
-+      if (!p)
-+        p = helper_process_buf;
-+      else
-+        p++;
-+      strcpy (p, helper_process);
-+      if (!g_access (helper_process_buf, X_OK))
-+        helper_process = helper_process_buf; /* Yes, use that one. */
-+    }
-+
-   new_argv[0] = helper_process;
-   _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_pipe[1]);
-   new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT];
-@@ -944,6 +962,7 @@ do_spawn_with_pipes (gint               
-   if (rc != -1)
-     CloseHandle ((HANDLE) rc);
-   
-+  g_free (helper_process_buf);
-   return TRUE;
-  cleanup_and_fail:
-@@ -965,6 +984,7 @@ do_spawn_with_pipes (gint               
-     close (stderr_pipe[0]);
-   if (stderr_pipe[1] != -1)
-     close (stderr_pipe[1]);
-+  g_free (helper_process_buf);
-   return FALSE;
- }
-
-
-
-
-
diff --git a/patches/glib-2.9.2-wk1/03-gspawn-w32-fixup.patch b/patches/glib-2.9.2-wk1/03-gspawn-w32-fixup.patch
deleted file mode 100755 (executable)
index 2445974..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-#! /bin/sh
-patch -p1 -f $* < $0
-exit $?
-
-This patch is needed to complete 02-gspawn-w32.patch by Werner: When
-the complete path is used, it may contain spaces, and thus it needs to
-be quoted.
-
-2006-05-29  Marcus Brinkmann  <marcus@g10code.com>
-
-       * glib/gspawn-win32.c (do_spawn_with_pipes): Protect the first
-       argument by quotes.
-
-diff -ru glib-2.9.2-wk1-orig/glib/gspawn-win32.c glib-2.9.2-wk1/glib/gspawn-win32.c
---- glib-2.9.2-wk1-orig/glib/gspawn-win32.c    2006-05-29 00:12:10.000000000 +0200
-+++ glib-2.9.2-wk1/glib/gspawn-win32.c 2006-05-29 00:13:16.000000000 +0200
-@@ -696,7 +696,7 @@
-         helper_process = helper_process_buf; /* Yes, use that one. */
-     }
--  new_argv[0] = helper_process;
-+  new_argv[0] = protect_argv_string (helper_process);
-   _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_pipe[1]);
-   new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT];
-   
-@@ -800,6 +800,7 @@
-         g_error_free (conv_error);
-         g_strfreev (protected_argv);
-         g_free (new_argv[ARG_WORKING_DIRECTORY]);
-+        g_free (new_argv[0]);
-         g_free (new_argv);
-         g_free (whelper);
-         
-@@ -814,6 +815,7 @@
-         g_error_free (conv_error);
-         g_strfreev (protected_argv);
-         g_free (new_argv[ARG_WORKING_DIRECTORY]);
-+        g_free (new_argv[0]);
-         g_free (new_argv);
-         g_free (whelper);
-         g_strfreev ((gchar **) wargv);
-@@ -855,6 +857,7 @@
-         g_error_free (conv_error);
-         g_strfreev (protected_argv);
-         g_free (new_argv[ARG_WORKING_DIRECTORY]);
-+        g_free (new_argv[0]);
-         g_free (new_argv);
-         
-         return FALSE;
-@@ -868,6 +871,7 @@
-         g_error_free (conv_error);
-         g_strfreev (protected_argv);
-         g_free (new_argv[ARG_WORKING_DIRECTORY]);
-+        g_free (new_argv[0]);
-         g_free (new_argv);
-         g_strfreev (cpargv);
-         
-@@ -899,6 +903,7 @@
-   g_strfreev (protected_argv);
-   g_free (new_argv[ARG_WORKING_DIRECTORY]);
-+  g_free (new_argv[0]);
-   g_free (new_argv);
-   /* Check if gspawn-win32-helper couldn't be run */
diff --git a/patches/glib-2.9.2-wk1/04-gspawn-w32-buffering.patch b/patches/glib-2.9.2-wk1/04-gspawn-w32-buffering.patch
deleted file mode 100755 (executable)
index e34ceba..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-#! /bin/sh
-patch -p1 -f $* < $0
-exit $?
-
-2006-01-01  Tor Lillqvist  <tml@novell.com>
-
-       * glib/gspawn-win32.c (g_spawn_sync_utf8): Set the GIOChannels for
-       stdout and stderr to unbuffered. Otherwise the giochannel layer
-       will try to read from them regardless whether the
-       g_io_channel_win32_poll() call here has indicated
-       readability or not. (#325310)
-
---- glib-2.9.2-wk1/glib/gspawn-win32.c 2006-05-28 21:34:46.000000000 +0200
-+++ glib/glib/gspawn-win32.c   2006-05-28 21:34:55.000000000 +0200
-@@ -1058,9 +1035,12 @@
-       outstr = g_string_new (NULL);
-       outchannel = g_io_channel_win32_new_fd (outpipe);
-       g_io_channel_set_encoding (outchannel, NULL, NULL);
-+      g_io_channel_set_buffered (outchannel, FALSE);
-       g_io_channel_win32_make_pollfd (outchannel,
-                                     G_IO_IN | G_IO_ERR | G_IO_HUP,
-                                     &outfd);
-+      if (debug)
-+      g_print ("outfd=%x\n", outfd.fd);
-     }
-       
-   if (errpipe >= 0)
-@@ -1068,9 +1048,12 @@
-       errstr = g_string_new (NULL);
-       errchannel = g_io_channel_win32_new_fd (errpipe);
-       g_io_channel_set_encoding (errchannel, NULL, NULL);
-+      g_io_channel_set_buffered (errchannel, FALSE);
-       g_io_channel_win32_make_pollfd (errchannel,
-                                     G_IO_IN | G_IO_ERR | G_IO_HUP,
-                                     &errfd);
-+      if (debug)
-+      g_print ("errfd=%x\n", errfd.fd);
-     }
-   /* Read data until we get EOF on all pipes. */