[patch] add G_GNUC_WARNUNCHECKED define
- From: Arjan van de Ven <arjanv redhat com>
- To: gtk-devel-list gnome org
- Subject: [patch] add G_GNUC_WARNUNCHECKED define
- Date: Mon, 5 Jul 2004 18:04:34 +0200
Hi,
gcc versions 3.4 and later have an attribute that you can give to a function
that will cause gcc to warn if you don't check/use the return value of such
function. The patch below adds a G_GNUC_WARNUNCHECKED define for this
attribute. A typical use for this is in realloc() definitions where not
using the return valueof such functions is always a bad bug in the program.
The patch below thus adds this attribute to g_realloc() and g_try_realloc().
Greetings,
Arjan van de Ven
diff -purN glib-2.4.2/glib.org/gmacros.h glib-2.4.2/glib/gmacros.h
--- glib-2.4.2/glib.org/gmacros.h 2004-07-05 16:40:35.605509000 +0200
+++ glib-2.4.2/glib/gmacros.h 2004-07-05 17:55:48.026517424 +0200
@@ -96,6 +96,13 @@
#define G_GNUC_DEPRECATED
#endif /* __GNUC__ */
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#define G_GNUC_WARNUNCHECKED \
+ __attribute__((warn_unused_result))
+#else
+#define G_GNUC_WARNUNCHECKED
+#endif /* __GNUC__ */
+
/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
* macros, so we can refer to them as strings unconditionally.
* usage not-recommended since gcc-3.0
diff -purN glib-2.4.2/glib.org/gmem.h glib-2.4.2/glib/gmem.h
--- glib-2.4.2/glib.org/gmem.h 2003-02-06 20:57:14.000000000 +0100
+++ glib-2.4.2/glib/gmem.h 2004-07-05 17:57:56.247024944 +0200
@@ -48,11 +48,11 @@ typedef struct _GMemVTable GMemVTable;
gpointer g_malloc (gulong n_bytes);
gpointer g_malloc0 (gulong n_bytes);
gpointer g_realloc (gpointer mem,
- gulong n_bytes);
+ gulong n_bytes) G_GNUC_WARNUNCHECKED;
void g_free (gpointer mem);
gpointer g_try_malloc (gulong n_bytes);
gpointer g_try_realloc (gpointer mem,
- gulong n_bytes);
+ gulong n_bytes) G_GNUC_WARNUNCHECKED;
/* Convenience memory allocators
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]