Subject: Re: bug#14569: 24.3.50; bootstrap fails on Cygwin

From: Ken Brown <[email-masked]>
Date: Tue, 11 Jun 2013 15:26:56 -0400

On 6/11/2013 2:50 PM, Paul Eggert wrote:
> On 06/11/13 09:58, Eli Zaretskii wrote:
>> Can you find out (by looking at the glib sources) when and why would
>> g_spawn_close_pid call 'abort'?  It might give us some clues.
>
> On POSIX platforms, g_spawn_close_pid does nothing.
> So apparently glib is compiled for Windows (i.e.,
> glib/gspawn.c is not being compiled, but glib/gspawn-win32.c
> is being compiled instead.

No, this is not the case.  I just replicated the glib build to make 
sure.  Cygwin is a POSIX platform, to the extent possible.

> The Emacs code that tickles gnulib is written this way:
>
> #if defined HAVE_GLIB && !defined WINDOWSNT
>        /* Tickle glib's child-handling code.  Ask glib to wait for Emacs itself;
> 	 this should always fail, but is enough to initialize glib's
> 	 private SIGCHLD handler.  */
>        g_source_unref (g_child_watch_source_new (getpid ()));
> #endif
>
> I did notice one problem: the code previously invoked
> g_child_watch_source_new (0), which is not safe if Emacs
> has already forked -- perhaps Cygwin was doing that?
> So I changed it to g_child_watch_source_new (getpid ())
> in trunk bzr 112929.
>
> Another thought is that there may be a mismatch between
> glib builds.  Since WINDOWSNT is not defined for Cygwin builds,
> a Cygwin Emacs will call g_child_watch_source_new.  My reading of
> the bleeding-edge glib source code is that a Cygwin glib should call
> waitpid and mess with the SIGCHLD handler, just as a
> POSIX glib would, so the above Emacs code is correct.
> But if you're building under Cygwin and linking with
> a mingw glib, the above code may well run into problems.
> Is this a possibility that we should worry about?

No.  This does not happen.  The Cygwin glib maintainer takes pains to 
patch the source if necessary to make sure that Cygwin is not treated 
like Windows.  See, for instance, the attached patch that is used in the 
Cygwin build.

Ken

--- origsrc/glib-2.27.2/configure.ac	2010-10-29 21:36:51.000000000 -0500
+++ src/glib-2.27.2/configure.ac	2010-11-04 14:53:53.616433900 -0500
@@ -1855,7 +1855,7 @@ dnl ************************************
 
 AC_MSG_CHECKING(for platform-dependent source)
 case "$host" in
-  *-*-cygwin*|*-*-mingw*)
+  *-*-mingw*)
     PLATFORMDEP=gwin32.lo
     ;;
   *)
@@ -2696,9 +2696,6 @@ dnl *** Win32 API libs ***
 dnl **********************
 
 case $host in
-  *-*-cygwin*)
-	G_LIBS_EXTRA="-luser32 -lkernel32"
-    ;;
   *-*-mingw*)
 	G_LIBS_EXTRA="-lws2_32 -lole32"
     ;;
--- origsrc/glib-2.32.1/docs/reference/gio/Makefile.am	2012-03-11 19:42:39.000000000 -0500
+++ src/glib-2.32.1/docs/reference/gio/Makefile.am	2012-04-30 04:02:06.244723100 -0500
@@ -77,6 +77,8 @@ IGNORE_HFILES = \
 	gunixvolume.h			\
 	gunixvolumemonitor.h		\
 	gwin32appinfo.h			\
+	gwin32inputstream.h		\
+	gwin32outputstream.h		\
 	gwin32mount.h			\
 	gwin32resolver.h		\
 	gwin32volumemonitor.h
--- origsrc/glib-2.32.2/gio/giomodule-priv.h	2012-04-30 11:24:02.000000000 -0500
+++ src/glib-2.32.2/gio/giomodule-priv.h	2012-05-01 00:33:18.725235600 -0500
@@ -35,7 +35,7 @@ gpointer _g_io_module_get_default (const
 				   const gchar         *envvar,
 				   GIOModuleVerifyFunc  verify_func);
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 void *_g_io_win32_get_module (void);
 #endif
 
