glib (2.0) fixes and darwin porting



I'm enclosing two sets of patches (against the glib mainline): the first
is all generic portability/bugfixing/sanity stuff. The second is a
gmodule implementation for the Darwin/Mac OS X dynamic linker, plus
associated glue. The ChangeLogs tell all.

There are two other issues I came across that aren't fixed by these
patches but are noted in http://bugzilla.gnome.org/show_bug.cgi?id=53069
and http://bugzilla.gnome.org/show_bug.cgi?id=53071

OK to commit?


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.664
diff -u -r1.664 ChangeLog
--- ChangeLog	2001/04/11 14:58:28	1.664
+++ ChangeLog	2001/04/12 11:55:58
@@ -1,3 +1,22 @@
+2001-04-12  Dan Winship  <danw ximian com>
+
+	* configure.in: Use AC_TRY_LINK when checking for "nonposix
+	getpwuid_r" so it notices "no getpwuid_r" correctly, and use
+	AC_EGREP_CPP when checking G_THREAD_CFLAGS, since AC_TRY_COMPILE
+	won't actually tell you if the flags cause the function to be
+	prototyped. Change a few instances of "" to "none" in
+	AC_MSG_RESULTs, and remove a no-longer-accurate part of the
+	development warning.
+
+	* testglib.c (main): Make template[] bigger to prevent an overrun.
+	Remove an unused variable. Initialize error to NULL.
+
+	* tests/gio-test.c (main): Add a cast to prevent a warning when
+	size_t is a long.
+
+	* tests/type-test.c (main): Add an #ifdef to prevent a warning
+	when G_HAVE_GINT64 is defined and G_GINT64_FORMAT isn't.
+
 2001-04-11  Alexander Larsson  <alexl redhat com>
 
 	* glib-2.0.m4: Pass pkg-config options
Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.189
diff -u -r1.189 configure.in
--- configure.in	2001/04/09 17:03:54	1.189
+++ configure.in	2001/04/12 11:56:02
@@ -657,7 +657,7 @@
       G_MODULE_IMPL=G_MODULE_IMPL_BEOS],
       [])
 fi   
