[dovecot-cvs] dovecot/src/lib array.h,1.22,1.23

tss at dovecot.org tss at dovecot.org
Sat Mar 31 08:01:09 EEST 2007


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

Modified Files:
	array.h 
Log Message:
Use COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE() for validating the data type.



Index: array.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/array.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- array.h	25 Jan 2007 13:17:12 -0000	1.22
+++ array.h	31 Mar 2007 05:01:06 -0000	1.23
@@ -45,13 +45,12 @@
 #  define ARRAY_TYPE_CAST_MODIFIABLE(array) \
 	(typeof(*(array)->v_modifiable))
 #  define ARRAY_TYPE_CHECK(array, data) \
-	typeof(const typeof(**(array)->v_modifiable) *) \
-		__tmp_array_data2 __attr_unused__ = \
-			(typeof(const typeof(typeof(*(data)) *)))NULL;
+	COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \
+		**(array)->v_modifiable, *data)
 #else
 #  define ARRAY_TYPE_CAST_CONST(array)
 #  define ARRAY_TYPE_CAST_MODIFIABLE(array)
-#  define ARRAY_TYPE_CHECK(array, data)
+#  define ARRAY_TYPE_CHECK(array, data) 0
 #endif
 
 static inline void
@@ -107,10 +106,9 @@
 	buffer_append(array->buffer, data, count * array->element_size);
 }
 
-#define array_append(array, data, count) STMT_START { \
-	ARRAY_TYPE_CHECK(array, data) \
-	_array_append(&(array)->arr, data, count); \
-} STMT_END
+#define array_append(array, data, count) \
+	_array_append(&(array)->arr + ARRAY_TYPE_CHECK(array, data), \
+		data, count)
 
 static inline void
 _array_append_array(struct array *dest_array, const struct array *src_array)
@@ -129,10 +127,9 @@
 		      data, count * array->element_size);
 }
 
-#define array_insert(array, idx, data, count) STMT_START { \
-	ARRAY_TYPE_CHECK(array, data) \
-	_array_insert(&(array)->arr, idx, data, count); \
-	} STMT_END
+#define array_insert(array, idx, data, count) \
+	_array_insert(&(array)->arr + ARRAY_TYPE_CHECK(array, data), \
+		idx, data, count)
 
 static inline void
 _array_delete(struct array *array, unsigned int idx, unsigned int count)
@@ -200,10 +197,8 @@
 	}
 	buffer_write(array->buffer, pos, data, array->element_size);
 }
-#define array_idx_set(array, idx, data) STMT_START { \
-	ARRAY_TYPE_CHECK(array, data) \
-	_array_idx_set(&(array)->arr, idx, data); \
-	} STMT_END
+#define array_idx_set(array, idx, data) \
+	_array_idx_set(&(array)->arr + ARRAY_TYPE_CHECK(array, data), idx, data)
 
 static inline void
 _array_idx_clear(struct array *array, unsigned int idx)



More information about the dovecot-cvs mailing list