From 1d598329467285fb553054cea28b50b1879851ae Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Tue, 8 Sep 1998 04:00:13 +0000 Subject: [PATCH] abandon the use of ATEXIT(), we keep the fallback macros for backwards Tue Sep 8 05:04:06 1998 Tim Janik * 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(). --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-0 | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-12 | 9 +++++++++ ChangeLog.pre-2-2 | 9 +++++++++ ChangeLog.pre-2-4 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ glib.h | 38 +++++++++++++++++++++++++++----------- glib/glib.h | 38 +++++++++++++++++++++++++++----------- glib/gutils.c | 35 +++++++++++++++++++++++++++++++++++ gutils.c | 35 +++++++++++++++++++++++++++++++++++ 12 files changed, 196 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index f72e7af..3d91963 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index f72e7af..3d91963 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +Tue Sep 8 05:04:06 1998 Tim Janik + + * 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 * configure.in: comment the -std1 check and save LIBS properly diff --git a/glib.h b/glib.h index 7285782..4ce6797 100644 --- 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 */ diff --git a/glib/glib.h b/glib/glib.h index 7285782..4ce6797 100644 --- a/glib/glib.h +++ b/glib/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 */ diff --git a/glib/gutils.c b/glib/gutils.c index 8a3b03d..f69256e 100644 --- a/glib/gutils.c +++ b/glib/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, diff --git a/gutils.c b/gutils.c index 8a3b03d..f69256e 100644 --- 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, -- 2.7.4