diff options
Diffstat (limited to 'upb/pb')
-rw-r--r-- | upb/pb/compile_decoder.c | 28 | ||||
-rw-r--r-- | upb/pb/compile_decoder_x64.c | 18 | ||||
-rw-r--r-- | upb/pb/compile_decoder_x64.dasc | 12 | ||||
-rw-r--r-- | upb/pb/compile_decoder_x64.h | 12 | ||||
-rw-r--r-- | upb/pb/decoder.c | 59 | ||||
-rw-r--r-- | upb/pb/encoder.c | 9 | ||||
-rw-r--r-- | upb/pb/textprinter.c | 2 | ||||
-rw-r--r-- | upb/pb/varint.int.h | 4 |
8 files changed, 73 insertions, 71 deletions
diff --git a/upb/pb/compile_decoder.c b/upb/pb/compile_decoder.c index 7724113..d86f840 100644 --- a/upb/pb/compile_decoder.c +++ b/upb/pb/compile_decoder.c @@ -183,7 +183,7 @@ bool op_has_longofs(int32_t instruction) { case OP_TAGN: return false; default: - assert(false); + UPB_ASSERT(false); return false; } } @@ -202,7 +202,7 @@ static void setofs(uint32_t *instruction, int32_t ofs) { } else { *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8); } - assert(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ + UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ } static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } @@ -214,7 +214,7 @@ static void label(compiler *c, unsigned int label) { int val; uint32_t *codep; - assert(label < MAXLABEL); + UPB_ASSERT(label < MAXLABEL); val = c->fwd_labels[label]; codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; while (codep) { @@ -235,7 +235,7 @@ static void label(compiler *c, unsigned int label) { * The returned value is the offset that should be written into the instruction. */ static int32_t labelref(compiler *c, int label) { - assert(label < MAXLABEL); + UPB_ASSERT(label < MAXLABEL); if (label == LABEL_DISPATCH) { /* No resolving required. */ return 0; @@ -335,7 +335,7 @@ static void putop(compiler *c, opcode op, ...) { int label = va_arg(ap, int); uint64_t tag = va_arg(ap, uint64_t); uint32_t instruction = op | (tag << 16); - assert(tag <= 0xffff); + UPB_ASSERT(tag <= 0xffff); setofs(&instruction, labelref(c, label)); put32(c, instruction); break; @@ -472,7 +472,7 @@ static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) { uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type; uint64_t encoded_tag = upb_vencode32(tag); /* No tag should be greater than 5 bytes. */ - assert(encoded_tag <= 0xffffffffff); + UPB_ASSERT(encoded_tag <= 0xffffffffff); return encoded_tag; } @@ -495,7 +495,7 @@ static void putchecktag(compiler *c, const upb_fielddef *f, static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) { upb_selector_t selector; bool ok = upb_handlers_getselector(f, type, &selector); - UPB_ASSERT_VAR(ok, ok); + UPB_ASSERT(ok); return selector; } @@ -507,7 +507,7 @@ static uint64_t repack(uint64_t dispatch, int new_wt2) { uint8_t wt1; uint8_t old_wt2; upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2); - assert(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */ + UPB_ASSERT(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */ return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2); } @@ -709,7 +709,7 @@ static void generate_primitivefield(compiler *c, const upb_fielddef *f, * setting in the fielddef. This will favor (in speed) whichever was * specified. */ - assert((int)parse_type >= 0 && parse_type <= OP_MAX); + UPB_ASSERT((int)parse_type >= 0 && parse_type <= OP_MAX); sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)]; if (upb_fielddef_isseq(f)) { @@ -751,7 +751,7 @@ static void compile_method(compiler *c, upb_pbdecodermethod *method) { upb_msg_field_iter i; upb_value val; - assert(method); + UPB_ASSERT(method); /* Clear all entries in the dispatch table. */ upb_inttable_uninit(&method->dispatch); @@ -899,7 +899,7 @@ const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, compiler *c; UPB_UNUSED(allowjit); - assert(upb_handlers_isfrozen(dest)); + UPB_ASSERT(upb_handlers_isfrozen(dest)); g = newgroup(owner); c = newcompiler(g, lazy); @@ -920,13 +920,13 @@ const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, #ifdef UPB_DUMP_BYTECODE { FILE *f = fopen("/tmp/upb-bytecode", "w"); - assert(f); + UPB_ASSERT(f); dumpbc(g->bytecode, g->bytecode_end, stderr); dumpbc(g->bytecode, g->bytecode_end, f); fclose(f); f = fopen("/tmp/upb-bytecode.bin", "wb"); - assert(f); + UPB_ASSERT(f); fwrite(g->bytecode, 1, g->bytecode_end - g->bytecode, f); fclose(f); } @@ -976,7 +976,7 @@ const upb_pbdecodermethod *upb_pbcodecache_getdecodermethod( upb_inttable_push(&c->groups, upb_value_constptr(g)); ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v); - UPB_ASSERT_VAR(ok, ok); + UPB_ASSERT(ok); return upb_value_getptr(v); } diff --git a/upb/pb/compile_decoder_x64.c b/upb/pb/compile_decoder_x64.c index 88561d6..29dbcb1 100644 --- a/upb/pb/compile_decoder_x64.c +++ b/upb/pb/compile_decoder_x64.c @@ -184,7 +184,7 @@ static char *upb_vasprintf(const char *fmt, va_list args) { char *ret = malloc(len + 1); /* + 1 for NULL terminator. */ if (!ret) abort(); int written = _upb_vsnprintf(ret, len + 1, fmt, args); - UPB_ASSERT_VAR(written, written == len); + UPB_ASSERT(written == len); return ret; } @@ -221,9 +221,9 @@ static int getjmptarget(jitcompiler *jc, const void *key) { int pclabel = 0; bool ok; - assert(upb_inttable_lookupptr(&jc->jmpdefined, key, NULL)); + UPB_ASSERT_DEBUGVAR(upb_inttable_lookupptr(&jc->jmpdefined, key, NULL)); ok = try_getjmptarget(jc, key, &pclabel); - UPB_ASSERT_VAR(ok, ok); + UPB_ASSERT(ok); return pclabel; } @@ -289,10 +289,10 @@ uint32_t dispatchofs(jitcompiler *jc, const upb_pbdecodermethod *method, int mc_target = machine_code_ofs2(jc, method, pcofs); int ret; - assert(mc_base > 0); - assert(mc_target > 0); + UPB_ASSERT(mc_base > 0); + UPB_ASSERT(mc_target > 0); ret = mc_target - mc_base; - assert(ret > 0); + UPB_ASSERT(ret > 0); return ret; } @@ -327,7 +327,7 @@ static void patchdispatch(jitcompiler *jc) { /* Update offset and repack. */ ofs = dispatchofs(jc, method, ofs); newval = upb_pbdecoder_packdispatch(ofs, wt1, wt2); - assert((int64_t)newval > 0); + UPB_ASSERT((int64_t)newval > 0); } else { /* Secondary slot. Since we have 64 bits for the value, we use an * absolute offset. */ @@ -335,7 +335,7 @@ static void patchdispatch(jitcompiler *jc) { newval = (uint64_t)((char*)jc->group->jit_code + mcofs); } ok = upb_inttable_replace(dispatch, key, upb_value_uint64(newval)); - UPB_ASSERT_VAR(ok, ok); + UPB_ASSERT(ok); } /* Update entry point for this method to point at mc base instead of bc @@ -467,7 +467,7 @@ void upb_pbdecoder_jit(mgroup *group) { group->debug_info = NULL; group->dl = NULL; - assert(group->bytecode); + UPB_ASSERT(group->bytecode); jc = newjitcompiler(group); emit_static_asm(jc); jitbytecode(jc); diff --git a/upb/pb/compile_decoder_x64.dasc b/upb/pb/compile_decoder_x64.dasc index edda7dd..512c174 100644 --- a/upb/pb/compile_decoder_x64.dasc +++ b/upb/pb/compile_decoder_x64.dasc @@ -153,7 +153,7 @@ static upb_func *gethandler(const upb_handlers *h, upb_selector_t sel) { static void asmlabel(jitcompiler *jc, const char *fmt, ...) { #ifndef NDEBUG int ofs = jc->dynasm->section->ofs; - assert(ofs != jc->lastlabelofs); + UPB_ASSERT(ofs != jc->lastlabelofs); jc->lastlabelofs = ofs; #endif @@ -183,7 +183,7 @@ static bool alwaysok(const upb_handlers *h, upb_selector_t sel) { bool ok = upb_handlers_getattr(h, sel, &attr); bool ret; - UPB_ASSERT_VAR(ok, ok); + UPB_ASSERT(ok); ret = upb_handlerattr_alwaysok(&attr); upb_handlerattr_uninit(&attr); return ret; @@ -641,7 +641,7 @@ static void jitprimitive(jitcompiler *jc, opcode op, case UPB_TYPE_STRING: case UPB_TYPE_BYTES: case UPB_TYPE_MESSAGE: - assert(false); break; + UPB_ASSERT(false); break; } | sethas CLOSURE, data->hasbit } else if (handler) { @@ -790,7 +790,7 @@ static void jitdispatch(jitcompiler *jc, | // Secondary wire type is a match, look up fn + UPB_MAX_FIELDNUMBER. | add rdx, UPB_MAX_FIELDNUMBER | // This key will never be in the array part, so do a hash lookup. - assert(has_hash_entries); + UPB_ASSERT(has_hash_entries); | ld64 dispatch | jmp ->hashlookup // Tail call. } @@ -815,7 +815,7 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs, uint32_t *delimend = (jc->pc - 1) + last_arg; const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); - assert((last_instruction & 0xff) == OP_CHECKDELIM); + UPB_ASSERT((last_instruction & 0xff) == OP_CHECKDELIM); if (getop(*(jc->pc - 1)) == OP_TAGN) { jc->pc += ptr_words; @@ -1131,7 +1131,7 @@ static void jitbytecode(jitcompiler *jc) { | call =>jmptarget(jc, &method->dispatch) break; case OP_HALT: - assert(false); + UPB_ASSERT(false); } } diff --git a/upb/pb/compile_decoder_x64.h b/upb/pb/compile_decoder_x64.h index 5d2b95a..ce775c6 100644 --- a/upb/pb/compile_decoder_x64.h +++ b/upb/pb/compile_decoder_x64.h @@ -338,7 +338,7 @@ static upb_func *gethandler(const upb_handlers *h, upb_selector_t sel) { static void asmlabel(jitcompiler *jc, const char *fmt, ...) { #ifndef NDEBUG int ofs = jc->dynasm->section->ofs; - assert(ofs != jc->lastlabelofs); + UPB_ASSERT(ofs != jc->lastlabelofs); jc->lastlabelofs = ofs; #endif @@ -370,7 +370,7 @@ static bool alwaysok(const upb_handlers *h, upb_selector_t sel) { bool ok = upb_handlers_getattr(h, sel, &attr); bool ret; - UPB_ASSERT_VAR(ok, ok); + UPB_ASSERT(ok); ret = upb_handlerattr_alwaysok(&attr); upb_handlerattr_uninit(&attr); return ret; @@ -964,7 +964,7 @@ static void jitprimitive(jitcompiler *jc, opcode op, case UPB_TYPE_STRING: case UPB_TYPE_BYTES: case UPB_TYPE_MESSAGE: - assert(false); break; + UPB_ASSERT(false); break; } /*| sethas CLOSURE, data->hasbit */ if (data->hasbit >= 0) { @@ -1188,7 +1188,7 @@ static void jitdispatch(jitcompiler *jc, /*| // This key will never be in the array part, so do a hash lookup. */ dasm_put(Dst, 2035, UPB_MAX_FIELDNUMBER); # 793 "upb/pb/compile_decoder_x64.dasc" - assert(has_hash_entries); + UPB_ASSERT(has_hash_entries); /*| ld64 dispatch */ { uintptr_t v = (uintptr_t)dispatch; @@ -1240,7 +1240,7 @@ static void jittag(jitcompiler *jc, uint64_t tag, int n, int ofs, uint32_t *delimend = (jc->pc - 1) + last_arg; const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); - assert((last_instruction & 0xff) == OP_CHECKDELIM); + UPB_ASSERT((last_instruction & 0xff) == OP_CHECKDELIM); if (getop(*(jc->pc - 1)) == OP_TAGN) { jc->pc += ptr_words; @@ -1715,7 +1715,7 @@ static void jitbytecode(jitcompiler *jc) { # 1132 "upb/pb/compile_decoder_x64.dasc" break; case OP_HALT: - assert(false); + UPB_ASSERT(false); } } diff --git a/upb/pb/decoder.c b/upb/pb/decoder.c index 8f4c867..182ecc9 100644 --- a/upb/pb/decoder.c +++ b/upb/pb/decoder.c @@ -117,7 +117,7 @@ void upb_pbdecoder_seterr(upb_pbdecoder *d, const char *msg) { /* How many bytes can be safely read from d->ptr without reading past end-of-buf * or past the current delimited end. */ static size_t curbufleft(const upb_pbdecoder *d) { - assert(d->data_end >= d->ptr); + UPB_ASSERT(d->data_end >= d->ptr); return d->data_end - d->ptr; } @@ -138,7 +138,7 @@ size_t delim_remaining(const upb_pbdecoder *d) { /* Advances d->ptr. */ static void advance(upb_pbdecoder *d, size_t len) { - assert(curbufleft(d) >= len); + UPB_ASSERT(curbufleft(d) >= len); d->ptr += len; } @@ -171,7 +171,7 @@ static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) { } static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) { - assert(curbufleft(d) == 0); + UPB_ASSERT(curbufleft(d) == 0); d->bufstart_ofs += (d->end - d->buf); switchtobuf(d, buf, buf + len); } @@ -180,7 +180,7 @@ static void checkpoint(upb_pbdecoder *d) { /* The assertion here is in the interests of efficiency, not correctness. * We are trying to ensure that we don't checkpoint() more often than * necessary. */ - assert(d->checkpoint != d->ptr); + UPB_ASSERT(d->checkpoint != d->ptr); d->checkpoint = d->ptr; } @@ -191,8 +191,8 @@ static void checkpoint(upb_pbdecoder *d) { * won't actually be read. */ static int32_t skip(upb_pbdecoder *d, size_t bytes) { - assert(!in_residual_buf(d, d->ptr) || d->size_param == 0); - assert(d->skip == 0); + UPB_ASSERT(!in_residual_buf(d, d->ptr) || d->size_param == 0); + UPB_ASSERT(d->skip == 0); if (bytes > delim_remaining(d)) { seterr(d, "Skipped value extended beyond enclosing submessage."); return upb_pbdecoder_suspend(d); @@ -220,7 +220,7 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, /* d->skip and d->residual_end could probably elegantly be represented * as a single variable, to more easily represent this invariant. */ - assert(!(d->skip && d->residual_end > d->residual)); + UPB_ASSERT(!(d->skip && d->residual_end > d->residual)); /* We need to remember the original size_param, so that the value we return * is relative to it, even if we do some skipping first. */ @@ -253,7 +253,7 @@ int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, if (d->residual_end > d->residual) { /* We have residual bytes from the last buffer. */ - assert(d->ptr == d->residual); + UPB_ASSERT(d->ptr == d->residual); } else { switchtobuf(d, buf, buf + size); } @@ -287,8 +287,8 @@ size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { return 0; } else { size_t ret = d->size_param - (d->end - d->checkpoint); - assert(!in_residual_buf(d, d->checkpoint)); - assert(d->buf == d->buf_param || d->buf == &dummy_char); + UPB_ASSERT(!in_residual_buf(d, d->checkpoint)); + UPB_ASSERT(d->buf == d->buf_param || d->buf == &dummy_char); d->bufstart_ofs += (d->checkpoint - d->buf); d->residual_end = d->residual; @@ -308,7 +308,7 @@ static size_t suspend_save(upb_pbdecoder *d) { if (d->checkpoint == d->residual) { /* Checkpoint was in residual buf; append user byte(s) to residual buf. */ - assert((d->residual_end - d->residual) + d->size_param <= + UPB_ASSERT((d->residual_end - d->residual) + d->size_param <= sizeof(d->residual)); if (!in_residual_buf(d, d->ptr)) { d->bufstart_ofs -= (d->residual_end - d->residual); @@ -318,11 +318,11 @@ static size_t suspend_save(upb_pbdecoder *d) { } else { /* Checkpoint was in user buf; old residual bytes not needed. */ size_t save; - assert(!in_residual_buf(d, d->checkpoint)); + UPB_ASSERT(!in_residual_buf(d, d->checkpoint)); d->ptr = d->checkpoint; save = curbufleft(d); - assert(save <= sizeof(d->residual)); + UPB_ASSERT(save <= sizeof(d->residual)); memcpy(d->residual, d->ptr, save); d->residual_end = d->residual + save; d->bufstart_ofs = offset(d); @@ -336,7 +336,7 @@ static size_t suspend_save(upb_pbdecoder *d) { * Requires that this many bytes are available in the current buffer. */ UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf, size_t bytes) { - assert(bytes <= curbufleft(d)); + UPB_ASSERT(bytes <= curbufleft(d)); memcpy(buf, d->ptr, bytes); advance(d, bytes); } @@ -349,7 +349,7 @@ UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, const size_t avail = curbufleft(d); consumebytes(d, buf, avail); bytes -= avail; - assert(bytes > 0); + UPB_ASSERT(bytes > 0); if (in_residual_buf(d, d->ptr)) { advancetobuf(d, d->buf_param, d->size_param); } @@ -532,7 +532,7 @@ UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, if (read == bytes && data == expected) { /* Advance past matched bytes. */ int32_t ok = getbytes(d, &data, read); - UPB_ASSERT_VAR(ok, ok < 0); + UPB_ASSERT(ok < 0); return DECODE_OK; } else if (read < bytes && memcmp(&data, &expected, read) == 0) { return suspend_save(d); @@ -607,7 +607,7 @@ have_tag: static void goto_endmsg(upb_pbdecoder *d) { upb_value v; bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v); - UPB_ASSERT_VAR(found, found); + UPB_ASSERT(found); d->pc = d->top->base + upb_value_getuint64(v); } @@ -641,7 +641,7 @@ static int32_t dispatch(upb_pbdecoder *d) { } else if (wire_type == ((v >> 8) & 0xff)) { bool found = upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val); - UPB_ASSERT_VAR(found, found); + UPB_ASSERT(found); d->pc = d->top->base + upb_value_getuint64(val); return DECODE_OK; } @@ -653,7 +653,7 @@ static int32_t dispatch(upb_pbdecoder *d) { * can re-check the delimited end. */ d->last--; /* Necessary if we get suspended */ d->pc = d->last; - assert(getop(*d->last) == OP_CHECKDELIM); + UPB_ASSERT(getop(*d->last) == OP_CHECKDELIM); /* Unknown field or ENDGROUP. */ retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type); @@ -671,7 +671,7 @@ static int32_t dispatch(upb_pbdecoder *d) { /* Callers know that the stack is more than one deep because the opcodes that * call this only occur after PUSH operations. */ upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) { - assert(d->top != d->stack); + UPB_ASSERT(d->top != d->stack); return d->top - 1; } @@ -703,7 +703,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, op = getop(instruction); arg = instruction >> 8; longofs = arg; - assert(d->ptr != d->residual_end); + UPB_ASSERT(d->ptr != d->residual_end); UPB_UNUSED(group); #ifdef UPB_DUMP_BYTECODE fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d " @@ -778,7 +778,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, } else { int32_t ret = skip(d, n); /* This shouldn't return DECODE_OK, because n > len. */ - assert(ret >= 0); + UPB_ASSERT(ret >= 0); return ret; } } @@ -800,7 +800,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, d->top->groupnum = *d->pc++; ) VMCASE(OP_POP, - assert(d->top > d->stack); + UPB_ASSERT(d->top > d->stack); decoder_pop(d); ) VMCASE(OP_PUSHLENDELIM, @@ -816,7 +816,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, /* We are guaranteed of this assert because we never allow ourselves to * consume bytes beyond data_end, which covers delim_end when non-NULL. */ - assert(!(d->delim_end && d->ptr > d->delim_end)); + UPB_ASSERT(!(d->delim_end && d->ptr > d->delim_end)); if (d->ptr == d->delim_end) d->pc += longofs; ) @@ -825,7 +825,7 @@ size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, d->pc += longofs; ) VMCASE(OP_RET, - assert(d->call_len > 0); + UPB_ASSERT(d->call_len > 0); d->pc = d->callstack[--d->call_len]; ) VMCASE(OP_BRANCH, @@ -952,7 +952,7 @@ bool upb_pbdecoder_end(void *closure, const void *handler_data) { if (p != method->code_base.ptr) p--; if (getop(*p) == OP_CHECKDELIM) { /* Rewind from OP_TAG* to OP_CHECKDELIM. */ - assert(getop(*d->pc) == OP_TAG1 || + UPB_ASSERT(getop(*d->pc) == OP_TAG1 || getop(*d->pc) == OP_TAG2 || getop(*d->pc) == OP_TAGN || getop(*d->pc) == OP_DISPATCH); @@ -1016,7 +1016,7 @@ upb_pbdecoder *upb_pbdecoder_create(upb_env *e, const upb_pbdecodermethod *m, upb_pbdecoder_reset(d); upb_bytessink_reset(&d->input_, &m->input_handler_, d); - assert(sink); + UPB_ASSERT(sink); if (d->method_->dest_handlers_) { if (sink->handlers != d->method_->dest_handlers_) return NULL; @@ -1024,7 +1024,8 @@ upb_pbdecoder *upb_pbdecoder_create(upb_env *e, const upb_pbdecodermethod *m, upb_sink_reset(&d->top->sink, sink->handlers, sink->closure); /* If this fails, increase the value in decoder.h. */ - assert(upb_env_bytesallocated(e) - size_before <= UPB_PB_DECODER_SIZE); + UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= + UPB_PB_DECODER_SIZE); return d; } @@ -1045,7 +1046,7 @@ size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) { } bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) { - assert(d->top >= d->stack); + UPB_ASSERT(d->top >= d->stack); if (max < (size_t)(d->top - d->stack)) { /* Can't set a limit smaller than what we are currently at. */ diff --git a/upb/pb/encoder.c b/upb/pb/encoder.c index 8f974a3..780425d 100644 --- a/upb/pb/encoder.c +++ b/upb/pb/encoder.c @@ -128,7 +128,7 @@ struct upb_pb_encoder { /* TODO(haberman): handle pushback */ static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) { size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL); - UPB_ASSERT_VAR(n, n == len); + UPB_ASSERT(n == len); } static upb_pb_encoder_segment *top(upb_pb_encoder *e) { @@ -168,7 +168,7 @@ static bool reserve(upb_pb_encoder *e, size_t bytes) { /* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have * previously called reserve() with at least this many bytes. */ static void encoder_advance(upb_pb_encoder *e, size_t bytes) { - assert((size_t)(e->limit - e->ptr) >= bytes); + UPB_ASSERT((size_t)(e->limit - e->ptr) >= bytes); e->ptr += bytes; } @@ -203,7 +203,7 @@ static bool encode_bytes(upb_pb_encoder *e, const void *data, size_t len) { * length. */ static void accumulate(upb_pb_encoder *e) { size_t run_len; - assert(e->ptr >= e->runbegin); + UPB_ASSERT(e->ptr >= e->runbegin); run_len = e->ptr - e->runbegin; e->segptr->seglen += run_len; top(e)->msglen += run_len; @@ -558,7 +558,8 @@ upb_pb_encoder *upb_pb_encoder_create(upb_env *env, const upb_handlers *h, e->ptr = e->buf; /* If this fails, increase the value in encoder.h. */ - assert(upb_env_bytesallocated(env) - size_before <= UPB_PB_ENCODER_SIZE); + UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= + UPB_PB_ENCODER_SIZE); return e; } diff --git a/upb/pb/textprinter.c b/upb/pb/textprinter.c index b9ff8d4..abfc2eb 100644 --- a/upb/pb/textprinter.c +++ b/upb/pb/textprinter.c @@ -112,7 +112,7 @@ bool putf(upb_textprinter *p, const char *fmt, ...) { if (!str) return false; written = vsprintf(str, fmt, args); va_end(args); - UPB_ASSERT_VAR(written, written == len); + UPB_ASSERT(written == len); ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL); upb_gfree(str); diff --git a/upb/pb/varint.int.h b/upb/pb/varint.int.h index 735bcbe..c8d4929 100644 --- a/upb/pb/varint.int.h +++ b/upb/pb/varint.int.h @@ -154,9 +154,9 @@ UPB_INLINE uint64_t upb_vencode32(uint32_t val) { char buf[UPB_PB_VARINT_MAX_LEN]; size_t bytes = upb_vencode64(val, buf); uint64_t ret = 0; - assert(bytes <= 5); + UPB_ASSERT(bytes <= 5); memcpy(&ret, buf, bytes); - assert(ret <= 0xffffffffffU); + UPB_ASSERT(ret <= 0xffffffffffU); return ret; } |