[dovecot-cvs] dovecot/src/lib array-decl.h, 1.1, 1.2 array.h, 1.14, 1.15 buffer.c, 1.31, 1.32 buffer.h, 1.18, 1.19 ioloop-epoll.c, 1.12, 1.13 istream.c, 1.34, 1.35 istream.h, 1.25, 1.26 lib.h, 1.20, 1.21 module-dir.c, 1.20, 1.21 seq-range-array.c, 1.5, 1.6 seq-range-array.h, 1.2, 1.3 str.c, 1.17, 1.18 str.h, 1.8, 1.9

cras at dovecot.org cras at dovecot.org
Wed Jun 28 16:10:38 EEST 2006


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

Modified Files:
	array-decl.h array.h buffer.c buffer.h ioloop-epoll.c 
	istream.c istream.h lib.h module-dir.c seq-range-array.c 
	seq-range-array.h str.c str.h 
Log Message:
Array API redesigned to work using unions. It now provides type safety
without having to enable DEBUG, as long as the compiler supports typeof().
Its API changed a bit. It now allows directly accessing the array contents,
although that's not necessarily recommended. Changed existing array usage to
be type safe in a bit more places. Removed array_t completely. Also did
s/modifyable/modifiable/.



Index: array-decl.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/array-decl.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- array-decl.h	4 Jul 2005 11:32:19 -0000	1.1
+++ array-decl.h	28 Jun 2006 13:10:33 -0000	1.2
@@ -1,23 +1,13 @@
 #ifndef __ARRAY_DECL_H
 #define __ARRAY_DECL_H
 
-#if defined (DEBUG) && defined (__GNUC__)
-#  define ARRAY_TYPE_CHECKS
-#endif
+#define ARRAY_DEFINE(name, array_type) union { struct array arr; array_type const *v; array_type *v_modifiable; } name
+#define ARRAY_INIT { { 0, 0 } }
 
-#ifdef ARRAY_TYPE_CHECKS
-#  define ARRAY_DEFINE(name, array_type) name; array_type *name ## __ ## type
-#  define ARRAY_DEFINE_EXTERN(name, array_type) \
-	name; extern array_type *name ## __ ## type
-#  define ARRAY_DEFINE_PTR(name, array_type) \
-	name; array_type **name ## __ ## type
-#  define ARRAY_INIT { 0, 0 }, 0
-#else
-#  define ARRAY_DEFINE(name, array_type) name
-#  define ARRAY_DEFINE_EXTERN(name, array_type) name
-#  define ARRAY_DEFINE_PTR(name, array_type) name
-#  define ARRAY_INIT { 0, 0 }
-#endif
+#define ARRAY_DEFINE_TYPE(name, array_type) \
+	union array ## __ ## name { struct array arr; array_type const *v; array_type *v_modifiable; }
+#define ARRAY_TYPE(name) \
+	union array ## __ ## name
 
 struct array {
 	buffer_t *buffer;

Index: array.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/array.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- array.h	13 Jan 2006 20:26:01 -0000	1.14
+++ array.h	28 Jun 2006 13:10:33 -0000	1.15
@@ -1,18 +1,15 @@
 #ifndef __ARRAY_H
 #define __ARRAY_H
 
-/* Array is a buffer accessible using fixed size elements. If DEBUG is
-   enabled, it also provides compile time type safety:
-
-   If DEBUG is enabled, an extra variable is defined along with the array
-   itself. This is used to cast array_idx() return value correctly, so
-   compiler gives a warning if it's assigned into variable with a different
-   type.
+/* Array is a buffer accessible using fixed size elements. As long as the
+   compiler provides typeof() function, the array provides type safety. If
+   a wrong type is tried to be added to the array, or if the array's contents
+   are tried to be used using a wrong type, the compiler will give a warning.
 
    Example usage:
 
    struct foo {
-	array_t ARRAY_DEFINE(bars, struct bar);
+	ARRAY_DEFINE(bars, struct bar);
 	...
    };
 
@@ -22,164 +19,160 @@
    struct bar *bar = array_idx(&foo->bars, 5);
    struct baz *baz = array_idx(&foo->bars, 5); // compiler warning
 
-   When passing array_t as a parameter to function, or when it's otherwise
-   accessed in a way that the extra variable cannot be accessed, the code
-   won't compile. For situations like those, there's a ARRAY_SET_TYPE() macro.
+   If you want to pass an array as a parameter to a function, you'll need to
+   create a type for the array using ARRAY_DEFINE_TYPE() and use the type in
+   the parameter using ARRAY_TYPE().
 
    Example:
 
-   void do_foo(array_t *bars) {
-	ARRAY_SET_TYPE(bars, struct foo);
+   ARRAY_DEFINE_TYPE(foo, struct foo);
+   void do_foo(ARRAY_TYPE(foo) *bars) {
 	struct foo *foo = array_idx(bars, 0);
    }
 */
 #include "array-decl.h"
 #include "buffer.h"
 
-#ifdef ARRAY_TYPE_CHECKS
-#  define ARRAY_CREATE(array, pool, array_type, init_count) STMT_START { \
-	array_type **_array_tmp = array ## __ ## type; _array_tmp = NULL; \
+#define ARRAY_CREATE(array, pool, array_type, init_count) STMT_START { \
+	array_type const *_array_tmp = (array)->v; _array_tmp = NULL; \
 	array_create(array, pool, sizeof(array_type), init_count); \
 	} STMT_END