--- origsrc/glib-2.27.2/gio/giomodule.c	2010-10-16 22:31:23.000000000 -0500
+++ src/glib-2.27.2/gio/giomodule.c	2010-11-04 14:53:53.616433900 -0500
@@ -478,7 +478,7 @@ extern GType _g_winhttp_vfs_get_type (vo
 
 extern GType _g_dummy_proxy_resolver_get_type (void);
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 
 #include <windows.h>
 
--- origsrc/glib-2.27.2/gio/tests/live-g-file.c	2010-07-09 06:23:33.000000000 -0500
+++ src/glib-2.27.2/gio/tests/live-g-file.c	2010-11-04 14:53:53.632033900 -0500
@@ -1148,7 +1148,7 @@ main (int argc, char *argv[])
 	  write_test = TRUE;
 	  only_create_struct = FALSE;
 	  target_path = DEFAULT_TEST_DIR;
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 	  posix_compat = FALSE;
 #else
 	  posix_compat = TRUE;
--- origsrc/glib-2.32.1/glib/gatomic.c	2012-03-11 19:42:41.000000000 -0500
+++ src/glib-2.32.1/glib/gatomic.c	2012-04-30 02:16:33.314500200 -0500
@@ -464,7 +464,7 @@ gsize
   return g_atomic_pointer_xor ((volatile gpointer *) atomic, val);
 }
 
-#elif defined (G_PLATFORM_WIN32)
+#elif defined (G_OS_WIN32)
 
 #include <windows.h>
 #if !defined(_M_AMD64) && !defined (_M_IA64) && !defined(_M_X64)
