From b2bbafb67457835c4cf9061610ea9549740669c2 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 Jul 2009 19:51:53 -0700 Subject: Header file changes for C++ compatibility. --- upb_context.h | 4 ++-- upb_msg.h | 16 +++++++++------- upb_string.h | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/upb_context.h b/upb_context.h index ffff214..4ddaed6 100644 --- a/upb_context.h +++ b/upb_context.h @@ -73,12 +73,12 @@ struct upb_symtab_entry *upb_context_lookup(struct upb_context *c, struct upb_string *symbol); INLINE struct upb_symtab_entry *upb_context_symbegin(struct upb_context *c) { - return upb_strtable_begin(&c->symtab); + return (struct upb_symtab_entry*)upb_strtable_begin(&c->symtab); } INLINE struct upb_symtab_entry *upb_context_symnext( struct upb_context *c, struct upb_symtab_entry *cur) { - return upb_strtable_next(&c->symtab, &cur->e); + return (struct upb_symtab_entry*)upb_strtable_next(&c->symtab, &cur->e); } /* Adding symbols. ************************************************************/ diff --git a/upb_msg.h b/upb_msg.h index e06fa6e..8910505 100644 --- a/upb_msg.h +++ b/upb_msg.h @@ -176,14 +176,16 @@ void upb_msg_ref(struct upb_msg *m, struct upb_msg_field *f, union upb_symbol_re * possible. These return NULL if no such field is found. */ INLINE struct upb_msg_field *upb_msg_fieldbynum(struct upb_msg *m, uint32_t number) { - struct upb_fieldsbynum_entry *e = upb_inttable_lookup( - &m->fields_by_num, number, sizeof(struct upb_fieldsbynum_entry)); + struct upb_fieldsbynum_entry *e = + (struct upb_fieldsbynum_entry*)upb_inttable_lookup( + &m->fields_by_num, number, sizeof(struct upb_fieldsbynum_entry)); return e ? &e->f : NULL; } INLINE struct upb_msg_field *upb_msg_fieldbyname(struct upb_msg *m, struct upb_string *name) { struct upb_fieldsbyname_entry *e = - upb_strtable_lookup(&m->fields_by_name, name); + (struct upb_fieldsbyname_entry*)upb_strtable_lookup( + &m->fields_by_name, name); return e ? &e->f : NULL; } @@ -236,7 +238,8 @@ INLINE void upb_msg_clear(void *s, struct upb_msg *m) /* Returns a pointer to a specific field in a message. */ INLINE union upb_value_ptr upb_msg_getptr(void *data, struct upb_msg_field *f) { - union upb_value_ptr p = {._void = ((char*)data + f->byte_offset)}; + union upb_value_ptr p; + p._void = ((char*)data + f->byte_offset); return p; } @@ -253,9 +256,8 @@ struct upb_array { INLINE union upb_value_ptr upb_array_getelementptr( struct upb_array *arr, uint32_t n, upb_field_type_t type) { - union upb_value_ptr ptr = { - ._void = ((char*)arr->elements._void + n*upb_type_info[type].size) - }; + union upb_value_ptr ptr; + ptr._void = (void*)((char*)arr->elements._void + n*upb_type_info[type].size); return ptr; } diff --git a/upb_string.h b/upb_string.h index 44bc653..7a05811 100644 --- a/upb_string.h +++ b/upb_string.h @@ -65,6 +65,7 @@ bool upb_strreadfile(const char *filename, struct upb_string *data); /* Allows defining upb_strings as literals, ie: * struct upb_string str = UPB_STRLIT("Hello, World!\n"); + * Doesn't work with C++ due to lack of struct initializer syntax. */ #define UPB_STRLIT(strlit) {.ptr=strlit, .byte_len=sizeof(strlit)-1} -- cgit v1.2.3