X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Ftrans.c;h=db8838372db0d8a2d7f3dd70944a840ce2cfffdc;hb=9689a6aa2bb0815ab95ea679d0d298acc4c5cd5b;hp=a8de27cdcc5f7ea82c499e56c82eb87d38717009;hpb=349d89dca4a4ab2420b57c8a0f1d233f3af4cd1c;p=libucw.git diff --git a/ucw/trans.c b/ucw/trans.c index a8de27cd..db883837 100644 --- a/ucw/trans.c +++ b/ucw/trans.c @@ -9,10 +9,10 @@ #undef LOCAL_DEBUG -#include "ucw/lib.h" -#include "ucw/trans.h" -#include "ucw/respool.h" -#include "ucw/mempool.h" +#include +#include +#include +#include #include @@ -93,7 +93,7 @@ trans_commit(void) DBG("Committing transaction %p", t); ASSERT(t); ASSERT(!t->thrown_exc); - rp_detach(t->rpool); + rp_commit(t->rpool); trans_pop(t, c); trans_drop(t, c); } @@ -126,14 +126,15 @@ trans_fold(void) } void -trans_caught(struct exception *x) +trans_caught(void) { // Exception has been finally caught. Roll back the current transaction, // including all sub-transactions that have been folded to it during // propagation. - DBG("... exception %p caught", x); struct trans *t = trans_get_current(); - ASSERT(t->thrown_exc == x); + struct exception *x = t->thrown_exc; + ASSERT(x); + DBG("... exception %p caught", x); t->thrown_exc = NULL; trans_rollback(); } @@ -170,7 +171,7 @@ trans_throw_exc(struct exception *x) // If we are already handling an exception (i.e., throw from a catch handler), // fold the current transaction into its parent. - if (t->thrown_exc) + while (t->thrown_exc) { if (!t->prev_trans) die("%s", x->msg); @@ -240,6 +241,18 @@ int main(void) { printf("Inner catch: %s\n", x->msg); trans_dump(); + TRANS_TRY + { + res_malloc(256, NULL); + trans_throw("ucw.test.nested", "nest", "Something is wrong recursively"); + } + TRANS_CATCH(y) + { + printf("Yet another layer: %s\n", y->msg); + trans_dump(); + // trans_throw_exc(y); + } + TRANS_END; trans_throw("ucw.test2", "out", "Error: %s", x->msg); } TRANS_END;