[dovecot-cvs] dovecot/src/lib array-decl.h, 1.2, 1.3 array.h, 1.18, 1.19

cras at dovecot.org cras at dovecot.org
Sat Sep 16 16:31:16 EEST 2006


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

Modified Files:
	array-decl.h array.h 
Log Message:
Some more array changes. v and v_modifiable are now pointer-to-pointers so
that they can actually be used to access the array's contents directly. Only
array_idx() uses this currently though, and only if asserts are disabled.



Index: array-decl.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/array-decl.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- array-decl.h	28 Jun 2006 13:10:33 -0000	1.2
+++ array-decl.h	16 Sep 2006 13:31:14 -0000	1.3
@@ -1,11 +1,11 @@
 #ifndef __ARRAY_DECL_H
 #define __ARRAY_DECL_H
 
-#define ARRAY_DEFINE(name, array_type) union { struct array arr; array_type const *v; array_type *v_modifiable; } name
+#define ARRAY_DEFINE(name, array_type) union { struct array arr; array_type const *const *v; array_type **v_modifiable; } name
 #define ARRAY_INIT { { 0, 0 } }
 
 #define ARRAY_DEFINE_TYPE(name, array_type) \
-	union array ## __ ## name { struct array arr; array_type const *v; array_type *v_modifiable; }
+	union array ## __ ## name { struct array arr; array_type const *const *v; array_type **v_modifiable; }
 #define ARRAY_TYPE(name) \
 	union array ## __ ## name
 

Index: array.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/array.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- array.h	10 Sep 2006 12:48:14 -0000	1.18
+++ array.h	16 Sep 2006 13:31:14 -0000	1.19
@@ -33,7 +33,7 @@
 #include "buffer.h"
 
 #define p_array_init(array, pool, init_count) \
-	array_create(array, pool, sizeof(*(array)->v), init_count);
+	array_create(array, pool, sizeof(**(array)->v), init_count);
 #define i_array_init(array, init_count) \
 	p_array_init(array, default_pool, init_count)
 #define t_array_init(array, init_count) \
@@ -41,11 +41,11 @@
 
 #ifdef __GNUC__
 #  define ARRAY_TYPE_CAST_CONST(array) \
-	(typeof((array)->v))
+	(typeof(*(array)->v))
 #  define ARRAY_TYPE_CAST_MODIFIABLE(array) \
-	(typeof((array)->v_modifiable))
+	(typeof(*(array)->v_modifiable))
 #  define ARRAY_TYPE_CHECK(array, data) \
-	typeof(const typeof(*(array)->v_modifiable) *) \
+	typeof(const typeof(**(array)->v_modifiable) *) \
 		__tmp_array_data2 __attr_unused__ = \
 			(typeof(const typeof(typeof(*(data)) *)))NULL;
 #else
@@ -159,8 +159,13 @@
 	i_assert(idx * array->element_size < array->buffer->used);
 	return CONST_PTR_OFFSET(array->buffer->data, idx * array->element_size);
 }
-#define array_idx(array, idx) \
+#ifdef DISABLE_ASSERTS
+#  define array_idx(array, idx) \
+	&((*(array)->v)[idx])
+#else
+#  define array_idx(array, idx) \
 	ARRAY_TYPE_CAST_CONST(array)_array_idx(&(array)->arr, idx)
+#endif
 
 static inline void *
 _array_get_modifiable(struct array *array, unsigned int *count_r)
@@ -186,9 +191,9 @@
 	}
 	return buffer_get_space_unsafe(array->buffer, pos, array->element_size);
 }
-#define array_idx_modifiable(array, count) \
+#define array_idx_modifiable(array, idx) \
 	ARRAY_TYPE_CAST_MODIFIABLE(array) \
-		_array_idx_modifiable(&(array)->arr, count)
+		_array_idx_modifiable(&(array)->arr, idx)
 
 static inline void
 _array_idx_set(struct array *array, unsigned int idx, const void *data)



More information about the dovecot-cvs mailing list