From 06efc6b12c69b0c778cd5d4dc1e9712b0dfb58ff Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 6 Jul 2009 03:00:15 -0700 Subject: Fixed a lot of bugs, parser and compiler now work a little! --- test_table.cc | 8 +--- upb.h | 2 + upb_context.c | 21 ++++++--- upb_msg.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++++---------- upb_msg.h | 4 ++ upb_parse.c | 11 +++-- upb_table.c | 19 ++++---- upb_table.h | 1 - upbc.c | 2 +- 9 files changed, 157 insertions(+), 50 deletions(-) diff --git a/test_table.cc b/test_table.cc index bcd0ca9..947a7a4 100644 --- a/test_table.cc +++ b/test_table.cc @@ -43,7 +43,7 @@ void test_strtable(const vector& keys, uint32_t num_to_insert) /* Initialize structures. */ struct upb_strtable table; std::map m; - upb_strtable_init(&table, num_to_insert, sizeof(struct strtable_entry)); + upb_strtable_init(&table, 0, sizeof(struct strtable_entry)); std::set all; for(size_t i = 0; i < num_to_insert; i++) { const string& key = keys[i]; @@ -245,12 +245,6 @@ int main() keys.push_back("google.protobuf.MethodOptions"); keys.push_back("google.protobuf.UninterpretedOption"); keys.push_back("google.protobuf.UninterpretedOption.NamePart"); - keys.push_back("A"); - keys.push_back("B"); - keys.push_back("C"); - keys.push_back("D"); - keys.push_back("E"); - keys.push_back("F"); test_strtable(keys, 18); return 0; diff --git a/upb.h b/upb.h index 1267662..b7f1f16 100644 --- a/upb.h +++ b/upb.h @@ -36,6 +36,8 @@ extern "C" { /* The maximum number of fields that any one .proto type can have. */ #define UPB_MAX_FIELDS (1<<16) +#define UPB_INDEX(base, i, m) (void*)((char*)(base) + ((i)*(m))) + INLINE uint32_t max(uint32_t a, uint32_t b) { return a > b ? a : b; } /* A list of types as they are encoded on-the-wire. */ diff --git a/upb_context.c b/upb_context.c index 17df688..ba6fc4a 100644 --- a/upb_context.c +++ b/upb_context.c @@ -26,13 +26,14 @@ bool upb_context_init(struct upb_context *c) upb_strtable_init(&c->symtab, 16, sizeof(struct upb_symtab_entry)); upb_strtable_init(&c->psymtab, 16, sizeof(struct upb_symtab_entry)); /* Add all the types in descriptor.proto so we can parse descriptors. */ - if(!addfd(&c->psymtab, &c->psymtab, &google_protobuf_filedescriptor)) { + if(!addfd(&c->psymtab, &c->symtab, &google_protobuf_filedescriptor)) { assert(false); return false; /* Indicates that upb is buggy or corrupt. */ } struct upb_string name = UPB_STRLIT("google.protobuf.FileDescriptorSet"); - c->fds_msg = upb_strtable_lookup(&c->psymtab, &name); - assert(c->fds_msg); + struct upb_symtab_entry *e = upb_strtable_lookup(&c->psymtab, &name); + assert(e); + c->fds_msg = e->ref.msg; c->fds_size = 16; c->fds_len = 0; c->fds = malloc(sizeof(*c->fds)); @@ -187,6 +188,7 @@ static bool insert_message(struct upb_strtable *t, free(fqname.ptr); return false; } + printf("Inserting: " UPB_STRFMT ", len=%d\n", UPB_STRARG(e.e.key), e.e.key.byte_len); upb_strtable_insert(t, &e.e); /* Add nested messages and enums. */ @@ -225,9 +227,15 @@ bool addfd(struct upb_strtable *addto, struct upb_strtable *existingdefs, /* Attempt to resolve all references. */ struct upb_symtab_entry *e; + printf("Table dump:\n"); for(e = upb_strtable_begin(addto); e; e = upb_strtable_next(addto, &e->e)) { - if(upb_strtable_lookup(existingdefs, &e->e.key)) + printf(" key: " UPB_STRFMT "\n", UPB_STRARG(e->e.key)); + } + for(e = upb_strtable_begin(addto); e; e = upb_strtable_next(addto, &e->e)) { + if(upb_strtable_lookup(existingdefs, &e->e.key)) { + printf("Redef!\n"); return false; /* Redefinition prohibited. */ + } if(e->type == UPB_SYM_MESSAGE) { struct upb_msg *m = e->ref.msg; for(unsigned int i = 0; i < m->num_fields; i++) { @@ -242,7 +250,9 @@ bool addfd(struct upb_strtable *addto, struct upb_strtable *existingdefs, UPB_SYM_ENUM); else continue; /* No resolving necessary. */ - if(!ref.msg) return false; /* Ref. to undefined symbol. */ + printf("Resolving '" UPB_STRFMT "'...", UPB_STRARG(*fd->type_name)); + if(!ref.msg) { printf("undefined: " UPB_STRFMT ", len=%d\n", UPB_STRARG(*fd->type_name), fd->type_name->byte_len);return false;} /* Ref. to undefined symbol. */ + printf("OK!\n"); upb_msg_ref(m, f, ref); } } @@ -271,6 +281,7 @@ bool upb_context_parsefds(struct upb_context *c, struct upb_string *fds_str) { upb_strtable_init(&tmp, 0, sizeof(struct upb_symtab_entry)); for(uint32_t i = 0; i < fds->file->len; i++) { if(!addfd(&tmp, &c->symtab, fds->file->elements[i])) { + printf("Not added successfully!\n"); free_symtab(&tmp); return false; } diff --git a/upb_msg.c b/upb_msg.c index d6b1594..65df800 100644 --- a/upb_msg.c +++ b/upb_msg.c @@ -3,12 +3,13 @@ * */ +#include #include #include "descriptor.h" #include "upb_msg.h" #include "upb_parse.h" -#define ALIGN_UP(p, t) (t + ((p - 1) & (~t - 1))) +#define ALIGN_UP(p, t) (p % t == 0 ? p : p + (t - (p % t))) static int div_round_up(int numerator, int denominator) { /* cf. http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-division */ @@ -54,10 +55,9 @@ bool upb_msg_init(struct upb_msg *m, struct google_protobuf_DescriptorProto *d) /* We count on the caller to keep this pointer alive. */ m->field_descriptors[i] = d->field->elements[i]; } - qsort(m->field_descriptors, m->num_fields, sizeof(void*), compare_fields); + //qsort(m->field_descriptors, m->num_fields, sizeof(void*), compare_fields); size_t max_align = 0; - for(unsigned int i = 0; i < m->num_fields; i++) { struct upb_msg_field *f = &m->fields[i]; google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[i]; @@ -68,6 +68,8 @@ bool upb_msg_init(struct upb_msg *m, struct google_protobuf_DescriptorProto *d) * a whole must be a multiple of the greatest alignment of any member. */ f->field_index = i; f->byte_offset = ALIGN_UP(m->size, type_info->align); + f->type = fd->type; + f->label = fd->label; m->size = f->byte_offset + type_info->size; max_align = max(max_align, type_info->align); if(fd->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REQUIRED) @@ -131,7 +133,7 @@ struct mm_upb_array { static uint32_t round_up_to_pow2(uint32_t v) { -#ifdef __GNUC__ +#if 0 // __GNUC__ return (1U<<31) >> (__builtin_clz(v-1)+1); #else /* cf. http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 */ @@ -148,7 +150,10 @@ static uint32_t round_up_to_pow2(uint32_t v) void upb_msg_reuse_str(struct upb_string **str, uint32_t size) { - if(!*str) *str = malloc(sizeof(struct mm_upb_string)); + if(!*str) { + *str = malloc(sizeof(struct mm_upb_string)); + memset(*str, 0, sizeof(struct mm_upb_string)); + } struct mm_upb_string *s = (void*)*str; if(s->size < size) { size = max(16, round_up_to_pow2(size)); @@ -158,14 +163,21 @@ void upb_msg_reuse_str(struct upb_string **str, uint32_t size) s->s.ptr = s->data; } -void upb_msg_reuse_array(struct upb_array **arr, uint32_t n, upb_field_type_t t) +void upb_msg_reuse_array(struct upb_array **arr, uint32_t size, upb_field_type_t t) { - if(!*arr) *arr = malloc(sizeof(struct mm_upb_array)); + if(!*arr) { + *arr = malloc(sizeof(struct mm_upb_array)); + memset(*arr, 0, sizeof(struct mm_upb_array)); + } struct mm_upb_array *a = (void*)*arr; - if(a->size < n) { - n = max(16, round_up_to_pow2(n)); - a->a.elements._void = realloc(a->a.elements._void, n*upb_type_info[t].size); - a->size = n; + if(a->size < size) { + size = max(16, round_up_to_pow2(size)); + size_t type_size = upb_type_info[t].size; + a->a.elements._void = realloc(a->a.elements._void, size * type_size); + /* Zero any newly initialized memory. */ + memset(UPB_INDEX(a->a.elements._void, a->size, type_size), 0, + (size - a->size) * type_size); + a->size = size; } } @@ -173,8 +185,8 @@ void upb_msg_reuse_strref(struct upb_string **str) { upb_msg_reuse_str(str, 0); void upb_msg_reuse_submsg(void **msg, struct upb_msg *m) { - if(!*msg) *msg = malloc(m->size); - upb_msg_clear(*msg, m); /* Clears set bits, leaves pointers. */ + if(!*msg) *msg = upb_msg_new(m); + else upb_msg_clear(*msg, m); /* Clears set bits, leaves pointers. */ } /* Parser. */ @@ -187,7 +199,7 @@ struct parse_frame_data { static void set_frame_data(struct upb_parse_state *s, struct upb_msg *m, void *data) { - struct parse_frame_data *frame = (void*)s->top->user_data; + struct parse_frame_data *frame = (void*)&s->top->user_data; frame->m = m; frame->data = data; } @@ -195,7 +207,7 @@ static void set_frame_data(struct upb_parse_state *s, struct upb_msg *m, static upb_field_type_t tag_cb(struct upb_parse_state *s, struct upb_tag *tag, void **user_field_desc) { - struct parse_frame_data *frame = (void*)s->top->user_data; + struct parse_frame_data *frame = (void*)&s->top->user_data; struct upb_msg_field *f = upb_msg_fieldbynum(frame->m, tag->field_number); if(!f || !upb_check_type(tag->wire_type, f->type)) return 0; /* Skip unknown or fields of the wrong type. */ @@ -208,17 +220,21 @@ static union upb_value_ptr get_value_ptr(void *data, struct upb_msg_field *f) union upb_value_ptr p = upb_msg_get_ptr(data, f); if(f->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REPEATED) { size_t len = upb_msg_is_set(data, f) ? (*p.array)->len : 0; - upb_msg_reuse_array(p.array, len, f->type); + upb_msg_reuse_array(p.array, len+1, f->type); (*p.array)->len = len + 1; + assert(p._void); p = upb_array_getelementptr(*p.array, len, f->type); + assert(p._void); } + upb_msg_set(data, f); + assert(p._void); return p; } static upb_status_t value_cb(struct upb_parse_state *s, void **buf, void *end, void *user_field_desc) { - struct parse_frame_data *frame = (void*)s->top->user_data; + struct parse_frame_data *frame = (void*)&s->top->user_data; struct upb_msg_field *f = user_field_desc; union upb_value_ptr p = get_value_ptr(frame->data, f); UPB_CHECK(upb_parse_value(buf, end, f->type, p)); @@ -229,7 +245,7 @@ static upb_status_t str_cb(struct upb_parse_state *_s, struct upb_string *str, void *user_field_desc) { struct upb_msg_parse_state *s = (void*)_s; - struct parse_frame_data *frame = (void*)s->s.top->user_data; + struct parse_frame_data *frame = (void*)&s->s.top->user_data; struct upb_msg_field *f = user_field_desc; union upb_value_ptr p = get_value_ptr(frame->data, f); if(s->byref) { @@ -246,11 +262,17 @@ static void submsg_start_cb(struct upb_parse_state *_s, void *user_field_desc) { struct upb_msg_parse_state *s = (void*)_s; struct upb_msg_field *f = user_field_desc; - struct parse_frame_data *frame = (void*)s->s.top->user_data; - union upb_value_ptr p = upb_msg_get_ptr(frame->data, f); - upb_msg_reuse_submsg(*p.message, f->ref.msg); - if(!s->merge) upb_msg_clear(frame->data, f->ref.msg); + struct parse_frame_data *frame = (void*)&s->s.top->user_data; + struct parse_frame_data *oldframe = (void*)((char*)s->s.top - s->s.udata_size); + union upb_value_ptr p = get_value_ptr(oldframe->data, f); + upb_msg_reuse_submsg(p.message, f->ref.msg); set_frame_data(&s->s, f->ref.msg, *p.message); + if(!s->merge) upb_msg_clear(frame->data, f->ref.msg); +} + +static void submsg_end_cb(struct upb_parse_state *s) +{ + struct parse_frame_data *frame = (void*)&s->top->user_data; } @@ -266,6 +288,7 @@ void upb_msg_parse_init(struct upb_msg_parse_state *s, void *msg, s->s.value_cb = value_cb; s->s.str_cb = str_cb; s->s.submsg_start_cb = submsg_start_cb; + s->s.submsg_end_cb = submsg_end_cb; } void upb_msg_parse_free(struct upb_msg_parse_state *s) @@ -293,3 +316,75 @@ void *upb_alloc_and_parse(struct upb_msg *m, struct upb_string *str, bool byref) return NULL; } } + +static void dump_value(union upb_value_ptr p, upb_field_type_t type, FILE *stream) +{ + switch(type) { + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_DOUBLE: + fprintf(stream, "%f", *p._double); break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FLOAT: + fprintf(stream, "%f", *p._float); break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FIXED64: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT64: + fprintf(stream, "%" PRIu64, *p.uint64); break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_FIXED32: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT32: + fprintf(stream, "%" PRIu32, *p.uint32); break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BOOL: + if(*p._bool) fputs("true", stream); + else fputs("false", stream); + break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_GROUP: + break; /* can't actually be stored */ + + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE: + fprintf(stream, "%p", (void*)*p.message); break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_STRING: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BYTES: + if(*p.string) + fprintf(stream, "\"" UPB_STRFMT "\"", UPB_STRARG(**p.string)); + else + fputs("(null)", stream); + break; + + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_ENUM: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT32: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED32: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT32: + fprintf(stream, "%" PRId32, *p.int32); break; + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED64: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT64: + case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_INT64: + fprintf(stream, "%" PRId64, *p.int64); break; + } +} + +void upb_msg_print(void *data, struct upb_msg *m, FILE *stream) +{ + fprintf(stream, "Message <" UPB_STRFMT ">\n", UPB_STRARG(*m->descriptor->name)); + for(uint32_t i = 0; i < m->num_fields; i++) { + struct upb_msg_field *f = &m->fields[i]; + google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[i]; + fprintf(stream, " " UPB_STRFMT, UPB_STRARG(*fd->name)); + + if(upb_msg_is_set(data, f)) fputs(" (set): ", stream); + else fputs(" (NOT set): ", stream); + + union upb_value_ptr p = upb_msg_get_ptr(data, f); + if(f->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REPEATED) { + if(*p.array) { + fputc('[', stream); + for(uint32_t j = 0; j < (*p.array)->len; j++) { + dump_value(upb_array_getelementptr(*p.array, j, f->type), f->type, stream); + if(j != (*p.array)->len - 1) fputs(", ", stream); + } + fputs("]\n", stream); + } else { + fputs("\n", stream); + } + } else { + dump_value(p, f->type, stream); + fputc('\n', stream); + } + } +} diff --git a/upb_msg.h b/upb_msg.h index e751c27..9e37a19 100644 --- a/upb_msg.h +++ b/upb_msg.h @@ -301,6 +301,10 @@ INLINE void upb_msg_clear(void *s, struct upb_msg *m) /* Parses the string data in s according to the message description in m. */ upb_status_t upb_msg_merge(void *data, struct upb_msg *m, struct upb_string *s); +/* Text dump *****************************************************************/ + +void upb_msg_print(void *data, struct upb_msg *m, FILE *stream); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/upb_parse.c b/upb_parse.c index f44a847..2af8e86 100644 --- a/upb_parse.c +++ b/upb_parse.c @@ -182,8 +182,8 @@ struct upb_type_info upb_type_info[] = { [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SFIXED64]= {alignof(int64_t), sizeof(int64_t), UPB_WIRE_TYPE_64BIT}, [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT32] = {alignof(int32_t), sizeof(int32_t), UPB_WIRE_TYPE_VARINT}, [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_SINT64] = {alignof(int64_t), sizeof(int64_t), UPB_WIRE_TYPE_VARINT}, - [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_STRING] = {alignof(struct upb_string), sizeof(struct upb_string), UPB_WIRE_TYPE_DELIMITED}, - [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BYTES] = {alignof(struct upb_string), sizeof(struct upb_string), UPB_WIRE_TYPE_DELIMITED}, + [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_STRING] = {alignof(struct upb_string*), sizeof(struct upb_string*), UPB_WIRE_TYPE_DELIMITED}, + [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_BYTES] = {alignof(struct upb_string*), sizeof(struct upb_string*), UPB_WIRE_TYPE_DELIMITED}, [GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_GROUP] = {0,0,0}, }; @@ -249,9 +249,11 @@ upb_status_t upb_parse_value(void **buf, void *end, upb_field_type_t ft, void upb_parse_init(struct upb_parse_state *state, size_t udata_size) { + memset(state, 0, sizeof(struct upb_parse_state)); state->offset = 0; size_t stack_bytes = (sizeof(*state->stack) + udata_size) * UPB_MAX_NESTING; state->stack = state->top = malloc(stack_bytes); + state->top->end_offset = SIZE_MAX; state->limit = (struct upb_parse_stack_frame*)((char*)state->stack + stack_bytes); state->udata_size = udata_size; } @@ -263,7 +265,7 @@ void upb_parse_free(struct upb_parse_state *state) static void pop_stack_frame(struct upb_parse_state *s) { - s->submsg_end_cb(s); + if(s->submsg_end_cb) s->submsg_end_cb(s); s->top--; s->top = (struct upb_parse_stack_frame*)((char*)s->top - s->udata_size); } @@ -275,7 +277,7 @@ static upb_status_t push_stack_frame(struct upb_parse_state *s, size_t end, s->top = (struct upb_parse_stack_frame*)((char*)s->top + s->udata_size); if(unlikely(s->top > s->limit)) return UPB_ERROR_STACK_OVERFLOW; s->top->end_offset = end; - s->submsg_start_cb(s, user_field_desc); + if(s->submsg_start_cb) s->submsg_start_cb(s, user_field_desc); return UPB_STATUS_OK; } @@ -302,6 +304,7 @@ static upb_status_t parse_delimited(struct upb_parse_state *s, } if(ft == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE) { + base_offset += ((char*)*buf - (char*)bufstart); UPB_CHECK(push_stack_frame(s, base_offset + delim_len, user_field_desc)); } else { void *delim_end = (char*)*buf + delim_len; diff --git a/upb_table.c b/upb_table.c index 1edf676..d53ab1c 100644 --- a/upb_table.c +++ b/upb_table.c @@ -119,10 +119,9 @@ void upb_inttable_insert(struct upb_inttable *t, struct upb_inttable_entry *e) /* Need to resize. New table of double the size, add old elements to it. */ struct upb_inttable new_table; upb_inttable_init(&new_table, upb_inttable_size(t)*2, t->t.entry_size); - for(uint32_t i = 1; i <= upb_inttable_size(t)/2; i++) { - struct upb_inttable_entry *old_e = intent(t, i); - if(old_e->key != EMPTYENT) intinsert(&new_table, old_e); - } + struct upb_inttable_entry *old_e; + for(old_e = upb_inttable_begin(t); old_e; old_e = upb_inttable_next(t, old_e)) + intinsert(&new_table, old_e); upb_inttable_free(t); *t = new_table; } @@ -167,6 +166,7 @@ static void strinsert(struct upb_strtable *t, struct upb_strtable_entry *e) evictee_e->next = empty_bucket; break; } + evictee_e = strent(t, evictee_e->next); } /* table_e remains set to our mainpos. */ } @@ -182,10 +182,9 @@ void upb_strtable_insert(struct upb_strtable *t, struct upb_strtable_entry *e) /* Need to resize. New table of double the size, add old elements to it. */ struct upb_strtable new_table; upb_strtable_init(&new_table, upb_strtable_size(t)*2, t->t.entry_size); - for(uint32_t i = 1; i <= upb_strtable_size(t)/2; i++) { - struct upb_strtable_entry *old_e = strent(t, i); - if(old_e->key.byte_len != 0) strinsert(&new_table, old_e); - } + struct upb_strtable_entry *old_e; + for(old_e = upb_strtable_begin(t); old_e; old_e = upb_strtable_next(t, old_e)) + strinsert(&new_table, old_e); upb_strtable_free(t); *t = new_table; } @@ -197,7 +196,7 @@ void *upb_inttable_begin(struct upb_inttable *t) { } void *upb_inttable_next(struct upb_inttable *t, struct upb_inttable_entry *cur) { - struct upb_inttable_entry *end = intent(t, upb_inttable_size(t)); + struct upb_inttable_entry *end = intent(t, upb_inttable_size(t)+1); do { cur = (void*)((char*)cur + t->t.entry_size); if(cur == end) return NULL; @@ -210,7 +209,7 @@ void *upb_strtable_begin(struct upb_strtable *t) { } void *upb_strtable_next(struct upb_strtable *t, struct upb_strtable_entry *cur) { - struct upb_strtable_entry *end = strent(t, upb_strtable_size(t)); + struct upb_strtable_entry *end = strent(t, upb_strtable_size(t)+1); do { cur = (void*)((char*)cur + t->t.entry_size); if(cur == end) return NULL; diff --git a/upb_table.h b/upb_table.h index 5f9be99..a5da0f2 100644 --- a/upb_table.h +++ b/upb_table.h @@ -27,7 +27,6 @@ typedef uint32_t upb_inttable_key_t; #define UPB_END_OF_CHAIN (uint32_t)0 #define UPB_EMPTY_ENTRY (uint32_t)0 -#define UPB_INDEX(base, i, m) (void*)((char*)(base) + ((i)*(m))) struct upb_inttable_entry { upb_inttable_key_t key; diff --git a/upbc.c b/upbc.c index 2cda5e4..b27568e 100644 --- a/upbc.c +++ b/upbc.c @@ -58,7 +58,7 @@ static void write_header(struct upb_symtab_entry entries[], int num_entries, fprintf(stream, "typedef enum " UPB_STRFMT " {\n", UPB_STRARG(enum_name)); if(ed->set_flags.has.value) { for(uint32_t j = 0; j < ed->value->len; j++) { /* Foreach enum value. */ - google_protobuf_EnumValueDescriptorProto *v = ed->value->elements[i]; + google_protobuf_EnumValueDescriptorProto *v = ed->value->elements[j]; struct upb_string value_name = upb_strdup(*v->name); to_preproc(value_name); /* " GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_UINT32 = 13," */ -- cgit v1.2.3