Adding macro M_CHAIN_OBJ

This commit is contained in:
Patrick Pelissier committed 2023-10-14 15:55:59 +02:00
1 parent 19e61467d5
commit 5f4303624f
3 files changed
+180 -6

No files matched your search

+83 -2
View File
@@ -488,6 +488,27 @@ static void struct_init_set(struct_t x, const struct_t y)
}
}
static void struct_initb(struct_t x)
{
M_CHAIN_OBJ(o1, TESTOBJ_OPLIST, x->o1)
M_CHAIN_OBJ(o2, TESTOBJ_OPLIST, x->o2)
M_CHAIN_OBJ(o3, M_BASIC_OPLIST, x->num) {
if (++g_flow == g_throw) M_THROW(1);
}
}
static void struct_init_setb(struct_t x, const struct_t y)
{
M_CHAIN_OBJ(o1, TESTOBJ_OPLIST, x->o1, y->o1) {
// Throw within the constructor (object partially constructed)
if (++g_flow == g_throw) M_THROW(1);
M_CHAIN_OBJ(o2, TESTOBJ_OPLIST, x->o2, y->o2)
M_CHAIN_OBJ(o3, M_BASIC_OPLIST, x->num, y->num) {
if (++g_flow == g_throw) M_THROW(1);
}
}
}
static void struct_clear(struct_t x)
{
testobj_clear(x->o1);
@@ -496,7 +517,7 @@ static void struct_clear(struct_t x)
#define M_OPL_struct_t() M_CLASSIC_OPLIST(struct)
static void test4(void)
static void test4a(void)
{
g_flow = 0;
g_throw = 4;
@@ -552,6 +573,65 @@ static void test4(void)
}
}
#define STRUCTB_OPLIST \
(INIT(struct_initb), INIT_SET(struct_init_setb), CLEAR(struct_clear), TYPE(struct_t))
static void test4b(void)
{
g_flow = 0;
g_throw = 4;
M_TRY(main) {
assert(++g_flow == 1);
M_LET(a, STRUCTB_OPLIST) {
assert(++g_flow == 3);
M_LET( (b, a), STRUCTB_OPLIST) {
assert(false);
}
}
} M_CATCH(main, 0) {
assert(++g_flow == 5);
}
g_flow = 0;
g_throw = 5;
M_TRY(main) {
assert(++g_flow == 1);
M_LET(a, STRUCTB_OPLIST) {
assert(++g_flow == 3);
M_LET( (b, a), STRUCTB_OPLIST) {
assert(false);
}
}
} M_CATCH(main, 0) {
assert(++g_flow == 6);
}
g_flow = 0;
g_throw = 2;
M_TRY(main) {
assert(++g_flow == 1);
M_LET(a, STRUCTB_OPLIST) {
assert(false);
}
} M_CATCH(main, 0) {
assert(++g_flow == 3);
}
g_flow = 0;
g_throw = 0;
M_TRY(main) {
assert(++g_flow == 1);
M_LET(a, STRUCTB_OPLIST) {
assert(++g_flow == 3);
M_LET( (b, a), STRUCTB_OPLIST) {
assert(++g_flow == 6);
}
}
} M_CATCH(main, 0) {
assert(false);
}
}
static void test_final(void)
{
// Throw without a try block shall raise the M_RAISE_FATAL macro
@@ -568,7 +648,8 @@ int main(void)
test1();
test2();
test3();
test4();
test4a();
test4b();
testobj_final_check();
test_final();
exit(1); // Shall not be reached.