From d75197375876538332d6d81aa4e8edd13b8f26c1 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 5 Jan 2010 17:42:05 -0800 Subject: Ported/fixed tests to new data types. --- src/upb_data.c | 4 ++++ src/upb_data.h | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/upb_data.c b/src/upb_data.c index 58aee8a..1bb76aa 100644 --- a/src/upb_data.c +++ b/src/upb_data.c @@ -290,13 +290,17 @@ static union upb_value_ptr get_value_ptr(upb_msg *msg, struct upb_fielddef *f) if(upb_isarray(f)) { if(!upb_msg_has(msg, f)) { if(!*p.arr || !upb_data_only(*p.data)) { + printf("Initializing array field " UPB_STRFMT "\n", UPB_STRARG(f->name)); if(*p.arr) upb_array_unref(*p.arr, f); *p.arr = upb_array_new(); + } else { + printf("REUSING array field " UPB_STRFMT "\n", UPB_STRARG(f->name)); } upb_array_truncate(*p.arr); upb_msg_sethas(msg, f); } else { + printf("APPENDING TO EXISTING array field " UPB_STRFMT "\n", UPB_STRARG(f->name)); assert(*p.arr); } upb_arraylen_t oldlen = upb_array_len(*p.arr); diff --git a/src/upb_data.h b/src/upb_data.h index 88ca9af..15e87c5 100644 --- a/src/upb_data.h +++ b/src/upb_data.h @@ -27,6 +27,10 @@ #include "upb_atomic.h" #include "upb_def.h" +#ifdef __cplusplus +extern "C" { +#endif + struct upb_msgdef; struct upb_fielddef; @@ -298,6 +302,13 @@ INLINE void upb_strcpyc(upb_strptr dest, const char *src) { // Returns a new string whose contents are a copy of s. upb_strptr upb_strdup(upb_strptr s); +// Like upb_strdup(), but duplicates a given buffer and length. +INLINE upb_strptr upb_strduplen(const void *src, upb_strlen_t len) { + upb_strptr s = upb_string_new(); + upb_strcpylen(s, src, len); + return s; +} + // Like upb_strdup(), but duplicates a C NULL-terminated string. upb_strptr upb_strdupc(const char *src); @@ -397,7 +408,8 @@ INLINE union upb_value_ptr _upb_array_getptr(upb_array *a, struct upb_fielddef *f, upb_arraylen_t elem) { size_t type_size = upb_type_info[f->type].size; - union upb_value_ptr p = {._void = &a->common.elements.uint8[elem * type_size]}; + union upb_value_ptr p; + p._void = &a->common.elements.uint8[elem * type_size]; return p; } @@ -459,7 +471,8 @@ void _upb_msg_free(upb_msg *msg, struct upb_msgdef *md); // INTERNAL-ONLY: // Returns a pointer to the given field. INLINE union upb_value_ptr _upb_msg_getptr(upb_msg *msg, struct upb_fielddef *f) { - union upb_value_ptr p = {._void = &msg->data[f->byte_offset]}; + union upb_value_ptr p; + p._void = &msg->data[f->byte_offset]; return p; } @@ -505,4 +518,8 @@ void upb_msgparser_reset(struct upb_msgparser *mp, upb_msg *m); size_t upb_msgparser_parse(struct upb_msgparser *mp, upb_strptr str, struct upb_status *status); +#ifdef __cplusplus +} /* extern "C" */ +#endif + #endif -- cgit v1.2.3