Fixes to un-break "make descriptorgen"

pull/13171/head
Joshua Haberman 13 years ago
parent 02ede91eb2
commit db59a5198f
  1. 5
      upb/bytestream.c
  2. 15
      upb/def.c
  3. 4
      upb/def.h

@ -32,6 +32,8 @@ upb_byteregion *upb_byteregion_newl(const void *str, size_t len) {
memcpy(ptr, str, len); memcpy(ptr, str, len);
ptr[len] = '\0'; ptr[len] = '\0';
upb_stringsrc_reset(src, ptr, len); 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); 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_bytesuccess_t upb_stringsrc_fetch(void *_src, uint64_t ofs, size_t *read) {
upb_stringsrc *src = _src; upb_stringsrc *src = _src;
assert(ofs < src->len); assert(ofs <= src->len);
if (ofs == src->len) { if (ofs == src->len) {
upb_status_seteof(&src->bytesrc.status); upb_status_seteof(&src->bytesrc.status);
*read = 0;
return UPB_BYTE_EOF; return UPB_BYTE_EOF;
} }
*read = src->len - ofs; *read = src->len - ofs;

@ -235,6 +235,7 @@ upb_fielddef *upb_fielddef_new() {
} }
static void upb_fielddef_init_default(upb_fielddef *f) { static void upb_fielddef_init_default(upb_fielddef *f) {
f->default_is_string = false;
switch (upb_fielddef_type(f)) { switch (upb_fielddef_type(f)) {
case UPB_TYPE(DOUBLE): upb_value_setdouble(&f->defaultval, 0); break; case UPB_TYPE(DOUBLE): upb_value_setdouble(&f->defaultval, 0); break;
case UPB_TYPE(FLOAT): upb_value_setfloat(&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(BOOL): upb_value_setbool(&f->defaultval, false); break;
case UPB_TYPE(STRING): case UPB_TYPE(STRING):
case UPB_TYPE(BYTES): 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(GROUP):
case UPB_TYPE(MESSAGE): upb_value_setptr(&f->defaultval, NULL); break; 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) { 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)); 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)); assert(upb_dyncast_unresolveddef(f->def));
upb_def_unref(f->def); upb_def_unref(f->def);
f->def = 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. // Resolve the enum's default from a string to an integer.
upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval); upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval);
assert(bytes); // Points to either a real default or the empty string. 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); upb_value_setint32(&f->defaultval, val);
} }
f->default_is_string = false;
upb_byteregion_free(bytes); upb_byteregion_free(bytes);
} }
return true; 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) { void upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len) {
assert(upb_isstring(f) || f->type == UPB_TYPE(ENUM)); assert(upb_isstring(f) || f->type == UPB_TYPE(ENUM));
if (f->default_is_string) {
upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval); upb_byteregion *bytes = upb_value_getbyteregion(f->defaultval);
assert(bytes); assert(bytes);
upb_byteregion_free(bytes); upb_byteregion_free(bytes);
}
upb_value_setbyteregion(&f->defaultval, upb_byteregion_newl(str, len)); 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) { 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. uint8_t label; // Use UPB_LABEL() constants.
int16_t hasbit; int16_t hasbit;
uint16_t offset; uint16_t offset;
bool default_is_symbolic; bool default_is_string;
bool active; bool active;
int32_t number; int32_t number;
char *name; 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, // returns true, the default returned from upb_fielddef_default() is a string,
// otherwise it is an integer. // otherwise it is an integer.
INLINE bool upb_fielddef_default_is_symbolic(const upb_fielddef *f) { 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 // The enum or submessage def for this field, if any. Only meaningful for

Loading…
Cancel
Save