[dovecot-cvs] dovecot/src/lib data-stack.h, 1.6, 1.7 imem.h, 1.12, 1.13 macros.h, 1.17, 1.18 mempool.h, 1.19, 1.20 strfuncs.h, 1.30, 1.31

tss at dovecot.org tss at dovecot.org
Wed Nov 1 19:19:37 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv6774

Modified Files:
	data-stack.h imem.h macros.h mempool.h strfuncs.h 
Log Message:
Use malloc attribute for the most commonly used memory and string allocation
functions. Use warn_unused_result attribute for reallocs.



Index: data-stack.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/data-stack.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- data-stack.h	13 Jan 2006 20:26:01 -0000	1.6
+++ data-stack.h	1 Nov 2006 19:19:35 -0000	1.7
@@ -53,8 +53,8 @@
 
    t_malloc() calls never fail, but return NULL if size == 0. If there's
    not enough memory left, i_panic() will be called. */
-void *t_malloc(size_t size);
-void *t_malloc0(size_t size);
+void *t_malloc(size_t size) __attr_malloc__;
+void *t_malloc0(size_t size) __attr_malloc__;
 
 /* Try growing allocated memory. Returns TRUE if successful. Works only
    for last allocated memory in current stack frame. */

Index: imem.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/imem.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- imem.h	1 Nov 2006 18:47:37 -0000	1.12
+++ imem.h	1 Nov 2006 19:19:35 -0000	1.13
@@ -7,21 +7,26 @@
 
 #define i_new(type, count) p_new(default_pool, type, count)
 
-void *i_malloc(size_t size);
-void *i_realloc(void *mem, size_t old_size, size_t new_size);
+void *i_malloc(size_t size) __attr_malloc__;
+void *i_realloc(void *mem, size_t old_size, size_t new_size)
+	__attr_warn_unused_result__;
 
 #define i_free(mem) p_free(default_pool, mem)
 #define i_free_and_null(mem) p_free_and_null(default_pool, mem)
 
 /* string functions */
-char *i_strdup(const char *str);
-char *i_strdup_empty(const char *str); /* like i_strdup(), but if str == "", return NULL */
-char *i_strdup_until(const void *str, const void *end); /* *end isn't included */
-char *i_strndup(const void *str, size_t max_chars);
-char *i_strdup_printf(const char *format, ...) __attr_format__(1, 2);
-char *i_strdup_vprintf(const char *format, va_list args) __attr_format__(1, 0);
+char *i_strdup(const char *str) __attr_malloc__;
+/* like i_strdup(), but if str == "", return NULL */
+char *i_strdup_empty(const char *str) __attr_malloc__;
+/* *end isn't included */
+char *i_strdup_until(const void *str, const void *end) __attr_malloc__;
+char *i_strndup(const void *str, size_t max_chars) __attr_malloc__;
+char *i_strdup_printf(const char *format, ...)
+	__attr_format__(1, 2) __attr_malloc__;
+char *i_strdup_vprintf(const char *format, va_list args)
+	__attr_format__(1, 0) __attr_malloc__;
 
-char *i_strconcat(const char *str1, ...)  __attr_sentinel__;
+char *i_strconcat(const char *str1, ...)  __attr_sentinel__ __attr_malloc__;
 
 void imem_init(void);
 

Index: macros.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/macros.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- macros.h	1 Nov 2006 18:47:38 -0000	1.17
+++ macros.h	1 Nov 2006 19:19:35 -0000	1.18
@@ -102,6 +102,8 @@
 #  define __attr_unused__ __attribute__((unused))
 #  define __attr_noreturn__ __attribute__((noreturn))
 #  define __attr_const__ __attribute__((const))
+#  define __attr_malloc__ __attribute__((malloc))
+#  define __attr_warn_unused_result__ __attribute__((warn_unused_result))
 #  if __GNUC__ > 3
 /* GCC 4.0 and later */
 #    define __attr_sentinel__ __attribute__((sentinel))

Index: mempool.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/mempool.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- mempool.h	8 Oct 2006 13:28:56 -0000	1.19
+++ mempool.h	1 Nov 2006 19:19:35 -0000	1.20
@@ -20,7 +20,8 @@
 
 	/* memory in old_size..new_size will be zeroed */
 	void *(*realloc)(pool_t pool, void *mem,
-			 size_t old_size, size_t new_size);
+			 size_t old_size, size_t new_size)
+		__attr_warn_unused_result__;
 
 	/* Frees all the memory in pool. NOTE: system_pool doesn't support
 	   this and crashes if it's used */

Index: strfuncs.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/strfuncs.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- strfuncs.h	1 Nov 2006 18:47:38 -0000	1.30
+++ strfuncs.h	1 Nov 2006 19:19:35 -0000	1.31
@@ -12,26 +12,34 @@
 int i_snprintf(char *dest, size_t max_chars, const char *format, ...)
 	__attr_format__(3, 4);
 
