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 = nullptr; \
56 x->name##_array_len = 0; \
62#define expand_xdr_array(name) \
63 u_int old_length = x->name##_array_len; \
64 if (n + 1 > (x->name##_array_len)) { \
65 if (x->name##_array_len == 0) x->name##_array_len = 1; \
67 x->name##_array_len *= 2; \
68 } while (n + 1 > (x->name##_array_len)); \
69 x->name##_array_val = (name *)realloc(x->name##_array_val, \
70 x->name##_array_len * sizeof(name)); \
71 memset(&x->name##_array_val[old_length], 0, \
72 (x->name##_array_len - old_length) * sizeof(name)); \
78#define def_set_xdr_array(name) \
79 static inline void set_##name(name##_array *x, name a, u_int n)
80#define set_xdr_array(name) \
81 def_set_xdr_array(name) { \
82 expand_xdr_array(name); \
83 assert(n < x->name##_array_len); \
84 x->name##_array_val[n] = a; \
90#define def_get_xdr_array(name) \
91 static inline name get_##name(name##_array *x, u_int n)
92#define get_xdr_array(name) \
93 def_get_xdr_array(name) { \
94 expand_xdr_array(name); \
95 assert(n < x->name##_array_len); \
96 return x->name##_array_val[n]; \
102#define def_clone_xdr_array(name) \
103 static inline name##_array clone_##name##_array(name##_array x)
104#define clone_xdr_array(name) \
105 def_clone_xdr_array(name) { \
106 name##_array retval = x; \
108 retval.name##_array_len = x.name##_array_len; \
109 IFDBG(D_XDR, FN; NDBG(retval.name##_array_len, u)); \
110 if (retval.name##_array_len > 0) { \
111 retval.name##_array_val = \
112 (name *)xcom_calloc((size_t)x.name##_array_len, sizeof(name)); \
113 for (i = 0; i < retval.name##_array_len; i++) { \
114 retval.name##_array_val[i] = x.name##_array_val[i]; \
115 IFDBG(D_XDR, FN; STRLIT("clone_xdr_array"); NDBG(i, u)); \
118 retval.name##_array_val = 0; \
126#define d_xdr_funcs(name) \
127 def_init_xdr_array(name); \
128 def_free_xdr_array(name); \
129 def_set_xdr_array(name); \
130 def_get_xdr_array(name); \
131 def_clone_xdr_array(name);
136#define define_xdr_funcs(name) \
137 init_xdr_array(name) free_xdr_array(name) set_xdr_array(name) \
138 get_xdr_array(name) clone_xdr_array(name)
143#define insert_sort(type, x, n) \
146 for (i = 1; i < n; i++) { \
150 while (j > 0 && insert_sort_gt(x[j - 1], tmp)) { \
163#define bin_search_first_body(x, first, last, key, p) \
167 while (l + 1 != u) { \
169 if (bin_search_lt((x)[m], (key))) { \
181#define bin_search_last_body(x, first, last, key, p) \
185 while (l + 1 != u) { \
187 if (bin_search_gt((x)[m], (key))) { \
197#define bin_search_first(x, first, last, key, p) \
199 bin_search_first_body(x, first, last, key, p); \
201 if (p > last || (!bin_search_eq((x)[p], (key)))) p = -1; \
207#define bin_search_first_gt(x, first, last, key, p) \
209 bin_search_last_body(x, first, last, key, p); \
211 if (p > last || (!bin_search_gt((x)[p], (key)))) p = -1; \
217#define bin_search_last(x, first, last, key, p) \
219 bin_search_last_body(x, first, last, key, p); \
221 if (p < first || (!bin_search_eq((x)[p], (key)))) p = -1; \
227#define bin_search_last_lt(x, first, last, key, p) \
229 bin_search_first_body(x, first, last, key, p); \
231 if (p < first || (!bin_search_lt((x)[p], (key)))) p = -1; \
234#define diff_get(type, a, i) get_##type##_array(a, i)
235#define diff_output(type, x) set_##type##_array(&retval, x, retval_i++)
236#define diff_gt(x, y) insert_sort_gt(x, y)
242#define diff_xdr_array(type, x, y) \
243 type##_array diff_##type##_array(type##_array x, type##_array y) { \
248 init_##type##_array(&retval); \
249 insert_sort(type, x.type##_val, x.type##_len); \
250 insert_sort(type, y.type##_val, y.type##_len); \
251 while (x_i < x.type##_len && y < y.type##_len) { \
252 if (diff_eq(diff_get(type, x, x_i), diff_get(type, y, y_i))) { \
255 } else if (diff_lt(diff_get(type, x, x_i), diff_get(type, y, y_i))) { \
256 diff_output(type, diff_get(type, x, x_i++)); \
258 diff_output(type, diff_get(type, y, y_i++)); \
261 while (x_i < x.type##_len) { \
262 diff_output(type, diff_get(type, x, x_i++)); \
264 while (y_i < y.type##_len) { \
265 diff_output(type, diff_get(type, y, y_i++)); \
267 retval.type##_len = retval_i; \
273#define x_reverse(type, x, in_n1, in_n2) \
277 while ((n1) < (n2)) { \
278 type tmp = (x)[n1]; \
288#define x_blkmove(type, x, n1, n2, n3) \
290 if ((n3) < (n1)-1) { \
291 x_reverse(type, (x), (n3) + 1, (n1)-1); \
292 x_reverse(type, (x), (n1), (n2)); \
293 x_reverse(type, (x), (n3) + 1, (n2)); \
294 } else if ((n3) > (n2)) { \
295 x_reverse(type, (x), (n1), (n2)); \
296 x_reverse(type, (x), (n2) + 1, (n3)); \
297 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