diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2011-12-23 16:51:23 -0800 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2011-12-23 16:51:23 -0800 |
commit | db59a5198f890ecdcac1227b0bb998160acac5c6 (patch) | |
tree | b708cdab7403bb78dbb9fb7aa82f7ba0e4379361 /upb | |
parent | 02ede91eb243f514f0db1e972d1882e92fa9c8d8 (diff) |
Fixes to un-break "make descriptorgen"
Diffstat (limited to 'upb')
-rw-r--r-- | upb/bytestream.c | 5 | ||||
-rw-r--r-- | upb/def.c | 21 | ||||
-rw-r--r-- | upb/def.h | 4 |
3 files changed, 19 insertions, 11 deletions
diff --git a/upb/bytestream.c b/upb/bytestream.c index 4f6e4b1..812e552 100644 --- a/upb/bytestream.c +++ b/upb/bytestream.c @@ -32,6 +32,8 @@ upb_byteregion *upb_byteregion_newl(const void *str, size_t len) { memcpy(ptr, str, len); ptr[len] = '\0'; upb_stringsrc_reset(src, ptr, len); + upb_byteregion_fetch(upb_stringsrc_allbytes(src)); + assert(len == upb_byteregion_available(upb_stringsrc_allbytes(src), 0)); return upb_stringsrc_allbytes(src); } @@ -241,9 +243,10 @@ upb_bytesink* upb_stdio_bytesink(upb_stdio *stdio) { return &stdio->sink; } upb_bytesuccess_t upb_stringsrc_fetch(void *_src, uint64_t ofs, size_t *read) { upb_stringsrc *src = _src; - assert(ofs < src->len); + assert(ofs <= src->len); if (ofs == src->len) { upb_status_seteof(&src->bytesrc.status); + *read = 0; return UPB_BYTE_EOF; } *read = src->len - ofs; @@ -235,6 +235,7 @@ upb_fielddef *upb_fielddef_new() { } static void upb_fielddef_init_default(upb_fielddef *f) { + f->default_is_string = false; switch (upb_fielddef_type(f)) { case UPB_TYPE(DOUBLE): upb_value_setdouble(&f->defaultval, 0); break; case UPB_TYPE(FLOAT): upb_value_setfloat(&f->defaultval, 0); break; @@ -252,15 +253,16 @@ static void upb_fielddef_init_default(upb_fielddef *f) { case UPB_TYPE(BOOL): upb_value_setbool(&f->defaultval, false); break; case UPB_TYPE(STRING): case UPB_TYPE(BYTES): - upb_value_setbyteregion(&f->defaultval, upb_byteregion_new("")); break; + f->default_is_string = true; + upb_value_setbyteregion(&f->defaultval, upb_byteregion_new("")); + break; case UPB_TYPE(GROUP): case UPB_TYPE(MESSAGE): upb_value_setptr(&f->defaultval, NULL); break; } - f->default_is_symbolic = false; } static void upb_fielddef_uninit_default(upb_fielddef *f) { - if (upb_isstring(f) || f->default_is_symbolic) { + if (f->default_is_string) { upb_byteregion_free(upb_value_getbyteregion(f->defaultval)); } } @@ -323,7 +325,7 @@ static bool upb_fielddef_resolve(upb_fielddef *f, upb_def *def, upb_status *s) { assert(upb_dyncast_unresolveddef(f->def)); upb_def_unref(f->def); f->def = def; - if (f->type == UPB_TYPE(ENUM) && f->default_is_symbolic) { + if (f->type == UPB_TYPE(ENUM) && f->default_is_string) { // Resolve the enum's default from a string to an integer. upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval); assert(bytes); // Points to either a real default or the empty string. @@ -347,6 +349,7 @@ static bool upb_fielddef_resolve(upb_fielddef *f, upb_def *def, upb_status *s) { } upb_value_setint32(&f->defaultval, val); } + f->default_is_string = false; upb_byteregion_free(bytes); } return true; @@ -387,11 +390,13 @@ void upb_fielddef_setdefault(upb_fielddef *f, upb_value value) { void upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len) { assert(upb_isstring(f) || f->type == UPB_TYPE(ENUM)); - upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval); - assert(bytes); - upb_byteregion_free(bytes); + if (f->default_is_string) { + upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval); + assert(bytes); + upb_byteregion_free(bytes); + } upb_value_setbyteregion(&f->defaultval, upb_byteregion_newl(str, len)); - f->default_is_symbolic = true; + f->default_is_string = true; } void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str) { @@ -109,7 +109,7 @@ typedef struct _upb_fielddef { uint8_t label; // Use UPB_LABEL() constants. int16_t hasbit; uint16_t offset; - bool default_is_symbolic; + bool default_is_string; bool active; int32_t number; char *name; @@ -161,7 +161,7 @@ INLINE upb_value upb_fielddef_default(const upb_fielddef *f) { // returns true, the default returned from upb_fielddef_default() is a string, // otherwise it is an integer. INLINE bool upb_fielddef_default_is_symbolic(const upb_fielddef *f) { - return f->default_is_symbolic; + return f->default_is_string; } // The enum or submessage def for this field, if any. Only meaningful for |