-# *** dlopen() and dlsym() in libdl
+dnl *** dlopen() and dlsym() in libdl
 if test -z "$G_MODULE_IMPL"; then
 	AC_CHECK_LIB(dl, dlopen,
 		     [AC_CHECK_LIB(dl, dlsym,
@@ -834,7 +834,7 @@
     PLATFORMDEP=
     ;;    
 esac
-AC_MSG_RESULT($PLATFORMDEP)
+AC_MSG_RESULT(${PLATFORMDEP:-none})
 AC_SUBST(PLATFORMDEP)
 
 AC_MSG_CHECKING([whether to compile timeloop])
@@ -1010,16 +1010,13 @@
     glib_save_CPPFLAGS="$CPPFLAGS"
     CPPFLAGS="$CPPFLAGS $G_THREAD_CFLAGS"
 
-    AC_TRY_COMPILE([#include <time.h>],
-	[time_t t; char b[30]; ctime_r (&t, b);], ,
-    	    [AC_TRY_COMPILE([#include <time.h>],
-		[time_t t; char b[30]; ctime_r (&t, b, 30);], ,
-			AC_MSG_WARN($FLAG_DOES_NOT_WORK))])
+    AC_EGREP_CPP(ctime_r, [#include <time.h>], ,
+	AC_MSG_WARN($FLAG_DOES_NOT_WORK))])
 
     CPPFLAGS="$glib_save_CPPFLAGS"
 
-    AC_MSG_CHECKING(thread related cflags)
-    AC_MSG_RESULT($G_THREAD_CFLAGS)
+    AC_MSG_CHECKING(thread-related cflags)
+    AC_MSG_RESULT(${G_THREAD_CFLAGS:-none})
     CFLAGS="$CFLAGS $G_THREAD_CFLAGS"
 fi
 
@@ -1149,8 +1146,8 @@
     ;;
 esac
 
-AC_MSG_CHECKING(thread related libraries)
-AC_MSG_RESULT($G_THREAD_LIBS)
+AC_MSG_CHECKING(thread-related libraries)
+AC_MSG_RESULT(${G_THREAD_LIBS:-none})
 
 dnl check for mt safe function variants and some posix functions
 dnl ************************************************************
@@ -1182,7 +1179,7 @@
 		else
 	 		AC_CACHE_CHECK([for nonposix getpwuid_r],
 				ac_cv_func_nonposix_getpwuid_r,
-				[AC_TRY_COMPILE([#include <pwd.h>],
+				[AC_TRY_LINK([#include <pwd.h>],
                                 	[char buffer[10000];
                                 	struct passwd pwd;
                                 	getpwuid_r (0, &pwd, buffer, 
@@ -1980,11 +1977,6 @@
 echo ""
 echo "  * You should not base stable software on this version of GLib."
 echo "  * GNOME developers should use a stable version of GLib."
-echo ""
-echo "If you install this version of GLib, we strongly recommend that you"
-echo "install it in a different prefix than GLib 1.2.  Use --prefix as an"
-echo "argument to configure to do this.  Otherwise, you will not be able to"
-echo "do development with GLib 1.2 any longer."
 echo ""
 echo " *** You should be using GLib 1.2 instead. ***"
 ])
Index: testglib.c
===================================================================
RCS file: /cvs/gnome/glib/testglib.c,v
retrieving revision 1.49
diff -u -r1.49 testglib.c
--- testglib.c	2001/03/09 21:31:21	1.49
+++ testglib.c	2001/04/12 11:56:05
@@ -394,10 +394,9 @@
   const char hello[] = "Hello, World";
   const int hellolen = sizeof (hello) - 1;
   int fd;
-  char template[10];
+  char template[32];
   GError *error;
   char *name_used;
-  gchar *p;
 #ifdef G_OS_WIN32
   gchar *glib_dll = g_strdup_printf ("glib-%d.%d.dll",
 				     GLIB_MAJOR_VERSION,
@@ -1213,6 +1212,7 @@
   close (fd);
   remove (template);
 
+  error = NULL;
   strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX");
   fd = g_file_open_tmp (template, &name_used, &error);
   if (fd != -1)
Index: tests/gio-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/gio-test.c,v
retrieving revision 1.6
diff -u -r1.6 gio-test.c
--- tests/gio-test.c	2001/01/25 21:16:46	1.6
+++ tests/gio-test.c	2001/04/12 11:56:05
@@ -399,7 +399,7 @@
 	  for (j = 0; j < buflen; j++)
 	    buf[j] = ' ' + ((buflen + j) % 95);
 	  g_print ("gio-test: child writing %d+%d bytes to %d\n",
-		   sizeof(i) + sizeof(buflen), buflen, writefd);
+		   (int)(sizeof(i) + sizeof(buflen)), buflen, writefd);
 	  write (writefd, &i, sizeof (i));
 	  write (writefd, &buflen, sizeof (buflen));
 	  write (writefd, buf, buflen);
Index: tests/type-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/type-test.c,v
retrieving revision 1.5
diff -u -r1.5 type-test.c
--- tests/type-test.c	2000/09/28 07:45:04	1.5
+++ tests/type-test.c	2001/04/12 11:56:06
@@ -52,9 +52,11 @@
 #ifdef G_HAVE_GINT64
   guint64 gu64t1 = G_GINT64_CONSTANT(0x1d636b02300a7aa7U),
 	  gu64t2 = G_GINT64_CONSTANT(0xa77a0a30026b631dU);
+#ifdef G_GINT64_FORMAT
   gint64 gi64t1;
   gint64 gi64t2;
-#endif
+#endif /* G_GINT64_FORMAT */
+#endif /* G_HAVE_GINT64 */
 
   /* type sizes */
   g_assert (sizeof (gint8) == 1);
Index: gmodule/ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/gmodule/ChangeLog,v
retrieving revision 1.52
diff -u -r1.52 ChangeLog
--- gmodule/ChangeLog	2001/03/14 20:18:03	1.52
+++ gmodule/ChangeLog	2001/04/12 11:56:07
@@ -1,3 +1,7 @@
+2001-04-12  Dan Winship  <danw ximian com>
+
+	* testgmodule.c (main): Fix spelling
+
 2001-03-13  Tor Lillqvist  <tml iki fi>
 
 	From Edward M. Lee  <tailbert yahoo com>:
Index: gmodule/testgmodule.c
===================================================================
RCS file: /cvs/gnome/glib/gmodule/testgmodule.c,v
retrieving revision 1.12
diff -u -r1.12 testgmodule.c
--- gmodule/testgmodule.c	2000/12/22 13:44:25	1.12
+++ gmodule/testgmodule.c	2001/04/12 11:56:07
@@ -71,14 +71,14 @@
   g_print ("check that not yet bound symbols in shared libraries of main module are retrievable:\n");
   string = "g_module_close";
   basename = g_path_get_basename (g_module_name (module_self));
-  g_print ("retrive symbol `%s' from \"%s\":\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\":\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_self, string, (gpointer) &f_self))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
     }
-  g_print ("retrived symbol `%s' as %p\n", string, f_self);
+  g_print ("retrieved symbol `%s' as %p\n", string, f_self);
   g_print ("load plugin from \"%s\"\n", plugin_a);
   module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY);
   if (!module_a)
@@ -98,7 +98,7 @@
    */
   string = "gplugin_a_func";
   basename = g_path_get_basename (g_module_name (module_a));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_a, string, (gpointer) &f_a))
     {
@@ -107,7 +107,7 @@
     }
   string = "gplugin_b_func";
   basename = g_path_get_basename (g_module_name (module_b));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_b, string, (gpointer) &f_b))
     {
@@ -123,7 +123,7 @@
    */
   string = "g_clash_func";
   basename = g_path_get_basename (g_module_name (module_self));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_self, string, (gpointer) &f_self))
     {
@@ -131,7 +131,7 @@
       return 1;
     }
   basename = g_path_get_basename (g_module_name (module_a));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_a, string, (gpointer) &f_a))
     {
@@ -139,7 +139,7 @@
       return 1;
     }
   basename = g_path_get_basename (g_module_name (module_b));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_b, string, (gpointer) &f_b))
     {
@@ -157,13 +157,13 @@
    */
   string = "gplugin_clash_func";
   basename = g_path_get_basename (g_module_name (module_self));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_self, string, (gpointer) &f_self))
     f_self = NULL;