--- origsrc/glib-2.32.1/glib/gcharset.c	2012-03-11 19:42:41.000000000 -0500
+++ src/glib-2.32.1/glib/gcharset.c	2012-04-30 02:17:01.563115900 -0500
@@ -496,7 +496,7 @@ guess_category_value (const gchar *categ
   if ((retval != NULL) && (retval[0] != '\0'))
     return retval;
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
   /* g_win32_getlocale() first checks for LC_ALL, LC_MESSAGES and
    * LANG, which we already did above. Oh well. The main point of
    * calling g_win32_getlocale() is to get the thread's locale as used
--- origsrc/glib-2.27.2/glib/gconvert.c	2010-09-13 08:40:53.000000000 -0500
+++ src/glib-2.27.2/glib/gconvert.c	2010-11-04 14:53:53.647634000 -0500
@@ -33,9 +33,6 @@
 
 #ifdef G_OS_WIN32
 #include "win_iconv.c"
-#endif
-
-#ifdef G_PLATFORM_WIN32
 #define STRICT
 #include <windows.h>
 #undef STRICT
@@ -1263,7 +1260,7 @@ g_locale_from_utf8 (const gchar *utf8str
 		      charset, "UTF-8", bytes_read, bytes_written, error);
 }
 
-#ifndef G_PLATFORM_WIN32
+#ifndef G_OS_WIN32
 
 typedef struct _GFilenameCharsetCache GFilenameCharsetCache;
 
@@ -1379,7 +1376,7 @@ g_get_filename_charsets (G_CONST_RETURN
   return cache->is_utf8;
 }
 
-#else /* G_PLATFORM_WIN32 */
+#else /* G_OS_WIN32 */
 
 gboolean
 g_get_filename_charsets (G_CONST_RETURN gchar ***filename_charsets) 
@@ -1408,7 +1405,7 @@ g_get_filename_charsets (G_CONST_RETURN
 #endif
 }
 
-#endif /* G_PLATFORM_WIN32 */
+#endif /* G_OS_WIN32 */
 
 static gboolean
 get_filename_charset (const gchar **filename_charset)
--- origsrc/glib-2.32.1/glib/gfileutils.c	2012-03-11 19:42:41.000000000 -0500
+++ src/glib-2.32.1/glib/gfileutils.c	2012-04-30 02:17:19.313131200 -0500
@@ -2176,7 +2176,7 @@ g_path_skip_root (const gchar *file_name
 {
   g_return_val_if_fail (file_name != NULL, NULL);
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
   /* Skip \\server\share or //server/share */
   if (G_IS_DIR_SEPARATOR (file_name[0]) &&
       G_IS_DIR_SEPARATOR (file_name[1]) &&
@@ -2186,7 +2186,6 @@ g_path_skip_root (const gchar *file_name
       gchar *p;
       p = strchr (file_name + 2, G_DIR_SEPARATOR);
 
-#ifdef G_OS_WIN32
       {
         gchar *q;
 
@@ -2194,7 +2193,6 @@ g_path_skip_root (const gchar *file_name
         if (p == NULL || (q != NULL && q < p))
         p = q;
       }
-#endif
 
       if (p && p > file_name + 2 && p[1])
         {
--- origsrc/glib-2.27.2/glib/glib.h	2010-09-17 17:01:03.000000000 -0500
+++ src/glib-2.27.2/glib/glib.h	2010-11-04 14:53:53.647634000 -0500
@@ -90,7 +90,7 @@
 #include <glib/gvariant.h>
 #include <glib/gversion.h>
 #include <glib/gversionmacros.h>
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 #include <glib/gwin32.h>
 #endif
 
--- origsrc/glib-2.27.2/glib/gutf8.c	2010-09-04 22:39:27.000000000 -0500
+++ src/glib-2.27.2/glib/gutf8.c	2010-11-04 14:53:53.663234000 -0500
@@ -27,7 +27,7 @@
 #endif
 #include <string.h>
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 #include <stdio.h>
 #define STRICT
 #include <windows.h>
--- origsrc/glib-2.32.1/glib/gutils.c	2012-03-11 19:42:42.000000000 -0500
+++ src/glib-2.32.1/glib/gutils.c	2012-04-30 02:13:18.139336800 -0500
@@ -71,7 +71,7 @@
 #include "garray.h"
 #include "glibintl.h"
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 #include "gconvert.h"
 #include "gwin32.h"
 #endif
@@ -85,16 +85,13 @@
  * These are portable utility functions.
  */
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 #  include <windows.h>
 #  ifndef GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
 #    define GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT 2
 #    define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 4
 #  endif
 #  include <lmcons.h>		/* For UNLEN */
-#endif /* G_PLATFORM_WIN32 */
-
-#ifdef G_OS_WIN32
 #  include <direct.h>
 #  include <shlobj.h>
    /* older SDK (e.g. msvc 5.0) does not have these*/
@@ -130,7 +127,7 @@
 #include <langinfo.h>
 #endif
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 
 gchar *
 _glib_get_dll_directory (void)
--- origsrc/glib-2.27.2/glib/gutils.h	2010-10-29 21:36:52.000000000 -0500
+++ src/glib-2.27.2/glib/gutils.h	2010-11-04 14:53:53.678834000 -0500
@@ -458,7 +458,7 @@ G_END_DECLS
  * On non-Windows platforms, expands to nothing.
  */
 
-#ifndef G_PLATFORM_WIN32
+#ifndef G_OS_WIN32
 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
 #else
 # define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)			\
@@ -486,6 +486,6 @@ DllMain (HINSTANCE hinstDLL,						\
 
 #endif	/* !G_DISABLE_DEPRECATED */
 
-#endif /* G_PLATFORM_WIN32 */
+#endif /* G_OS_WIN32 */
 
 #endif /* __G_UTILS_H__ */
--- origsrc/glib-2.27.2/glib/gwin32.h	2009-03-31 18:04:20.000000000 -0500
+++ src/glib-2.27.2/glib/gwin32.h	2010-11-04 14:53:53.678834000 -0500
@@ -33,7 +33,7 @@
 
 #include <glib/gtypes.h>
 
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
 
 G_BEGIN_DECLS
 
@@ -41,8 +41,6 @@ G_BEGIN_DECLS
 #define MAXPATHLEN 1024
 #endif
 
-#ifdef G_OS_WIN32
-
 /*
  * To get prototypes for the following POSIXish functions, you have to
  * include the indicated non-POSIX headers. The functions are defined
@@ -67,7 +65,6 @@ G_BEGIN_DECLS
  */
 gint		g_win32_ftruncate	(gint		 f,
 					 guint		 size);
-#endif /* G_OS_WIN32 */
 
 /* The MS setlocale uses locale names of the form "English_United
  * States.1252" etc. We want the Unixish standard form "en", "zh_TW"
@@ -109,6 +106,6 @@ gchar*          g_win32_locale_filename_
 
 G_END_DECLS
 
-#endif	 /* G_PLATFORM_WIN32 */
+#endif	 /* G_OS_WIN32 */
 
 #endif /* __G_WIN32_H__ */
--- origsrc/glib-2.27.2/glib/libcharset/localcharset.c	2009-03-31 18:04:20.000000000 -0500
+++ src/glib-2.27.2/glib/libcharset/localcharset.c	2010-11-04 14:53:53.678834000 -0500
@@ -46,10 +46,6 @@
 #   include <locale.h>
 #  endif
 # endif
-# ifdef __CYGWIN__
-#  define WIN32_LEAN_AND_MEAN
-#  include <windows.h>
-# endif
 #elif defined WIN32_NATIVE
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
@@ -111,7 +107,7 @@ _g_locale_get_charset_aliases (void)
   cp = charset_aliases;
   if (cp == NULL)
     {
-#if !(defined VMS || defined WIN32_NATIVE || defined __CYGWIN__)
+#if !(defined VMS || defined WIN32_NATIVE)
       FILE *fp;
       const char *dir;
       const char *base = "charset.alias";
@@ -237,7 +233,7 @@ _g_locale_get_charset_aliases (void)
 	   "DECKOREAN" "\0" "EUC-KR" "\0";
 # endif
 
-# if defined WIN32_NATIVE || defined __CYGWIN__
+# if defined WIN32_NATIVE
       /* To avoid the troubles of installing a separate file in the same
 	 directory as the DLL and of retrieving the DLL's directory at
 	 runtime, simply inline the aliases here.  */
@@ -292,53 +288,6 @@ _g_locale_charset_raw (void)
   /* Most systems support nl_langinfo (CODESET) nowadays.  */
   codeset = nl_langinfo (CODESET);
 
-#  ifdef __CYGWIN__
-  /* Cygwin 2006 does not have locales.  nl_langinfo (CODESET) always
-     returns "US-ASCII".  As long as this is not fixed, return the suffix
-     of the locale name from the environment variables (if present) or
-     the codepage as a number.  */
-  if (codeset != NULL && strcmp (codeset, "US-ASCII") == 0)
-    {
-      const char *locale;
-      static char buf[2 + 10 + 1];
-
-      locale = getenv ("LC_ALL");
-      if (locale == NULL || locale[0] == '\0')
-	{
-	  locale = getenv ("LC_CTYPE");
-	  if (locale == NULL || locale[0] == '\0')
-	    locale = getenv ("LANG");
-	}
-      if (locale != NULL && locale[0] != '\0')
-	{
-	  /* If the locale name contains an encoding after the dot, return
-	     it.  */
-	  const char *dot = strchr (locale, '.');
-
-	  if (dot != NULL)
-	    {
-	      const char *modifier;
-
-	      dot++;
-	      /* Look for the possible @... trailer and remove it, if any.  */
-	      modifier = strchr (dot, '@');
-	      if (modifier == NULL)
-		return dot;
-	      if (modifier - dot < sizeof (buf))
-		{
-		  memcpy (buf, dot, modifier - dot);
-		  buf [modifier - dot] = '\0';
-		  return buf;
-		}
-	    }
-	}
-
-      /* Woe32 has a function returning the locale's codepage as a number.  */
-      sprintf (buf, "CP%u", GetACP ());
-      codeset = buf;
-    }
-#  endif
-
 # else
 
   /* On old systems which lack it, use setlocale or getenv.  */
--- origsrc/glib-2.27.2/glib/tests/uri.c	2010-07-05 22:29:21.000000000 -0500
+++ src/glib-2.27.2/glib/tests/uri.c	2010-11-04 14:53:58.093641700 -0500
@@ -56,7 +56,7 @@ to_uri_tests[] = {
   { "c:\\windows", "otherhost", NULL, G_CONVERT_ERROR_NOT_ABSOLUTE_PATH},
 #endif
   { "etc", "localhost", NULL, G_CONVERT_ERROR_NOT_ABSOLUTE_PATH},
-#ifndef G_PLATFORM_WIN32
+#ifndef G_OS_WIN32
   { "/etc/\xE5\xE4\xF6", NULL, "file:///etc/%E5%E4%F6" },
   { "/etc/\xC3\xB6\xC3\xA4\xC3\xA5", NULL, "file:///etc/%C3%B6%C3%A4%C3%A5"},
 #endif
--- origsrc/glib-2.27.2/tests/Makefile.am	2010-08-16 13:43:54.000000000 -0500
+++ src/glib-2.27.2/tests/Makefile.am	2010-11-04 14:53:53.694434000 -0500
@@ -19,7 +19,9 @@ libadd_libgmodule = $(libgmodule)
 libadd_libglib = $(libglib)
 if PLATFORM_WIN32
 no_undefined = -no-undefined
+endif
 
+if OS_WIN32
 module_test_exp = module-test.exp
 
 module-test.exp: module-test.o
--- origsrc/glib-2.27.2/tests/testglib.c	2010-10-16 22:31:23.000000000 -0500
+++ src/glib-2.27.2/tests/testglib.c	2010-11-04 14:53:53.694434000 -0500
@@ -744,7 +744,7 @@ test_info (void)
 
   if (g_test_verbose())
     {
-#ifdef G_PLATFORM_WIN32
+#ifdef G_OS_WIN32
       g_print ("current locale: %s\n", g_win32_getlocale ());
 
       g_print ("found more.com as %s\n", g_find_program_in_path ("more.com"));