diff options
author | Tim Janik <timj@src.gnome.org> | 1997-12-10 22:43:24 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1997-12-10 22:43:24 +0000 |
commit | 8a6dea2d5541059c4ce9094e6bf149bb3623859e (patch) | |
tree | 4836f500a204a8201546a0b18cc86d6dd1528e7f /glib | |
parent | 68269a3f2a8dca675a700153e9758e0bd9a30d51 (diff) | |
download | gtk+-8a6dea2d5541059c4ce9094e6bf149bb3623859e.tar.gz |
GLib:
* glib_pre1.h:
* glib_pre2.h:
* glib.h: this file now gets concatenated by makeglib_h from
glib_pre1.h and glib_pre2.h to merge in glibconfig.h wich got
created by configure (done by Jay Painter).
* glib_pre2.h: the g_assert*() and g_return_*_fail() macros
are wrapped by G_STMT_START and G_STMT_END now, to avoid conflicts
when used within if (...) g_macro(); else ... conditionals.
Gtk+:
* fixed some compiler errors, because g_return_if_fail() wasn't used
with a trailing semicolon in some places. fixed few other warnings also.
-timj
Diffstat (limited to 'glib')
-rw-r--r-- | glib/ChangeLog | 12 | ||||
-rw-r--r-- | glib/glib_pre2.h | 64 |
2 files changed, 57 insertions, 19 deletions
diff --git a/glib/ChangeLog b/glib/ChangeLog index b119426ca6..c0feaca0db 100644 --- a/glib/ChangeLog +++ b/glib/ChangeLog @@ -1,3 +1,15 @@ +Wed Dec 10 23:27:20 1997 Tim Janik <timj@psynet.net> + + * glib_pre1.h: + * glib_pre2.h: + * glib.h: this file now gets concatenated by makeglib_h from + glib_pre1.h and glib_pre2.h to merge in glibconfig.h wich got + created by configure (done by Jay Painter). + + * glib_pre2.h: the g_assert*() and g_return_*_fail() macros + are wrapped by G_STMT_START and G_STMT_END now, to avoid conflicts + when used within if (...) g_macro(); else ... conditionals. + Tue Dec 17 13:14:07 1996 Peter Mattis <pmattis@charnley.HIP.Berkeley.EDU> * glib.h: Changed 'g_return_if_fail' and 'g_return_val_if_fail' to diff --git a/glib/glib_pre2.h b/glib/glib_pre2.h index 9133d0017e..102066d569 100644 --- a/glib/glib_pre2.h +++ b/glib/glib_pre2.h @@ -130,31 +130,57 @@ ((type *) g_mem_chunk_alloc (chunk)) +#define g_string(x) #x + + +/* Provide simple macro statement wrappers (adapted from Pearl): + * G_STMT_START { statements; } G_STMT_END; + * can be used as a single statement, as in + * if (x) G_STMT_START { ... } G_STMT_END; else ... + * + * For gcc we will wrap the statements within `({' and `})' braces. + * For SunOS they will be wrapped within `if (1)' and `else (void)0', + * and otherwise within `do' and `while (0)'. + */ +#if !(defined (G_STMT_START) && defined (G_STMT_END)) +# if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) +# define G_STMT_START (void)( +# define G_STMT_END ) +# else +# if (defined (sun) || defined (__sun__)) +# define G_STMT_START if (1) +# define G_STMT_END else (void)0 +# else +# define G_STMT_START do +# define G_STMT_END while (0) +# endif +# endif +#endif + + /* Provide macros for error handling. The "assert" macros will - * exit on failur. The "return" macros will exit the current + * exit on failure. The "return" macros will exit the current * function. Two different definitions are given for the macros * in order to support gcc's __PRETTY_FUNCTION__ capability. */ -#define g_string(x) #x - #ifdef __GNUC__ -#define g_assert(expr) \ +#define g_assert(expr) G_STMT_START{\ if (!(expr)) \ g_error ("file %s: line %d (%s): \"%s\"", \ __FILE__, \ __LINE__, \ __PRETTY_FUNCTION__, \ - #expr) + #expr); }G_STMT_END -#define g_assert_not_reached() \ +#define g_assert_not_reached() G_STMT_START{ \ g_error ("file %s: line %d (%s): \"should not be reached\"", \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__) + __PRETTY_FUNCTION__); }G_STMT_END -#define g_return_if_fail(expr) \ +#define g_return_if_fail(expr) G_STMT_START{ \ if (!(expr)) \ { \ g_warning ("file %s: line %d (%s): \"%s\"", \ @@ -163,9 +189,9 @@ __PRETTY_FUNCTION__, \ #expr); \ return; \ - } + }; }G_STMT_END -#define g_return_val_if_fail(expr,val) \ +#define g_return_val_if_fail(expr,val) G_STMT_START{ \ if (!(expr)) \ { \ g_warning ("file %s: line %d (%s): \"%s\"", \ @@ -174,23 +200,23 @@ __PRETTY_FUNCTION__, \ #expr); \ return val; \ - } + }; }G_STMT_END #else /* __GNUC__ */ -#define g_assert(expr) \ +#define g_assert(expr) G_STMT_START{\ if (!(expr)) \ g_error ("file %s: line %d: \"%s\"", \ __FILE__, \ __LINE__, \ - #expr) + #expr); }G_STMT_END -#define g_assert_not_reached() \ +#define g_assert_not_reached() G_STMT_START{ \ g_error ("file %s: line %d: \"should not be reached\"", \ __FILE__, \ - __LINE__) + __LINE__); }G_STMT_END -#define g_return_if_fail(expr) \ +#define g_return_if_fail(expr) G_STMT_START{ \ if (!(expr)) \ { \ g_warning ("file %s: line %d: \"%s\"", \ @@ -198,9 +224,9 @@ __LINE__, \ #expr); \ return; \ - } + }; }G_STMT_END -#define g_return_val_if_fail(expr, val) \ +#define g_return_val_if_fail(expr, val) G_STMT_START{ \ if (!(expr)) \ { \ g_warning ("file %s: line %d: \"%s\"", \ @@ -208,7 +234,7 @@ __LINE__, \ #expr); \ return val; \ - } + }; }G_STMT_END #endif /* __GNUC__ */ |