diff --git a/upb/decode.c b/upb/decode.c index 588b35171e..84bdf375d5 100644 --- a/upb/decode.c +++ b/upb/decode.c @@ -147,9 +147,7 @@ typedef union { static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg, const upb_msglayout *layout); -UPB_NORETURN static void decode_err(upb_decstate *d) { - _upb_longjmp(d->err, 1); -} +UPB_NORETURN static void decode_err(upb_decstate *d) { UPB_LONGJMP(d->err, 1); } const char *fastdecode_err(upb_decstate *d) { longjmp(d->err, 1); @@ -673,7 +671,7 @@ bool _upb_decode(const char *buf, size_t size, void *msg, state.arena.last_size = arena->last_size; state.arena.parent = arena; - if (UPB_UNLIKELY(_upb_setjmp(state.err))) { + if (UPB_UNLIKELY(UPB_SETJMP(state.err))) { ok = false; } else { if (!decode_tryfastdispatch(&state, &buf, msg, l)) { diff --git a/upb/def.c b/upb/def.c index 5ac9ceddc9..600153e8d5 100644 --- a/upb/def.c +++ b/upb/def.c @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -909,13 +910,13 @@ static void symtab_errf(symtab_addctx *ctx, const char *fmt, ...) { va_start(argp, fmt); upb_status_vseterrf(ctx->status, fmt, argp); va_end(argp); - longjmp(ctx->err, 1); + UPB_LONGJMP(ctx->err, 1); } UPB_NORETURN UPB_NOINLINE static void symtab_oomerr(symtab_addctx *ctx) { upb_status_setoom(ctx->status); - longjmp(ctx->err, 1); + UPB_LONGJMP(ctx->err, 1); } void *symtab_alloc(symtab_addctx *ctx, size_t bytes) { @@ -2093,7 +2094,7 @@ static const upb_filedef *_upb_symtab_addfile( file->enum_count = 0; file->ext_count = 0; - if (UPB_UNLIKELY(_upb_setjmp(ctx.err))) { + if (UPB_UNLIKELY(UPB_SETJMP(ctx.err))) { UPB_ASSERT(!upb_ok(status)); remove_filedef(s, file); file = NULL; diff --git a/upb/encode.c b/upb/encode.c index 818e76a840..6d56544346 100644 --- a/upb/encode.c +++ b/upb/encode.c @@ -2,12 +2,12 @@ #include "upb/encode.h" +#include #include #include "upb/msg.h" -#include "upb/upb.h" - #include "upb/port_def.inc" +#include "upb/upb.h" #define UPB_PB_VARINT_MAX_LEN 10 @@ -41,7 +41,7 @@ static size_t upb_roundup_pow2(size_t bytes) { } UPB_NORETURN static void encode_err(upb_encstate *e) { - _upb_longjmp(e->err, 1); + UPB_LONGJMP(e->err, 1); } UPB_NOINLINE @@ -420,7 +420,7 @@ char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena, e.limit = NULL; e.ptr = NULL; - if (_upb_setjmp(e.err)) { + if (UPB_SETJMP(e.err)) { *size = 0; return NULL; } diff --git a/upb/json_decode.c b/upb/json_decode.c index ed8c2bffbf..1a18253d27 100644 --- a/upb/json_decode.c +++ b/upb/json_decode.c @@ -58,7 +58,7 @@ static bool jsondec_isvalue(const upb_fielddef *f) { UPB_NORETURN static void jsondec_err(jsondec *d, const char *msg) { upb_status_seterrf(d->status, "Error parsing JSON @%d:%d: %s", d->line, (int)(d->ptr - d->line_begin), msg); - _upb_longjmp(d->err, 1); + UPB_LONGJMP(d->err, 1); } UPB_NORETURN static void jsondec_errf(jsondec *d, const char *fmt, ...) { @@ -68,7 +68,7 @@ UPB_NORETURN static void jsondec_errf(jsondec *d, const char *fmt, ...) { va_start(argp, fmt); upb_status_vappenderrf(d->status, fmt, argp); va_end(argp); - _upb_longjmp(d->err, 1); + UPB_LONGJMP(d->err, 1); } static void jsondec_skipws(jsondec *d) { @@ -1435,7 +1435,7 @@ bool upb_json_decode(const char *buf, size_t size, upb_msg *msg, d.debug_field = NULL; d.is_first = false; - if (_upb_setjmp(d.err)) return false; + if (UPB_SETJMP(d.err)) return false; jsondec_tomsg(&d, msg, m); return true; diff --git a/upb/port_def.inc b/upb/port_def.inc index f1ed4645e9..4cd082589a 100644 --- a/upb/port_def.inc +++ b/upb/port_def.inc @@ -125,6 +125,15 @@ #define UPB_UNREACHABLE() do { assert(0); } while(0) #endif +/* UPB_SETJMP() / UPB_LONGJMP(): avoid setting/restoring signal mask. */ +#ifdef __APPLE__ +#define UPB_SETJMP(buf) _setjmp(buf) +#define UPB_LONGJMP(buf, val) _longjmp(buf, val) +#else +#define UPB_SETJMP(buf) setjmp(buf) +#define UPB_LONGJMP(buf, val) longjmp(buf, val) +#endif + /* Configure whether fasttable is switched on or not. *************************/ #if defined(__x86_64__) && defined(__GNUC__) diff --git a/upb/upb.h b/upb/upb.h index 7e21f2163c..c432f453a4 100644 --- a/upb/upb.h +++ b/upb/upb.h @@ -325,23 +325,6 @@ UPB_INLINE int _upb_lg2ceil(int x) { #endif } -/* We want to avoid saving/restoring the signal mask. */ -UPB_INLINE int _upb_setjmp(jmp_buf buf) { -#ifdef __APPLE__ - return _setjmp(buf); -#else - return setjmp(buf); -#endif -} - -UPB_NORETURN UPB_INLINE void _upb_longjmp(jmp_buf buf, int val) { -#ifdef __APPLE__ - _longjmp(buf, val); -#else - longjmp(buf, val); -#endif -} - #include "upb/port_undef.inc" #ifdef __cplusplus