-#  define ARRAY_SET_TYPE(array, array_type) \
-	array_type **array ## __ ## type = NULL
-#else
-#  define ARRAY_CREATE(array, pool, array_type, init_count) \
-	array_create(array, pool, sizeof(array_type), init_count)
-/* The reason we do this for non-ARRAY_TYPE_CHECKS as well is because if we
-   left this empty, some compilers wouldn't like an extra ";" character at
-   the beginning of the function (eg. gcc 2.95).
 
-   However just declaring the variable gives "unused variable" warning.
-   I couldn't think of anything better, so we just use gcc-specific
-   unused-attribute to get rid of that with gcc. */
-#  define ARRAY_SET_TYPE(array, array_type) \
-	array_type **array ## __ ## type __attr_unused__ = NULL
+#ifdef __GNUC__
+#  define ARRAY_TYPE_CAST_CONST(array) \
+	(typeof((array)->v))
+#  define ARRAY_TYPE_CAST_MODIFIABLE(array) \
+	(typeof((array)->v_modifiable))
+#  define ARRAY_TYPE_CHECK(array, data) \
+	typeof((array)->v_modifiable) __tmp_array_data2 __attr_unused__ = \
+		(typeof(const typeof(typeof(*(data)) *)))NULL;
+#else
+#  define ARRAY_TYPE_CAST_CONST(array)
+#  define ARRAY_TYPE_CAST_MODIFIABLE(array)
+#  define ARRAY_TYPE_CHECK(array, data)
 #endif
 
 static inline void
-array_create_from_buffer(array_t *array, buffer_t *buffer, size_t element_size)
+_array_create_from_buffer(struct array *array, buffer_t *buffer,
+			  size_t element_size)
 {
 	array->buffer = buffer;
 	array->element_size = element_size;
 }
+#define array_create_from_buffer(array, buffer, element_size) \
+	_array_create_from_buffer(&(array)->arr, buffer, element_size)
 
 static inline void
-array_create(array_t *array, pool_t pool,
-	     size_t element_size, unsigned int init_count)
+_array_create(struct array *array, pool_t pool,
+	      size_t element_size, unsigned int init_count)
 {
 	buffer_t *buffer;
 
         buffer = buffer_create_dynamic(pool, init_count * element_size);
-	array_create_from_buffer(array, buffer, element_size);
+	_array_create_from_buffer(array, buffer, element_size);
 }
