abandon the use of ATEXIT(), we keep the fallback macros for backwards
authorTim Janik <timj@gtk.org>
Tue, 8 Sep 1998 04:00:13 +0000 (04:00 +0000)
committerTim Janik <timj@src.gnome.org>
Tue, 8 Sep 1998 04:00:13 +0000 (04:00 +0000)
Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>

        * glib.h: abandon the use of ATEXIT(), we keep the fallback
        macros for backwards compatibility. people ought to use g_atexit().

        * gutils.c (g_atexit): new function to take over the implementation
        of ATEXIT. this function is guarranteed to succeed, similar to
        g_malloc().

12 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib.h
glib/glib.h
glib/gutils.c
gutils.c

index f72e7af..3d91963 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
index f72e7af..3d91963 100644 (file)
@@ -1,3 +1,12 @@
+Tue Sep  8 05:04:06 1998  Tim Janik  <timj@gtk.org>
+
+       * glib.h: abandon the use of ATEXIT(), we keep the fallback
+       macros for backwards compatibility. people ought to use g_atexit().
+
+       * gutils.c (g_atexit): new function to take over the implementation
+       of ATEXIT. this function is guarranteed to succeed, similar to
+       g_malloc().
+
 Mon Sep  7 20:07:38 PDT 1998 Manish Singh <yosh@gimp.org>
 
        * configure.in: comment the -std1 check and save LIBS properly
