From 621c0cdcb5efc4f7c2382031becded018ef0b62b Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 4 Sep 2011 19:29:36 -0700 Subject: Const invasion: large parts of upb made const-correct. --- benchmarks/parsestream.upb.c | 6 +++--- benchmarks/parsetoproto2.upb.cc | 18 +++++++++--------- benchmarks/parsetostruct.upb.c | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'benchmarks') diff --git a/benchmarks/parsestream.upb.c b/benchmarks/parsestream.upb.c index 2d34206..4d13e9d 100644 --- a/benchmarks/parsestream.upb.c +++ b/benchmarks/parsestream.upb.c @@ -9,7 +9,7 @@ static char *input_str; static size_t input_len; -static upb_msgdef *def; +static const upb_msgdef *def; static upb_decoder decoder; static upb_stringsrc stringsrc; @@ -31,14 +31,14 @@ static bool initialize() // Initialize upb state, decode descriptor. upb_status status = UPB_STATUS_INIT; upb_symtab *s = upb_symtab_new(); - upb_read_descriptorfile(s, MESSAGE_DESCRIPTOR_FILE, &status); + upb_load_descriptor_file_into_symtab(s, MESSAGE_DESCRIPTOR_FILE, &status); if(!upb_ok(&status)) { fprintf(stderr, "Error reading descriptor: %s\n", upb_status_getstr(&status)); return false; } - def = upb_dyncast_msgdef(upb_symtab_lookup(s, MESSAGE_NAME)); + def = upb_dyncast_msgdef_const(upb_symtab_lookup(s, MESSAGE_NAME)); if(!def) { fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME); return false; diff --git a/benchmarks/parsetoproto2.upb.cc b/benchmarks/parsetoproto2.upb.cc index 286c7f3..75cd10c 100644 --- a/benchmarks/parsetoproto2.upb.cc +++ b/benchmarks/parsetoproto2.upb.cc @@ -29,7 +29,7 @@ MESSAGE_CIDENT msg[NUM_MESSAGES]; MESSAGE_CIDENT msg2; static upb_stringsrc strsrc; static upb_decoder d; -upb_msgdef *def; +static const upb_msgdef *def; #define PROTO2_APPEND(type, ctype) \ upb_flow_t proto2_append_ ## type(void *_r, upb_value fval, upb_value val) { \ @@ -50,10 +50,10 @@ PROTO2_APPEND(bool, bool) upb_flow_t proto2_setstr(void *m, upb_value fval, upb_value val) { assert(m != NULL); - upb_fielddef *f = upb_value_getfielddef(fval); + const upb_fielddef *f = upb_value_getfielddef(fval); std::string **str = (std::string**)UPB_INDEX(m, f->offset, 1); if (*str == f->default_ptr) *str = new std::string; - upb_strref *ref = upb_value_getstrref(val); + const upb_strref *ref = upb_value_getstrref(val); // XXX: only supports contiguous strings atm. (*str)->assign(ref->ptr, ref->len); return UPB_CONTINUE; @@ -64,7 +64,7 @@ upb_flow_t proto2_append_str(void *_r, upb_value fval, upb_value val) { typedef google::protobuf::RepeatedPtrField R; (void)fval; R *r = (R*)_r; - upb_strref *ref = upb_value_getstrref(val); + const upb_strref *ref = upb_value_getstrref(val); // XXX: only supports contiguous strings atm. r->Add()->assign(ref->ptr, ref->len); return UPB_CONTINUE; @@ -72,13 +72,13 @@ upb_flow_t proto2_append_str(void *_r, upb_value fval, upb_value val) { upb_sflow_t proto2_startseq(void *m, upb_value fval) { assert(m != NULL); - upb_fielddef *f = upb_value_getfielddef(fval); + const upb_fielddef *f = upb_value_getfielddef(fval); return UPB_CONTINUE_WITH(UPB_INDEX(m, f->offset, 1)); } upb_sflow_t proto2_startsubmsg(void *m, upb_value fval) { assert(m != NULL); - upb_fielddef *f = upb_value_getfielddef(fval); + const upb_fielddef *f = upb_value_getfielddef(fval); google::protobuf::Message *prototype = (google::protobuf::Message*)f->prototype; void **subm = (void**)UPB_INDEX(m, f->offset, 1); if (*subm == NULL || *subm == f->default_ptr) @@ -122,7 +122,7 @@ upb_sflow_t proto2_startsubmsg_r(void *_r, upb_value fval) { public: typedef void Type; }; - upb_fielddef *f = upb_value_getfielddef(fval); + const upb_fielddef *f = upb_value_getfielddef(fval); UpbRepeatedPtrField *r = (UpbRepeatedPtrField*)_r; void *submsg = r->Add((google::protobuf::Message*)f->prototype); assert(submsg != NULL); @@ -225,7 +225,7 @@ static bool initialize() return false; } int n; - upb_def **defs = upb_load_descriptor(data, len, &n, &status); + upb_def **defs = upb_load_defs_from_descriptor(data, len, &n, &status); free(data); if(!upb_ok(&status)) { fprintf(stderr, "Error reading descriptor: %s\n", @@ -257,7 +257,7 @@ static bool initialize() for(int i = 0; i < n; i++) upb_def_unref(defs[i]); free(defs); - def = upb_dyncast_msgdef(upb_symtab_lookup(s, MESSAGE_NAME)); + def = upb_dyncast_msgdef_const(upb_symtab_lookup(s, MESSAGE_NAME)); if(!def) { fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME); return false; diff --git a/benchmarks/parsetostruct.upb.c b/benchmarks/parsetostruct.upb.c index 6a36544..5e7aa35 100644 --- a/benchmarks/parsetostruct.upb.c +++ b/benchmarks/parsetostruct.upb.c @@ -7,7 +7,7 @@ #include "upb/pb/decoder.h" #include "upb/pb/glue.h" -static upb_msgdef *def; +static const upb_msgdef *def; static size_t len; static void *msg[NUM_MESSAGES]; static upb_stringsrc strsrc; @@ -18,14 +18,14 @@ static bool initialize() // Initialize upb state, decode descriptor. upb_status status = UPB_STATUS_INIT; upb_symtab *s = upb_symtab_new(); - upb_read_descriptorfile(s, MESSAGE_DESCRIPTOR_FILE, &status); + upb_load_descriptor_file_into_symtab(s, MESSAGE_DESCRIPTOR_FILE, &status); if(!upb_ok(&status)) { fprintf(stderr, "Error reading descriptor: %s\n", upb_status_getstr(&status)); return false; } - def = upb_dyncast_msgdef(upb_symtab_lookup(s, MESSAGE_NAME)); + def = upb_dyncast_msgdef_const(upb_symtab_lookup(s, MESSAGE_NAME)); if(!def) { fprintf(stderr, "Error finding symbol '%s'.\n", MESSAGE_NAME); return false; -- cgit v1.2.3