-  g_print ("retrived function `%s' from self: %p\n", string, f_self);
+  g_print ("retrieved function `%s' from self: %p\n", string, f_self);
   basename = g_path_get_basename (g_module_name (module_a));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_a, string, (gpointer) &f_a))
     {
@@ -171,7 +171,7 @@
       return 1;
     }
   basename = g_path_get_basename (g_module_name (module_b));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_b, string, (gpointer) &f_b))
     {
@@ -189,7 +189,7 @@
    */
   string = "gplugin_a_module_func";
   basename = g_path_get_basename (g_module_name (module_a));
-  g_print ("retrive symbol `%s' from \"%s\"\n", string, basename);
+  g_print ("retrieve symbol `%s' from \"%s\"\n", string, basename);
   g_free (basename);
   if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
     {
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.664
diff -u -r1.664 ChangeLog
--- ChangeLog	2001/04/11 14:58:28	1.664
+++ ChangeLog	2001/04/12 12:08:31
@@ -1,3 +1,7 @@
+2001-04-12  Dan Winship  <danw ximian com>
+
+	* configure.in: Add a check for the Darwin dynamic linker
+
 	* configure.in: Use AC_TRY_LINK when checking for "nonposix
 	getpwuid_r" so it notices "no getpwuid_r" correctly, and use
 	AC_EGREP_CPP when checking G_THREAD_CFLAGS, since AC_TRY_COMPILE
Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.189
diff -u -r1.189 configure.in
--- configure.in	2001/04/09 17:03:54	1.189
+++ configure.in	2001/04/12 12:07:46
@@ -665,6 +665,13 @@
 		                   G_MODULE_IMPL=G_MODULE_IMPL_DL],[])],
 		     [])
 fi
