X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=err.h;h=cf428563e960def9a98c2109b67e3e8f93955452;hp=469164cd635724e1248a0e5c57a27170f2cdfc2f;hb=854f7c5d08cd37aeb7414e26ed6666fad26f5f7a;hpb=4cec5755115eb3c48dc50dfcc5558f71f00d59c6 diff --git a/err.h b/err.h index 469164c..cf42856 100644 --- a/err.h +++ b/err.h @@ -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 */