+#define array_create(array, pool, element_size, init_count) \
+	_array_create(&(array)->arr, pool, element_size, init_count)
 
 static inline void
-array_free(array_t *array)
+_array_free(struct array *array)
 {
 	buffer_free(array->buffer);
 	array->buffer = NULL;
 }
+#define array_free(array) \
+	_array_free(&(array)->arr)
 
 static inline bool
-array_is_created(const array_t *array)
+_array_is_created(const struct array *array)
 {
 	return array->buffer != NULL;
 }
+#define array_is_created(array) \
+	_array_is_created(&(array)->arr)
 
 static inline void
-array_clear(array_t *array)
+_array_clear(struct array *array)
 {
 	buffer_set_used_size(array->buffer, 0);
 }
+#define array_clear(array) \
+	_array_clear(&(array)->arr)
 
 static inline void
-_array_append(array_t *array, const void *data, unsigned int count)
+_array_append(struct array *array, const void *data, unsigned int count)
 {
 	buffer_append(array->buffer, data, count * array->element_size);
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_append _array_append
-#else
-#  define array_append(array, data, count) STMT_START { \
-	typeof(const typeof(**(array ## __ ## type)) *) _array_tmp = data; \
-	_array_append(array, _array_tmp, count); \
-	} STMT_END
-#endif
+
+#define array_append(array, data, count) STMT_START { \
+	ARRAY_TYPE_CHECK(array, data) \
+	_array_append(&(array)->arr, data, count); \
+} STMT_END
 
 static inline void
-array_append_array(array_t *dest_array, const array_t *src_array)
+_array_append_array(struct array *dest_array, const struct array *src_array)
 {
 	i_assert(dest_array->element_size == src_array->element_size);
 	buffer_append_buf(dest_array->buffer, src_array->buffer, 0, (size_t)-1);
 }
+#define array_append_array(dest_array, src_array) \
+	_array_append_array(&(dest_array)->arr, &(src_array)->arr)
 
 static inline void
-_array_insert(array_t *array, unsigned int idx,
+_array_insert(struct array *array, unsigned int idx,
 	      const void *data, unsigned int count)
 {
 	buffer_insert(array->buffer, idx * array->element_size,
 		      data, count * array->element_size);
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_insert _array_insert
-#else
-#  define array_insert(array, idx, data, count) STMT_START { \
-	typeof(const typeof(**(array ## __ ## type)) *) _array_tmp = data; \
-	_array_insert(array, idx, _array_tmp, count); \
+
+#define array_insert(array, idx, data, count) STMT_START { \
+	ARRAY_TYPE_CHECK(array, data) \
+	_array_insert(&(array)->arr, idx, data, count); \
 	} STMT_END
-#endif
 
 static inline void
-array_delete(array_t *array, unsigned int idx, unsigned int count)
+_array_delete(struct array *array, unsigned int idx, unsigned int count)
 {
 	buffer_delete(array->buffer, idx * array->element_size,
 		      count * array->element_size);
 }
+#define array_delete(array, idx, count) \
+	_array_delete(&(array)->arr, idx, count)
 
 static inline const void *
-_array_get(const array_t *array, unsigned int *count_r)
+_array_get(const struct array *array, unsigned int *count_r)
 {
 	if (count_r != NULL)
 		*count_r = array->buffer->used / array->element_size;
 	return array->buffer->data;
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_get _array_get
-#else
-#  define array_get(array, count) \
-	(typeof(typeof(**array ## __ ## type) const *))_array_get(array, count)
-#endif
+#define array_get(array, count) \
+	ARRAY_TYPE_CAST_CONST(array)_array_get(&(array)->arr, count)
 
 static inline const void *
-_array_idx(const array_t *array, unsigned int idx)
+_array_idx(const struct array *array, unsigned int idx)
 {
 	i_assert(idx * array->element_size < array->buffer->used);
 	return CONST_PTR_OFFSET(array->buffer->data, idx * array->element_size);
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_idx _array_idx
-#else
-#  define array_idx(array, idx) \
-	(typeof(typeof(**array ## __ ## type) const *))_array_idx(array, idx)
-#endif
+#define array_idx(array, idx) \
+	ARRAY_TYPE_CAST_CONST(array)_array_idx(&(array)->arr, idx)
 
 static inline void *
-_array_get_modifyable(array_t *array, unsigned int *count_r)
+_array_get_modifiable(struct array *array, unsigned int *count_r)
 {
 	if (count_r != NULL)
 		*count_r = array->buffer->used / array->element_size;
-	return buffer_get_modifyable_data(array->buffer, NULL);
+	return buffer_get_modifiable_data(array->buffer, NULL);
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_get_modifyable _array_get_modifyable
-#else
-#  define array_get_modifyable(array, count) \
-	(typeof(*array ## __ ## type))_array_get_modifyable(array, count)
-#endif
+#define array_get_modifiable(array, count) \
+	ARRAY_TYPE_CAST_MODIFIABLE(array) \
+		_array_get_modifiable(&(array)->arr, count)
 
 static inline void *
-_array_idx_modifyable(array_t *array, unsigned int idx)
+_array_idx_modifiable(struct array *array, unsigned int idx)
 {
 	size_t pos;
 
@@ -191,15 +184,12 @@
 	}
 	return buffer_get_space_unsafe(array->buffer, pos, array->element_size);
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_idx_modifyable _array_idx_modifyable
-#else
-#  define array_idx_modifyable(array, count) \
-	(typeof(*array ## __ ## type))_array_idx_modifyable(array, count)
-#endif
+#define array_idx_modifiable(array, count) \
+	ARRAY_TYPE_CAST_MODIFIABLE(array) \
+		_array_idx_modifiable(&(array)->arr, count)
 
 static inline void
-_array_idx_set(array_t *array, unsigned int idx, const void *data)
+_array_idx_set(struct array *array, unsigned int idx, const void *data)
 {
 	size_t pos;
 
@@ -210,17 +200,13 @@
 	}
 	buffer_write(array->buffer, pos, data, array->element_size);
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_idx_set _array_idx_set
-#else
-#  define array_idx_set(array, idx, data) STMT_START { \
-	typeof(const typeof(**(array ## __ ## type)) *) _array_tmp = data; \
-	_array_idx_set(array, idx, _array_tmp); \
+#define array_idx_set(array, idx, data) STMT_START { \
+	ARRAY_TYPE_CHECK(array, data) \
+	_array_idx_set(&(array)->arr, idx, data); \
 	} STMT_END
-#endif
 
 static inline void *
-_array_append_space(array_t *array)
+_array_append_space(struct array *array)
 {
 	void *data;
 
@@ -228,15 +214,11 @@
 	memset(data, 0, array->element_size);
 	return data;
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_append_space _array_append_space
-#else
-#  define array_append_space(array) \
-	(typeof(*array ## __ ## type))_array_append_space(array)
-#endif
+#define array_append_space(array) \
+	ARRAY_TYPE_CAST_MODIFIABLE(array)_array_append_space(&(array)->arr)
 
 static inline void *
-_array_insert_space(array_t *array, unsigned int idx)
+_array_insert_space(struct array *array, unsigned int idx)
 {
 	void *data;
 	size_t pos;
@@ -249,29 +231,30 @@
 	memset(data, 0, array->element_size);
 	return data;
 }
-#ifndef ARRAY_TYPE_CHECKS
-#  define array_insert_space _array_insert_space
-#else
-#  define array_insert_space(array, idx) \
-	(typeof(*array ## __ ## type))_array_insert_space(array, idx)
-#endif
+#define array_insert_space(array, idx) \
+	ARRAY_TYPE_CAST_MODIFIABLE(array) \
+		_array_insert_space(&(array)->arr, idx)
 
 static inline unsigned int
-array_count(const array_t *array)
+_array_count(const struct array *array)
 {
 	return array->buffer->used / array->element_size;
 }
+#define array_count(array) \
+	_array_count(&(array)->arr)
 
 static inline bool
-array_cmp(const array_t *array1, const array_t *array2)
+_array_cmp(const struct array *array1, const struct array *array2)
 {
-	if (!array_is_created(array1) || array1->buffer->used == 0)
-		return !array_is_created(array2) || array2->buffer->used == 0;
+	if (!_array_is_created(array1) || array1->buffer->used == 0)
+		return !_array_is_created(array2) || array2->buffer->used == 0;
 
-	if (!array_is_created(array2))
+	if (!_array_is_created(array2))
 		return FALSE;
 
 	return buffer_cmp(array1->buffer, array2->buffer);
 }
+#define array_cmp(array1, array2) \
+	_array_cmp(&(array1)->arr, &(array2)->arr)
 
 #endif

Index: buffer.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- buffer.c	14 Feb 2006 18:59:12 -0000	1.31
+++ buffer.c	28 Jun 2006 13:10:33 -0000	1.32
@@ -265,7 +265,7 @@
 	return buffer_get_space_unsafe(buf, buf->used, size);
 }
 
-void *buffer_get_modifyable_data(const buffer_t *_buf, size_t *used_size_r)
+void *buffer_get_modifiable_data(const buffer_t *_buf, size_t *used_size_r)
 {
 	const struct real_buffer *buf = (const struct real_buffer *)_buf;
 

Index: buffer.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- buffer.h	14 Jan 2006 18:47:22 -0000	1.18
+++ buffer.h	28 Jun 2006 13:10:33 -0000	1.19
@@ -17,9 +17,9 @@
 
 /* Create a static sized buffer. Writes past this size will kill the program. */
 buffer_t *buffer_create_static_hard(pool_t pool, size_t size);
-/* Create a modifyable buffer from given data. */
+/* Create a modifiable buffer from given data. */
 buffer_t *buffer_create_data(pool_t pool, void *data, size_t size);
-/* Create a non-modifyable buffer from given data. */
+/* Create a non-modifiable buffer from given data. */
 buffer_t *buffer_create_const_data(pool_t pool, const void *data, size_t size);
 void buffer_update_const_data(buffer_t *buffer, const void *data, size_t size);
 /* Creates a dynamically growing buffer. Whenever write would exceed the
@@ -75,9 +75,9 @@
 void *buffer_append_space_unsafe(buffer_t *buf, size_t size);
 
 /* Like buffer_get_data(), but don't return it as const. Returns NULL if the
-   buffer is non-modifyable. WARNING: The returned address may become invalid
+   buffer is non-modifiable. WARNING: The returned address may become invalid
    if you add more data to buffer. */
-void *buffer_get_modifyable_data(const buffer_t *buf, size_t *used_size_r);
+void *buffer_get_modifiable_data(const buffer_t *buf, size_t *used_size_r);
 
 /* Set the "used size" of buffer, ie. 0 would set the buffer empty.
    Must not be used to grow buffer. */

Index: ioloop-epoll.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ioloop-epoll.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- ioloop-epoll.c	16 Jun 2006 10:38:57 -0000	1.12
+++ ioloop-epoll.c	28 Jun 2006 13:10:33 -0000	1.13
@@ -34,7 +34,7 @@
 	struct epoll_event *events;
 
 	unsigned int idx_size;
-	array_t ARRAY_DEFINE(fd_index, struct io_list *);
+	ARRAY_DEFINE(fd_index, struct io_list *);
 };
 
 struct io_list {
@@ -150,7 +150,7 @@
 	int ret, op, fd = io->fd;
 	bool first;
 
-	list = array_idx_modifyable(&ctx->fd_index, fd);
+	list = array_idx_modifiable(&ctx->fd_index, fd);
 	if (*list == NULL)
 		*list = p_new(ioloop->pool, struct io_list, 1);
 
@@ -184,7 +184,7 @@
 	int ret, op;
 	bool last;
 
-	list = array_idx_modifyable(&ctx->fd_index, io->fd);
+	list = array_idx_modifiable(&ctx->fd_index, io->fd);
 	last = iolist_del(*list, io);
 
 	event.data.ptr = *list;

Index: istream.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- istream.c	26 Feb 2006 10:05:06 -0000	1.34
+++ istream.c	28 Jun 2006 13:10:33 -0000	1.35
@@ -155,7 +155,7 @@
 		str_truncate(stream->line_str, 0);
 		str_append_n(stream->line_str, stream->buffer + stream->skip,
 			     end - stream->skip);
-		ret = str_c_modifyable(stream->line_str);
+		ret = str_c_modifiable(stream->line_str);
 	}
 
 	i++;
@@ -178,7 +178,7 @@
 	}
 
 	if (_stream->w_buffer == NULL) {
-		i_error("i_stream_next_line() called for unmodifyable stream");
+		i_error("i_stream_next_line() called for unmodifiable stream");
 		return NULL;
 	}
 
@@ -221,7 +221,7 @@
         return _stream->buffer + _stream->skip;
 }
 
-unsigned char *i_stream_get_modifyable_data(struct istream *stream,
+unsigned char *i_stream_get_modifiable_data(struct istream *stream,
 					    size_t *size)
 {
 	struct _istream *_stream = stream->real_stream;

Index: istream.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/istream.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- istream.h	30 May 2006 13:36:07 -0000	1.25
+++ istream.h	28 Jun 2006 13:10:33 -0000	1.26
@@ -88,7 +88,7 @@
 const unsigned char *i_stream_get_data(struct istream *stream, size_t *size);
 /* Like i_stream_get_data(), but returns non-const data. This only works with
    buffered streams (currently only file), others return NULL. */
-unsigned char *i_stream_get_modifyable_data(struct istream *stream,
+unsigned char *i_stream_get_modifiable_data(struct istream *stream,
 					    size_t *size);
 /* Like i_stream_get_data(), but read more when needed. Returns 1 if more
    than threshold bytes are available, 0 if less, -1 if error or EOF with no

Index: lib.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/lib.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- lib.h	25 Sep 2005 10:44:04 -0000	1.20
+++ lib.h	28 Jun 2006 13:10:33 -0000	1.21
@@ -29,7 +29,6 @@
 #include "imem.h"
 
 typedef struct buffer buffer_t;
-typedef struct array array_t;
 typedef struct buffer string_t;
 
 struct istream;

Index: module-dir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/module-dir.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- module-dir.c	16 Jun 2006 10:15:56 -0000	1.20
+++ module-dir.c	28 Jun 2006 13:10:33 -0000	1.21
@@ -164,7 +164,7 @@
 	const char **module_names_arr;
 	struct module *modules, *module;
 	unsigned int i, count;
-	array_t ARRAY_DEFINE(names, const char *);
+	ARRAY_DEFINE(names, const char *);
 	pool_t pool;
 
 	if (getenv("DEBUG") != NULL)
@@ -195,7 +195,7 @@
 		array_append(&names, &name, 1);
 	}
 
-	names_p = array_get_modifyable(&names, NULL);
+	names_p = array_get_modifiable(&names, NULL);
 	count = array_count(&names);
 	qsort(names_p, count, sizeof(const char *), module_name_cmp);
 

Index: seq-range-array.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/seq-range-array.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- seq-range-array.c	20 Apr 2006 16:02:37 -0000	1.5
+++ seq-range-array.c	28 Jun 2006 13:10:33 -0000	1.6
@@ -4,13 +4,13 @@
 #include "array.h"
 #include "seq-range-array.h"
 
-static bool seq_range_lookup(array_t *array, uint32_t seq, unsigned int *idx_r)
+static bool seq_range_lookup(ARRAY_TYPE(seq_range) *array,
+			     uint32_t seq, unsigned int *idx_r)
 {
-        ARRAY_SET_TYPE(array, struct seq_range);
 	struct seq_range *data;
 	unsigned int idx, left_idx, right_idx, count;
 
-	data = array_get_modifyable(array, &count);
+	data = array_get_modifiable(array, &count);
 
 	idx = 0; left_idx = 0; right_idx = count;
 	while (left_idx < right_idx) {
@@ -31,20 +31,18 @@
 	return FALSE;
 }
 
-void seq_range_array_add(array_t *array, unsigned int init_count, uint32_t seq)
+void seq_range_array_add(ARRAY_TYPE(seq_range) *array,
+			 unsigned int init_count, uint32_t seq)
 {
-        ARRAY_SET_TYPE(array, struct seq_range);
 	struct seq_range *data, value;
 	unsigned int idx, count;
 
 	value.seq1 = value.seq2 = seq;
 
-	if (!array_is_created(array)) {
-		array_create(array, default_pool,
-			     sizeof(struct seq_range), init_count);
-	}
+	if (!array_is_created(array))
+		ARRAY_CREATE(array, default_pool, struct seq_range, init_count);
 
-	data = array_get_modifyable(array, &count);
+	data = array_get_modifiable(array, &count);
 	if (count == 0) {
 		array_append(array, &value, 1);
 		return;
@@ -102,16 +100,15 @@
 	}
 }
 
-void seq_range_array_remove(array_t *array, uint32_t seq)
+void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq)
 {
-        ARRAY_SET_TYPE(array, struct seq_range);
 	struct seq_range *data, value;
 	unsigned int idx, left_idx, right_idx, count;
 
 	if (!array_is_created(array))
 		return;
 
-	data = array_get_modifyable(array, &count);
+	data = array_get_modifiable(array, &count);
 	if (count == 0)
 		return;
 
@@ -174,7 +171,7 @@
 	}
 }
 
-bool seq_range_exists(array_t *array, uint32_t seq)
+bool seq_range_exists(ARRAY_TYPE(seq_range) *array, uint32_t seq)
 {
 	unsigned int idx;
 

Index: seq-range-array.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/seq-range-array.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- seq-range-array.h	13 Jan 2006 20:26:01 -0000	1.2
+++ seq-range-array.h	28 Jun 2006 13:10:33 -0000	1.3
@@ -5,8 +5,11 @@
 	uint32_t seq1, seq2;
 };
 
-void seq_range_array_add(array_t *array, unsigned int init_count, uint32_t seq);
-void seq_range_array_remove(array_t *array, uint32_t seq);
-bool seq_range_exists(array_t *array, uint32_t seq);
+ARRAY_DEFINE_TYPE(seq_range, struct seq_range);
+
+void seq_range_array_add(ARRAY_TYPE(seq_range) *array, unsigned int init_count,
+			 uint32_t seq);
+void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq);
+bool seq_range_exists(ARRAY_TYPE(seq_range) *array, uint32_t seq);
 
 #endif

Index: str.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/str.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- str.c	14 Jan 2006 18:47:22 -0000	1.17
+++ str.c	28 Jun 2006 13:10:33 -0000	1.18
@@ -50,10 +50,10 @@
 	return buffer_get_data(str, NULL);
 }
 
-char *str_c_modifyable(string_t *str)
+char *str_c_modifiable(string_t *str)
 {
 	str_add_nul(str);
-	return buffer_get_modifyable_data(str, NULL);
+	return buffer_get_modifiable_data(str, NULL);
 }
 
 size_t str_len(const string_t *str)

Index: str.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/str.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- str.h	14 Jan 2006 18:47:22 -0000	1.8
+++ str.h	28 Jun 2006 13:10:33 -0000	1.9
@@ -8,7 +8,7 @@
 
 const char *str_c(string_t *str);
 const unsigned char *str_data(const string_t *str);
-char *str_c_modifyable(string_t *str);
+char *str_c_modifiable(string_t *str);
 size_t str_len(const string_t *str);
 
 /* Append string/character */



More information about the dovecot-cvs mailing list