diff --git a/glib.h b/glib.h
index 7285782..4ce6797 100644 (file)
--- a/glib.h
+++ b/glib.h
@@ -276,28 +276,36 @@ extern "C" {
 #endif /* !__GNUC__ */
 
 
-/* Hacker macro to place breakpoints for x86 machines.
- * Actual use is strongly deprecated of course ;)
+/* we try to provide a usefull equivalent for ATEXIT if it is
+ * not defined, but use is actually abandoned. people should
+ * use g_atexit() instead.
+ * keep this in sync with gutils.c.
  */
-#if    defined (__i386__) && defined (__GNUC__)
-#define        G_BREAKPOINT()          G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
-#else  /* !__i386__ */
-#define        G_BREAKPOINT()
-#endif /* __i386__ */
-
-
 #ifndef ATEXIT
 #  ifdef HAVE_ATEXIT
 #    ifdef NeXT /* @#%@! NeXTStep */
 #      define ATEXIT(proc)   (!atexit (proc))
-#    else
+#    else /* !NeXT */
 #      define ATEXIT(proc)   (atexit (proc))
-#    endif /* NeXT */
+#    endif /* !NeXT */
 #  elif defined (HAVE_ON_EXIT)
 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
+#  else
+#  error Could not determine proper atexit() implementation
 #  endif
+#else
+#  define G_NATIVE_ATEXIT
 #endif /* ATEXIT */
 
+/* Hacker macro to place breakpoints for x86 machines.
+ * Actual use is strongly deprecated of course ;)
+ */
+#if    defined (__i386__) && defined (__GNUC__)
+#define        G_BREAKPOINT()          G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
+#else  /* !__i386__ */
+#define        G_BREAKPOINT()
+#endif /* __i386__ */
+
 
 /* Provide macros for easily allocating memory. The macros
  *  will cast the allocated memory to the specified type
@@ -663,6 +671,7 @@ typedef void                (*GScannerMsgFunc)      (GScanner      *scanner,
 typedef gint           (*GTraverseFunc)        (gpointer       key,
                                                 gpointer       value,
                                                 gpointer       data);
+typedef        void            (*GVoidFunc)            (void);
 
 
 struct _GList
@@ -1237,6 +1246,13 @@ gchar*   g_get_current_dir       (void);
 } G_STMT_END
 #endif
 
+/* we use a GLib function as a replacement for ATEXIT, so
+ * the programmer is not required to check the return value
+ * (if there is any in the implementation) and doesn't encounter
+ * missing include files.
+ */
+void   g_atexit                (GVoidFunc    func);
+
 
 /* Bit tests
  */
index 7285782..4ce6797 100644 (file)
@@ -276,28 +276,36 @@ extern "C" {
 #endif /* !__GNUC__ */
 
 
-/* Hacker macro to place breakpoints for x86 machines.
- * Actual use is strongly deprecated of course ;)
+/* we try to provide a usefull equivalent for ATEXIT if it is
+ * not defined, but use is actually abandoned. people should
+ * use g_atexit() instead.
+ * keep this in sync with gutils.c.
  */
-#if    defined (__i386__) && defined (__GNUC__)
-#define        G_BREAKPOINT()          G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
-#else  /* !__i386__ */
-#define        G_BREAKPOINT()
-#endif /* __i386__ */
-
-
 #ifndef ATEXIT
 #  ifdef HAVE_ATEXIT
 #    ifdef NeXT /* @#%@! NeXTStep */
 #      define ATEXIT(proc)   (!atexit (proc))
-#    else
+#    else /* !NeXT */
 #      define ATEXIT(proc)   (atexit (proc))
-#    endif /* NeXT */
+#    endif /* !NeXT */
 #  elif defined (HAVE_ON_EXIT)
 #    define ATEXIT(proc)   (on_exit ((void (*)(int, void *))(proc), NULL))
+#  else
+#  error Could not determine proper atexit() implementation
 #  endif
+#else
+#  define G_NATIVE_ATEXIT
 #endif /* ATEXIT */
 
+/* Hacker macro to place breakpoints for x86 machines.
+ * Actual use is strongly deprecated of course ;)
+ */
+#if    defined (__i386__) && defined (__GNUC__)
+#define        G_BREAKPOINT()          G_STMT_START{ __asm__ volatile ("int $03"); }G_STMT_END
+#else  /* !__i386__ */
+#define        G_BREAKPOINT()
+#endif /* __i386__ */
+
 
 /* Provide macros for easily allocating memory. The macros
  *  will cast the allocated memory to the specified type
@@ -663,6 +671,7 @@ typedef void                (*GScannerMsgFunc)      (GScanner      *scanner,
 typedef gint           (*GTraverseFunc)        (gpointer       key,
                                                 gpointer       value,
                                                 gpointer       data);
+typedef        void            (*GVoidFunc)            (void);
 
 
 struct _GList
@@ -1237,6 +1246,13 @@ gchar*   g_get_current_dir       (void);
 } G_STMT_END
 #endif
 
+/* we use a GLib function as a replacement for ATEXIT, so
+ * the programmer is not required to check the return value
+ * (if there is any in the implementation) and doesn't encounter
+ * missing include files.
+ */
+void   g_atexit                (GVoidFunc    func);
+
 
 /* Bit tests
  */
index 8a3b03d..f69256e 100644 (file)
@@ -38,6 +38,41 @@ const guint glib_interface_age = GLIB_INTERFACE_AGE;
 const guint glib_binary_age = GLIB_BINARY_AGE;
 
 
+void
+g_atexit (GVoidFunc func)
+{
+  gint result;
+  gchar *error = NULL;
+
+  /* keep this in sync with glib.h */
+
+#ifdef G_NATIVE_ATEXIT
+  result = ATEXIT (func);
+  if (result)
+    error = g_strerror (errno);
+#elif defined (HAVE_ATEXIT)
+#  ifdef NeXT /* @#%@! NeXTStep */
+  result = !atexit ((void (*)(void)) func);
+  if (result)
+    error = g_strerror (errno);
+#  else
+  result = atexit ((void (*)(void)) func);
+  if (result)
+    error = g_strerror (errno);
+#  endif /* NeXT */
+#elif defined (HAVE_ON_EXIT)
+  result = on_exit ((void (*)(int, void *)) func, NULL);
+  if (result)
+    error = g_strerror (errno);
+#else
+  result = 0;
+  error = "no implementation";
+#endif /* G_NATIVE_ATEXIT */
+
+  if (error)
+    g_error ("Could not register atexit() function: %s", error);
+}
+
 gint
 g_snprintf (gchar      *str,
            gulong       n,
index 8a3b03d..f69256e 100644 (file)
--- a/gutils.c
+++ b/gutils.c
@@ -38,6 +38,41 @@ const guint glib_interface_age = GLIB_INTERFACE_AGE;
 const guint glib_binary_age = GLIB_BINARY_AGE;
 
 
+void
+g_atexit (GVoidFunc func)
+{
+  gint result;
+  gchar *error = NULL;
+
+  /* keep this in sync with glib.h */
+
+#ifdef G_NATIVE_ATEXIT
+  result = ATEXIT (func);
+  if (result)
+    error = g_strerror (errno);
+#elif defined (HAVE_ATEXIT)
+#  ifdef NeXT /* @#%@! NeXTStep */
+  result = !atexit ((void (*)(void)) func);
+  if (result)
+    error = g_strerror (errno);
+#  else
+  result = atexit ((void (*)(void)) func);
+  if (result)
+    error = g_strerror (errno);
+#  endif /* NeXT */
+#elif defined (HAVE_ON_EXIT)
+  result = on_exit ((void (*)(int, void *)) func, NULL);
+  if (result)
+    error = g_strerror (errno);
+#else
+  result = 0;
+  error = "no implementation";
+#endif /* G_NATIVE_ATEXIT */
+
+  if (error)
+    g_error ("Could not register atexit() function: %s", error);
+}
+
 gint
 g_snprintf (gchar      *str,
            gulong       n,