+dnl *** NSLinkModule (dyld) in system libraries (Darwin)
+if test -z "$G_MODULE_IMPL"; then
+ 	AC_CHECK_FUNC(NSLinkModule,
+		      [G_MODULE_IMPL=G_MODULE_IMPL_DYLD
+		       G_MODULE_NEED_USCORE=1],
+		      [])
+fi
 dnl *** shl_load() in libdld (HP-UX)
 if test -z "$G_MODULE_IMPL"; then
         AC_MSG_CHECKING(how to export all symbols)
Index: gmodule/ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/gmodule/ChangeLog,v
retrieving revision 1.52
diff -u -r1.52 ChangeLog
--- gmodule/ChangeLog	2001/03/14 20:18:03	1.52
+++ gmodule/ChangeLog	2001/04/12 12:07:47
@@ -1,3 +1,10 @@
+2001-04-12  Dan Winship  <danw ximian com>
+
+	* gmodule-dyld.c: gmodule implementation for Darwin/Mac OS X
+
+	* gmodule.c: 
+	* gmoduleconf.h.in: Add gmodule-dyld support
+
 	* testgmodule.c (main): Fix spelling
 
 2001-03-13  Tor Lillqvist  <tml iki fi>
Index: gmodule/gmodule-dyld.c
===================================================================
RCS file: gmodule-dyld.c
diff -N gmodule-dyld.c
--- /dev/null	Tue May  5 16:32:27 1998
+++ gmodule-dyld.c	Thu Apr 12 08:07:47 2001
@@ -0,0 +1,150 @@
+/* GMODULE - GLIB wrapper code for dynamic module loading
+ * Copyright (C) 1998, 2000 Tim Janik
+ *
+ * dyld (Darwin) GMODULE implementation
+ * Copyright (C) 2001 Dan Winship
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <mach-o/dyld.h>
+#include "glibintl.h"
+
+static gpointer self_module = (gpointer)1;
+
+static gpointer
+_g_module_open (const gchar *file_name,
+		gboolean     bind_lazy)
+{
+  NSObjectFileImage image;
+  NSObjectFileImageReturnCode ret;
+  NSModule module;
+  unsigned long options;
+  char *msg;
+
+  ret = NSCreateObjectFileImageFromFile (file_name, &image);
+  if (ret != NSObjectFileImageSuccess)
+    {
+      switch (ret)
+	{
+	case NSObjectFileImageInappropriateFile:
+	case NSObjectFileImageFormat:
+	  msg = g_strdup_printf (_("%s is not a loadable module"), file_name);
+	  break;
+
+	case NSObjectFileImageArch:
+	  msg = g_strdup_printf (_("%s is not built for this architecture"),
+				 file_name);
+	  break;
+
+	case NSObjectFileImageAccess:
+	  msg = g_strdup_printf ("%s: %s", file_name,
+				 g_strerror (access (file_name, F_OK) == 0 ?
+					     EPERM : ENOENT));
+	  break;
+
+	default:
+	  msg = g_strdup_printf (_("unknown error for %s"), file_name);
+	  break;
+	}
+
+      g_module_set_error (msg);
+      g_free (msg);
+      return NULL;
+    }
+
+  options = NSLINKMODULE_OPTION_RETURN_ON_ERROR | NSLINKMODULE_OPTION_PRIVATE;
+  if (!bind_lazy)
+    options |= NSLINKMODULE_OPTION_BINDNOW;
+  module = NSLinkModule (image, file_name, options);
+  NSDestroyObjectFileImage (image);
+  if (!module)
+    {
+      NSLinkEditErrors c;
+      int error_number;
+      const char *file, *error;
+
+      NSLinkEditError (&c, &error_number, &file, &error);
+      msg = g_strdup_printf (_("could not link %s: %s"), file_name, error);
+      g_module_set_error (msg);
+      g_free (msg);
+      return NULL;
+    }
+
+  return module;
+}
+
+static gpointer
+_g_module_self (void)
+{
+  return &self_module;
+}
+
+static void
+_g_module_close (gpointer handle,
+		 gboolean is_unref)
+{
+  if (handle == &self_module)
+    return;
+
+  if (!NSUnLinkModule (handle, 0))
+    g_module_set_error (_("could not unlink module"));
+}
+
+static gpointer
+_g_module_symbol (gpointer     handle,
+		  const gchar *symbol_name)
+{
+  NSSymbol sym;
+  char *msg;
+
+  if (handle == &self_module)
+    {
+      if (NSIsSymbolNameDefined (symbol_name))
+	sym = NSLookupAndBindSymbol (symbol_name);
+      else
+	sym = NULL;
+    }
+  else
+    sym = NSLookupSymbolInModule (handle, symbol_name);
+
+  if (!sym)
+    {
+      msg = g_strdup_printf (_("no such symbol %s"), symbol_name);
+      g_module_set_error (msg);
+      g_free (msg);
+      return NULL;
+    }
+
+  return NSAddressOfSymbol (sym);
+}
+
+static gchar*
+_g_module_build_path (const gchar *directory,
+		      const gchar *module_name)
+{
+  if (directory && *directory)
+    {
+      if (strncmp (module_name, "lib", 3) == 0)
+	return g_strconcat (directory, "/", module_name, NULL);
+      else
+	return g_strconcat (directory, "/lib", module_name, ".so", NULL);
+    }
+  else if (strncmp (module_name, "lib", 3) == 0)
+    return g_strdup (module_name);
+  else
+    return g_strconcat ("lib", module_name, ".so", NULL);
+}
Index: gmodule/gmodule.c
===================================================================
RCS file: /cvs/gnome/glib/gmodule/gmodule.c,v
retrieving revision 1.32
diff -u -r1.32 gmodule.c
--- gmodule/gmodule.c	2001/03/07 14:22:25	1.32
+++ gmodule/gmodule.c	2001/04/12 12:07:48
@@ -139,6 +139,8 @@
 #include "gmodule-dld.c"
 #elif	(G_MODULE_IMPL == G_MODULE_IMPL_WIN32)
 #include "gmodule-win32.c"
+#elif   (G_MODULE_IMPL == G_MODULE_IMPL_DYLD)
+#include "gmodule-dyld.c"
 #else
 #undef	SUPPORT_OR_RETURN
 #define	SUPPORT_OR_RETURN(rv)	{ g_module_set_error ("dynamic modules are " \
Index: gmodule/gmoduleconf.h.in
===================================================================
RCS file: /cvs/gnome/glib/gmodule/gmoduleconf.h.in,v
retrieving revision 1.7
diff -u -r1.7 gmoduleconf.h.in
--- gmodule/gmoduleconf.h.in	2001/02/17 06:28:07	1.7
+++ gmodule/gmoduleconf.h.in	2001/04/12 12:07:48
@@ -31,6 +31,7 @@
 #define	G_MODULE_IMPL_WIN32	3
 #define	G_MODULE_IMPL_OS2	4
 #define	G_MODULE_IMPL_BEOS	5
+#define	G_MODULE_IMPL_DYLD	6
 
 #define	G_MODULE_IMPL		@G_MODULE_IMPL@
 #undef	G_MODULE_HAVE_DLERROR


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]