Use a macro instead of an inline function for setjmp/longjmp.

pull/13171/head
Joshua Haberman 4 years ago
parent ca279f8afa
commit bc200451ce
  1. 6
      upb/decode.c
  2. 7
      upb/def.c
  3. 8
      upb/encode.c
  4. 6
      upb/json_decode.c
  5. 9
      upb/port_def.inc
  6. 17
      upb/upb.h

@ -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)) {

@ -3,6 +3,7 @@
#include <ctype.h>
#include <errno.h>
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
@ -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;

@ -2,12 +2,12 @@
#include "upb/encode.h"
#include <setjmp.h>
#include <string.h>
#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;
}

@ -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;

@ -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__)

@ -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

Loading…
Cancel
Save