From 1dea81b1c244d357a6e46ee22c14b36280bf2100 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 21 Jan 2011 17:29:16 -0800 Subject: Interface refinement: rename some constants. * UPB_STOP -> UPB_BREAK, better represents breaking out of a parsing loop. * UPB_STATUS_OK -> UPB_OK, for all status codes, more concise at no readability cost (perhaps an improvement). --- core/upb.c | 5 ++--- core/upb.h | 16 ++++++++-------- core/upb_def.c | 22 ++++++++++------------ core/upb_stream.h | 6 ++++-- 4 files changed, 24 insertions(+), 25 deletions(-) (limited to 'core') diff --git a/core/upb.c b/core/upb.c index 05e9b7d..da2a0f0 100644 --- a/core/upb.c +++ b/core/upb.c @@ -60,9 +60,8 @@ void upb_copyerr(upb_status *to, upb_status *from) } void upb_clearerr(upb_status *status) { - status->code = UPB_STATUS_OK; - upb_string_unref(status->str); - status->str = NULL; + status->code = UPB_OK; + upb_string_recycle(&status->str); } void upb_printerr(upb_status *status) { diff --git a/core/upb.h b/core/upb.h index fb6d9ea..d394a08 100644 --- a/core/upb.h +++ b/core/upb.h @@ -291,16 +291,16 @@ INLINE void upb_value_write(upb_valueptr ptr, upb_value val, // resumed. enum upb_status_code { // The operation completed successfully. - UPB_STATUS_OK = 0, + UPB_OK = 0, // The bytesrc is at EOF and all data was read successfully. - UPB_STATUS_EOF = 1, + UPB_EOF = 1, // A read or write from a streaming src/sink could not be completed right now. - UPB_STATUS_TRYAGAIN = 2, + UPB_TRYAGAIN = 2, // An unrecoverable error occurred. - UPB_STATUS_ERROR = -1, + UPB_ERROR = -1, // A recoverable error occurred (for example, data of the wrong type was // encountered which we can skip over). @@ -308,21 +308,21 @@ enum upb_status_code { }; // TODO: consider adding error space and code, to let ie. errno be stored -// as a proper code. +// as a proper code, or application-specific error codes. typedef struct { char code; upb_string *str; } upb_status; -#define UPB_STATUS_INIT {UPB_STATUS_OK, NULL} +#define UPB_STATUS_INIT {UPB_OK, NULL} #define UPB_ERRORMSG_MAXLEN 256 INLINE bool upb_ok(upb_status *status) { - return status->code == UPB_STATUS_OK; + return status->code == UPB_OK; } INLINE void upb_status_init(upb_status *status) { - status->code = UPB_STATUS_OK; + status->code = UPB_OK; status->str = NULL; } diff --git a/core/upb_def.c b/core/upb_def.c index 0176dc9..79b6632 100644 --- a/core/upb_def.c +++ b/core/upb_def.c @@ -470,9 +470,8 @@ static upb_flow_t upb_enumdef_EnumValueDescriptorProto_value(void *_b, static upb_flow_t upb_enumdef_EnumValueDescriptorProto_endmsg(void *_b) { upb_defbuilder *b = _b; if(!b->saw_number || !b->saw_name) { - upb_seterr(&b->status, UPB_STATUS_ERROR, - "Enum value missing name or number."); - return UPB_STOP; + upb_seterr(&b->status, UPB_ERROR, "Enum value missing name or number."); + return UPB_BREAK; } upb_ntoi_ent ntoi_ent = {{b->name, 0}, b->number}; upb_iton_ent iton_ent = {{b->number, 0}, b->name}; @@ -629,7 +628,7 @@ static upb_flow_t upb_fielddef_value(void *_b, upb_fielddef *f, upb_value val) { break; case GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_NAME_FIELDNUM: { upb_string *str = upb_string_new(); - if (!upb_value_getfullstr(val, str, NULL)) return UPB_STOP; + if (!upb_value_getfullstr(val, str, NULL)) return UPB_BREAK; if(b->f->def) upb_def_unref(b->f->def); b->f->def = UPB_UPCAST(upb_unresolveddef_new(str)); b->f->owned = true; @@ -683,9 +682,8 @@ static upb_flow_t upb_msgdef_endmsg(void *_b) { upb_defbuilder *b = _b; upb_msgdef *m = upb_defbuilder_top(b); if(!m->base.fqname) { - upb_seterr(&b->status, UPB_STATUS_ERROR, - "Encountered message with no name."); - return UPB_STOP; + upb_seterr(&b->status, UPB_ERROR, "Encountered message with no name."); + return UPB_BREAK; } // Create an ordering over the fields. @@ -864,7 +862,7 @@ static bool upb_symtab_findcycles(upb_msgdef *m, int depth, upb_status *status) // where we recurse over the type tree (like for example, right now) and an // absurdly deep tree could cause us to stack overflow on systems with very // limited stacks. - upb_seterr(status, UPB_STATUS_ERROR, "Type " UPB_STRFMT " was found at " + upb_seterr(status, UPB_ERROR, "Type " UPB_STRFMT " was found at " "depth %d in the type graph, which exceeds the maximum type " "depth of %d.", UPB_UPCAST(m)->fqname, depth, UPB_MAX_TYPE_DEPTH); @@ -873,7 +871,7 @@ static bool upb_symtab_findcycles(upb_msgdef *m, int depth, upb_status *status) // Cycle! int cycle_len = depth - 1; if(cycle_len > UPB_MAX_TYPE_CYCLE_LEN) { - upb_seterr(status, UPB_STATUS_ERROR, "Type " UPB_STRFMT " was involved " + upb_seterr(status, UPB_ERROR, "Type " UPB_STRFMT " was involved " "in a cycle of length %d, which exceeds the maximum type " "cycle length of %d.", UPB_UPCAST(m)->fqname, cycle_len, UPB_MAX_TYPE_CYCLE_LEN); @@ -931,7 +929,7 @@ bool upb_resolverefs(upb_strtable *tmptab, upb_strtable *symtab, upb_symtab_ent *found; if(!(found = upb_resolve(tmptab, base, name)) && !(found = upb_resolve(symtab, base, name))) { - upb_seterr(status, UPB_STATUS_ERROR, + upb_seterr(status, UPB_ERROR, "could not resolve symbol '" UPB_STRFMT "'" " in context '" UPB_STRFMT "'", UPB_STRARG(name), UPB_STRARG(base)); @@ -941,7 +939,7 @@ bool upb_resolverefs(upb_strtable *tmptab, upb_strtable *symtab, // Check the type of the found def. upb_fieldtype_t expected = upb_issubmsg(f) ? UPB_DEF_MSG : UPB_DEF_ENUM; if(found->def->type != expected) { - upb_seterr(status, UPB_STATUS_ERROR, "Unexpected type"); + upb_seterr(status, UPB_ERROR, "Unexpected type"); return false; } upb_msgdef_resolve(m, f, found->def); @@ -983,7 +981,7 @@ bool upb_symtab_add_defs(upb_symtab *s, upb_def **defs, int num_defs, // allow_redef is set. if (upb_strtable_lookup(&tmptab, def->fqname) || (!allow_redef && upb_strtable_lookup(&s->symtab, def->fqname))) { - upb_seterr(status, UPB_STATUS_ERROR, "Redefinition of symbol " UPB_STRFMT, + upb_seterr(status, UPB_ERROR, "Redefinition of symbol " UPB_STRFMT, UPB_STRARG(def->fqname)); goto err; } diff --git a/core/upb_stream.h b/core/upb_stream.h index 40836e9..66bfec2 100644 --- a/core/upb_stream.h +++ b/core/upb_stream.h @@ -39,8 +39,10 @@ typedef enum { // Caller should continue sending values to the sink. UPB_CONTINUE, - // Stop processing for now; check status for details. - UPB_STOP, + // Stop processing for now; check status for details. If no status was set, + // a generic error will be returned. If the error is resumable, processing + // will resume by delivering this callback again. + UPB_BREAK, // Skips to the end of the current submessage (or if we are at the top // level, skips to the end of the entire message). -- cgit v1.2.3