]> mj.ucw.cz Git - libucw.git/commitdiff
Corrected definition of the PURE attribute.
authorMartin Mares <mj@ucw.cz>
Thu, 4 May 2006 20:55:42 +0000 (22:55 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 4 May 2006 20:55:42 +0000 (22:55 +0200)
Added LIKE_MALLOC and SENTINEL_CHECK attributes.
Polished a comment.

lib/lib.h

index 9f7f59d4ddf58f8467e1b1b38854626ac56496f2..b20ba7e9b284a0aa9d0815a66af71caf803fb87b 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -21,7 +21,7 @@
 #define _GNU_SOURCE
 #endif
 
-/* Ugly structure handling macros */
+/* Macros for handling structurues, offsets and alignment */
 
 #define CHECK_PTR_TYPE(x, type) ((x)-(type)(x) + (type)(x))
 #define PTR_TO(s, i) &((s*)0)->i
 #define CONSTRUCTOR __attribute__((constructor))
 #define PACKED __attribute__((packed))
 #define CONST __attribute__((const))
-#define PURE __attribute__((const))
+#define PURE __attribute__((pure))
 #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z)))
 #define likely(x) __builtin_expect((x),1)
 #define unlikely(x) __builtin_expect((x),0)
 
+#if __GNUC__ >= 4
+#define LIKE_MALLOC __attribute__((malloc))
+#define SENTINEL_CHECK __attribute__((sentinel))
+#else
+#define LIKE_MALLOC
+#define SENTINEL_CHECK
+#endif
+
 #else
 #error This program requires the GNU C compiler.
 #endif
@@ -141,13 +149,13 @@ static inline void log_switch_enable(void) { ASSERT(log_switch_nest); log_switch
  * their own xmalloc and we don't want to interfere with them, hence
  * the renaming.
  */
-void *xmalloc(unsigned);
+void *xmalloc(unsigned) LIKE_MALLOC;
 void *xrealloc(void *, unsigned);
 void xfree(void *);
 #endif
 
-void *xmalloc_zero(unsigned);
-byte *xstrdup(byte *);
+void *xmalloc_zero(unsigned) LIKE_MALLOC;
+byte *xstrdup(byte *) LIKE_MALLOC;
 
 /* Content-Type pattern matching and filters */