diff --git a/m-array.h b/m-array.h index 5b472b7c..7061986f 100644 --- a/m-array.h +++ b/m-array.h @@ -1134,7 +1134,9 @@ M_F(name, _subtype_ct) *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ + M_IF_EXCEPTION( v->size --); \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + M_IF_EXCEPTION( v->size ++); \ } \ /********************************** INTERNAL *********************************/ diff --git a/m-list.h b/m-list.h index c5d5d675..f6702f32 100644 --- a/m-list.h +++ b/m-list.h @@ -897,7 +897,10 @@ M_F(name, _subtype_ct) *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ - M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + M_IF_EXCEPTION(struct M_F(name, _s) *next = *v ); \ + M_ON_EXCEPTION( *v = next->next, M_C3(m_l1st_,name,_del)(next)) { \ + M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + } \ } @@ -910,7 +913,10 @@ M_F(name, _subtype_ct) *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ - M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + M_IF_EXCEPTION(struct M_F(name, _s) *next = v->back); \ + M_ON_EXCEPTION( v->back = next->next, v->front = (v->front == next) ? NULL : v->front, M_C3(m_l1st_,name,_del)(next)) { \ + M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + } \ } @@ -920,10 +926,15 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ + M_IF_EXCEPTION(struct M_F(name, _s) *front = v->front, *back = v->back); \ M_F(name, _subtype_ct) *data = M_F(name, _push_front_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ - M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + M_IF_EXCEPTION(struct M_F(name, _s) *m_volatile tofree = v->front); \ + M_IF_EXCEPTION(M_ASSERT(tofree != NULL)); \ + M_ON_EXCEPTION( v->back = back, v->front = front, (front != NULL ? front : tofree)->next = NULL, M_C3(m_l1st_,name,_del)(tofree)) { \ + M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ + } \ } diff --git a/tests/except-array.c b/tests/except-array.c index 360ee05b..064eaa47 100644 --- a/tests/except-array.c +++ b/tests/except-array.c @@ -61,6 +61,8 @@ static void test1(unsigned n) assert(b); } array_obj_insert_v(tmp, 12, 3); + array_obj_emplace_back_ui(tmp, 345); + array_obj_emplace_back_str(tmp, "345"); } } M_CATCH(test1, 0) { // Nothing to do diff --git a/tests/except-list.c b/tests/except-list.c index 60b3b92e..64f4db01 100644 --- a/tests/except-list.c +++ b/tests/except-list.c @@ -58,6 +58,8 @@ static void test1(unsigned n) } list_obj_it_t it; list_obj_it(it, tmp); list_obj_next(it); list_obj_insert(tmp, it, obj); + list_obj_emplace_back_ui(list, 345); + list_obj_emplace_back_str(list, "345"); } } M_CATCH(test1, 0) { // Nothing to do @@ -102,6 +104,8 @@ static void test2(unsigned n) } list2_obj_it_t it; list2_obj_it(it, tmp); list2_obj_next(it); list2_obj_insert(tmp, it, obj); + list2_obj_emplace_back_ui(tmp, 345); + list2_obj_emplace_back_str(tmp, "345"); } } M_CATCH(test1, 0) { // Nothing to do @@ -132,6 +136,8 @@ static void test3(unsigned n) list2_obj_push_front(list, obj); } list2_obj_push_front_new(list); + list2_obj_emplace_front_ui(list, 345); + list2_obj_emplace_front_str(list, "345"); } } M_CATCH(test1, 0) { // Nothing to do