-char *p_strdup(pool_t pool, const char *str);
-char *p_strdup_empty(pool_t pool, const char *str); /* return NULL if str = "" */
-char *p_strdup_until(pool_t pool, const void *start, const void *end); /* *end isn't included */
-char *p_strndup(pool_t pool, const void *str, size_t max_chars);
+char *p_strdup(pool_t pool, const char *str) __attr_malloc__;
+/* return NULL if str = "" */
+char *p_strdup_empty(pool_t pool, const char *str) __attr_malloc__;
+/* *end isn't included */
+char *p_strdup_until(pool_t pool, const void *start, const void *end)
+	__attr_malloc__;
+char *p_strndup(pool_t pool, const void *str, size_t max_chars) __attr_malloc__;
 char *p_strdup_printf(pool_t pool, const char *format, ...)
-	__attr_format__(2, 3);
+	__attr_format__(2, 3) __attr_malloc__;
 char *p_strdup_vprintf(pool_t pool, const char *format, va_list args)
-	__attr_format__(2, 0);
-char *p_strconcat(pool_t pool, const char *str1, ...) __attr_sentinel__;
+	__attr_format__(2, 0) __attr_malloc__;
+char *p_strconcat(pool_t pool, const char *str1, ...)
+	__attr_sentinel__ __attr_malloc__;
 
 /* same with temporary memory allocations: */
-const char *t_strdup(const char *str);
-char *t_strdup_noconst(const char *str);
-const char *t_strdup_empty(const char *str); /* return NULL if str = "" */
-const char *t_strdup_until(const void *start, const void *end); /* *end isn't included */
-const char *t_strndup(const void *str, size_t max_chars);
-const char *t_strdup_printf(const char *format, ...) __attr_format__(1, 2);
+const char *t_strdup(const char *str) __attr_malloc__;
+char *t_strdup_noconst(const char *str) __attr_malloc__;
+/* return NULL if str = "" */
+const char *t_strdup_empty(const char *str) __attr_malloc__;
+/* *end isn't included */
+const char *t_strdup_until(const void *start, const void *end) __attr_malloc__;
+const char *t_strndup(const void *str, size_t max_chars) __attr_malloc__;
+const char *t_strdup_printf(const char *format, ...)
+	__attr_format__(1, 2) __attr_malloc__;
 const char *t_strdup_vprintf(const char *format, va_list args)
-	__attr_format__(1, 0);
-const char *t_strconcat(const char *str1, ...) __attr_sentinel__;
+	__attr_format__(1, 0) __attr_malloc__;
+const char *t_strconcat(const char *str1, ...)
+	__attr_sentinel__ __attr_malloc__;
 
 /* Like t_strdup(), but stop at cutchar. */
 const char *t_strcut(const char *str, char cutchar);
@@ -63,12 +71,16 @@
 int strcasecmp_p(const void *p1, const void *p2);
 
 /* separators is an array of separator characters, not a separator string. */
-char **p_strsplit(pool_t pool, const char *data, const char *separators);
-const char **t_strsplit(const char *data, const char *separators);
+char **p_strsplit(pool_t pool, const char *data, const char *separators)
+	__attr_malloc__;
+const char **t_strsplit(const char *data, const char *separators)
+	__attr_malloc__;
 /* like p_strsplit(), but treats multiple adjacent separators as a single
    separator. */
-char **p_strsplit_spaces(pool_t pool, const char *data, const char *separators);
-const char **t_strsplit_spaces(const char *data, const char *separators);
+char **p_strsplit_spaces(pool_t pool, const char *data, const char *separators)
+	__attr_malloc__;
+const char **t_strsplit_spaces(const char *data, const char *separators)
+	__attr_malloc__;
 void p_strsplit_free(pool_t pool, char **arr);
 
 const char *dec2str(uintmax_t number);
@@ -76,11 +88,13 @@
 /* Return length of NULL-terminated list string array */
 unsigned int strarray_length(const char *const *arr);
 /* Return all strings from array joined into one string. */
-const char *t_strarray_join(const char *const *arr, const char *separator);
+const char *t_strarray_join(const char *const *arr, const char *separator)
+	__attr_malloc__;
 /* Removes a value from NULL-terminated string array. Returns TRUE if found. */
 bool strarray_remove(const char **arr, const char *value);
 
 /* INTERNAL */
-char *_vstrconcat(const char *str1, va_list args, size_t *ret_len);
+char *_vstrconcat(const char *str1, va_list args, size_t *ret_len)
+	__attr_malloc__;
 
 #endif



More information about the dovecot-cvs mailing list