Make M*LIB stricter for INIT_MOVE operator:
* either the default INIT_MOVE operator works ('=')
* either an INIT_MOVE method is defined
* or it is disabled.
As a consequence, fix usage of testobj_t and mpz_t in the repository
The emulation layer of INIT_MOVE using INIT_SET+CLEAR is removed:
it wasn't working correctly with the local memory context
(INIT_MOVE doesn't need any local memory context to work,
whereas INIT_SET/CLEAR does)
Remove macro M_DO_INIT_MOVE as it is now useless and uses M_CALL_INIT_MOVE.
The INIT_MOVE default method no longer sets the old 'src' to '0':
it was useless (it doesn't catch any error) and complicates compiler parsing.
Fix POD & A1 & CSTR & classic oplists definition (missing INIT_MOVE operators).
This commit is contained in:
1 parent
3a39ce5a4a
commit
d548117538
19 files changed
+126
-157
No files matched your search
+3
-3
@@ -33,9 +33,9 @@ END_COVERAGE
|
||||
#define ARRAY_UINT_OPLIST ARRAY_OPLIST(array_uint)
|
||||
|
||||
// Array with the minimum number of methods.
|
||||
ARRAY_DEF(array_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
||||
ARRAY_DEF(array_min2_z, testobj_t, (INIT(testobj_init), CLEAR(testobj_clear)))
|
||||
ARRAY_DEF(array_min3_z, testobj_t, (CLEAR(testobj_clear)))
|
||||
ARRAY_DEF(array_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear), INIT_MOVE(M_COPY_A1_DEFAULT) ))
|
||||
ARRAY_DEF(array_min2_z, testobj_t, (INIT(testobj_init), CLEAR(testobj_clear), INIT_MOVE(M_COPY_A1_DEFAULT) ) )
|
||||
ARRAY_DEF(array_min3_z, testobj_t, (CLEAR(testobj_clear), INIT_MOVE(M_COPY_A1_DEFAULT)))
|
||||
|
||||
ARRAY_DEF(array_ulong, uint64_t)
|
||||
ARRAY_DEF(array_string, string_t)
|
||||
|
||||
+10
-23
@@ -746,65 +746,54 @@ typedef struct { int b,c; } ts;
|
||||
static void f_ti(ti x)
|
||||
{
|
||||
ti y;
|
||||
M_MOVE_A1_DEFAULT(y,x);
|
||||
M_COPY_A1_DEFAULT(y,x);
|
||||
assert(y[0] == 9);
|
||||
assert(x[0] == 0);
|
||||
}
|
||||
|
||||
static void f_ts(ts x)
|
||||
{
|
||||
ts y;
|
||||
M_MOVE_DEFAULT(y,x);
|
||||
M_SET_DEFAULT(y,x);
|
||||
assert(y.b == 2);
|
||||
assert(y.c == 3);
|
||||
assert(x.b == 0);
|
||||
assert(x.c == 0);
|
||||
}
|
||||
|
||||
static void f_ts2(ts *x)
|
||||
{
|
||||
ts y;
|
||||
M_MOVE_DEFAULT(y,*x);
|
||||
M_SET_DEFAULT(y,*x);
|
||||
assert(y.b == 2);
|
||||
assert(y.c == 3);
|
||||
assert(x->b == 0);
|
||||
assert(x->c == 0);
|
||||
}
|
||||
|
||||
static void test_move_default(void)
|
||||
{
|
||||
int o, p;
|
||||
o = 9;
|
||||
M_MOVE_DEFAULT(p, o);
|
||||
M_SET_DEFAULT(p, o);
|
||||
assert(p == 9);
|
||||
assert(o == 0);
|
||||
|
||||
double u, k;
|
||||
k = -1.0;
|
||||
u = 9.5;
|
||||
M_MOVE_DEFAULT(k, u);
|
||||
M_SET_DEFAULT(k, u);
|
||||
assert(k == 9.5);
|
||||
assert(u == 0.0); // NOTE: memset(0) sets an IEEE-754 number to 0.0
|
||||
|
||||
int *ptr = &o, *m;
|
||||
M_MOVE_DEFAULT(m, ptr);
|
||||
assert( ptr == NULL);
|
||||
assert( m == &o);
|
||||
|
||||
M_SET_DEFAULT(m, ptr);
|
||||
(void)m;
|
||||
|
||||
ti x, y;
|
||||
x[0] = 9;
|
||||
M_MOVE_A1_DEFAULT(y, x);
|
||||
M_COPY_A1_DEFAULT(y, x);
|
||||
assert(y[0] == 9);
|
||||
assert(x[0] == 0);
|
||||
|
||||
x[0] = 9;
|
||||
f_ti(x);
|
||||
assert(x[0] == 0);
|
||||
|
||||
ts y2, x2 = { 2, 3};
|
||||
M_MOVE_DEFAULT(y2, x2);
|
||||
M_SET_DEFAULT(y2, x2);
|
||||
assert(y2.b == 2 && y2.c == 3);
|
||||
assert(x2.b == 0 && x2.c == 0);
|
||||
|
||||
x2.b = 2; x2.c = 3;
|
||||
f_ts(x2);
|
||||
@@ -812,8 +801,6 @@ static void test_move_default(void)
|
||||
assert(x2.c == 3);
|
||||
|
||||
f_ts2(&x2);
|
||||
assert(x2.b == 0);
|
||||
assert(x2.c == 0);
|
||||
}
|
||||
|
||||
static void test_builtin(void)
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ END_COVERAGE
|
||||
DEQUE_DEF(deque_mpz, testobj_t, TESTOBJ_OPLIST)
|
||||
|
||||
// Deque with the minimum number of methods.
|
||||
DEQUE_DEF(deque_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
||||
DEQUE_DEF(deque_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear), INIT_MOVE(M_COPY_A1_DEFAULT) ))
|
||||
|
||||
// Dequeue of an enumerate
|
||||
typedef enum {
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ LIST_DUAL_PUSH_DEF(list2_mpz, testobj_t, TESTOBJ_OPLIST)
|
||||
#define LIST2_DOUBLE_OPLIST LIST_OPLIST(list2_double)
|
||||
|
||||
// Array with the minimum number of methods.
|
||||
LIST_DEF(list_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
||||
LIST_DUAL_PUSH_DEF(list2_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear)))
|
||||
LIST_DEF(list_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear), INIT_MOVE(M_COPY_A1_DEFAULT) ))
|
||||
LIST_DUAL_PUSH_DEF(list2_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear), INIT_MOVE(M_COPY_A1_DEFAULT)))
|
||||
|
||||
LIST_DEF(list_string, string_t)
|
||||
#define M_OPL_list_string_t() LIST_OPLIST(list_string, STRING_OPLIST)
|
||||
|
||||
@@ -295,31 +295,26 @@ static void test_basic(void)
|
||||
tree_move_up(it2, &data);
|
||||
tree_get_str(s, t, false);
|
||||
assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{10,[{2,[{1,[{5}]}]}]}]}]"));
|
||||
assert(data == 0);
|
||||
|
||||
data = 11;
|
||||
tree_move_left(it2, &data);
|
||||
tree_get_str(s, t, false);
|
||||
assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{10,[{11},{2,[{1,[{5}]}]}]}]}]"));
|
||||
assert(data == 0);
|
||||
|
||||
data = 12;
|
||||
tree_move_right(it2, &data);
|
||||
tree_get_str(s, t, false);
|
||||
assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{10,[{11},{2,[{1,[{5}]}]},{12}]}]}]"));
|
||||
assert(data == 0);
|
||||
|
||||
data = 13;
|
||||
tree_move_child(it2, &data);
|
||||
tree_get_str(s, t, false);
|
||||
assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{10,[{11},{2,[{13},{1,[{5}]}]},{12}]}]}]"));
|
||||
assert(data == 0);
|
||||
|
||||
data = 14;
|
||||
tree_move_down(it2, &data);
|
||||
tree_get_str(s, t, false);
|
||||
assert(string_equal_str_p(s, "[{0,[{-1,[{3}]},{10,[{11},{2,[{14,[{13},{1,[{5}]}]}]},{12}]}]}]"));
|
||||
assert(data == 0);
|
||||
|
||||
tree_it_set(&it, root);
|
||||
assert(tree_it_equal_p(it, root));
|
||||
|
||||
@@ -236,6 +236,7 @@ static inline size_t test_obj_except__hash(const test_obj_except__t z)
|
||||
INIT_SET(test_obj_except__init_set), \
|
||||
SET(test_obj_except__set), \
|
||||
CLEAR(test_obj_except__clear), \
|
||||
INIT_MOVE(M_COPY_A1_DEFAULT), \
|
||||
TYPE(test_obj_except__t), \
|
||||
ADD(test_obj_except__add), \
|
||||
OUT_STR(test_obj_except__out_str), \
|
||||
|
||||
+4
-2
@@ -227,11 +227,12 @@ static inline void testobj_str(string_t str, const testobj_t z, bool append)
|
||||
// This enables testing good macro expansion in OPLIST usage
|
||||
#define testobj_clear_indirect(op, x) testobj_clear(x)
|
||||
|
||||
#define TESTOBJ_OPLIST \
|
||||
#define TESTOBJ_OPLIST \
|
||||
(INIT(testobj_init), \
|
||||
INIT_SET(testobj_init_set), \
|
||||
SET(testobj_set), \
|
||||
CLEAR(API_1(testobj_clear_indirect)), \
|
||||
INIT_MOVE(M_COPY_A1_DEFAULT), \
|
||||
TYPE(testobj_t), \
|
||||
OUT_STR(testobj_out_str), \
|
||||
IN_STR(testobj_in_str), \
|
||||
@@ -242,11 +243,12 @@ static inline void testobj_str(string_t str, const testobj_t z, bool append)
|
||||
EMPLACE_TYPE( LIST( (_ui, testobj_init_set_ui, unsigned int), (_str, testobj_init_set_str, const char *), ( /*empty*/, testobj_init_set, testobj_t) ) ) \
|
||||
)
|
||||
|
||||
#define TESTOBJ_CMP_OPLIST \
|
||||
#define TESTOBJ_CMP_OPLIST \
|
||||
(INIT(testobj_init), \
|
||||
INIT_SET(testobj_init_set), \
|
||||
SET(testobj_set), \
|
||||
CLEAR(testobj_clear), \
|
||||
INIT_MOVE(M_COPY_A1_DEFAULT), \
|
||||
TYPE(testobj_t), \
|
||||
OUT_STR(testobj_out_str), \
|
||||
IN_STR(testobj_in_str), \
|
||||
|
||||
Reference in new issue
Block a user