38#define def_init_xdr_array(name) \
39 static inline void init_##name##_array(name##_array *x)
40#define init_xdr_array(name) \
41 def_init_xdr_array(name) { \
42 x->name##_array_len = 2; \
43 x->name##_array_val = \
44 (name *)xcom_calloc((size_t)x->name##_array_len, sizeof(name)); \
50#define def_free_xdr_array(name) \
51 static inline void free_##name##_array(name##_array *x)
52#define free_xdr_array(name) \
53 def_free_xdr_array(name) { \
54 free(x->name##_array_val); \
55 x->name##_array_val = 0; \
56 x->name##_array_len = 0; \
59#define in_range(x, name, n) \
60 (((int)n) >= 0 && ((int)n) < ((int)(x).name##_array_len))
65#define expand_xdr_array(name) \
66 u_int old_length = x->name##_array_len; \
67 if (n + 1 > (x->name##_array_len)) { \
68 if (x->name##_array_len == 0) x->name##_array_len = 1; \
70 x->name##_array_len *= 2; \
71 } while (n + 1 > (x->name##_array_len)); \
72 x->name##_array_val = (name *)realloc(x->name##_array_val, \
73 x->name##_array_len * sizeof(name)); \
74 memset(&x->name##_array_val[old_length], 0, \
75 (x->name##_array_len - old_length) * sizeof(name)); \
81#define def_set_xdr_array(name) \
82 static inline void set_##name(name##_array *x, name a, u_int n)
83#define set_xdr_array(name) \
84 def_set_xdr_array(name) { \
85 expand_xdr_array(name); \
86 assert(n < x->name##_array_len); \
87 x->name##_array_val[n] = a; \
93#define def_get_xdr_array(name) \
94 static inline name get_##name(name##_array *x, u_int n)
95#define get_xdr_array(name) \
96 def_get_xdr_array(name) { \
97 expand_xdr_array(name); \
98 assert(n < x->name##_array_len); \
99 return x->name##_array_val[n]; \
105#define def_clone_xdr_array(name) \
106 static inline name##_array clone_##name##_array(name##_array x)
107#define clone_xdr_array(name) \
108 def_clone_xdr_array(name) { \
109 name##_array retval = x; \
111 retval.name##_array_len = x.name##_array_len; \
112 IFDBG(D_XDR, FN; NDBG(retval.name##_array_len, u)); \
113 if (retval.name##_array_len > 0) { \
114 retval.name##_array_val = \
115 (name *)xcom_calloc((size_t)x.name##_array_len, sizeof(name)); \
116 for (i = 0; i < retval.name##_array_len; i++) { \
117 retval.name##_array_val[i] = x.name##_array_val[i]; \
118 IFDBG(D_XDR, FN; STRLIT("clone_xdr_array"); NDBG(i, u)); \
121 retval.name##_array_val = 0; \
129#define d_xdr_funcs(name) \
130 def_init_xdr_array(name); \
131 def_free_xdr_array(name); \
132 def_set_xdr_array(name); \
133 def_get_xdr_array(name); \
134 def_clone_xdr_array(name);
139#define define_xdr_funcs(name) \
140 init_xdr_array(name) free_xdr_array(name) set_xdr_array(name) \
141 get_xdr_array(name) clone_xdr_array(name)
146#define insert_sort(type, x, n) \
149 for (i = 1; i < n; i++) { \
153 while (j > 0 && insert_sort_gt(x[j - 1], tmp)) { \
166#define bin_search_first_body(x, first, last, key, p) \
170 while (l + 1 != u) { \
172 if (bin_search_lt((x)[m], (key))) { \
184#define bin_search_last_body(x, first, last, key, p) \
188 while (l + 1 != u) { \
190 if (bin_search_gt((x)[m], (key))) { \
200#define bin_search_first(x, first, last, key, p) \
202 bin_search_first_body(x, first, last, key, p); \
204 if (p > last || (!bin_search_eq((x)[p], (key)))) p = -1; \
210#define bin_search_first_gt(x, first, last, key, p) \
212 bin_search_last_body(x, first, last, key, p); \
214 if (p > last || (!bin_search_gt((x)[p], (key)))) p = -1; \
220#define bin_search_last(x, first, last, key, p) \
222 bin_search_last_body(x, first, last, key, p); \
224 if (p < first || (!bin_search_eq((x)[p], (key)))) p = -1; \
230#define bin_search_last_lt(x, first, last, key, p) \
232 bin_search_first_body(x, first, last, key, p); \
234 if (p < first || (!bin_search_lt((x)[p], (key)))) p = -1; \
237#define diff_get(type, a, i) get_##type##_array(a, i)
238#define diff_output(type, x) set_##type##_array(&retval, x, retval_i++)
239#define diff_gt(x, y) insert_sort_gt(x, y)
245#define diff_xdr_array(type, x, y) \
246 type##_array diff_##type##_array(type##_array x, type##_array y) { \
251 init_##type##_array(&retval); \
252 insert_sort(type, x.type##_val, x.type##_len); \
253 insert_sort(type, y.type##_val, y.type##_len); \
254 while (x_i < x.type##_len && y < y.type##_len) { \
255 if (diff_eq(diff_get(type, x, x_i), diff_get(type, y, y_i))) { \
258 } else if (diff_lt(diff_get(type, x, x_i), diff_get(type, y, y_i))) { \
259 diff_output(type, diff_get(type, x, x_i++)); \
261 diff_output(type, diff_get(type, y, y_i++)); \
264 while (x_i < x.type##_len) { \
265 diff_output(type, diff_get(type, x, x_i++)); \
267 while (y_i < y.type##_len) { \
268 diff_output(type, diff_get(type, y, y_i++)); \
270 retval.type##_len = retval_i; \
276#define x_reverse(type, x, in_n1, in_n2) \
280 while ((n1) < (n2)) { \
281 type tmp = (x)[n1]; \
291#define x_blkmove(type, x, n1, n2, n3) \
293 if ((n3) < (n1)-1) { \
294 x_reverse(type, (x), (n3) + 1, (n1)-1); \
295 x_reverse(type, (x), (n1), (n2)); \
296 x_reverse(type, (x), (n3) + 1, (n2)); \
297 } else if ((n3) > (n2)) { \
298 x_reverse(type, (x), (n1), (n2)); \
299 x_reverse(type, (x), (n2) + 1, (n3)); \
300 x_reverse(type, (x), (n1), (n3)); \
__u_long u_long
Definition: types.h:74
bool_t(* xdrproc_t)(XDR *, void *,...)
Definition: xdr.h:143
u_long xdr_sizeof(xdrproc_t, void *) __THROW
Definition: xdr_sizeof.c:95