X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=err.h;h=cf428563e960def9a98c2109b67e3e8f93955452;hp=2800526a93fdb8a98ff1ffbf6d68d1ba834eec5c;hb=f7df28b4d0155c780fa46a09d2dbcf7825faebae;hpb=4535c379ced2bdb6a4b414f71080fa0c6f5180aa diff --git a/err.h b/err.h index 2800526..cf42856 100644 --- a/err.h +++ b/err.h @@ -13,7 +13,7 @@ */ /* - * functions for debug and error handling + * functions for debug and error handling, for internal use only */ #ifdef DEBUG @@ -38,7 +38,7 @@ * functions from other uci functions is only allowed at the end of the * calling function. */ -#define UCI_HANDLE_ERR(ctx) do { \ +#define UCI_HANDLE_ERR(ctx) do { \ int __val; \ if (!ctx) \ return UCI_ERR_INVAL; \ @@ -50,6 +50,26 @@ } while (0) /* + * In a block enclosed by UCI_TRAP_SAVE and UCI_TRAP_RESTORE, all exceptions + * are intercepted and redirected to the label specified in 'handler' + * after UCI_TRAP_RESTORE, or when reaching the 'handler' label, the old + * exception handler is restored + */ +#define UCI_TRAP_SAVE(ctx, handler) do { \ + jmp_buf __old_trap; \ + int __val; \ + memcpy(__old_trap, ctx->trap, sizeof(ctx->trap)); \ + __val = setjmp(ctx->trap); \ + if (__val) { \ + ctx->errno = __val; \ + memcpy(ctx->trap, __old_trap, sizeof(ctx->trap)); \ + goto handler; \ + } +#define UCI_TRAP_RESTORE(ctx) \ + memcpy(ctx->trap, __old_trap, sizeof(ctx->trap)); \ +} while(0) + +/* * check the specified condition. * throw an invalid argument exception if it's false */ @@ -60,4 +80,3 @@ } \ } while (0) -