Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: third_party/protobuf/ruby/ext/google/protobuf_c/upb.c

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Amalgamated source file 1 // Amalgamated source file
2 #include "upb.h" 2 #include "upb.h"
3 3
4 4
5 #include <ctype.h>
5 #include <stdlib.h> 6 #include <stdlib.h>
6 #include <string.h> 7 #include <string.h>
7 8
8 typedef struct { 9 typedef struct {
9 size_t len; 10 size_t len;
10 char str[1]; /* Null-terminated string data follows. */ 11 char str[1]; /* Null-terminated string data follows. */
11 } str_t; 12 } str_t;
12 13
13 static str_t *newstr(const char *data, size_t len) { 14 static str_t *newstr(const char *data, size_t len) {
14 str_t *ret = malloc(sizeof(*ret) + len); 15 str_t *ret = upb_gmalloc(sizeof(*ret) + len);
15 if (!ret) return NULL; 16 if (!ret) return NULL;
16 ret->len = len; 17 ret->len = len;
17 memcpy(ret->str, data, len); 18 memcpy(ret->str, data, len);
18 ret->str[len] = '\0'; 19 ret->str[len] = '\0';
19 return ret; 20 return ret;
20 } 21 }
21 22
22 static void freestr(str_t *s) { free(s); } 23 static void freestr(str_t *s) { upb_gfree(s); }
23 24
24 /* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ 25 /* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */
25 static bool upb_isbetween(char c, char low, char high) { 26 static bool upb_isbetween(char c, char low, char high) {
26 return c >= low && c <= high; 27 return c >= low && c <= high;
27 } 28 }
28 29
29 static bool upb_isletter(char c) { 30 static bool upb_isletter(char c) {
30 return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_'; 31 return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_';
31 } 32 }
32 33
(...skipping 24 matching lines...) Expand all
57 if (!upb_isalphanum(c)) { 58 if (!upb_isalphanum(c)) {
58 upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)", 59 upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)",
59 str); 60 str);
60 return false; 61 return false;
61 } 62 }
62 } 63 }
63 } 64 }
64 return !start; 65 return !start;
65 } 66 }
66 67
68 static bool upb_isoneof(const upb_refcounted *def) {
69 return def->vtbl == &upb_oneofdef_vtbl;
70 }
71
72 static bool upb_isfield(const upb_refcounted *def) {
73 return def->vtbl == &upb_fielddef_vtbl;
74 }
75
76 static const upb_oneofdef *upb_trygetoneof(const upb_refcounted *def) {
77 return upb_isoneof(def) ? (const upb_oneofdef*)def : NULL;
78 }
79
80 static const upb_fielddef *upb_trygetfield(const upb_refcounted *def) {
81 return upb_isfield(def) ? (const upb_fielddef*)def : NULL;
82 }
83
67 84
68 /* upb_def ********************************************************************/ 85 /* upb_def ********************************************************************/
69 86
70 upb_deftype_t upb_def_type(const upb_def *d) { return d->type; } 87 upb_deftype_t upb_def_type(const upb_def *d) { return d->type; }
71 88
72 const char *upb_def_fullname(const upb_def *d) { return d->fullname; } 89 const char *upb_def_fullname(const upb_def *d) { return d->fullname; }
73 90
91 const char *upb_def_name(const upb_def *d) {
92 const char *p;
93
94 if (d->fullname == NULL) {
95 return NULL;
96 } else if ((p = strrchr(d->fullname, '.')) == NULL) {
97 /* No '.' in the name, return the full string. */
98 return d->fullname;
99 } else {
100 /* Return one past the last '.'. */
101 return p + 1;
102 }
103 }
104
74 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) { 105 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) {
75 assert(!upb_def_isfrozen(def)); 106 assert(!upb_def_isfrozen(def));
76 if (!upb_isident(fullname, strlen(fullname), true, s)) return false; 107 if (!upb_isident(fullname, strlen(fullname), true, s)) {
77 free((void*)def->fullname); 108 return false;
78 def->fullname = upb_strdup(fullname); 109 }
110
111 fullname = upb_gstrdup(fullname);
112 if (!fullname) {
113 upb_upberr_setoom(s);
114 return false;
115 }
116
117 upb_gfree((void*)def->fullname);
118 def->fullname = fullname;
79 return true; 119 return true;
80 } 120 }
81 121
122 const upb_filedef *upb_def_file(const upb_def *d) { return d->file; }
123
82 upb_def *upb_def_dup(const upb_def *def, const void *o) { 124 upb_def *upb_def_dup(const upb_def *def, const void *o) {
83 switch (def->type) { 125 switch (def->type) {
84 case UPB_DEF_MSG: 126 case UPB_DEF_MSG:
85 return upb_msgdef_upcast_mutable( 127 return upb_msgdef_upcast_mutable(
86 upb_msgdef_dup(upb_downcast_msgdef(def), o)); 128 upb_msgdef_dup(upb_downcast_msgdef(def), o));
87 case UPB_DEF_FIELD: 129 case UPB_DEF_FIELD:
88 return upb_fielddef_upcast_mutable( 130 return upb_fielddef_upcast_mutable(
89 upb_fielddef_dup(upb_downcast_fielddef(def), o)); 131 upb_fielddef_dup(upb_downcast_fielddef(def), o));
90 case UPB_DEF_ENUM: 132 case UPB_DEF_ENUM:
91 return upb_enumdef_upcast_mutable( 133 return upb_enumdef_upcast_mutable(
92 upb_enumdef_dup(upb_downcast_enumdef(def), o)); 134 upb_enumdef_dup(upb_downcast_enumdef(def), o));
93 default: assert(false); return NULL; 135 default: assert(false); return NULL;
94 } 136 }
95 } 137 }
96 138
97 static bool upb_def_init(upb_def *def, upb_deftype_t type, 139 static bool upb_def_init(upb_def *def, upb_deftype_t type,
98 const struct upb_refcounted_vtbl *vtbl, 140 const struct upb_refcounted_vtbl *vtbl,
99 const void *owner) { 141 const void *owner) {
100 if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return fal se; 142 if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return fal se;
101 def->type = type; 143 def->type = type;
102 def->fullname = NULL; 144 def->fullname = NULL;
103 def->came_from_user = false; 145 def->came_from_user = false;
146 def->file = NULL;
104 return true; 147 return true;
105 } 148 }
106 149
107 static void upb_def_uninit(upb_def *def) { 150 static void upb_def_uninit(upb_def *def) {
108 free((void*)def->fullname); 151 upb_gfree((void*)def->fullname);
109 } 152 }
110 153
111 static const char *msgdef_name(const upb_msgdef *m) { 154 static const char *msgdef_name(const upb_msgdef *m) {
112 const char *name = upb_def_fullname(upb_msgdef_upcast(m)); 155 const char *name = upb_def_fullname(upb_msgdef_upcast(m));
113 return name ? name : "(anonymous)"; 156 return name ? name : "(anonymous)";
114 } 157 }
115 158
116 static bool upb_validate_field(upb_fielddef *f, upb_status *s) { 159 static bool upb_validate_field(upb_fielddef *f, upb_status *s) {
117 if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { 160 if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
118 upb_status_seterrmsg(s, "fielddef must have name and number set"); 161 upb_status_seterrmsg(s, "fielddef must have name and number set");
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 return field_rank(f1) - field_rank(f2); 278 return field_rank(f1) - field_rank(f2);
236 } 279 }
237 280
238 static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { 281 static bool assign_msg_indices(upb_msgdef *m, upb_status *s) {
239 /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the 282 /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the
240 * lowest indexes, but we do not publicly guarantee this. */ 283 * lowest indexes, but we do not publicly guarantee this. */
241 upb_msg_field_iter j; 284 upb_msg_field_iter j;
242 int i; 285 int i;
243 uint32_t selector; 286 uint32_t selector;
244 int n = upb_msgdef_numfields(m); 287 int n = upb_msgdef_numfields(m);
245 upb_fielddef **fields = malloc(n * sizeof(*fields)); 288 upb_fielddef **fields;
246 if (!fields) return false; 289
290 if (n == 0) {
291 m->selector_count = UPB_STATIC_SELECTOR_COUNT;
292 m->submsg_field_count = 0;
293 return true;
294 }
295
296 fields = upb_gmalloc(n * sizeof(*fields));
297 if (!fields) {
298 upb_upberr_setoom(s);
299 return false;
300 }
247 301
248 m->submsg_field_count = 0; 302 m->submsg_field_count = 0;
249 for(i = 0, upb_msg_field_begin(&j, m); 303 for(i = 0, upb_msg_field_begin(&j, m);
250 !upb_msg_field_done(&j); 304 !upb_msg_field_done(&j);
251 upb_msg_field_next(&j), i++) { 305 upb_msg_field_next(&j), i++) {
252 upb_fielddef *f = upb_msg_iter_field(&j); 306 upb_fielddef *f = upb_msg_iter_field(&j);
253 assert(f->msg.def == m); 307 assert(f->msg.def == m);
254 if (!upb_validate_field(f, s)) { 308 if (!upb_validate_field(f, s)) {
255 free(fields); 309 upb_gfree(fields);
256 return false; 310 return false;
257 } 311 }
258 if (upb_fielddef_issubmsg(f)) { 312 if (upb_fielddef_issubmsg(f)) {
259 m->submsg_field_count++; 313 m->submsg_field_count++;
260 } 314 }
261 fields[i] = f; 315 fields[i] = f;
262 } 316 }
263 317
264 qsort(fields, n, sizeof(*fields), cmp_fields); 318 qsort(fields, n, sizeof(*fields), cmp_fields);
265 319
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 TRY(UPB_HANDLER_STARTSUBMSG) 359 TRY(UPB_HANDLER_STARTSUBMSG)
306 TRY(UPB_HANDLER_ENDSUBMSG) 360 TRY(UPB_HANDLER_ENDSUBMSG)
307 TRY(UPB_HANDLER_STARTSEQ) 361 TRY(UPB_HANDLER_STARTSEQ)
308 TRY(UPB_HANDLER_ENDSEQ) 362 TRY(UPB_HANDLER_ENDSEQ)
309 } 363 }
310 upb_inttable_uninit(&t); 364 upb_inttable_uninit(&t);
311 } 365 }
312 #undef TRY 366 #undef TRY
313 #endif 367 #endif
314 368
315 free(fields); 369 upb_gfree(fields);
316 return true; 370 return true;
317 } 371 }
318 372
319 bool upb_def_freeze(upb_def *const* defs, int n, upb_status *s) { 373 bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) {
320 int i; 374 size_t i;
321 int maxdepth;
322 bool ret;
323 upb_status_clear(s);
324 375
325 /* First perform validation, in two passes so we can check that we have a 376 /* First perform validation, in two passes so we can check that we have a
326 * transitive closure without needing to search. */ 377 * transitive closure without needing to search. */
327 for (i = 0; i < n; i++) { 378 for (i = 0; i < n; i++) {
328 upb_def *def = defs[i]; 379 upb_def *def = defs[i];
329 if (upb_def_isfrozen(def)) { 380 if (upb_def_isfrozen(def)) {
330 /* Could relax this requirement if it's annoying. */ 381 /* Could relax this requirement if it's annoying. */
331 upb_status_seterrmsg(s, "def is already frozen"); 382 upb_status_seterrmsg(s, "def is already frozen");
332 goto err; 383 goto err;
333 } else if (def->type == UPB_DEF_FIELD) { 384 } else if (def->type == UPB_DEF_FIELD) {
334 upb_status_seterrmsg(s, "standalone fielddefs can not be frozen"); 385 upb_status_seterrmsg(s, "standalone fielddefs can not be frozen");
335 goto err; 386 goto err;
336 } else if (def->type == UPB_DEF_ENUM) { 387 } else if (def->type == UPB_DEF_ENUM) {
337 if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) { 388 if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) {
338 goto err; 389 goto err;
339 } 390 }
340 } else { 391 } else {
341 /* Set now to detect transitive closure in the second pass. */ 392 /* Set now to detect transitive closure in the second pass. */
342 def->came_from_user = true; 393 def->came_from_user = true;
343 } 394 }
344 } 395 }
345 396
346 /* Second pass of validation. Also assign selector bases and indexes, and 397 /* Second pass of validation. Also assign selector bases and indexes, and
347 * compact tables. */ 398 * compact tables. */
348 for (i = 0; i < n; i++) { 399 for (i = 0; i < n; i++) {
349 upb_msgdef *m = upb_dyncast_msgdef_mutable(defs[i]); 400 upb_def *def = defs[i];
350 upb_enumdef *e = upb_dyncast_enumdef_mutable(defs[i]); 401 upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
402 upb_enumdef *e = upb_dyncast_enumdef_mutable(def);
351 if (m) { 403 if (m) {
352 upb_inttable_compact(&m->itof); 404 upb_inttable_compact(&m->itof);
353 if (!assign_msg_indices(m, s)) { 405 if (!assign_msg_indices(m, s)) {
354 goto err; 406 goto err;
355 } 407 }
356 } else if (e) { 408 } else if (e) {
357 upb_inttable_compact(&e->iton); 409 upb_inttable_compact(&e->iton);
358 } 410 }
359 } 411 }
360 412
361 /* Def graph contains FieldDefs between each MessageDef, so double the 413 return true;
362 * limit. */
363 maxdepth = UPB_MAX_MESSAGE_DEPTH * 2;
364
365 /* Validation all passed; freeze the defs. */
366 ret = upb_refcounted_freeze((upb_refcounted * const *)defs, n, s, maxdepth);
367 assert(!(s && ret != upb_ok(s)));
368 return ret;
369 414
370 err: 415 err:
371 for (i = 0; i < n; i++) { 416 for (i = 0; i < n; i++) {
372 defs[i]->came_from_user = false; 417 upb_def *def = defs[i];
418 def->came_from_user = false;
373 } 419 }
374 assert(!(s && upb_ok(s))); 420 assert(!(s && upb_ok(s)));
375 return false; 421 return false;
376 } 422 }
377 423
424 bool upb_def_freeze(upb_def *const* defs, size_t n, upb_status *s) {
425 /* Def graph contains FieldDefs between each MessageDef, so double the
426 * limit. */
427 const size_t maxdepth = UPB_MAX_MESSAGE_DEPTH * 2;
428
429 if (!_upb_def_validate(defs, n, s)) {
430 return false;
431 }
432
433
434 /* Validation all passed; freeze the objects. */
435 return upb_refcounted_freeze((upb_refcounted *const*)defs, n, s, maxdepth);
436 }
437
378 438
379 /* upb_enumdef ****************************************************************/ 439 /* upb_enumdef ****************************************************************/
380 440
381 static void upb_enumdef_free(upb_refcounted *r) { 441 static void upb_enumdef_free(upb_refcounted *r) {
382 upb_enumdef *e = (upb_enumdef*)r; 442 upb_enumdef *e = (upb_enumdef*)r;
383 upb_inttable_iter i; 443 upb_inttable_iter i;
384 upb_inttable_begin(&i, &e->iton); 444 upb_inttable_begin(&i, &e->iton);
385 for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) { 445 for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) {
386 /* To clean up the upb_strdup() from upb_enumdef_addval(). */ 446 /* To clean up the upb_gstrdup() from upb_enumdef_addval(). */
387 free(upb_value_getcstr(upb_inttable_iter_value(&i))); 447 upb_gfree(upb_value_getcstr(upb_inttable_iter_value(&i)));
388 } 448 }
389 upb_strtable_uninit(&e->ntoi); 449 upb_strtable_uninit(&e->ntoi);
390 upb_inttable_uninit(&e->iton); 450 upb_inttable_uninit(&e->iton);
391 upb_def_uninit(upb_enumdef_upcast_mutable(e)); 451 upb_def_uninit(upb_enumdef_upcast_mutable(e));
392 free(e); 452 upb_gfree(e);
393 } 453 }
394 454
455 const struct upb_refcounted_vtbl upb_enumdef_vtbl = {NULL, &upb_enumdef_free};
456
395 upb_enumdef *upb_enumdef_new(const void *owner) { 457 upb_enumdef *upb_enumdef_new(const void *owner) {
396 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_enumdef_free}; 458 upb_enumdef *e = upb_gmalloc(sizeof(*e));
397 upb_enumdef *e = malloc(sizeof(*e));
398 if (!e) return NULL; 459 if (!e) return NULL;
399 if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM, &vtbl, owner)) 460
461 if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM,
462 &upb_enumdef_vtbl, owner)) {
400 goto err2; 463 goto err2;
464 }
465
401 if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2; 466 if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2;
402 if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1; 467 if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1;
403 return e; 468 return e;
404 469
405 err1: 470 err1:
406 upb_strtable_uninit(&e->ntoi); 471 upb_strtable_uninit(&e->ntoi);
407 err2: 472 err2:
408 free(e); 473 upb_gfree(e);
409 return NULL; 474 return NULL;
410 } 475 }
411 476
412 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner) { 477 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner) {
413 upb_enum_iter i; 478 upb_enum_iter i;
414 upb_enumdef *new_e = upb_enumdef_new(owner); 479 upb_enumdef *new_e = upb_enumdef_new(owner);
415 if (!new_e) return NULL; 480 if (!new_e) return NULL;
416 for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) { 481 for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) {
417 bool success = upb_enumdef_addval( 482 bool success = upb_enumdef_addval(
418 new_e, upb_enum_iter_name(&i),upb_enum_iter_number(&i), NULL); 483 new_e, upb_enum_iter_name(&i),upb_enum_iter_number(&i), NULL);
419 if (!success) { 484 if (!success) {
420 upb_enumdef_unref(new_e, owner); 485 upb_enumdef_unref(new_e, owner);
421 return NULL; 486 return NULL;
422 } 487 }
423 } 488 }
424 return new_e; 489 return new_e;
425 } 490 }
426 491
427 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) { 492 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) {
428 upb_def *d = upb_enumdef_upcast_mutable(e); 493 upb_def *d = upb_enumdef_upcast_mutable(e);
429 return upb_def_freeze(&d, 1, status); 494 return upb_def_freeze(&d, 1, status);
430 } 495 }
431 496
432 const char *upb_enumdef_fullname(const upb_enumdef *e) { 497 const char *upb_enumdef_fullname(const upb_enumdef *e) {
433 return upb_def_fullname(upb_enumdef_upcast(e)); 498 return upb_def_fullname(upb_enumdef_upcast(e));
434 } 499 }
435 500
501 const char *upb_enumdef_name(const upb_enumdef *e) {
502 return upb_def_name(upb_enumdef_upcast(e));
503 }
504
436 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname, 505 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname,
437 upb_status *s) { 506 upb_status *s) {
438 return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s); 507 return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s);
439 } 508 }
440 509
441 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, 510 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num,
442 upb_status *status) { 511 upb_status *status) {
512 char *name2;
513
443 if (!upb_isident(name, strlen(name), false, status)) { 514 if (!upb_isident(name, strlen(name), false, status)) {
444 return false; 515 return false;
445 } 516 }
517
446 if (upb_enumdef_ntoiz(e, name, NULL)) { 518 if (upb_enumdef_ntoiz(e, name, NULL)) {
447 upb_status_seterrf(status, "name '%s' is already defined", name); 519 upb_status_seterrf(status, "name '%s' is already defined", name);
448 return false; 520 return false;
449 } 521 }
522
450 if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) { 523 if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) {
451 upb_status_seterrmsg(status, "out of memory"); 524 upb_status_seterrmsg(status, "out of memory");
452 return false; 525 return false;
453 } 526 }
454 if (!upb_inttable_lookup(&e->iton, num, NULL) && 527
455 !upb_inttable_insert(&e->iton, num, upb_value_cstr(upb_strdup(name)))) { 528 if (!upb_inttable_lookup(&e->iton, num, NULL)) {
456 upb_status_seterrmsg(status, "out of memory"); 529 name2 = upb_gstrdup(name);
457 upb_strtable_remove(&e->ntoi, name, NULL); 530 if (!name2 || !upb_inttable_insert(&e->iton, num, upb_value_cstr(name2))) {
458 return false; 531 upb_status_seterrmsg(status, "out of memory");
532 upb_strtable_remove(&e->ntoi, name, NULL);
533 return false;
534 }
459 } 535 }
536
460 if (upb_enumdef_numvals(e) == 1) { 537 if (upb_enumdef_numvals(e) == 1) {
461 bool ok = upb_enumdef_setdefault(e, num, NULL); 538 bool ok = upb_enumdef_setdefault(e, num, NULL);
462 UPB_ASSERT_VAR(ok, ok); 539 UPB_ASSERT_VAR(ok, ok);
463 } 540 }
541
464 return true; 542 return true;
465 } 543 }
466 544
467 int32_t upb_enumdef_default(const upb_enumdef *e) { 545 int32_t upb_enumdef_default(const upb_enumdef *e) {
468 assert(upb_enumdef_iton(e, e->defaultval)); 546 assert(upb_enumdef_iton(e, e->defaultval));
469 return e->defaultval; 547 return e->defaultval;
470 } 548 }
471 549
472 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) { 550 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) {
473 assert(!upb_enumdef_isfrozen(e)); 551 assert(!upb_enumdef_isfrozen(e));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 596
519 /* upb_fielddef ***************************************************************/ 597 /* upb_fielddef ***************************************************************/
520 598
521 static void upb_fielddef_init_default(upb_fielddef *f); 599 static void upb_fielddef_init_default(upb_fielddef *f);
522 600
523 static void upb_fielddef_uninit_default(upb_fielddef *f) { 601 static void upb_fielddef_uninit_default(upb_fielddef *f) {
524 if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes) 602 if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes)
525 freestr(f->defaultval.bytes); 603 freestr(f->defaultval.bytes);
526 } 604 }
527 605
606 const char *upb_fielddef_fullname(const upb_fielddef *e) {
607 return upb_def_fullname(upb_fielddef_upcast(e));
608 }
609
528 static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit, 610 static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit,
529 void *closure) { 611 void *closure) {
530 const upb_fielddef *f = (const upb_fielddef*)r; 612 const upb_fielddef *f = (const upb_fielddef*)r;
531 if (upb_fielddef_containingtype(f)) { 613 if (upb_fielddef_containingtype(f)) {
532 visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure); 614 visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure);
533 } 615 }
534 if (upb_fielddef_containingoneof(f)) { 616 if (upb_fielddef_containingoneof(f)) {
535 visit(r, upb_oneofdef_upcast2(upb_fielddef_containingoneof(f)), closure); 617 visit(r, upb_oneofdef_upcast(upb_fielddef_containingoneof(f)), closure);
536 } 618 }
537 if (upb_fielddef_subdef(f)) { 619 if (upb_fielddef_subdef(f)) {
538 visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure); 620 visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure);
539 } 621 }
540 } 622 }
541 623
542 static void freefield(upb_refcounted *r) { 624 static void freefield(upb_refcounted *r) {
543 upb_fielddef *f = (upb_fielddef*)r; 625 upb_fielddef *f = (upb_fielddef*)r;
544 upb_fielddef_uninit_default(f); 626 upb_fielddef_uninit_default(f);
545 if (f->subdef_is_symbolic) 627 if (f->subdef_is_symbolic)
546 free(f->sub.name); 628 upb_gfree(f->sub.name);
547 upb_def_uninit(upb_fielddef_upcast_mutable(f)); 629 upb_def_uninit(upb_fielddef_upcast_mutable(f));
548 free(f); 630 upb_gfree(f);
549 } 631 }
550 632
551 static const char *enumdefaultstr(const upb_fielddef *f) { 633 static const char *enumdefaultstr(const upb_fielddef *f) {
552 const upb_enumdef *e; 634 const upb_enumdef *e;
553 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); 635 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM);
554 e = upb_fielddef_enumsubdef(f); 636 e = upb_fielddef_enumsubdef(f);
555 if (f->default_is_string && f->defaultval.bytes) { 637 if (f->default_is_string && f->defaultval.bytes) {
556 /* Default was explicitly set as a string. */ 638 /* Default was explicitly set as a string. */
557 str_t *s = f->defaultval.bytes; 639 str_t *s = f->defaultval.bytes;
558 return s->str; 640 return s->str;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 /* Default is unset; try to pull in enumdef default. */ 676 /* Default is unset; try to pull in enumdef default. */
595 if (upb_enumdef_numvals(e) > 0) { 677 if (upb_enumdef_numvals(e) > 0) {
596 *val = upb_enumdef_default(e); 678 *val = upb_enumdef_default(e);
597 return true; 679 return true;
598 } 680 }
599 } 681 }
600 } 682 }
601 return false; 683 return false;
602 } 684 }
603 685
686 const struct upb_refcounted_vtbl upb_fielddef_vtbl = {visitfield, freefield};
687
604 upb_fielddef *upb_fielddef_new(const void *o) { 688 upb_fielddef *upb_fielddef_new(const void *o) {
605 static const struct upb_refcounted_vtbl vtbl = {visitfield, freefield}; 689 upb_fielddef *f = upb_gmalloc(sizeof(*f));
606 upb_fielddef *f = malloc(sizeof(*f));
607 if (!f) return NULL; 690 if (!f) return NULL;
608 if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD, &vtbl, o)) { 691 if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD,
609 free(f); 692 &upb_fielddef_vtbl, o)) {
693 upb_gfree(f);
610 return NULL; 694 return NULL;
611 } 695 }
612 f->msg.def = NULL; 696 f->msg.def = NULL;
613 f->sub.def = NULL; 697 f->sub.def = NULL;
614 f->oneof = NULL; 698 f->oneof = NULL;
615 f->subdef_is_symbolic = false; 699 f->subdef_is_symbolic = false;
616 f->msg_is_symbolic = false; 700 f->msg_is_symbolic = false;
617 f->label_ = UPB_LABEL_OPTIONAL; 701 f->label_ = UPB_LABEL_OPTIONAL;
618 f->type_ = UPB_TYPE_INT32; 702 f->type_ = UPB_TYPE_INT32;
619 f->number_ = 0; 703 f->number_ = 0;
(...skipping 30 matching lines...) Expand all
650 newf->default_is_string = f->default_is_string; 734 newf->default_is_string = f->default_is_string;
651 newf->defaultval = f->defaultval; 735 newf->defaultval = f->defaultval;
652 } 736 }
653 737
654 if (f->subdef_is_symbolic) { 738 if (f->subdef_is_symbolic) {
655 srcname = f->sub.name; /* Might be NULL. */ 739 srcname = f->sub.name; /* Might be NULL. */
656 } else { 740 } else {
657 srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL; 741 srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL;
658 } 742 }
659 if (srcname) { 743 if (srcname) {
660 char *newname = malloc(strlen(f->sub.def->fullname) + 2); 744 char *newname = upb_gmalloc(strlen(f->sub.def->fullname) + 2);
661 if (!newname) { 745 if (!newname) {
662 upb_fielddef_unref(newf, owner); 746 upb_fielddef_unref(newf, owner);
663 return NULL; 747 return NULL;
664 } 748 }
665 strcpy(newname, "."); 749 strcpy(newname, ".");
666 strcat(newname, f->sub.def->fullname); 750 strcat(newname, f->sub.def->fullname);
667 upb_fielddef_setsubdefname(newf, newname, NULL); 751 upb_fielddef_setsubdefname(newf, newname, NULL);
668 free(newname); 752 upb_gfree(newname);
669 } 753 }
670 754
671 return newf; 755 return newf;
672 } 756 }
673 757
674 bool upb_fielddef_typeisset(const upb_fielddef *f) { 758 bool upb_fielddef_typeisset(const upb_fielddef *f) {
675 return f->type_is_set_; 759 return f->type_is_set_;
676 } 760 }
677 761
678 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) { 762 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) {
(...skipping 30 matching lines...) Expand all
709 } 793 }
710 794
711 bool upb_fielddef_packed(const upb_fielddef *f) { 795 bool upb_fielddef_packed(const upb_fielddef *f) {
712 return f->packed_; 796 return f->packed_;
713 } 797 }
714 798
715 const char *upb_fielddef_name(const upb_fielddef *f) { 799 const char *upb_fielddef_name(const upb_fielddef *f) {
716 return upb_def_fullname(upb_fielddef_upcast(f)); 800 return upb_def_fullname(upb_fielddef_upcast(f));
717 } 801 }
718 802
803 size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) {
804 const char *name = upb_fielddef_name(f);
805 size_t src, dst = 0;
806 bool ucase_next = false;
807
808 #define WRITE(byte) \
809 ++dst; \
810 if (dst < len) buf[dst - 1] = byte; \
811 else if (dst == len) buf[dst - 1] = '\0'
812
813 if (!name) {
814 WRITE('\0');
815 return 0;
816 }
817
818 /* Implement the transformation as described in the spec:
819 * 1. upper case all letters after an underscore.
820 * 2. remove all underscores.
821 */
822 for (src = 0; name[src]; src++) {
823 if (name[src] == '_') {
824 ucase_next = true;
825 continue;
826 }
827
828 if (ucase_next) {
829 WRITE(toupper(name[src]));
830 ucase_next = false;
831 } else {
832 WRITE(name[src]);
833 }
834 }
835
836 WRITE('\0');
837 return dst;
838
839 #undef WRITE
840 }
841
719 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { 842 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) {
720 return f->msg_is_symbolic ? NULL : f->msg.def; 843 return f->msg_is_symbolic ? NULL : f->msg.def;
721 } 844 }
722 845
723 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { 846 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) {
724 return f->oneof; 847 return f->oneof;
725 } 848 }
726 849
727 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) { 850 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) {
728 return (upb_msgdef*)upb_fielddef_containingtype(f); 851 return (upb_msgdef*)upb_fielddef_containingtype(f);
729 } 852 }
730 853
731 const char *upb_fielddef_containingtypename(upb_fielddef *f) { 854 const char *upb_fielddef_containingtypename(upb_fielddef *f) {
732 return f->msg_is_symbolic ? f->msg.name : NULL; 855 return f->msg_is_symbolic ? f->msg.name : NULL;
733 } 856 }
734 857
735 static void release_containingtype(upb_fielddef *f) { 858 static void release_containingtype(upb_fielddef *f) {
736 if (f->msg_is_symbolic) free(f->msg.name); 859 if (f->msg_is_symbolic) upb_gfree(f->msg.name);
737 } 860 }
738 861
739 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, 862 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name,
740 upb_status *s) { 863 upb_status *s) {
864 char *name_copy;
741 assert(!upb_fielddef_isfrozen(f)); 865 assert(!upb_fielddef_isfrozen(f));
742 if (upb_fielddef_containingtype(f)) { 866 if (upb_fielddef_containingtype(f)) {
743 upb_status_seterrmsg(s, "field has already been added to a message."); 867 upb_status_seterrmsg(s, "field has already been added to a message.");
744 return false; 868 return false;
745 } 869 }
746 /* TODO: validate name (upb_isident() doesn't quite work atm because this name 870 /* TODO: validate name (upb_isident() doesn't quite work atm because this name
747 * may have a leading "."). */ 871 * may have a leading "."). */
872
873 name_copy = upb_gstrdup(name);
874 if (!name_copy) {
875 upb_upberr_setoom(s);
876 return false;
877 }
878
748 release_containingtype(f); 879 release_containingtype(f);
749 f->msg.name = upb_strdup(name); 880 f->msg.name = name_copy;
750 f->msg_is_symbolic = true; 881 f->msg_is_symbolic = true;
751 return true; 882 return true;
752 } 883 }
753 884
754 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) { 885 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) {
755 if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) { 886 if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) {
756 upb_status_seterrmsg(s, "Already added to message or oneof"); 887 upb_status_seterrmsg(s, "Already added to message or oneof");
757 return false; 888 return false;
758 } 889 }
759 return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s); 890 return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s);
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 upb_status_seterrmsg(s, "invalid subdef type for this enum field"); 1271 upb_status_seterrmsg(s, "invalid subdef type for this enum field");
1141 return false; 1272 return false;
1142 } else { 1273 } else {
1143 upb_status_seterrmsg(s, "only message and enum fields can have a subdef"); 1274 upb_status_seterrmsg(s, "only message and enum fields can have a subdef");
1144 return false; 1275 return false;
1145 } 1276 }
1146 } 1277 }
1147 1278
1148 static void release_subdef(upb_fielddef *f) { 1279 static void release_subdef(upb_fielddef *f) {
1149 if (f->subdef_is_symbolic) { 1280 if (f->subdef_is_symbolic) {
1150 free(f->sub.name); 1281 upb_gfree(f->sub.name);
1151 } else if (f->sub.def) { 1282 } else if (f->sub.def) {
1152 upb_unref2(f->sub.def, f); 1283 upb_unref2(f->sub.def, f);
1153 } 1284 }
1154 } 1285 }
1155 1286
1156 bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef, 1287 bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef,
1157 upb_status *s) { 1288 upb_status *s) {
1158 assert(!upb_fielddef_isfrozen(f)); 1289 assert(!upb_fielddef_isfrozen(f));
1159 assert(upb_fielddef_hassubdef(f)); 1290 assert(upb_fielddef_hassubdef(f));
1160 if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false; 1291 if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false;
1161 release_subdef(f); 1292 release_subdef(f);
1162 f->sub.def = subdef; 1293 f->sub.def = subdef;
1163 f->subdef_is_symbolic = false; 1294 f->subdef_is_symbolic = false;
1164 if (f->sub.def) upb_ref2(f->sub.def, f); 1295 if (f->sub.def) upb_ref2(f->sub.def, f);
1165 return true; 1296 return true;
1166 } 1297 }
1167 1298
1168 bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef, 1299 bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef,
1169 upb_status *s) { 1300 upb_status *s) {
1170 return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s); 1301 return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s);
1171 } 1302 }
1172 1303
1173 bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef, 1304 bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef,
1174 upb_status *s) { 1305 upb_status *s) {
1175 return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s); 1306 return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s);
1176 } 1307 }
1177 1308
1178 bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name, 1309 bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name,
1179 upb_status *s) { 1310 upb_status *s) {
1311 char *name_copy;
1180 assert(!upb_fielddef_isfrozen(f)); 1312 assert(!upb_fielddef_isfrozen(f));
1181 if (!upb_fielddef_hassubdef(f)) { 1313 if (!upb_fielddef_hassubdef(f)) {
1182 upb_status_seterrmsg(s, "field type does not accept a subdef"); 1314 upb_status_seterrmsg(s, "field type does not accept a subdef");
1183 return false; 1315 return false;
1184 } 1316 }
1317
1318 name_copy = upb_gstrdup(name);
1319 if (!name_copy) {
1320 upb_upberr_setoom(s);
1321 return false;
1322 }
1323
1185 /* TODO: validate name (upb_isident() doesn't quite work atm because this name 1324 /* TODO: validate name (upb_isident() doesn't quite work atm because this name
1186 * may have a leading "."). */ 1325 * may have a leading "."). */
1187 release_subdef(f); 1326 release_subdef(f);
1188 f->sub.name = upb_strdup(name); 1327 f->sub.name = name_copy;
1189 f->subdef_is_symbolic = true; 1328 f->subdef_is_symbolic = true;
1190 return true; 1329 return true;
1191 } 1330 }
1192 1331
1193 bool upb_fielddef_issubmsg(const upb_fielddef *f) { 1332 bool upb_fielddef_issubmsg(const upb_fielddef *f) {
1194 return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; 1333 return upb_fielddef_type(f) == UPB_TYPE_MESSAGE;
1195 } 1334 }
1196 1335
1197 bool upb_fielddef_isstring(const upb_fielddef *f) { 1336 bool upb_fielddef_isstring(const upb_fielddef *f) {
1198 return upb_fielddef_type(f) == UPB_TYPE_STRING || 1337 return upb_fielddef_type(f) == UPB_TYPE_STRING ||
1199 upb_fielddef_type(f) == UPB_TYPE_BYTES; 1338 upb_fielddef_type(f) == UPB_TYPE_BYTES;
1200 } 1339 }
1201 1340
1202 bool upb_fielddef_isseq(const upb_fielddef *f) { 1341 bool upb_fielddef_isseq(const upb_fielddef *f) {
1203 return upb_fielddef_label(f) == UPB_LABEL_REPEATED; 1342 return upb_fielddef_label(f) == UPB_LABEL_REPEATED;
1204 } 1343 }
1205 1344
1206 bool upb_fielddef_isprimitive(const upb_fielddef *f) { 1345 bool upb_fielddef_isprimitive(const upb_fielddef *f) {
1207 return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f); 1346 return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f);
1208 } 1347 }
1209 1348
1210 bool upb_fielddef_ismap(const upb_fielddef *f) { 1349 bool upb_fielddef_ismap(const upb_fielddef *f) {
1211 return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) && 1350 return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) &&
1212 upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); 1351 upb_msgdef_mapentry(upb_fielddef_msgsubdef(f));
1213 } 1352 }
1214 1353
1354 bool upb_fielddef_haspresence(const upb_fielddef *f) {
1355 if (upb_fielddef_isseq(f)) return false;
1356 if (upb_fielddef_issubmsg(f)) return true;
1357
1358 /* Primitive field: return true unless there is a message that specifies
1359 * presence should not exist. */
1360 if (f->msg_is_symbolic || !f->msg.def) return true;
1361 return f->msg.def->syntax == UPB_SYNTAX_PROTO2;
1362 }
1363
1215 bool upb_fielddef_hassubdef(const upb_fielddef *f) { 1364 bool upb_fielddef_hassubdef(const upb_fielddef *f) {
1216 return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; 1365 return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM;
1217 } 1366 }
1218 1367
1219 static bool between(int32_t x, int32_t low, int32_t high) { 1368 static bool between(int32_t x, int32_t low, int32_t high) {
1220 return x >= low && x <= high; 1369 return x >= low && x <= high;
1221 } 1370 }
1222 1371
1223 bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); } 1372 bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); }
1224 bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); } 1373 bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); }
(...skipping 13 matching lines...) Expand all
1238 for(upb_msg_field_begin(&i, m); 1387 for(upb_msg_field_begin(&i, m);
1239 !upb_msg_field_done(&i); 1388 !upb_msg_field_done(&i);
1240 upb_msg_field_next(&i)) { 1389 upb_msg_field_next(&i)) {
1241 upb_fielddef *f = upb_msg_iter_field(&i); 1390 upb_fielddef *f = upb_msg_iter_field(&i);
1242 visit(r, upb_fielddef_upcast2(f), closure); 1391 visit(r, upb_fielddef_upcast2(f), closure);
1243 } 1392 }
1244 for(upb_msg_oneof_begin(&o, m); 1393 for(upb_msg_oneof_begin(&o, m);
1245 !upb_msg_oneof_done(&o); 1394 !upb_msg_oneof_done(&o);
1246 upb_msg_oneof_next(&o)) { 1395 upb_msg_oneof_next(&o)) {
1247 upb_oneofdef *f = upb_msg_iter_oneof(&o); 1396 upb_oneofdef *f = upb_msg_iter_oneof(&o);
1248 visit(r, upb_oneofdef_upcast2(f), closure); 1397 visit(r, upb_oneofdef_upcast(f), closure);
1249 } 1398 }
1250 } 1399 }
1251 1400
1252 static void freemsg(upb_refcounted *r) { 1401 static void freemsg(upb_refcounted *r) {
1253 upb_msgdef *m = (upb_msgdef*)r; 1402 upb_msgdef *m = (upb_msgdef*)r;
1254 upb_strtable_uninit(&m->ntoo);
1255 upb_strtable_uninit(&m->ntof); 1403 upb_strtable_uninit(&m->ntof);
1256 upb_inttable_uninit(&m->itof); 1404 upb_inttable_uninit(&m->itof);
1257 upb_def_uninit(upb_msgdef_upcast_mutable(m)); 1405 upb_def_uninit(upb_msgdef_upcast_mutable(m));
1258 free(m); 1406 upb_gfree(m);
1259 } 1407 }
1260 1408
1409 const struct upb_refcounted_vtbl upb_msgdef_vtbl = {visitmsg, freemsg};
1410
1261 upb_msgdef *upb_msgdef_new(const void *owner) { 1411 upb_msgdef *upb_msgdef_new(const void *owner) {
1262 static const struct upb_refcounted_vtbl vtbl = {visitmsg, freemsg}; 1412 upb_msgdef *m = upb_gmalloc(sizeof(*m));
1263 upb_msgdef *m = malloc(sizeof(*m));
1264 if (!m) return NULL; 1413 if (!m) return NULL;
1265 if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &vtbl, owner)) 1414
1415 if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &upb_msgdef_vtbl,
1416 owner)) {
1266 goto err2; 1417 goto err2;
1267 if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err3; 1418 }
1268 if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err2; 1419
1269 if (!upb_strtable_init(&m->ntoo, UPB_CTYPE_PTR)) goto err1; 1420 if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err2;
1421 if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err1;
1270 m->map_entry = false; 1422 m->map_entry = false;
1423 m->syntax = UPB_SYNTAX_PROTO2;
1271 return m; 1424 return m;
1272 1425
1273 err1: 1426 err1:
1274 upb_strtable_uninit(&m->ntof); 1427 upb_inttable_uninit(&m->itof);
1275 err2: 1428 err2:
1276 upb_inttable_uninit(&m->itof); 1429 upb_gfree(m);
1277 err3:
1278 free(m);
1279 return NULL; 1430 return NULL;
1280 } 1431 }
1281 1432
1282 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) { 1433 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) {
1283 bool ok; 1434 bool ok;
1284 upb_msg_field_iter i; 1435 upb_msg_field_iter i;
1285 upb_msg_oneof_iter o; 1436 upb_msg_oneof_iter o;
1286 1437
1287 upb_msgdef *newm = upb_msgdef_new(owner); 1438 upb_msgdef *newm = upb_msgdef_new(owner);
1288 if (!newm) return NULL; 1439 if (!newm) return NULL;
1289 ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm), 1440 ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm),
1290 upb_def_fullname(upb_msgdef_upcast(m)), 1441 upb_def_fullname(upb_msgdef_upcast(m)),
1291 NULL); 1442 NULL);
1292 newm->map_entry = m->map_entry; 1443 newm->map_entry = m->map_entry;
1444 newm->syntax = m->syntax;
1293 UPB_ASSERT_VAR(ok, ok); 1445 UPB_ASSERT_VAR(ok, ok);
1294 for(upb_msg_field_begin(&i, m); 1446 for(upb_msg_field_begin(&i, m);
1295 !upb_msg_field_done(&i); 1447 !upb_msg_field_done(&i);
1296 upb_msg_field_next(&i)) { 1448 upb_msg_field_next(&i)) {
1297 upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f); 1449 upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f);
1298 /* Fields in oneofs are dup'd below. */ 1450 /* Fields in oneofs are dup'd below. */
1299 if (upb_fielddef_containingoneof(f)) continue; 1451 if (upb_fielddef_containingoneof(f)) continue;
1300 if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) { 1452 if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) {
1301 upb_msgdef_unref(newm, owner); 1453 upb_msgdef_unref(newm, owner);
1302 return NULL; 1454 return NULL;
(...skipping 13 matching lines...) Expand all
1316 1468
1317 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) { 1469 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) {
1318 upb_def *d = upb_msgdef_upcast_mutable(m); 1470 upb_def *d = upb_msgdef_upcast_mutable(m);
1319 return upb_def_freeze(&d, 1, status); 1471 return upb_def_freeze(&d, 1, status);
1320 } 1472 }
1321 1473
1322 const char *upb_msgdef_fullname(const upb_msgdef *m) { 1474 const char *upb_msgdef_fullname(const upb_msgdef *m) {
1323 return upb_def_fullname(upb_msgdef_upcast(m)); 1475 return upb_def_fullname(upb_msgdef_upcast(m));
1324 } 1476 }
1325 1477
1478 const char *upb_msgdef_name(const upb_msgdef *m) {
1479 return upb_def_name(upb_msgdef_upcast(m));
1480 }
1481
1326 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, 1482 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname,
1327 upb_status *s) { 1483 upb_status *s) {
1328 return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s); 1484 return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s);
1329 } 1485 }
1330 1486
1487 bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax) {
1488 if (syntax != UPB_SYNTAX_PROTO2 && syntax != UPB_SYNTAX_PROTO3) {
1489 return false;
1490 }
1491
1492 m->syntax = syntax;
1493 return true;
1494 }
1495
1496 upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) {
1497 return m->syntax;
1498 }
1499
1331 /* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error 1500 /* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error
1332 * on status |s| and return false if not. */ 1501 * on status |s| and return false if not. */
1333 static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f, 1502 static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f,
1334 upb_status *s) { 1503 upb_status *s) {
1335 if (upb_fielddef_containingtype(f) != NULL) { 1504 if (upb_fielddef_containingtype(f) != NULL) {
1336 upb_status_seterrmsg(s, "fielddef already belongs to a message"); 1505 upb_status_seterrmsg(s, "fielddef already belongs to a message");
1337 return false; 1506 return false;
1338 } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { 1507 } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
1339 upb_status_seterrmsg(s, "field name or number were not set"); 1508 upb_status_seterrmsg(s, "field name or number were not set");
1340 return false; 1509 return false;
1341 } else if (upb_msgdef_ntofz(m, upb_fielddef_name(f)) || 1510 } else if (upb_msgdef_itof(m, upb_fielddef_number(f))) {
1342 upb_msgdef_itof(m, upb_fielddef_number(f))) { 1511 upb_status_seterrmsg(s, "duplicate field number");
1343 upb_status_seterrmsg(s, "duplicate field name or number for field"); 1512 return false;
1513 } else if (upb_strtable_lookup(&m->ntof, upb_fielddef_name(f), NULL)) {
1514 upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
1344 return false; 1515 return false;
1345 } 1516 }
1346 return true; 1517 return true;
1347 } 1518 }
1348 1519
1349 static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) { 1520 static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) {
1350 release_containingtype(f); 1521 release_containingtype(f);
1351 f->msg.def = m; 1522 f->msg.def = m;
1352 f->msg_is_symbolic = false; 1523 f->msg_is_symbolic = false;
1353 upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f)); 1524 upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1394 upb_status *s) { 1565 upb_status *s) {
1395 upb_oneof_iter it; 1566 upb_oneof_iter it;
1396 1567
1397 /* Check various conditions that would prevent this oneof from being added. */ 1568 /* Check various conditions that would prevent this oneof from being added. */
1398 if (upb_oneofdef_containingtype(o)) { 1569 if (upb_oneofdef_containingtype(o)) {
1399 upb_status_seterrmsg(s, "oneofdef already belongs to a message"); 1570 upb_status_seterrmsg(s, "oneofdef already belongs to a message");
1400 return false; 1571 return false;
1401 } else if (upb_oneofdef_name(o) == NULL) { 1572 } else if (upb_oneofdef_name(o) == NULL) {
1402 upb_status_seterrmsg(s, "oneofdef name was not set"); 1573 upb_status_seterrmsg(s, "oneofdef name was not set");
1403 return false; 1574 return false;
1404 } else if (upb_msgdef_ntooz(m, upb_oneofdef_name(o))) { 1575 } else if (upb_strtable_lookup(&m->ntof, upb_oneofdef_name(o), NULL)) {
1405 upb_status_seterrmsg(s, "duplicate oneof name"); 1576 upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
1406 return false; 1577 return false;
1407 } 1578 }
1408 1579
1409 /* Check that all of the oneof's fields do not conflict with names or numbers 1580 /* Check that all of the oneof's fields do not conflict with names or numbers
1410 * of fields already in the message. */ 1581 * of fields already in the message. */
1411 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { 1582 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) {
1412 const upb_fielddef *f = upb_oneof_iter_field(&it); 1583 const upb_fielddef *f = upb_oneof_iter_field(&it);
1413 if (!check_field_add(m, f, s)) { 1584 if (!check_field_add(m, f, s)) {
1414 return false; 1585 return false;
1415 } 1586 }
1416 } 1587 }
1417 1588
1418 /* Everything checks out -- commit now. */ 1589 /* Everything checks out -- commit now. */
1419 1590
1420 /* Add oneof itself first. */ 1591 /* Add oneof itself first. */
1421 o->parent = m; 1592 o->parent = m;
1422 upb_strtable_insert(&m->ntoo, upb_oneofdef_name(o), upb_value_ptr(o)); 1593 upb_strtable_insert(&m->ntof, upb_oneofdef_name(o), upb_value_ptr(o));
1423 upb_ref2(o, m); 1594 upb_ref2(o, m);
1424 upb_ref2(m, o); 1595 upb_ref2(m, o);
1425 1596
1426 /* Add each field of the oneof directly to the msgdef. */ 1597 /* Add each field of the oneof directly to the msgdef. */
1427 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { 1598 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) {
1428 upb_fielddef *f = upb_oneof_iter_field(&it); 1599 upb_fielddef *f = upb_oneof_iter_field(&it);
1429 add_field(m, f, NULL); 1600 add_field(m, f, NULL);
1430 } 1601 }
1431 1602
1432 if (ref_donor) upb_oneofdef_unref(o, ref_donor); 1603 if (ref_donor) upb_oneofdef_unref(o, ref_donor);
1433 1604
1434 return true; 1605 return true;
1435 } 1606 }
1436 1607
1437 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { 1608 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) {
1438 upb_value val; 1609 upb_value val;
1439 return upb_inttable_lookup32(&m->itof, i, &val) ? 1610 return upb_inttable_lookup32(&m->itof, i, &val) ?
1440 upb_value_getptr(val) : NULL; 1611 upb_value_getptr(val) : NULL;
1441 } 1612 }
1442 1613
1443 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, 1614 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name,
1444 size_t len) { 1615 size_t len) {
1445 upb_value val; 1616 upb_value val;
1446 return upb_strtable_lookup2(&m->ntof, name, len, &val) ? 1617
1447 upb_value_getptr(val) : NULL; 1618 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
1619 return NULL;
1620 }
1621
1622 return upb_trygetfield(upb_value_getptr(val));
1448 } 1623 }
1449 1624
1450 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, 1625 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name,
1451 size_t len) { 1626 size_t len) {
1452 upb_value val; 1627 upb_value val;
1453 return upb_strtable_lookup2(&m->ntoo, name, len, &val) ? 1628
1454 upb_value_getptr(val) : NULL; 1629 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
1630 return NULL;
1631 }
1632
1633 return upb_trygetoneof(upb_value_getptr(val));
1634 }
1635
1636 bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len,
1637 const upb_fielddef **f, const upb_oneofdef **o) {
1638 upb_value val;
1639
1640 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) {
1641 return false;
1642 }
1643
1644 *o = upb_trygetoneof(upb_value_getptr(val));
1645 *f = upb_trygetfield(upb_value_getptr(val));
1646 assert((*o != NULL) ^ (*f != NULL)); /* Exactly one of the two should be set. */
1647 return true;
1455 } 1648 }
1456 1649
1457 int upb_msgdef_numfields(const upb_msgdef *m) { 1650 int upb_msgdef_numfields(const upb_msgdef *m) {
1458 return upb_strtable_count(&m->ntof); 1651 /* The number table contains only fields. */
1652 return upb_inttable_count(&m->itof);
1459 } 1653 }
1460 1654
1461 int upb_msgdef_numoneofs(const upb_msgdef *m) { 1655 int upb_msgdef_numoneofs(const upb_msgdef *m) {
1462 return upb_strtable_count(&m->ntoo); 1656 /* The name table includes oneofs, and the number table does not. */
1657 return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof);
1463 } 1658 }
1464 1659
1465 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) { 1660 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) {
1466 assert(!upb_msgdef_isfrozen(m)); 1661 assert(!upb_msgdef_isfrozen(m));
1467 m->map_entry = map_entry; 1662 m->map_entry = map_entry;
1468 } 1663 }
1469 1664
1470 bool upb_msgdef_mapentry(const upb_msgdef *m) { 1665 bool upb_msgdef_mapentry(const upb_msgdef *m) {
1471 return m->map_entry; 1666 return m->map_entry;
1472 } 1667 }
(...skipping 10 matching lines...) Expand all
1483 1678
1484 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) { 1679 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) {
1485 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); 1680 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter));
1486 } 1681 }
1487 1682
1488 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) { 1683 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) {
1489 upb_inttable_iter_setdone(iter); 1684 upb_inttable_iter_setdone(iter);
1490 } 1685 }
1491 1686
1492 void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) { 1687 void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) {
1493 upb_strtable_begin(iter, &m->ntoo); 1688 upb_strtable_begin(iter, &m->ntof);
1689 /* We need to skip past any initial fields. */
1690 while (!upb_strtable_done(iter) &&
1691 !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter)))) {
1692 upb_strtable_next(iter);
1693 }
1494 } 1694 }
1495 1695
1496 void upb_msg_oneof_next(upb_msg_oneof_iter *iter) { upb_strtable_next(iter); } 1696 void upb_msg_oneof_next(upb_msg_oneof_iter *iter) {
1697 /* We need to skip past fields to return only oneofs. */
1698 do {
1699 upb_strtable_next(iter);
1700 } while (!upb_strtable_done(iter) &&
1701 !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter))));
1702 }
1497 1703
1498 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) { 1704 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) {
1499 return upb_strtable_done(iter); 1705 return upb_strtable_done(iter);
1500 } 1706 }
1501 1707
1502 upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) { 1708 upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) {
1503 return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter)); 1709 return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter));
1504 } 1710 }
1505 1711
1506 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) { 1712 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) {
(...skipping 12 matching lines...) Expand all
1519 } 1725 }
1520 if (o->parent) { 1726 if (o->parent) {
1521 visit(r, upb_msgdef_upcast2(o->parent), closure); 1727 visit(r, upb_msgdef_upcast2(o->parent), closure);
1522 } 1728 }
1523 } 1729 }
1524 1730
1525 static void freeoneof(upb_refcounted *r) { 1731 static void freeoneof(upb_refcounted *r) {
1526 upb_oneofdef *o = (upb_oneofdef*)r; 1732 upb_oneofdef *o = (upb_oneofdef*)r;
1527 upb_strtable_uninit(&o->ntof); 1733 upb_strtable_uninit(&o->ntof);
1528 upb_inttable_uninit(&o->itof); 1734 upb_inttable_uninit(&o->itof);
1529 upb_def_uninit(upb_oneofdef_upcast_mutable(o)); 1735 upb_gfree((void*)o->name);
1530 free(o); 1736 upb_gfree(o);
1531 } 1737 }
1532 1738
1739 const struct upb_refcounted_vtbl upb_oneofdef_vtbl = {visitoneof, freeoneof};
1740
1533 upb_oneofdef *upb_oneofdef_new(const void *owner) { 1741 upb_oneofdef *upb_oneofdef_new(const void *owner) {
1534 static const struct upb_refcounted_vtbl vtbl = {visitoneof, freeoneof}; 1742 upb_oneofdef *o = upb_gmalloc(sizeof(*o));
1535 upb_oneofdef *o = malloc(sizeof(*o)); 1743
1744 if (!o) {
1745 return NULL;
1746 }
1747
1536 o->parent = NULL; 1748 o->parent = NULL;
1537 if (!o) return NULL; 1749 o->name = NULL;
1538 if (!upb_def_init(upb_oneofdef_upcast_mutable(o), UPB_DEF_ONEOF, &vtbl, 1750
1539 owner)) 1751 if (!upb_refcounted_init(upb_oneofdef_upcast_mutable(o), &upb_oneofdef_vtbl,
1752 owner)) {
1540 goto err2; 1753 goto err2;
1754 }
1755
1541 if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2; 1756 if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2;
1542 if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1; 1757 if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1;
1758
1543 return o; 1759 return o;
1544 1760
1545 err1: 1761 err1:
1546 upb_inttable_uninit(&o->itof); 1762 upb_inttable_uninit(&o->itof);
1547 err2: 1763 err2:
1548 free(o); 1764 upb_gfree(o);
1549 return NULL; 1765 return NULL;
1550 } 1766 }
1551 1767
1552 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner) { 1768 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner) {
1553 bool ok; 1769 bool ok;
1554 upb_oneof_iter i; 1770 upb_oneof_iter i;
1555 upb_oneofdef *newo = upb_oneofdef_new(owner); 1771 upb_oneofdef *newo = upb_oneofdef_new(owner);
1556 if (!newo) return NULL; 1772 if (!newo) return NULL;
1557 ok = upb_def_setfullname(upb_oneofdef_upcast_mutable(newo), 1773 ok = upb_oneofdef_setname(newo, upb_oneofdef_name(o), NULL);
1558 upb_def_fullname(upb_oneofdef_upcast(o)), NULL);
1559 UPB_ASSERT_VAR(ok, ok); 1774 UPB_ASSERT_VAR(ok, ok);
1560 for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) { 1775 for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) {
1561 upb_fielddef *f = upb_fielddef_dup(upb_oneof_iter_field(&i), &f); 1776 upb_fielddef *f = upb_fielddef_dup(upb_oneof_iter_field(&i), &f);
1562 if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) { 1777 if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) {
1563 upb_oneofdef_unref(newo, owner); 1778 upb_oneofdef_unref(newo, owner);
1564 return NULL; 1779 return NULL;
1565 } 1780 }
1566 } 1781 }
1567 return newo; 1782 return newo;
1568 } 1783 }
1569 1784
1570 const char *upb_oneofdef_name(const upb_oneofdef *o) { 1785 const char *upb_oneofdef_name(const upb_oneofdef *o) { return o->name; }
1571 return upb_def_fullname(upb_oneofdef_upcast(o));
1572 }
1573 1786
1574 bool upb_oneofdef_setname(upb_oneofdef *o, const char *fullname, 1787 bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s) {
1575 upb_status *s) { 1788 assert(!upb_oneofdef_isfrozen(o));
1576 if (upb_oneofdef_containingtype(o)) { 1789 if (upb_oneofdef_containingtype(o)) {
1577 upb_status_seterrmsg(s, "oneof already added to a message"); 1790 upb_status_seterrmsg(s, "oneof already added to a message");
1578 return false; 1791 return false;
1579 } 1792 }
1580 return upb_def_setfullname(upb_oneofdef_upcast_mutable(o), fullname, s); 1793
1794 if (!upb_isident(name, strlen(name), true, s)) {
1795 return false;
1796 }
1797
1798 name = upb_gstrdup(name);
1799 if (!name) {
1800 upb_status_seterrmsg(s, "One of memory");
1801 return false;
1802 }
1803
1804 upb_gfree((void*)o->name);
1805 o->name = name;
1806 return true;
1581 } 1807 }
1582 1808
1583 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { 1809 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) {
1584 return o->parent; 1810 return o->parent;
1585 } 1811 }
1586 1812
1587 int upb_oneofdef_numfields(const upb_oneofdef *o) { 1813 int upb_oneofdef_numfields(const upb_oneofdef *o) {
1588 return upb_strtable_count(&o->ntof); 1814 return upb_strtable_count(&o->ntof);
1589 } 1815 }
1590 1816
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1689 } 1915 }
1690 1916
1691 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) { 1917 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) {
1692 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); 1918 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter));
1693 } 1919 }
1694 1920
1695 void upb_oneof_iter_setdone(upb_oneof_iter *iter) { 1921 void upb_oneof_iter_setdone(upb_oneof_iter *iter) {
1696 upb_inttable_iter_setdone(iter); 1922 upb_inttable_iter_setdone(iter);
1697 } 1923 }
1698 1924
1699 1925 /* upb_filedef ****************************************************************/
1700 #include <stdlib.h> 1926
1701 #include <stdio.h> 1927 static void visitfiledef(const upb_refcounted *r, upb_refcounted_visit *visit,
1702 #include <string.h> 1928 void *closure) {
1703 1929 const upb_filedef *f = (const upb_filedef*)r;
1704 typedef struct cleanup_ent { 1930 size_t i;
1705 upb_cleanup_func *cleanup; 1931
1706 void *ud; 1932 for(i = 0; i < upb_filedef_defcount(f); i++) {
1707 struct cleanup_ent *next; 1933 visit(r, upb_def_upcast(upb_filedef_def(f, i)), closure);
1708 } cleanup_ent; 1934 }
1709 1935 }
1710 static void *seeded_alloc(void *ud, void *ptr, size_t oldsize, size_t size); 1936
1711 1937 static void freefiledef(upb_refcounted *r) {
1712 /* Default allocator **********************************************************/ 1938 upb_filedef *f = (upb_filedef*)r;
1713 1939 size_t i;
1714 /* Just use realloc, keeping all allocated blocks in a linked list to destroy at 1940
1715 * the end. */ 1941 for(i = 0; i < upb_filedef_depcount(f); i++) {
1716 1942 upb_filedef_unref(upb_filedef_dep(f, i), f);
1717 typedef struct mem_block { 1943 }
1718 /* List is doubly-linked, because in cases where realloc() moves an existing 1944
1719 * block, we need to be able to remove the old pointer from the list 1945 upb_inttable_uninit(&f->defs);
1720 * efficiently. */ 1946 upb_inttable_uninit(&f->deps);
1721 struct mem_block *prev, *next; 1947 upb_gfree((void*)f->name);
1722 #ifndef NDEBUG 1948 upb_gfree((void*)f->package);
1723 size_t size; /* Doesn't include mem_block structure. */ 1949 upb_gfree(f);
1724 #endif 1950 }
1725 } mem_block; 1951
1726 1952 const struct upb_refcounted_vtbl upb_filedef_vtbl = {visitfiledef, freefiledef};
1727 typedef struct { 1953
1728 mem_block *head; 1954 upb_filedef *upb_filedef_new(const void *owner) {
1729 } default_alloc_ud; 1955 upb_filedef *f = upb_gmalloc(sizeof(*f));
1730 1956
1731 static void *default_alloc(void *_ud, void *ptr, size_t oldsize, size_t size) { 1957 if (!f) {
1732 default_alloc_ud *ud = _ud; 1958 return NULL;
1733 mem_block *from, *block; 1959 }
1734 void *ret; 1960
1735 UPB_UNUSED(oldsize); 1961 f->package = NULL;
1736 1962 f->name = NULL;
1737 from = ptr ? (void*)((char*)ptr - sizeof(mem_block)) : NULL; 1963 f->syntax = UPB_SYNTAX_PROTO2;
1738 1964
1739 #ifndef NDEBUG 1965 if (!upb_refcounted_init(upb_filedef_upcast_mutable(f), &upb_filedef_vtbl,
1740 if (from) { 1966 owner)) {
1741 assert(oldsize <= from->size); 1967 goto err;
1742 } 1968 }
1743 #endif 1969
1744 1970 if (!upb_inttable_init(&f->defs, UPB_CTYPE_CONSTPTR)) {
1745 /* TODO(haberman): we probably need to provide even better alignment here, 1971 goto err;
1746 * like 16-byte alignment of the returned data pointer. */ 1972 }
1747 block = realloc(from, size + sizeof(mem_block)); 1973
1748 if (!block) return NULL; 1974 if (!upb_inttable_init(&f->deps, UPB_CTYPE_CONSTPTR)) {
1749 ret = (char*)block + sizeof(*block); 1975 goto err2;
1750 1976 }
1751 #ifndef NDEBUG 1977
1752 block->size = size; 1978 return f;
1753 #endif 1979
1754 1980
1755 if (from) { 1981 err2:
1756 if (block != from) { 1982 upb_inttable_uninit(&f->defs);
1757 /* The block was moved, so pointers in next and prev blocks must be 1983
1758 * updated to its new location. */ 1984 err:
1759 if (block->next) block->next->prev = block; 1985 upb_gfree(f);
1760 if (block->prev) block->prev->next = block; 1986 return NULL;
1761 if (ud->head == from) ud->head = block; 1987 }
1988
1989 const char *upb_filedef_name(const upb_filedef *f) {
1990 return f->name;
1991 }
1992
1993 const char *upb_filedef_package(const upb_filedef *f) {
1994 return f->package;
1995 }
1996
1997 upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
1998 return f->syntax;
1999 }
2000
2001 size_t upb_filedef_defcount(const upb_filedef *f) {
2002 return upb_inttable_count(&f->defs);
2003 }
2004
2005 size_t upb_filedef_depcount(const upb_filedef *f) {
2006 return upb_inttable_count(&f->deps);
2007 }
2008
2009 const upb_def *upb_filedef_def(const upb_filedef *f, size_t i) {
2010 upb_value v;
2011
2012 if (upb_inttable_lookup32(&f->defs, i, &v)) {
2013 return upb_value_getconstptr(v);
2014 } else {
2015 return NULL;
2016 }
2017 }
2018
2019 const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) {
2020 upb_value v;
2021
2022 if (upb_inttable_lookup32(&f->deps, i, &v)) {
2023 return upb_value_getconstptr(v);
2024 } else {
2025 return NULL;
2026 }
2027 }
2028
2029 bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s) {
2030 name = upb_gstrdup(name);
2031 if (!name) {
2032 upb_upberr_setoom(s);
2033 return false;
2034 }
2035 upb_gfree((void*)f->name);
2036 f->name = name;
2037 return true;
2038 }
2039
2040 bool upb_filedef_setpackage(upb_filedef *f, const char *package,
2041 upb_status *s) {
2042 if (!upb_isident(package, strlen(package), true, s)) return false;
2043 package = upb_gstrdup(package);
2044 if (!package) {
2045 upb_upberr_setoom(s);
2046 return false;
2047 }
2048 upb_gfree((void*)f->package);
2049 f->package = package;
2050 return true;
2051 }
2052
2053 bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax,
2054 upb_status *s) {
2055 UPB_UNUSED(s);
2056 if (syntax != UPB_SYNTAX_PROTO2 &&
2057 syntax != UPB_SYNTAX_PROTO3) {
2058 upb_status_seterrmsg(s, "Unknown syntax value.");
2059 return false;
2060 }
2061 f->syntax = syntax;
2062
2063 {
2064 /* Set all messages in this file to match. */
2065 size_t i;
2066 for (i = 0; i < upb_filedef_defcount(f); i++) {
2067 /* Casting const away is safe since all defs in mutable filedef must
2068 * also be mutable. */
2069 upb_def *def = (upb_def*)upb_filedef_def(f, i);
2070
2071 upb_msgdef *m = upb_dyncast_msgdef_mutable(def);
2072 if (m) {
2073 m->syntax = syntax;
2074 }
1762 } 2075 }
1763 } else { 2076 }
1764 /* Insert at head of linked list. */
1765 block->prev = NULL;
1766 block->next = ud->head;
1767 if (block->next) block->next->prev = block;
1768 ud->head = block;
1769 }
1770
1771 return ret;
1772 }
1773
1774 static void default_alloc_cleanup(void *_ud) {
1775 default_alloc_ud *ud = _ud;
1776 mem_block *block = ud->head;
1777
1778 while (block) {
1779 void *to_free = block;
1780 block = block->next;
1781 free(to_free);
1782 }
1783 }
1784
1785
1786 /* Standard error functions ***************************************************/
1787
1788 static bool default_err(void *ud, const upb_status *status) {
1789 UPB_UNUSED(ud);
1790 UPB_UNUSED(status);
1791 return false;
1792 }
1793
1794 static bool write_err_to(void *ud, const upb_status *status) {
1795 upb_status *copy_to = ud;
1796 upb_status_copy(copy_to, status);
1797 return false;
1798 }
1799
1800
1801 /* upb_env ********************************************************************/
1802
1803 void upb_env_init(upb_env *e) {
1804 default_alloc_ud *ud = (default_alloc_ud*)&e->default_alloc_ud;
1805 e->ok_ = true;
1806 e->bytes_allocated = 0;
1807 e->cleanup_head = NULL;
1808
1809 ud->head = NULL;
1810
1811 /* Set default functions. */
1812 upb_env_setallocfunc(e, default_alloc, ud);
1813 upb_env_seterrorfunc(e, default_err, NULL);
1814 }
1815
1816 void upb_env_uninit(upb_env *e) {
1817 cleanup_ent *ent = e->cleanup_head;
1818
1819 while (ent) {
1820 ent->cleanup(ent->ud);
1821 ent = ent->next;
1822 }
1823
1824 /* Must do this after running cleanup functions, because this will delete
1825 the memory we store our cleanup entries in! */
1826 if (e->alloc == default_alloc) {
1827 default_alloc_cleanup(e->alloc_ud);
1828 }
1829 }
1830
1831 UPB_FORCEINLINE void upb_env_setallocfunc(upb_env *e, upb_alloc_func *alloc,
1832 void *ud) {
1833 e->alloc = alloc;
1834 e->alloc_ud = ud;
1835 }
1836
1837 UPB_FORCEINLINE void upb_env_seterrorfunc(upb_env *e, upb_error_func *func,
1838 void *ud) {
1839 e->err = func;
1840 e->err_ud = ud;
1841 }
1842
1843 void upb_env_reporterrorsto(upb_env *e, upb_status *status) {
1844 e->err = write_err_to;
1845 e->err_ud = status;
1846 }
1847
1848 bool upb_env_ok(const upb_env *e) {
1849 return e->ok_;
1850 }
1851
1852 bool upb_env_reporterror(upb_env *e, const upb_status *status) {
1853 e->ok_ = false;
1854 return e->err(e->err_ud, status);
1855 }
1856
1857 bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud) {
1858 cleanup_ent *ent = upb_env_malloc(e, sizeof(cleanup_ent));
1859 if (!ent) return false;
1860
1861 ent->cleanup = func;
1862 ent->ud = ud;
1863 ent->next = e->cleanup_head;
1864 e->cleanup_head = ent;
1865 2077
1866 return true; 2078 return true;
1867 } 2079 }
1868 2080
1869 void *upb_env_malloc(upb_env *e, size_t size) { 2081 bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor,
1870 e->bytes_allocated += size; 2082 upb_status *s) {
1871 if (e->alloc == seeded_alloc) { 2083 if (def->file) {
1872 /* This is equivalent to the next branch, but allows inlining for a 2084 upb_status_seterrmsg(s, "Def is already part of another filedef.");
1873 * measurable perf benefit. */ 2085 return false;
1874 return seeded_alloc(e->alloc_ud, NULL, 0, size); 2086 }
1875 } else { 2087
1876 return e->alloc(e->alloc_ud, NULL, 0, size); 2088 if (upb_inttable_push(&f->defs, upb_value_constptr(def))) {
1877 } 2089 def->file = f;
1878 } 2090 upb_ref2(def, f);
1879 2091 if (ref_donor) upb_def_unref(def, ref_donor);
1880 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) { 2092 if (def->type == UPB_DEF_MSG) {
1881 char *ret; 2093 upb_downcast_msgdef_mutable(def)->syntax = f->syntax;
1882 assert(oldsize <= size);
1883 ret = e->alloc(e->alloc_ud, ptr, oldsize, size);
1884
1885 #ifndef NDEBUG
1886 /* Overwrite non-preserved memory to ensure callers are passing the oldsize
1887 * that they truly require. */
1888 memset(ret + oldsize, 0xff, size - oldsize);
1889 #endif
1890
1891 return ret;
1892 }
1893
1894 size_t upb_env_bytesallocated(const upb_env *e) {
1895 return e->bytes_allocated;
1896 }
1897
1898
1899 /* upb_seededalloc ************************************************************/
1900
1901 /* Be conservative and choose 16 in case anyone is using SSE. */
1902 static const size_t maxalign = 16;
1903
1904 static size_t align_up(size_t size) {
1905 return ((size + maxalign - 1) / maxalign) * maxalign;
1906 }
1907
1908 UPB_FORCEINLINE static void *seeded_alloc(void *ud, void *ptr, size_t oldsize,
1909 size_t size) {
1910 upb_seededalloc *a = ud;
1911
1912 size = align_up(size);
1913
1914 assert(a->mem_limit >= a->mem_ptr);
1915
1916 if (oldsize == 0 && size <= (size_t)(a->mem_limit - a->mem_ptr)) {
1917 /* Fast path: we can satisfy from the initial allocation. */
1918 void *ret = a->mem_ptr;
1919 a->mem_ptr += size;
1920 return ret;
1921 } else {
1922 char *chptr = ptr;
1923 /* Slow path: fallback to other allocator. */
1924 a->need_cleanup = true;
1925 /* Is `ptr` part of the user-provided initial block? Don't pass it to the
1926 * default allocator if so; otherwise, it may try to realloc() the block. */
1927 if (chptr >= a->mem_base && chptr < a->mem_limit) {
1928 void *ret;
1929 assert(chptr + oldsize <= a->mem_limit);
1930 ret = a->alloc(a->alloc_ud, NULL, 0, size);
1931 if (ret) memcpy(ret, ptr, oldsize);
1932 return ret;
1933 } else {
1934 return a->alloc(a->alloc_ud, ptr, oldsize, size);
1935 } 2094 }
1936 } 2095 return true;
1937 } 2096 } else {
1938 2097 upb_upberr_setoom(s);
1939 void upb_seededalloc_init(upb_seededalloc *a, void *mem, size_t len) { 2098 return false;
1940 default_alloc_ud *ud = (default_alloc_ud*)&a->default_alloc_ud; 2099 }
1941 a->mem_base = mem; 2100 }
1942 a->mem_ptr = mem; 2101
1943 a->mem_limit = (char*)mem + len; 2102 bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep) {
1944 a->need_cleanup = false; 2103 if (upb_inttable_push(&f->deps, upb_value_constptr(dep))) {
1945 a->returned_allocfunc = false; 2104 /* Regular ref instead of ref2 because files can't form cycles. */
1946 2105 upb_filedef_ref(dep, f);
1947 ud->head = NULL; 2106 return true;
1948 2107 } else {
1949 upb_seededalloc_setfallbackalloc(a, default_alloc, ud); 2108 return false;
1950 } 2109 }
1951
1952 void upb_seededalloc_uninit(upb_seededalloc *a) {
1953 if (a->alloc == default_alloc && a->need_cleanup) {
1954 default_alloc_cleanup(a->alloc_ud);
1955 }
1956 }
1957
1958 UPB_FORCEINLINE void upb_seededalloc_setfallbackalloc(upb_seededalloc *a,
1959 upb_alloc_func *alloc,
1960 void *ud) {
1961 assert(!a->returned_allocfunc);
1962 a->alloc = alloc;
1963 a->alloc_ud = ud;
1964 }
1965
1966 upb_alloc_func *upb_seededalloc_getallocfunc(upb_seededalloc *a) {
1967 a->returned_allocfunc = true;
1968 return seeded_alloc;
1969 } 2110 }
1970 /* 2111 /*
1971 ** TODO(haberman): it's unclear whether a lot of the consistency checks should 2112 ** TODO(haberman): it's unclear whether a lot of the consistency checks should
1972 ** assert() or return false. 2113 ** assert() or return false.
1973 */ 2114 */
1974 2115
1975 2116
1976 #include <stdlib.h>
1977 #include <string.h> 2117 #include <string.h>
1978 2118
1979 2119
2120 static void *upb_calloc(size_t size) {
2121 void *mem = upb_gmalloc(size);
2122 if (mem) {
2123 memset(mem, 0, size);
2124 }
2125 return mem;
2126 }
1980 2127
1981 /* Defined for the sole purpose of having a unique pointer value for 2128 /* Defined for the sole purpose of having a unique pointer value for
1982 * UPB_NO_CLOSURE. */ 2129 * UPB_NO_CLOSURE. */
1983 char _upb_noclosure; 2130 char _upb_noclosure;
1984 2131
1985 static void freehandlers(upb_refcounted *r) { 2132 static void freehandlers(upb_refcounted *r) {
1986 upb_handlers *h = (upb_handlers*)r; 2133 upb_handlers *h = (upb_handlers*)r;
1987 2134
1988 upb_inttable_iter i; 2135 upb_inttable_iter i;
1989 upb_inttable_begin(&i, &h->cleanup_); 2136 upb_inttable_begin(&i, &h->cleanup_);
1990 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { 2137 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
1991 void *val = (void*)upb_inttable_iter_key(&i); 2138 void *val = (void*)upb_inttable_iter_key(&i);
1992 upb_value func_val = upb_inttable_iter_value(&i); 2139 upb_value func_val = upb_inttable_iter_value(&i);
1993 upb_handlerfree *func = upb_value_getfptr(func_val); 2140 upb_handlerfree *func = upb_value_getfptr(func_val);
1994 func(val); 2141 func(val);
1995 } 2142 }
1996 2143
1997 upb_inttable_uninit(&h->cleanup_); 2144 upb_inttable_uninit(&h->cleanup_);
1998 upb_msgdef_unref(h->msg, h); 2145 upb_msgdef_unref(h->msg, h);
1999 free(h->sub); 2146 upb_gfree(h->sub);
2000 free(h); 2147 upb_gfree(h);
2001 } 2148 }
2002 2149
2003 static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit, 2150 static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit,
2004 void *closure) { 2151 void *closure) {
2005 const upb_handlers *h = (const upb_handlers*)r; 2152 const upb_handlers *h = (const upb_handlers*)r;
2006 upb_msg_field_iter i; 2153 upb_msg_field_iter i;
2007 for(upb_msg_field_begin(&i, h->msg); 2154 for(upb_msg_field_begin(&i, h->msg);
2008 !upb_msg_field_done(&i); 2155 !upb_msg_field_done(&i);
2009 upb_msg_field_next(&i)) { 2156 upb_msg_field_next(&i)) {
2010 upb_fielddef *f = upb_msg_iter_field(&i); 2157 upb_fielddef *f = upb_msg_iter_field(&i);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2240 2387
2241 /* Public interface ***********************************************************/ 2388 /* Public interface ***********************************************************/
2242 2389
2243 upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) { 2390 upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) {
2244 int extra; 2391 int extra;
2245 upb_handlers *h; 2392 upb_handlers *h;
2246 2393
2247 assert(upb_msgdef_isfrozen(md)); 2394 assert(upb_msgdef_isfrozen(md));
2248 2395
2249 extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1); 2396 extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1);
2250 h = calloc(sizeof(*h) + extra, 1); 2397 h = upb_calloc(sizeof(*h) + extra);
2251 if (!h) return NULL; 2398 if (!h) return NULL;
2252 2399
2253 h->msg = md; 2400 h->msg = md;
2254 upb_msgdef_ref(h->msg, h); 2401 upb_msgdef_ref(h->msg, h);
2255 upb_status_clear(&h->status_); 2402 upb_status_clear(&h->status_);
2256 h->sub = calloc(md->submsg_field_count, sizeof(*h->sub)); 2403
2257 if (!h->sub) goto oom; 2404 if (md->submsg_field_count > 0) {
2405 h->sub = upb_calloc(md->submsg_field_count * sizeof(*h->sub));
2406 if (!h->sub) goto oom;
2407 } else {
2408 h->sub = 0;
2409 }
2410
2258 if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner)) 2411 if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner))
2259 goto oom; 2412 goto oom;
2260 if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom; 2413 if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom;
2261 2414
2262 /* calloc() above initialized all handlers to NULL. */ 2415 /* calloc() above initialized all handlers to NULL. */
2263 return h; 2416 return h;
2264 2417
2265 oom: 2418 oom:
2266 freehandlers(upb_handlers_upcast_mutable(h)); 2419 freehandlers(upb_handlers_upcast_mutable(h));
2267 return NULL; 2420 return NULL;
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2662 ** 3. for mutable objects "from" and "to", if there exists a ref2(to, from) 2815 ** 3. for mutable objects "from" and "to", if there exists a ref2(to, from)
2663 ** this implies group(from) == group(to). (In practice, what we implement 2816 ** this implies group(from) == group(to). (In practice, what we implement
2664 ** is even stronger; "from" and "to" will share a group if there has *ever* 2817 ** is even stronger; "from" and "to" will share a group if there has *ever*
2665 ** been a ref2(to, from), but all that is necessary for correctness is the 2818 ** been a ref2(to, from), but all that is necessary for correctness is the
2666 ** weaker one). 2819 ** weaker one).
2667 ** 4. mutable and immutable objects are never in the same group. 2820 ** 4. mutable and immutable objects are never in the same group.
2668 */ 2821 */
2669 2822
2670 2823
2671 #include <setjmp.h> 2824 #include <setjmp.h>
2672 #include <stdlib.h>
2673 2825
2674 static void freeobj(upb_refcounted *o); 2826 static void freeobj(upb_refcounted *o);
2675 2827
2676 const char untracked_val; 2828 const char untracked_val;
2677 const void *UPB_UNTRACKED_REF = &untracked_val; 2829 const void *UPB_UNTRACKED_REF = &untracked_val;
2678 2830
2679 /* arch-specific atomic primitives *******************************************/ 2831 /* arch-specific atomic primitives *******************************************/
2680 2832
2681 #ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/ 2833 #ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/
2682 2834
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2738 /* User must define functions that lock/unlock a global mutex and link this 2890 /* User must define functions that lock/unlock a global mutex and link this
2739 * file against them. */ 2891 * file against them. */
2740 void upb_lock(); 2892 void upb_lock();
2741 void upb_unlock(); 2893 void upb_unlock();
2742 2894
2743 #endif 2895 #endif
2744 2896
2745 /* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some 2897 /* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some
2746 * code-paths that can normally never fail, like upb_refcounted_ref(). Since 2898 * code-paths that can normally never fail, like upb_refcounted_ref(). Since
2747 * we have no way to propagage out-of-memory errors back to the user, and since 2899 * we have no way to propagage out-of-memory errors back to the user, and since
2748 * these errors can only occur in UPB_DEBUG_REFS mode, we immediately fail. */ 2900 * these errors can only occur in UPB_DEBUG_REFS mode, we use an allocator that
2749 #define CHECK_OOM(predicate) if (!(predicate)) { assert(predicate); exit(1); } 2901 * immediately aborts on failure (avoiding the global allocator, which might
2902 * inject failures). */
2903
2904 #include <stdlib.h>
2905
2906 static void *upb_debugrefs_allocfunc(upb_alloc *alloc, void *ptr,
2907 size_t oldsize, size_t size) {
2908 UPB_UNUSED(alloc);
2909 UPB_UNUSED(oldsize);
2910 if (size == 0) {
2911 free(ptr);
2912 return NULL;
2913 } else {
2914 void *ret = realloc(ptr, size);
2915
2916 if (!ret) {
2917 abort();
2918 }
2919
2920 return ret;
2921 }
2922 }
2923
2924 upb_alloc upb_alloc_debugrefs = {&upb_debugrefs_allocfunc};
2750 2925
2751 typedef struct { 2926 typedef struct {
2752 int count; /* How many refs there are (duplicates only allowed for ref2). */ 2927 int count; /* How many refs there are (duplicates only allowed for ref2). */
2753 bool is_ref2; 2928 bool is_ref2;
2754 } trackedref; 2929 } trackedref;
2755 2930
2756 static trackedref *trackedref_new(bool is_ref2) { 2931 static trackedref *trackedref_new(bool is_ref2) {
2757 trackedref *ret = malloc(sizeof(*ret)); 2932 trackedref *ret = upb_malloc(&upb_alloc_debugrefs, sizeof(*ret));
2758 CHECK_OOM(ret);
2759 ret->count = 1; 2933 ret->count = 1;
2760 ret->is_ref2 = is_ref2; 2934 ret->is_ref2 = is_ref2;
2761 return ret; 2935 return ret;
2762 } 2936 }
2763 2937
2764 static void track(const upb_refcounted *r, const void *owner, bool ref2) { 2938 static void track(const upb_refcounted *r, const void *owner, bool ref2) {
2765 upb_value v; 2939 upb_value v;
2766 2940
2767 assert(owner); 2941 assert(owner);
2768 if (owner == UPB_UNTRACKED_REF) return; 2942 if (owner == UPB_UNTRACKED_REF) return;
2769 2943
2770 upb_lock(); 2944 upb_lock();
2771 if (upb_inttable_lookupptr(r->refs, owner, &v)) { 2945 if (upb_inttable_lookupptr(r->refs, owner, &v)) {
2772 trackedref *ref = upb_value_getptr(v); 2946 trackedref *ref = upb_value_getptr(v);
2773 /* Since we allow multiple ref2's for the same to/from pair without 2947 /* Since we allow multiple ref2's for the same to/from pair without
2774 * allocating separate memory for each one, we lose the fine-grained 2948 * allocating separate memory for each one, we lose the fine-grained
2775 * tracking behavior we get with regular refs. Since ref2s only happen 2949 * tracking behavior we get with regular refs. Since ref2s only happen
2776 * inside upb, we'll accept this limitation until/unless there is a really 2950 * inside upb, we'll accept this limitation until/unless there is a really
2777 * difficult upb-internal bug that can't be figured out without it. */ 2951 * difficult upb-internal bug that can't be figured out without it. */
2778 assert(ref2); 2952 assert(ref2);
2779 assert(ref->is_ref2); 2953 assert(ref->is_ref2);
2780 ref->count++; 2954 ref->count++;
2781 } else { 2955 } else {
2782 trackedref *ref = trackedref_new(ref2); 2956 trackedref *ref = trackedref_new(ref2);
2783 bool ok = upb_inttable_insertptr(r->refs, owner, upb_value_ptr(ref)); 2957 upb_inttable_insertptr2(r->refs, owner, upb_value_ptr(ref),
2784 CHECK_OOM(ok); 2958 &upb_alloc_debugrefs);
2785 if (ref2) { 2959 if (ref2) {
2786 /* We know this cast is safe when it is a ref2, because it's coming from 2960 /* We know this cast is safe when it is a ref2, because it's coming from
2787 * another refcounted object. */ 2961 * another refcounted object. */
2788 const upb_refcounted *from = owner; 2962 const upb_refcounted *from = owner;
2789 assert(!upb_inttable_lookupptr(from->ref2s, r, NULL)); 2963 assert(!upb_inttable_lookupptr(from->ref2s, r, NULL));
2790 ok = upb_inttable_insertptr(from->ref2s, r, upb_value_ptr(NULL)); 2964 upb_inttable_insertptr2(from->ref2s, r, upb_value_ptr(NULL),
2791 CHECK_OOM(ok); 2965 &upb_alloc_debugrefs);
2792 } 2966 }
2793 } 2967 }
2794 upb_unlock(); 2968 upb_unlock();
2795 } 2969 }
2796 2970
2797 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { 2971 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) {
2798 upb_value v; 2972 upb_value v;
2799 bool found; 2973 bool found;
2800 trackedref *ref; 2974 trackedref *ref;
2801 2975
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 * originate from the given owner. */ 3013 * originate from the given owner. */
2840 static void getref2s(const upb_refcounted *owner, upb_inttable *tab) { 3014 static void getref2s(const upb_refcounted *owner, upb_inttable *tab) {
2841 upb_inttable_iter i; 3015 upb_inttable_iter i;
2842 3016
2843 upb_lock(); 3017 upb_lock();
2844 upb_inttable_begin(&i, owner->ref2s); 3018 upb_inttable_begin(&i, owner->ref2s);
2845 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { 3019 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
2846 upb_value v; 3020 upb_value v;
2847 upb_value count; 3021 upb_value count;
2848 trackedref *ref; 3022 trackedref *ref;
2849 bool ok;
2850 bool found; 3023 bool found;
2851 3024
2852 upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i); 3025 upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i);
2853 3026
2854 /* To get the count we need to look in the target's table. */ 3027 /* To get the count we need to look in the target's table. */
2855 found = upb_inttable_lookupptr(to->refs, owner, &v); 3028 found = upb_inttable_lookupptr(to->refs, owner, &v);
2856 assert(found); 3029 assert(found);
2857 ref = upb_value_getptr(v); 3030 ref = upb_value_getptr(v);
2858 count = upb_value_int32(ref->count); 3031 count = upb_value_int32(ref->count);
2859 3032
2860 ok = upb_inttable_insertptr(tab, to, count); 3033 upb_inttable_insertptr2(tab, to, count, &upb_alloc_debugrefs);
2861 CHECK_OOM(ok);
2862 } 3034 }
2863 upb_unlock(); 3035 upb_unlock();
2864 } 3036 }
2865 3037
2866 typedef struct { 3038 typedef struct {
2867 upb_inttable ref2; 3039 upb_inttable ref2;
2868 const upb_refcounted *obj; 3040 const upb_refcounted *obj;
2869 } check_state; 3041 } check_state;
2870 3042
2871 static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj, 3043 static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj,
2872 void *closure) { 3044 void *closure) {
2873 check_state *s = closure; 3045 check_state *s = closure;
2874 upb_inttable *ref2 = &s->ref2; 3046 upb_inttable *ref2 = &s->ref2;
2875 upb_value v; 3047 upb_value v;
2876 bool removed; 3048 bool removed;
2877 int32_t newcount; 3049 int32_t newcount;
2878 3050
2879 assert(obj == s->obj); 3051 assert(obj == s->obj);
2880 assert(subobj); 3052 assert(subobj);
2881 removed = upb_inttable_removeptr(ref2, subobj, &v); 3053 removed = upb_inttable_removeptr(ref2, subobj, &v);
2882 /* The following assertion will fail if the visit() function visits a subobj 3054 /* The following assertion will fail if the visit() function visits a subobj
2883 * that it did not have a ref2 on, or visits the same subobj too many times. * / 3055 * that it did not have a ref2 on, or visits the same subobj too many times. * /
2884 assert(removed); 3056 assert(removed);
2885 newcount = upb_value_getint32(v) - 1; 3057 newcount = upb_value_getint32(v) - 1;
2886 if (newcount > 0) { 3058 if (newcount > 0) {
2887 upb_inttable_insert(ref2, (uintptr_t)subobj, upb_value_int32(newcount)); 3059 upb_inttable_insert2(ref2, (uintptr_t)subobj, upb_value_int32(newcount),
3060 &upb_alloc_debugrefs);
2888 } 3061 }
2889 } 3062 }
2890 3063
2891 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, 3064 static void visit(const upb_refcounted *r, upb_refcounted_visit *v,
2892 void *closure) { 3065 void *closure) {
2893 bool ok;
2894
2895 /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know 3066 /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know
2896 * exactly the set of nodes that visit() should visit. So we verify visit()'s 3067 * exactly the set of nodes that visit() should visit. So we verify visit()'s
2897 * correctness here. */ 3068 * correctness here. */
2898 check_state state; 3069 check_state state;
2899 state.obj = r; 3070 state.obj = r;
2900 ok = upb_inttable_init(&state.ref2, UPB_CTYPE_INT32); 3071 upb_inttable_init2(&state.ref2, UPB_CTYPE_INT32, &upb_alloc_debugrefs);
2901 CHECK_OOM(ok);
2902 getref2s(r, &state.ref2); 3072 getref2s(r, &state.ref2);
2903 3073
2904 /* This should visit any children in the ref2 table. */ 3074 /* This should visit any children in the ref2 table. */
2905 if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state); 3075 if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state);
2906 3076
2907 /* This assertion will fail if the visit() function missed any children. */ 3077 /* This assertion will fail if the visit() function missed any children. */
2908 assert(upb_inttable_count(&state.ref2) == 0); 3078 assert(upb_inttable_count(&state.ref2) == 0);
2909 upb_inttable_uninit(&state.ref2); 3079 upb_inttable_uninit2(&state.ref2, &upb_alloc_debugrefs);
2910 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); 3080 if (r->vtbl->visit) r->vtbl->visit(r, v, closure);
2911 } 3081 }
2912 3082
2913 static bool trackinit(upb_refcounted *r) { 3083 static void trackinit(upb_refcounted *r) {
2914 r->refs = malloc(sizeof(*r->refs)); 3084 r->refs = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->refs));
2915 r->ref2s = malloc(sizeof(*r->ref2s)); 3085 r->ref2s = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->ref2s));
2916 if (!r->refs || !r->ref2s) goto err1; 3086 upb_inttable_init2(r->refs, UPB_CTYPE_PTR, &upb_alloc_debugrefs);
2917 3087 upb_inttable_init2(r->ref2s, UPB_CTYPE_PTR, &upb_alloc_debugrefs);
2918 if (!upb_inttable_init(r->refs, UPB_CTYPE_PTR)) goto err1;
2919 if (!upb_inttable_init(r->ref2s, UPB_CTYPE_PTR)) goto err2;
2920 return true;
2921
2922 err2:
2923 upb_inttable_uninit(r->refs);
2924 err1:
2925 free(r->refs);
2926 free(r->ref2s);
2927 return false;
2928 } 3088 }
2929 3089
2930 static void trackfree(const upb_refcounted *r) { 3090 static void trackfree(const upb_refcounted *r) {
2931 upb_inttable_uninit(r->refs); 3091 upb_inttable_uninit2(r->refs, &upb_alloc_debugrefs);
2932 upb_inttable_uninit(r->ref2s); 3092 upb_inttable_uninit2(r->ref2s, &upb_alloc_debugrefs);
2933 free(r->refs); 3093 upb_free(&upb_alloc_debugrefs, r->refs);
2934 free(r->ref2s); 3094 upb_free(&upb_alloc_debugrefs, r->ref2s);
2935 } 3095 }
2936 3096
2937 #else 3097 #else
2938 3098
2939 static void track(const upb_refcounted *r, const void *owner, bool ref2) { 3099 static void track(const upb_refcounted *r, const void *owner, bool ref2) {
2940 UPB_UNUSED(r); 3100 UPB_UNUSED(r);
2941 UPB_UNUSED(owner); 3101 UPB_UNUSED(owner);
2942 UPB_UNUSED(ref2); 3102 UPB_UNUSED(ref2);
2943 } 3103 }
2944 3104
2945 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { 3105 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) {
2946 UPB_UNUSED(r); 3106 UPB_UNUSED(r);
2947 UPB_UNUSED(owner); 3107 UPB_UNUSED(owner);
2948 UPB_UNUSED(ref2); 3108 UPB_UNUSED(ref2);
2949 } 3109 }
2950 3110
2951 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { 3111 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) {
2952 UPB_UNUSED(r); 3112 UPB_UNUSED(r);
2953 UPB_UNUSED(owner); 3113 UPB_UNUSED(owner);
2954 UPB_UNUSED(ref2); 3114 UPB_UNUSED(ref2);
2955 } 3115 }
2956 3116
2957 static bool trackinit(upb_refcounted *r) { 3117 static void trackinit(upb_refcounted *r) {
2958 UPB_UNUSED(r); 3118 UPB_UNUSED(r);
2959 return true;
2960 } 3119 }
2961 3120
2962 static void trackfree(const upb_refcounted *r) { 3121 static void trackfree(const upb_refcounted *r) {
2963 UPB_UNUSED(r); 3122 UPB_UNUSED(r);
2964 } 3123 }
2965 3124
2966 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, 3125 static void visit(const upb_refcounted *r, upb_refcounted_visit *v,
2967 void *closure) { 3126 void *closure) {
2968 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); 3127 if (r->vtbl->visit) r->vtbl->visit(r, v, closure);
2969 } 3128 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
3059 static upb_refcounted *pop(tarjan *t) { 3218 static upb_refcounted *pop(tarjan *t) {
3060 upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack)); 3219 upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack));
3061 assert(color(t, r) == GREEN); 3220 assert(color(t, r) == GREEN);
3062 /* This defines the attr layout for nodes in the WHITE state. 3221 /* This defines the attr layout for nodes in the WHITE state.
3063 * Top of group stack is [group, NULL]; we point at group. */ 3222 * Top of group stack is [group, NULL]; we point at group. */
3064 setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8); 3223 setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8);
3065 return r; 3224 return r;
3066 } 3225 }
3067 3226
3068 static void tarjan_newgroup(tarjan *t) { 3227 static void tarjan_newgroup(tarjan *t) {
3069 uint32_t *group = malloc(sizeof(*group)); 3228 uint32_t *group = upb_gmalloc(sizeof(*group));
3070 if (!group) oom(t); 3229 if (!group) oom(t);
3071 /* Push group and empty group leader (we'll fill in leader later). */ 3230 /* Push group and empty group leader (we'll fill in leader later). */
3072 if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) || 3231 if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) ||
3073 !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) { 3232 !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) {
3074 free(group); 3233 upb_gfree(group);
3075 oom(t); 3234 oom(t);
3076 } 3235 }
3077 *group = 0; 3236 *group = 0;
3078 } 3237 }
3079 3238
3080 static uint32_t idx(tarjan *t, const upb_refcounted *r) { 3239 static uint32_t idx(tarjan *t, const upb_refcounted *r) {
3081 assert(color(t, r) == GREEN); 3240 assert(color(t, r) == GREEN);
3082 return (getattr(t, r) >> 2) & 0x7FFFFFFF; 3241 return (getattr(t, r) >> 2) & 0x7FFFFFFF;
3083 } 3242 }
3084 3243
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 * while() loop we guarantee ourselves the chance to remove each node. * / 3398 * while() loop we guarantee ourselves the chance to remove each node. * /
3240 while (color(&t, obj->next) == WHITE && 3399 while (color(&t, obj->next) == WHITE &&
3241 group(&t, obj->next) != obj->next->group) { 3400 group(&t, obj->next) != obj->next->group) {
3242 upb_refcounted *leader; 3401 upb_refcounted *leader;
3243 3402
3244 /* Remove from old group. */ 3403 /* Remove from old group. */
3245 upb_refcounted *move = obj->next; 3404 upb_refcounted *move = obj->next;
3246 if (obj == move) { 3405 if (obj == move) {
3247 /* Removing the last object from a group. */ 3406 /* Removing the last object from a group. */
3248 assert(*obj->group == obj->individual_count); 3407 assert(*obj->group == obj->individual_count);
3249 free(obj->group); 3408 upb_gfree(obj->group);
3250 } else { 3409 } else {
3251 obj->next = move->next; 3410 obj->next = move->next;
3252 /* This may decrease to zero; we'll collect GRAY objects (if any) that 3411 /* This may decrease to zero; we'll collect GRAY objects (if any) that
3253 * remain in the group in the third pass. */ 3412 * remain in the group in the third pass. */
3254 assert(*move->group >= move->individual_count); 3413 assert(*move->group >= move->individual_count);
3255 *move->group -= move->individual_count; 3414 *move->group -= move->individual_count;
3256 } 3415 }
3257 3416
3258 /* Add to new group. */ 3417 /* Add to new group. */
3259 leader = groupleader(&t, move); 3418 leader = groupleader(&t, move);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3295 upb_inttable_begin(&iter, &t.objattr); 3454 upb_inttable_begin(&iter, &t.objattr);
3296 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) { 3455 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) {
3297 upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter); 3456 upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter);
3298 if (obj->group == NULL || *obj->group == 0) { 3457 if (obj->group == NULL || *obj->group == 0) {
3299 if (obj->group) { 3458 if (obj->group) {
3300 upb_refcounted *o; 3459 upb_refcounted *o;
3301 3460
3302 /* We eagerly free() the group's count (since we can't easily determine 3461 /* We eagerly free() the group's count (since we can't easily determine
3303 * the group's remaining size it's the easiest way to ensure it gets 3462 * the group's remaining size it's the easiest way to ensure it gets
3304 * done). */ 3463 * done). */
3305 free(obj->group); 3464 upb_gfree(obj->group);
3306 3465
3307 /* Visit to release ref2's (done in a separate pass since release_ref2 3466 /* Visit to release ref2's (done in a separate pass since release_ref2
3308 * depends on o->group being unmodified so it can test merged()). */ 3467 * depends on o->group being unmodified so it can test merged()). */
3309 o = obj; 3468 o = obj;
3310 do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj); 3469 do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj);
3311 3470
3312 /* Mark "group" fields as NULL so we know to free the objects later in 3471 /* Mark "group" fields as NULL so we know to free the objects later in
3313 * this loop, but also don't try to delete the group twice. */ 3472 * this loop, but also don't try to delete the group twice. */
3314 o = obj; 3473 o = obj;
3315 do { o->group = NULL; } while ((o = o->next) != obj); 3474 do { o->group = NULL; } while ((o = o->next) != obj);
3316 } 3475 }
3317 freeobj(obj); 3476 freeobj(obj);
3318 } 3477 }
3319 } 3478 }
3320 3479
3321 err4: 3480 err4:
3322 if (!ret) { 3481 if (!ret) {
3323 upb_inttable_begin(&iter, &t.groups); 3482 upb_inttable_begin(&iter, &t.groups);
3324 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) 3483 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter))
3325 free(upb_value_getptr(upb_inttable_iter_value(&iter))); 3484 upb_gfree(upb_value_getptr(upb_inttable_iter_value(&iter)));
3326 } 3485 }
3327 upb_inttable_uninit(&t.groups); 3486 upb_inttable_uninit(&t.groups);
3328 err3: 3487 err3:
3329 upb_inttable_uninit(&t.stack); 3488 upb_inttable_uninit(&t.stack);
3330 err2: 3489 err2:
3331 upb_inttable_uninit(&t.objattr); 3490 upb_inttable_uninit(&t.objattr);
3332 err1: 3491 err1:
3333 return ret; 3492 return ret;
3334 } 3493 }
3335 3494
3336 3495
3337 /* Misc internal functions ***************************************************/ 3496 /* Misc internal functions ***************************************************/
3338 3497
3339 static bool merged(const upb_refcounted *r, const upb_refcounted *r2) { 3498 static bool merged(const upb_refcounted *r, const upb_refcounted *r2) {
3340 return r->group == r2->group; 3499 return r->group == r2->group;
3341 } 3500 }
3342 3501
3343 static void merge(upb_refcounted *r, upb_refcounted *from) { 3502 static void merge(upb_refcounted *r, upb_refcounted *from) {
3344 upb_refcounted *base; 3503 upb_refcounted *base;
3345 upb_refcounted *tmp; 3504 upb_refcounted *tmp;
3346 3505
3347 if (merged(r, from)) return; 3506 if (merged(r, from)) return;
3348 *r->group += *from->group; 3507 *r->group += *from->group;
3349 free(from->group); 3508 upb_gfree(from->group);
3350 base = from; 3509 base = from;
3351 3510
3352 /* Set all refcount pointers in the "from" chain to the merged refcount. 3511 /* Set all refcount pointers in the "from" chain to the merged refcount.
3353 * 3512 *
3354 * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound 3513 * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound
3355 * if the user continuously extends a group by one object. Prevent this by 3514 * if the user continuously extends a group by one object. Prevent this by
3356 * using one of the techniques in this paper: 3515 * using one of the techniques in this paper:
3357 * ftp://www.ncedc.org/outgoing/geomorph/dino/orals/p245-tarjan.pdf */ 3516 * ftp://www.ncedc.org/outgoing/geomorph/dino/orals/p245-tarjan.pdf */
3358 do { from->group = r->group; } while ((from = from->next) != base); 3517 do { from->group = r->group; } while ((from = from->next) != base);
3359 3518
(...skipping 13 matching lines...) Expand all
3373 if (!merged(obj, subobj)) { 3532 if (!merged(obj, subobj)) {
3374 assert(subobj->is_frozen); 3533 assert(subobj->is_frozen);
3375 unref(subobj); 3534 unref(subobj);
3376 } 3535 }
3377 } 3536 }
3378 3537
3379 static void unref(const upb_refcounted *r) { 3538 static void unref(const upb_refcounted *r) {
3380 if (unrefgroup(r->group)) { 3539 if (unrefgroup(r->group)) {
3381 const upb_refcounted *o; 3540 const upb_refcounted *o;
3382 3541
3383 free(r->group); 3542 upb_gfree(r->group);
3384 3543
3385 /* In two passes, since release_ref2 needs a guarantee that any subobjs 3544 /* In two passes, since release_ref2 needs a guarantee that any subobjs
3386 * are alive. */ 3545 * are alive. */
3387 o = r; 3546 o = r;
3388 do { visit(o, release_ref2, NULL); } while((o = o->next) != r); 3547 do { visit(o, release_ref2, NULL); } while((o = o->next) != r);
3389 3548
3390 o = r; 3549 o = r;
3391 do { 3550 do {
3392 const upb_refcounted *next = o->next; 3551 const upb_refcounted *next = o->next;
3393 assert(o->is_frozen || o->individual_count == 0); 3552 assert(o->is_frozen || o->individual_count == 0);
(...skipping 23 matching lines...) Expand all
3417 assert(*(char*)&x != 1); 3576 assert(*(char*)&x != 1);
3418 #else 3577 #else
3419 assert(*(char*)&x == 1); 3578 assert(*(char*)&x == 1);
3420 #endif 3579 #endif
3421 #endif 3580 #endif
3422 3581
3423 r->next = r; 3582 r->next = r;
3424 r->vtbl = vtbl; 3583 r->vtbl = vtbl;
3425 r->individual_count = 0; 3584 r->individual_count = 0;
3426 r->is_frozen = false; 3585 r->is_frozen = false;
3427 r->group = malloc(sizeof(*r->group)); 3586 r->group = upb_gmalloc(sizeof(*r->group));
3428 if (!r->group) return false; 3587 if (!r->group) return false;
3429 *r->group = 0; 3588 *r->group = 0;
3430 if (!trackinit(r)) { 3589 trackinit(r);
3431 free(r->group);
3432 return false;
3433 }
3434 upb_refcounted_ref(r, owner); 3590 upb_refcounted_ref(r, owner);
3435 return true; 3591 return true;
3436 } 3592 }
3437 3593
3438 bool upb_refcounted_isfrozen(const upb_refcounted *r) { 3594 bool upb_refcounted_isfrozen(const upb_refcounted *r) {
3439 return r->is_frozen; 3595 return r->is_frozen;
3440 } 3596 }
3441 3597
3442 void upb_refcounted_ref(const upb_refcounted *r, const void *owner) { 3598 void upb_refcounted_ref(const upb_refcounted *r, const void *owner) {
3443 track(r, owner, false); 3599 track(r, owner, false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3482 upb_refcounted_unref(r, from); 3638 upb_refcounted_unref(r, from);
3483 } 3639 }
3484 3640
3485 void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) { 3641 void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) {
3486 checkref(r, owner, false); 3642 checkref(r, owner, false);
3487 } 3643 }
3488 3644
3489 bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s, 3645 bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s,
3490 int maxdepth) { 3646 int maxdepth) {
3491 int i; 3647 int i;
3648 bool ret;
3492 for (i = 0; i < n; i++) { 3649 for (i = 0; i < n; i++) {
3493 assert(!roots[i]->is_frozen); 3650 assert(!roots[i]->is_frozen);
3494 } 3651 }
3495 return freeze(roots, n, s, maxdepth); 3652 ret = freeze(roots, n, s, maxdepth);
3653 assert(!s || ret == upb_ok(s));
3654 return ret;
3496 } 3655 }
3497 3656
3498 3657
3499 #include <stdlib.h>
3500
3501 /* Fallback implementation if the shim is not specialized by the JIT. */ 3658 /* Fallback implementation if the shim is not specialized by the JIT. */
3502 #define SHIM_WRITER(type, ctype) \ 3659 #define SHIM_WRITER(type, ctype) \
3503 bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \ 3660 bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \
3504 uint8_t *m = c; \ 3661 uint8_t *m = c; \
3505 const upb_shim_data *d = hd; \ 3662 const upb_shim_data *d = hd; \
3506 if (d->hasbit > 0) \ 3663 if (d->hasbit > 0) \
3507 *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ 3664 *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \
3508 *(ctype*)&m[d->offset] = val; \ 3665 *(ctype*)&m[d->offset] = val; \
3509 return true; \ 3666 return true; \
3510 } \ 3667 } \
3511 3668
3512 SHIM_WRITER(double, double) 3669 SHIM_WRITER(double, double)
3513 SHIM_WRITER(float, float) 3670 SHIM_WRITER(float, float)
3514 SHIM_WRITER(int32, int32_t) 3671 SHIM_WRITER(int32, int32_t)
3515 SHIM_WRITER(int64, int64_t) 3672 SHIM_WRITER(int64, int64_t)
3516 SHIM_WRITER(uint32, uint32_t) 3673 SHIM_WRITER(uint32, uint32_t)
3517 SHIM_WRITER(uint64, uint64_t) 3674 SHIM_WRITER(uint64, uint64_t)
3518 SHIM_WRITER(bool, bool) 3675 SHIM_WRITER(bool, bool)
3519 #undef SHIM_WRITER 3676 #undef SHIM_WRITER
3520 3677
3521 bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, 3678 bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset,
3522 int32_t hasbit) { 3679 int32_t hasbit) {
3523 upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; 3680 upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
3524 bool ok; 3681 bool ok;
3525 3682
3526 upb_shim_data *d = malloc(sizeof(*d)); 3683 upb_shim_data *d = upb_gmalloc(sizeof(*d));
3527 if (!d) return false; 3684 if (!d) return false;
3528 d->offset = offset; 3685 d->offset = offset;
3529 d->hasbit = hasbit; 3686 d->hasbit = hasbit;
3530 3687
3531 upb_handlerattr_sethandlerdata(&attr, d); 3688 upb_handlerattr_sethandlerdata(&attr, d);
3532 upb_handlerattr_setalwaysok(&attr, true); 3689 upb_handlerattr_setalwaysok(&attr, true);
3533 upb_handlers_addcleanup(h, d, free); 3690 upb_handlers_addcleanup(h, d, upb_gfree);
3534 3691
3535 #define TYPE(u, l) \ 3692 #define TYPE(u, l) \
3536 case UPB_TYPE_##u: \ 3693 case UPB_TYPE_##u: \
3537 ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break; 3694 ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break;
3538 3695
3539 ok = false; 3696 ok = false;
3540 3697
3541 switch (upb_fielddef_type(f)) { 3698 switch (upb_fielddef_type(f)) {
3542 TYPE(INT64, int64); 3699 TYPE(INT64, int64);
3543 TYPE(INT32, int32); 3700 TYPE(INT32, int32);
(...skipping 30 matching lines...) Expand all
3574 } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) { 3731 } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) {
3575 *type = UPB_TYPE_BOOL; 3732 *type = UPB_TYPE_BOOL;
3576 } else { 3733 } else {
3577 return NULL; 3734 return NULL;
3578 } 3735 }
3579 3736
3580 return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s); 3737 return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s);
3581 } 3738 }
3582 3739
3583 3740
3584 #include <stdlib.h>
3585 #include <string.h> 3741 #include <string.h>
3586 3742
3587 static void upb_symtab_free(upb_refcounted *r) { 3743 static void upb_symtab_free(upb_refcounted *r) {
3588 upb_symtab *s = (upb_symtab*)r; 3744 upb_symtab *s = (upb_symtab*)r;
3589 upb_strtable_iter i; 3745 upb_strtable_iter i;
3590 upb_strtable_begin(&i, &s->symtab); 3746 upb_strtable_begin(&i, &s->symtab);
3591 for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { 3747 for (; !upb_strtable_done(&i); upb_strtable_next(&i)) {
3592 const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i)); 3748 const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i));
3593 upb_def_unref(def, s); 3749 upb_def_unref(def, s);
3594 } 3750 }
3595 upb_strtable_uninit(&s->symtab); 3751 upb_strtable_uninit(&s->symtab);
3596 free(s); 3752 upb_gfree(s);
3597 } 3753 }
3598 3754
3599
3600 upb_symtab *upb_symtab_new(const void *owner) { 3755 upb_symtab *upb_symtab_new(const void *owner) {
3601 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free}; 3756 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free};
3602 upb_symtab *s = malloc(sizeof(*s)); 3757
3758 upb_symtab *s = upb_gmalloc(sizeof(*s));
3759 if (!s) {
3760 return NULL;
3761 }
3762
3603 upb_refcounted_init(upb_symtab_upcast_mutable(s), &vtbl, owner); 3763 upb_refcounted_init(upb_symtab_upcast_mutable(s), &vtbl, owner);
3604 upb_strtable_init(&s->symtab, UPB_CTYPE_PTR); 3764 upb_strtable_init(&s->symtab, UPB_CTYPE_PTR);
3605 return s; 3765 return s;
3606 } 3766 }
3607 3767
3608 void upb_symtab_freeze(upb_symtab *s) { 3768 void upb_symtab_freeze(upb_symtab *s) {
3609 upb_refcounted *r; 3769 upb_refcounted *r;
3610 bool ok; 3770 bool ok;
3611 3771
3612 assert(!upb_symtab_isfrozen(s)); 3772 assert(!upb_symtab_isfrozen(s));
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
3766 upb_inttable_insertptr(seen, memoize_key, upb_value_bool(need_dup)); 3926 upb_inttable_insertptr(seen, memoize_key, upb_value_bool(need_dup));
3767 return need_dup; 3927 return need_dup;
3768 3928
3769 oom: 3929 oom:
3770 upb_status_seterrmsg(s, "out of memory"); 3930 upb_status_seterrmsg(s, "out of memory");
3771 return false; 3931 return false;
3772 } 3932 }
3773 3933
3774 /* TODO(haberman): we need a lot more testing of error conditions. 3934 /* TODO(haberman): we need a lot more testing of error conditions.
3775 * The came_from_user stuff in particular is not tested. */ 3935 * The came_from_user stuff in particular is not tested. */
3776 bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, int n, void *ref_donor, 3936 static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
3777 upb_status *status) { 3937 void *ref_donor, upb_refcounted *freeze_also,
3778 int i; 3938 upb_status *status) {
3939 size_t i;
3940 size_t add_n;
3941 size_t freeze_n;
3779 upb_strtable_iter iter; 3942 upb_strtable_iter iter;
3943 upb_refcounted **add_objs = NULL;
3780 upb_def **add_defs = NULL; 3944 upb_def **add_defs = NULL;
3945 size_t add_objs_size;
3781 upb_strtable addtab; 3946 upb_strtable addtab;
3782 upb_inttable seen; 3947 upb_inttable seen;
3783 3948
3949 if (n == 0 && !freeze_also) {
3950 return true;
3951 }
3952
3784 assert(!upb_symtab_isfrozen(s)); 3953 assert(!upb_symtab_isfrozen(s));
3785 if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) { 3954 if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) {
3786 upb_status_seterrmsg(status, "out of memory"); 3955 upb_status_seterrmsg(status, "out of memory");
3787 return false; 3956 return false;
3788 } 3957 }
3789 3958
3790 /* Add new defs to our "add" set. */ 3959 /* Add new defs to our "add" set. */
3791 for (i = 0; i < n; i++) { 3960 for (i = 0; i < n; i++) {
3792 upb_def *def = defs[i]; 3961 upb_def *def = defs[i];
3793 const char *fullname; 3962 const char *fullname;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3915 upb_status_seterrf( 4084 upb_status_seterrf(
3916 status, "couldn't resolve name '%s' in message '%s'", name, base); 4085 status, "couldn't resolve name '%s' in message '%s'", name, base);
3917 goto err; 4086 goto err;
3918 } else if (!upb_fielddef_setsubdef(f, subdef, status)) { 4087 } else if (!upb_fielddef_setsubdef(f, subdef, status)) {
3919 goto err; 4088 goto err;
3920 } 4089 }
3921 } 4090 }
3922 } 4091 }
3923 } 4092 }
3924 4093
3925 /* We need an array of the defs in addtab, for passing to upb_def_freeze. */ 4094 /* We need an array of the defs in addtab, for passing to
3926 add_defs = malloc(sizeof(void*) * upb_strtable_count(&addtab)); 4095 * upb_refcounted_freeze(). */
4096 add_objs_size = upb_strtable_count(&addtab);
4097 if (freeze_also) {
4098 add_objs_size++;
4099 }
4100
4101 add_defs = upb_gmalloc(sizeof(void*) * add_objs_size);
3927 if (add_defs == NULL) goto oom_err; 4102 if (add_defs == NULL) goto oom_err;
3928 upb_strtable_begin(&iter, &addtab); 4103 upb_strtable_begin(&iter, &addtab);
3929 for (n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { 4104 for (add_n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
3930 add_defs[n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); 4105 add_defs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter));
3931 } 4106 }
3932 4107
3933 if (!upb_def_freeze(add_defs, n, status)) goto err; 4108 /* Validate defs. */
4109 if (!_upb_def_validate(add_defs, add_n, status)) {
4110 goto err;
4111 }
4112
4113 /* Cheat a little and give the array a new type.
4114 * This is probably undefined behavior, but this code will be deleted soon. */
4115 add_objs = (upb_refcounted**)add_defs;
4116
4117 freeze_n = add_n;
4118 if (freeze_also) {
4119 add_objs[freeze_n++] = freeze_also;
4120 }
4121
4122 if (!upb_refcounted_freeze(add_objs, freeze_n, status,
4123 UPB_MAX_MESSAGE_DEPTH * 2)) {
4124 goto err;
4125 }
3934 4126
3935 /* This must be delayed until all errors have been detected, since error 4127 /* This must be delayed until all errors have been detected, since error
3936 * recovery code uses this table to cleanup defs. */ 4128 * recovery code uses this table to cleanup defs. */
3937 upb_strtable_uninit(&addtab); 4129 upb_strtable_uninit(&addtab);
3938 4130
3939 /* TODO(haberman) we don't properly handle errors after this point (like 4131 /* TODO(haberman) we don't properly handle errors after this point (like
3940 * OOM in upb_strtable_insert() below). */ 4132 * OOM in upb_strtable_insert() below). */
3941 for (i = 0; i < n; i++) { 4133 for (i = 0; i < add_n; i++) {
3942 upb_def *def = add_defs[i]; 4134 upb_def *def = (upb_def*)add_objs[i];
3943 const char *name = upb_def_fullname(def); 4135 const char *name = upb_def_fullname(def);
3944 upb_value v; 4136 upb_value v;
3945 bool success; 4137 bool success;
3946 4138
3947 if (upb_strtable_remove(&s->symtab, name, &v)) { 4139 if (upb_strtable_remove(&s->symtab, name, &v)) {
3948 const upb_def *def = upb_value_getptr(v); 4140 const upb_def *def = upb_value_getptr(v);
3949 upb_def_unref(def, s); 4141 upb_def_unref(def, s);
3950 } 4142 }
3951 success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def)); 4143 success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def));
3952 UPB_ASSERT_VAR(success, success == true); 4144 UPB_ASSERT_VAR(success, success == true);
3953 } 4145 }
3954 free(add_defs); 4146 upb_gfree(add_defs);
3955 return true; 4147 return true;
3956 4148
3957 oom_err: 4149 oom_err:
3958 upb_status_seterrmsg(status, "out of memory"); 4150 upb_status_seterrmsg(status, "out of memory");
3959 err: { 4151 err: {
3960 /* For defs the user passed in, we need to donate the refs back. For defs 4152 /* For defs the user passed in, we need to donate the refs back. For defs
3961 * we dup'd, we need to just unref them. */ 4153 * we dup'd, we need to just unref them. */
3962 upb_strtable_begin(&iter, &addtab); 4154 upb_strtable_begin(&iter, &addtab);
3963 for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { 4155 for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
3964 upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter)); 4156 upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter));
3965 bool came_from_user = def->came_from_user; 4157 bool came_from_user = def->came_from_user;
3966 def->came_from_user = false; 4158 def->came_from_user = false;
3967 if (came_from_user) { 4159 if (came_from_user) {
3968 upb_def_donateref(def, s, ref_donor); 4160 upb_def_donateref(def, s, ref_donor);
3969 } else { 4161 } else {
3970 upb_def_unref(def, s); 4162 upb_def_unref(def, s);
3971 } 4163 }
3972 } 4164 }
3973 } 4165 }
3974 upb_strtable_uninit(&addtab); 4166 upb_strtable_uninit(&addtab);
3975 free(add_defs); 4167 upb_gfree(add_defs);
3976 assert(!upb_ok(status)); 4168 assert(!upb_ok(status));
3977 return false; 4169 return false;
3978 } 4170 }
3979 4171
4172 bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n,
4173 void *ref_donor, upb_status *status) {
4174 return symtab_add(s, defs, n, ref_donor, NULL, status);
4175 }
4176
4177 bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) {
4178 size_t n;
4179 size_t i;
4180 upb_def **defs;
4181 bool ret;
4182
4183 n = upb_filedef_defcount(file);
4184 defs = upb_gmalloc(sizeof(*defs) * n);
4185
4186 if (defs == NULL) {
4187 upb_status_seterrmsg(status, "Out of memory");
4188 return false;
4189 }
4190
4191 for (i = 0; i < n; i++) {
4192 defs[i] = upb_filedef_mutabledef(file, i);
4193 }
4194
4195 ret = symtab_add(s, defs, n, NULL, upb_filedef_upcast_mutable(file), status);
4196
4197 upb_gfree(defs);
4198 return ret;
4199 }
4200
3980 /* Iteration. */ 4201 /* Iteration. */
3981 4202
3982 static void advance_to_matching(upb_symtab_iter *iter) { 4203 static void advance_to_matching(upb_symtab_iter *iter) {
3983 if (iter->type == UPB_DEF_ANY) 4204 if (iter->type == UPB_DEF_ANY)
3984 return; 4205 return;
3985 4206
3986 while (!upb_strtable_done(&iter->iter) && 4207 while (!upb_strtable_done(&iter->iter) &&
3987 iter->type != upb_symtab_iter_def(iter)->type) { 4208 iter->type != upb_symtab_iter_def(iter)->type) {
3988 upb_strtable_next(&iter->iter); 4209 upb_strtable_next(&iter->iter);
3989 } 4210 }
(...skipping 18 matching lines...) Expand all
4008 const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) { 4229 const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) {
4009 return upb_value_getptr(upb_strtable_iter_value(&iter->iter)); 4230 return upb_value_getptr(upb_strtable_iter_value(&iter->iter));
4010 } 4231 }
4011 /* 4232 /*
4012 ** upb_table Implementation 4233 ** upb_table Implementation
4013 ** 4234 **
4014 ** Implementation is heavily inspired by Lua's ltable.c. 4235 ** Implementation is heavily inspired by Lua's ltable.c.
4015 */ 4236 */
4016 4237
4017 4238
4018 #include <stdlib.h>
4019 #include <string.h> 4239 #include <string.h>
4020 4240
4021 #define UPB_MAXARRSIZE 16 /* 64k. */ 4241 #define UPB_MAXARRSIZE 16 /* 64k. */
4022 4242
4023 /* From Chromium. */ 4243 /* From Chromium. */
4024 #define ARRAY_SIZE(x) \ 4244 #define ARRAY_SIZE(x) \
4025 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) 4245 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
4026 4246
4247 #ifdef NDEBUG
4248 static void upb_check_alloc(upb_table *t, upb_alloc *a) {
4249 UPB_UNUSED(t);
4250 UPB_UNUSED(a);
4251 }
4252 #else
4253 static void upb_check_alloc(upb_table *t, upb_alloc *a) {
4254 assert(t->alloc == a);
4255 }
4256 #endif
4257
4027 static const double MAX_LOAD = 0.85; 4258 static const double MAX_LOAD = 0.85;
4028 4259
4029 /* The minimum utilization of the array part of a mixed hash/array table. This 4260 /* The minimum utilization of the array part of a mixed hash/array table. This
4030 * is a speed/memory-usage tradeoff (though it's not straightforward because of 4261 * is a speed/memory-usage tradeoff (though it's not straightforward because of
4031 * cache effects). The lower this is, the more memory we'll use. */ 4262 * cache effects). The lower this is, the more memory we'll use. */
4032 static const double MIN_DENSITY = 0.1; 4263 static const double MIN_DENSITY = 0.1;
4033 4264
4034 bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } 4265 bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; }
4035 4266
4036 int log2ceil(uint64_t v) { 4267 int log2ceil(uint64_t v) {
4037 int ret = 0; 4268 int ret = 0;
4038 bool pow2 = is_pow2(v); 4269 bool pow2 = is_pow2(v);
4039 while (v >>= 1) ret++; 4270 while (v >>= 1) ret++;
4040 ret = pow2 ? ret : ret + 1; /* Ceiling. */ 4271 ret = pow2 ? ret : ret + 1; /* Ceiling. */
4041 return UPB_MIN(UPB_MAXARRSIZE, ret); 4272 return UPB_MIN(UPB_MAXARRSIZE, ret);
4042 } 4273 }
4043 4274
4044 char *upb_strdup(const char *s) { 4275 char *upb_strdup(const char *s, upb_alloc *a) {
4045 return upb_strdup2(s, strlen(s)); 4276 return upb_strdup2(s, strlen(s), a);
4046 } 4277 }
4047 4278
4048 char *upb_strdup2(const char *s, size_t len) { 4279 char *upb_strdup2(const char *s, size_t len, upb_alloc *a) {
4049 size_t n; 4280 size_t n;
4050 char *p; 4281 char *p;
4051 4282
4052 /* Prevent overflow errors. */ 4283 /* Prevent overflow errors. */
4053 if (len == SIZE_MAX) return NULL; 4284 if (len == SIZE_MAX) return NULL;
4054 /* Always null-terminate, even if binary data; but don't rely on the input to 4285 /* Always null-terminate, even if binary data; but don't rely on the input to
4055 * have a null-terminating byte since it may be a raw binary buffer. */ 4286 * have a null-terminating byte since it may be a raw binary buffer. */
4056 n = len + 1; 4287 n = len + 1;
4057 p = malloc(n); 4288 p = upb_malloc(a, n);
4058 if (p) { 4289 if (p) {
4059 memcpy(p, s, len); 4290 memcpy(p, s, len);
4060 p[len] = 0; 4291 p[len] = 0;
4061 } 4292 }
4062 return p; 4293 return p;
4063 } 4294 }
4064 4295
4065 /* A type to represent the lookup key of either a strtable or an inttable. */ 4296 /* A type to represent the lookup key of either a strtable or an inttable. */
4066 typedef union { 4297 typedef union {
4067 uintptr_t num; 4298 uintptr_t num;
(...skipping 20 matching lines...) Expand all
4088 typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); 4319 typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2);
4089 4320
4090 /* Base table (shared code) ***************************************************/ 4321 /* Base table (shared code) ***************************************************/
4091 4322
4092 /* For when we need to cast away const. */ 4323 /* For when we need to cast away const. */
4093 static upb_tabent *mutable_entries(upb_table *t) { 4324 static upb_tabent *mutable_entries(upb_table *t) {
4094 return (upb_tabent*)t->entries; 4325 return (upb_tabent*)t->entries;
4095 } 4326 }
4096 4327
4097 static bool isfull(upb_table *t) { 4328 static bool isfull(upb_table *t) {
4098 return (double)(t->count + 1) / upb_table_size(t) > MAX_LOAD; 4329 if (upb_table_size(t) == 0) {
4330 return true;
4331 } else {
4332 return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD;
4333 }
4099 } 4334 }
4100 4335
4101 static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2) { 4336 static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2,
4337 upb_alloc *a) {
4102 size_t bytes; 4338 size_t bytes;
4103 4339
4104 t->count = 0; 4340 t->count = 0;
4105 t->ctype = ctype; 4341 t->ctype = ctype;
4106 t->size_lg2 = size_lg2; 4342 t->size_lg2 = size_lg2;
4107 t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; 4343 t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0;
4344 #ifndef NDEBUG
4345 t->alloc = a;
4346 #endif
4108 bytes = upb_table_size(t) * sizeof(upb_tabent); 4347 bytes = upb_table_size(t) * sizeof(upb_tabent);
4109 if (bytes > 0) { 4348 if (bytes > 0) {
4110 t->entries = malloc(bytes); 4349 t->entries = upb_malloc(a, bytes);
4111 if (!t->entries) return false; 4350 if (!t->entries) return false;
4112 memset(mutable_entries(t), 0, bytes); 4351 memset(mutable_entries(t), 0, bytes);
4113 } else { 4352 } else {
4114 t->entries = NULL; 4353 t->entries = NULL;
4115 } 4354 }
4116 return true; 4355 return true;
4117 } 4356 }
4118 4357
4119 static void uninit(upb_table *t) { free(mutable_entries(t)); } 4358 static void uninit(upb_table *t, upb_alloc *a) {
4359 upb_check_alloc(t, a);
4360 upb_free(a, mutable_entries(t));
4361 }
4120 4362
4121 static upb_tabent *emptyent(upb_table *t) { 4363 static upb_tabent *emptyent(upb_table *t) {
4122 upb_tabent *e = mutable_entries(t) + upb_table_size(t); 4364 upb_tabent *e = mutable_entries(t) + upb_table_size(t);
4123 while (1) { if (upb_tabent_isempty(--e)) return e; assert(e > t->entries); } 4365 while (1) { if (upb_tabent_isempty(--e)) return e; assert(e > t->entries); }
4124 } 4366 }
4125 4367
4126 static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) { 4368 static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) {
4127 return (upb_tabent*)upb_getentry(t, hash); 4369 return (upb_tabent*)upb_getentry(t, hash);
4128 } 4370 }
4129 4371
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4262 4504
4263 static size_t begin(const upb_table *t) { 4505 static size_t begin(const upb_table *t) {
4264 return next(t, -1); 4506 return next(t, -1);
4265 } 4507 }
4266 4508
4267 4509
4268 /* upb_strtable ***************************************************************/ 4510 /* upb_strtable ***************************************************************/
4269 4511
4270 /* A simple "subclass" of upb_table that only adds a hash function for strings. */ 4512 /* A simple "subclass" of upb_table that only adds a hash function for strings. */
4271 4513
4272 static upb_tabkey strcopy(lookupkey_t k2) { 4514 static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) {
4273 char *str = malloc(k2.str.len + sizeof(uint32_t) + 1); 4515 char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1);
4274 if (str == NULL) return 0; 4516 if (str == NULL) return 0;
4275 memcpy(str, &k2.str.len, sizeof(uint32_t)); 4517 memcpy(str, &k2.str.len, sizeof(uint32_t));
4276 memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); 4518 memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1);
4277 return (uintptr_t)str; 4519 return (uintptr_t)str;
4278 } 4520 }
4279 4521
4280 static uint32_t strhash(upb_tabkey key) { 4522 static uint32_t strhash(upb_tabkey key) {
4281 uint32_t len; 4523 uint32_t len;
4282 char *str = upb_tabstr(key, &len); 4524 char *str = upb_tabstr(key, &len);
4283 return MurmurHash2(str, len, 0); 4525 return MurmurHash2(str, len, 0);
4284 } 4526 }
4285 4527
4286 static bool streql(upb_tabkey k1, lookupkey_t k2) { 4528 static bool streql(upb_tabkey k1, lookupkey_t k2) {
4287 uint32_t len; 4529 uint32_t len;
4288 char *str = upb_tabstr(k1, &len); 4530 char *str = upb_tabstr(k1, &len);
4289 return len == k2.str.len && memcmp(str, k2.str.str, len) == 0; 4531 return len == k2.str.len && memcmp(str, k2.str.str, len) == 0;
4290 } 4532 }
4291 4533
4292 bool upb_strtable_init(upb_strtable *t, upb_ctype_t ctype) { 4534 bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) {
4293 return init(&t->t, ctype, 2); 4535 return init(&t->t, ctype, 2, a);
4294 } 4536 }
4295 4537
4296 void upb_strtable_uninit(upb_strtable *t) { 4538 void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) {
4297 size_t i; 4539 size_t i;
4298 for (i = 0; i < upb_table_size(&t->t); i++) 4540 for (i = 0; i < upb_table_size(&t->t); i++)
4299 free((void*)t->t.entries[i].key); 4541 upb_free(a, (void*)t->t.entries[i].key);
4300 uninit(&t->t); 4542 uninit(&t->t, a);
4301 } 4543 }
4302 4544
4303 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2) { 4545 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) {
4304 upb_strtable new_table; 4546 upb_strtable new_table;
4305 upb_strtable_iter i; 4547 upb_strtable_iter i;
4306 4548
4307 if (!init(&new_table.t, t->t.ctype, size_lg2)) 4549 upb_check_alloc(&t->t, a);
4550
4551 if (!init(&new_table.t, t->t.ctype, size_lg2, a))
4308 return false; 4552 return false;
4309 upb_strtable_begin(&i, t); 4553 upb_strtable_begin(&i, t);
4310 for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { 4554 for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) {
4311 upb_strtable_insert2( 4555 upb_strtable_insert3(
4312 &new_table, 4556 &new_table,
4313 upb_strtable_iter_key(&i), 4557 upb_strtable_iter_key(&i),
4314 upb_strtable_iter_keylength(&i), 4558 upb_strtable_iter_keylength(&i),
4315 upb_strtable_iter_value(&i)); 4559 upb_strtable_iter_value(&i),
4560 a);
4316 } 4561 }
4317 upb_strtable_uninit(t); 4562 upb_strtable_uninit2(t, a);
4318 *t = new_table; 4563 *t = new_table;
4319 return true; 4564 return true;
4320 } 4565 }
4321 4566
4322 bool upb_strtable_insert2(upb_strtable *t, const char *k, size_t len, 4567 bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len,
4323 upb_value v) { 4568 upb_value v, upb_alloc *a) {
4324 lookupkey_t key; 4569 lookupkey_t key;
4325 upb_tabkey tabkey; 4570 upb_tabkey tabkey;
4326 uint32_t hash; 4571 uint32_t hash;
4327 4572
4573 upb_check_alloc(&t->t, a);
4574
4328 if (isfull(&t->t)) { 4575 if (isfull(&t->t)) {
4329 /* Need to resize. New table of double the size, add old elements to it. */ 4576 /* Need to resize. New table of double the size, add old elements to it. */
4330 if (!upb_strtable_resize(t, t->t.size_lg2 + 1)) { 4577 if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) {
4331 return false; 4578 return false;
4332 } 4579 }
4333 } 4580 }
4334 4581
4335 key = strkey2(k, len); 4582 key = strkey2(k, len);
4336 tabkey = strcopy(key); 4583 tabkey = strcopy(key, a);
4337 if (tabkey == 0) return false; 4584 if (tabkey == 0) return false;
4338 4585
4339 hash = MurmurHash2(key.str.str, key.str.len, 0); 4586 hash = MurmurHash2(key.str.str, key.str.len, 0);
4340 insert(&t->t, key, tabkey, v, hash, &strhash, &streql); 4587 insert(&t->t, key, tabkey, v, hash, &strhash, &streql);
4341 return true; 4588 return true;
4342 } 4589 }
4343 4590
4344 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, 4591 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
4345 upb_value *v) { 4592 upb_value *v) {
4346 uint32_t hash = MurmurHash2(key, len, 0); 4593 uint32_t hash = MurmurHash2(key, len, 0);
4347 return lookup(&t->t, strkey2(key, len), v, hash, &streql); 4594 return lookup(&t->t, strkey2(key, len), v, hash, &streql);
4348 } 4595 }
4349 4596
4350 bool upb_strtable_remove2(upb_strtable *t, const char *key, size_t len, 4597 bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
4351 upb_value *val) { 4598 upb_value *val, upb_alloc *alloc) {
4352 uint32_t hash = MurmurHash2(key, strlen(key), 0); 4599 uint32_t hash = MurmurHash2(key, strlen(key), 0);
4353 upb_tabkey tabkey; 4600 upb_tabkey tabkey;
4354 if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) { 4601 if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) {
4355 free((void*)tabkey); 4602 upb_free(alloc, (void*)tabkey);
4356 return true; 4603 return true;
4357 } else { 4604 } else {
4358 return false; 4605 return false;
4359 } 4606 }
4360 } 4607 }
4361 4608
4362 /* Iteration */ 4609 /* Iteration */
4363 4610
4364 static const upb_tabent *str_tabent(const upb_strtable_iter *i) { 4611 static const upb_tabent *str_tabent(const upb_strtable_iter *i) {
4365 return &i->t->t.entries[i->index]; 4612 return &i->t->t.entries[i->index];
4366 } 4613 }
4367 4614
4368 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) { 4615 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) {
4369 i->t = t; 4616 i->t = t;
4370 i->index = begin(&t->t); 4617 i->index = begin(&t->t);
4371 } 4618 }
4372 4619
4373 void upb_strtable_next(upb_strtable_iter *i) { 4620 void upb_strtable_next(upb_strtable_iter *i) {
4374 i->index = next(&i->t->t, i->index); 4621 i->index = next(&i->t->t, i->index);
4375 } 4622 }
4376 4623
4377 bool upb_strtable_done(const upb_strtable_iter *i) { 4624 bool upb_strtable_done(const upb_strtable_iter *i) {
4378 return i->index >= upb_table_size(&i->t->t) || 4625 return i->index >= upb_table_size(&i->t->t) ||
4379 upb_tabent_isempty(str_tabent(i)); 4626 upb_tabent_isempty(str_tabent(i));
4380 } 4627 }
4381 4628
4382 const char *upb_strtable_iter_key(upb_strtable_iter *i) { 4629 const char *upb_strtable_iter_key(const upb_strtable_iter *i) {
4383 assert(!upb_strtable_done(i)); 4630 assert(!upb_strtable_done(i));
4384 return upb_tabstr(str_tabent(i)->key, NULL); 4631 return upb_tabstr(str_tabent(i)->key, NULL);
4385 } 4632 }
4386 4633
4387 size_t upb_strtable_iter_keylength(upb_strtable_iter *i) { 4634 size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) {
4388 uint32_t len; 4635 uint32_t len;
4389 assert(!upb_strtable_done(i)); 4636 assert(!upb_strtable_done(i));
4390 upb_tabstr(str_tabent(i)->key, &len); 4637 upb_tabstr(str_tabent(i)->key, &len);
4391 return len; 4638 return len;
4392 } 4639 }
4393 4640
4394 upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { 4641 upb_value upb_strtable_iter_value(const upb_strtable_iter *i) {
4395 assert(!upb_strtable_done(i)); 4642 assert(!upb_strtable_done(i));
4396 return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype); 4643 return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype);
4397 } 4644 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4452 upb_inttable_begin(&i, t); 4699 upb_inttable_begin(&i, t);
4453 for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { 4700 for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) {
4454 assert(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL)); 4701 assert(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL));
4455 } 4702 }
4456 assert(count == upb_inttable_count(t)); 4703 assert(count == upb_inttable_count(t));
4457 } 4704 }
4458 #endif 4705 #endif
4459 } 4706 }
4460 4707
4461 bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, 4708 bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype,
4462 size_t asize, int hsize_lg2) { 4709 size_t asize, int hsize_lg2, upb_alloc *a) {
4463 size_t array_bytes; 4710 size_t array_bytes;
4464 4711
4465 if (!init(&t->t, ctype, hsize_lg2)) return false; 4712 if (!init(&t->t, ctype, hsize_lg2, a)) return false;
4466 /* Always make the array part at least 1 long, so that we know key 0 4713 /* Always make the array part at least 1 long, so that we know key 0
4467 * won't be in the hash part, which simplifies things. */ 4714 * won't be in the hash part, which simplifies things. */
4468 t->array_size = UPB_MAX(1, asize); 4715 t->array_size = UPB_MAX(1, asize);
4469 t->array_count = 0; 4716 t->array_count = 0;
4470 array_bytes = t->array_size * sizeof(upb_value); 4717 array_bytes = t->array_size * sizeof(upb_value);
4471 t->array = malloc(array_bytes); 4718 t->array = upb_malloc(a, array_bytes);
4472 if (!t->array) { 4719 if (!t->array) {
4473 uninit(&t->t); 4720 uninit(&t->t, a);
4474 return false; 4721 return false;
4475 } 4722 }
4476 memset(mutable_array(t), 0xff, array_bytes); 4723 memset(mutable_array(t), 0xff, array_bytes);
4477 check(t); 4724 check(t);
4478 return true; 4725 return true;
4479 } 4726 }
4480 4727
4481 bool upb_inttable_init(upb_inttable *t, upb_ctype_t ctype) { 4728 bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) {
4482 return upb_inttable_sizedinit(t, ctype, 0, 4); 4729 return upb_inttable_sizedinit(t, ctype, 0, 4, a);
4483 } 4730 }
4484 4731
4485 void upb_inttable_uninit(upb_inttable *t) { 4732 void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) {
4486 uninit(&t->t); 4733 uninit(&t->t, a);
4487 free(mutable_array(t)); 4734 upb_free(a, mutable_array(t));
4488 } 4735 }
4489 4736
4490 bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val) { 4737 bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
4491 /* XXX: Table can't store value (uint64_t)-1. Need to somehow statically 4738 upb_alloc *a) {
4492 * guarantee that this is not necessary, or fix the limitation. */
4493 upb_tabval tabval; 4739 upb_tabval tabval;
4494 tabval.val = val.val; 4740 tabval.val = val.val;
4495 UPB_UNUSED(tabval); 4741 UPB_UNUSED(tabval);
4496 assert(upb_arrhas(tabval)); 4742 assert(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */
4743
4744 upb_check_alloc(&t->t, a);
4497 4745
4498 if (key < t->array_size) { 4746 if (key < t->array_size) {
4499 assert(!upb_arrhas(t->array[key])); 4747 assert(!upb_arrhas(t->array[key]));
4500 t->array_count++; 4748 t->array_count++;
4501 mutable_array(t)[key].val = val.val; 4749 mutable_array(t)[key].val = val.val;
4502 } else { 4750 } else {
4503 if (isfull(&t->t)) { 4751 if (isfull(&t->t)) {
4504 /* Need to resize the hash part, but we re-use the array part. */ 4752 /* Need to resize the hash part, but we re-use the array part. */
4505 size_t i; 4753 size_t i;
4506 upb_table new_table; 4754 upb_table new_table;
4507 if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1)) 4755
4756 if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) {
4508 return false; 4757 return false;
4758 }
4759
4509 for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { 4760 for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) {
4510 const upb_tabent *e = &t->t.entries[i]; 4761 const upb_tabent *e = &t->t.entries[i];
4511 uint32_t hash; 4762 uint32_t hash;
4512 upb_value v; 4763 upb_value v;
4513 4764
4514 _upb_value_setval(&v, e->val.val, t->t.ctype); 4765 _upb_value_setval(&v, e->val.val, t->t.ctype);
4515 hash = upb_inthash(e->key); 4766 hash = upb_inthash(e->key);
4516 insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); 4767 insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql);
4517 } 4768 }
4518 4769
4519 assert(t->t.count == new_table.count); 4770 assert(t->t.count == new_table.count);
4520 4771
4521 uninit(&t->t); 4772 uninit(&t->t, a);
4522 t->t = new_table; 4773 t->t = new_table;
4523 } 4774 }
4524 insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); 4775 insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql);
4525 } 4776 }
4526 check(t); 4777 check(t);
4527 return true; 4778 return true;
4528 } 4779 }
4529 4780
4530 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) { 4781 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) {
4531 const upb_tabval *table_v = inttable_val_const(t, key); 4782 const upb_tabval *table_v = inttable_val_const(t, key);
(...skipping 25 matching lines...) Expand all
4557 } 4808 }
4558 } else { 4809 } else {
4559 upb_tabkey removed; 4810 upb_tabkey removed;
4560 uint32_t hash = upb_inthash(key); 4811 uint32_t hash = upb_inthash(key);
4561 success = rm(&t->t, intkey(key), val, &removed, hash, &inteql); 4812 success = rm(&t->t, intkey(key), val, &removed, hash, &inteql);
4562 } 4813 }
4563 check(t); 4814 check(t);
4564 return success; 4815 return success;
4565 } 4816 }
4566 4817
4567 bool upb_inttable_push(upb_inttable *t, upb_value val) { 4818 bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) {
4568 return upb_inttable_insert(t, upb_inttable_count(t), val); 4819 upb_check_alloc(&t->t, a);
4820 return upb_inttable_insert2(t, upb_inttable_count(t), val, a);
4569 } 4821 }
4570 4822
4571 upb_value upb_inttable_pop(upb_inttable *t) { 4823 upb_value upb_inttable_pop(upb_inttable *t) {
4572 upb_value val; 4824 upb_value val;
4573 bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val); 4825 bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val);
4574 UPB_ASSERT_VAR(ok, ok); 4826 UPB_ASSERT_VAR(ok, ok);
4575 return val; 4827 return val;
4576 } 4828 }
4577 4829
4578 bool upb_inttable_insertptr(upb_inttable *t, const void *key, upb_value val) { 4830 bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
4579 return upb_inttable_insert(t, (uintptr_t)key, val); 4831 upb_alloc *a) {
4832 upb_check_alloc(&t->t, a);
4833 return upb_inttable_insert2(t, (uintptr_t)key, val, a);
4580 } 4834 }
4581 4835
4582 bool upb_inttable_lookupptr(const upb_inttable *t, const void *key, 4836 bool upb_inttable_lookupptr(const upb_inttable *t, const void *key,
4583 upb_value *v) { 4837 upb_value *v) {
4584 return upb_inttable_lookup(t, (uintptr_t)key, v); 4838 return upb_inttable_lookup(t, (uintptr_t)key, v);
4585 } 4839 }
4586 4840
4587 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) { 4841 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) {
4588 return upb_inttable_remove(t, (uintptr_t)key, val); 4842 return upb_inttable_remove(t, (uintptr_t)key, val);
4589 } 4843 }
4590 4844
4591 void upb_inttable_compact(upb_inttable *t) { 4845 void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) {
4592 /* Create a power-of-two histogram of the table keys. */ 4846 /* A power-of-two histogram of the table keys. */
4593 int counts[UPB_MAXARRSIZE + 1] = {0}; 4847 size_t counts[UPB_MAXARRSIZE + 1] = {0};
4594 uintptr_t max_key = 0; 4848
4849 /* The max key in each bucket. */
4850 uintptr_t max[UPB_MAXARRSIZE + 1] = {0};
4851
4595 upb_inttable_iter i; 4852 upb_inttable_iter i;
4596 size_t arr_size; 4853 size_t arr_count;
4597 int arr_count; 4854 int size_lg2;
4598 upb_inttable new_t; 4855 upb_inttable new_t;
4599 4856
4857 upb_check_alloc(&t->t, a);
4858
4600 upb_inttable_begin(&i, t); 4859 upb_inttable_begin(&i, t);
4601 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { 4860 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
4602 uintptr_t key = upb_inttable_iter_key(&i); 4861 uintptr_t key = upb_inttable_iter_key(&i);
4603 if (key > max_key) { 4862 int bucket = log2ceil(key);
4604 max_key = key; 4863 max[bucket] = UPB_MAX(max[bucket], key);
4605 } 4864 counts[bucket]++;
4606 counts[log2ceil(key)]++;
4607 } 4865 }
4608 4866
4609 arr_size = 1; 4867 /* Find the largest power of two that satisfies the MIN_DENSITY
4868 * definition (while actually having some keys). */
4610 arr_count = upb_inttable_count(t); 4869 arr_count = upb_inttable_count(t);
4611 4870
4612 if (upb_inttable_count(t) >= max_key * MIN_DENSITY) { 4871 for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) {
4613 /* We can put 100% of the entries in the array part. */ 4872 if (counts[size_lg2] == 0) {
4614 arr_size = max_key + 1; 4873 /* We can halve again without losing any entries. */
4615 } else { 4874 continue;
4616 /* Find the largest power of two that satisfies the MIN_DENSITY 4875 } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) {
4617 * definition. */ 4876 break;
4618 int size_lg2;
4619 for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 1; size_lg2--) {
4620 arr_size = 1 << size_lg2;
4621 arr_count -= counts[size_lg2];
4622 if (arr_count >= arr_size * MIN_DENSITY) {
4623 break;
4624 }
4625 } 4877 }
4878
4879 arr_count -= counts[size_lg2];
4626 } 4880 }
4627 4881
4628 /* Array part must always be at least 1 entry large to catch lookups of key 4882 assert(arr_count <= upb_inttable_count(t));
4629 * 0. Key 0 must always be in the array part because "0" in the hash part
4630 * denotes an empty entry. */
4631 arr_size = UPB_MAX(arr_size, 1);
4632 4883
4633 { 4884 {
4634 /* Insert all elements into new, perfectly-sized table. */ 4885 /* Insert all elements into new, perfectly-sized table. */
4635 int hash_count = upb_inttable_count(t) - arr_count; 4886 size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */
4636 int hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; 4887 size_t hash_count = upb_inttable_count(t) - arr_count;
4637 int hashsize_lg2 = log2ceil(hash_size); 4888 size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0;
4889 size_t hashsize_lg2 = log2ceil(hash_size);
4638 4890
4639 assert(hash_count >= 0); 4891 upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a);
4640 upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2);
4641 upb_inttable_begin(&i, t); 4892 upb_inttable_begin(&i, t);
4642 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { 4893 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
4643 uintptr_t k = upb_inttable_iter_key(&i); 4894 uintptr_t k = upb_inttable_iter_key(&i);
4644 upb_inttable_insert(&new_t, k, upb_inttable_iter_value(&i)); 4895 upb_inttable_insert2(&new_t, k, upb_inttable_iter_value(&i), a);
4645 } 4896 }
4646 assert(new_t.array_size == arr_size); 4897 assert(new_t.array_size == arr_size);
4647 assert(new_t.t.size_lg2 == hashsize_lg2); 4898 assert(new_t.t.size_lg2 == hashsize_lg2);
4648 } 4899 }
4649 upb_inttable_uninit(t); 4900 upb_inttable_uninit2(t, a);
4650 *t = new_t; 4901 *t = new_t;
4651 } 4902 }
4652 4903
4653 /* Iteration. */ 4904 /* Iteration. */
4654 4905
4655 static const upb_tabent *int_tabent(const upb_inttable_iter *i) { 4906 static const upb_tabent *int_tabent(const upb_inttable_iter *i) {
4656 assert(!i->array_part); 4907 assert(!i->array_part);
4657 return &i->t->t.entries[i->index]; 4908 return &i->t->t.entries[i->index];
4658 } 4909 }
4659 4910
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
4915 * It may be tempting to "optimize" this by initializing these final 5166 * It may be tempting to "optimize" this by initializing these final
4916 * four bytes up-front and then being careful never to overwrite them, 5167 * four bytes up-front and then being careful never to overwrite them,
4917 * this is safer and simpler. */ 5168 * this is safer and simpler. */
4918 static void nullz(upb_status *status) { 5169 static void nullz(upb_status *status) {
4919 const char *ellipsis = "..."; 5170 const char *ellipsis = "...";
4920 size_t len = strlen(ellipsis); 5171 size_t len = strlen(ellipsis);
4921 assert(sizeof(status->msg) > len); 5172 assert(sizeof(status->msg) > len);
4922 memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); 5173 memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len);
4923 } 5174 }
4924 5175
5176
5177 /* upb_upberr *****************************************************************/
5178
5179 upb_errorspace upb_upberr = {"upb error"};
5180
5181 void upb_upberr_setoom(upb_status *status) {
5182 status->error_space_ = &upb_upberr;
5183 upb_status_seterrmsg(status, "Out of memory");
5184 }
5185
5186
5187 /* upb_status *****************************************************************/
5188
4925 void upb_status_clear(upb_status *status) { 5189 void upb_status_clear(upb_status *status) {
4926 if (!status) return; 5190 if (!status) return;
4927 status->ok_ = true; 5191 status->ok_ = true;
4928 status->code_ = 0; 5192 status->code_ = 0;
4929 status->msg[0] = '\0'; 5193 status->msg[0] = '\0';
4930 } 5194 }
4931 5195
4932 bool upb_ok(const upb_status *status) { return status->ok_; } 5196 bool upb_ok(const upb_status *status) { return status->ok_; }
4933 5197
4934 upb_errorspace *upb_status_errspace(const upb_status *status) { 5198 upb_errorspace *upb_status_errspace(const upb_status *status) {
(...skipping 18 matching lines...) Expand all
4953 va_end(args); 5217 va_end(args);
4954 } 5218 }
4955 5219
4956 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { 5220 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) {
4957 if (!status) return; 5221 if (!status) return;
4958 status->ok_ = false; 5222 status->ok_ = false;
4959 _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); 5223 _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args);
4960 nullz(status); 5224 nullz(status);
4961 } 5225 }
4962 5226
4963 void upb_status_seterrcode(upb_status *status, upb_errorspace *space,
4964 int code) {
4965 if (!status) return;
4966 status->ok_ = false;
4967 status->error_space_ = space;
4968 status->code_ = code;
4969 space->set_message(status, code);
4970 }
4971
4972 void upb_status_copy(upb_status *to, const upb_status *from) { 5227 void upb_status_copy(upb_status *to, const upb_status *from) {
4973 if (!to) return; 5228 if (!to) return;
4974 *to = *from; 5229 *to = *from;
4975 } 5230 }
4976 /* This file was generated by upbc (the upb compiler). 5231
5232
5233 /* upb_alloc ******************************************************************/
5234
5235 static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
5236 size_t size) {
5237 UPB_UNUSED(alloc);
5238 UPB_UNUSED(oldsize);
5239 if (size == 0) {
5240 free(ptr);
5241 return NULL;
5242 } else {
5243 return realloc(ptr, size);
5244 }
5245 }
5246
5247 upb_alloc upb_alloc_global = {&upb_global_allocfunc};
5248
5249
5250 /* upb_arena ******************************************************************/
5251
5252 /* Be conservative and choose 16 in case anyone is using SSE. */
5253 static const size_t maxalign = 16;
5254
5255 static size_t align_up(size_t size) {
5256 return ((size + maxalign - 1) / maxalign) * maxalign;
5257 }
5258
5259 typedef struct mem_block {
5260 struct mem_block *next;
5261 size_t size;
5262 size_t used;
5263 bool owned;
5264 /* Data follows. */
5265 } mem_block;
5266
5267 typedef struct cleanup_ent {
5268 struct cleanup_ent *next;
5269 upb_cleanup_func *cleanup;
5270 void *ud;
5271 } cleanup_ent;
5272
5273 static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size,
5274 bool owned) {
5275 mem_block *block = ptr;
5276
5277 block->next = a->block_head;
5278 block->size = size;
5279 block->used = align_up(sizeof(mem_block));
5280 block->owned = owned;
5281
5282 a->block_head = block;
5283
5284 /* TODO(haberman): ASAN poison. */
5285 }
5286
5287
5288 static mem_block *upb_arena_allocblock(upb_arena *a, size_t size) {
5289 size_t block_size = UPB_MAX(size, a->next_block_size) + sizeof(mem_block);
5290 mem_block *block = upb_malloc(a->block_alloc, block_size);
5291
5292 if (!block) {
5293 return NULL;
5294 }
5295
5296 upb_arena_addblock(a, block, block_size, true);
5297 a->next_block_size = UPB_MIN(block_size * 2, a->max_block_size);
5298
5299 return block;
5300 }
5301
5302 static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
5303 size_t size) {
5304 upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */
5305 mem_block *block = a->block_head;
5306 void *ret;
5307
5308 if (size == 0) {
5309 return NULL; /* We are an arena, don't need individual frees. */
5310 }
5311
5312 size = align_up(size);
5313
5314 /* TODO(haberman): special-case if this is a realloc of the last alloc? */
5315
5316 if (!block || block->size - block->used < size) {
5317 /* Slow path: have to allocate a new block. */
5318 block = upb_arena_allocblock(a, size);
5319
5320 if (!block) {
5321 return NULL; /* Out of memory. */
5322 }
5323 }
5324
5325 ret = (char*)block + block->used;
5326 block->used += size;
5327
5328 if (oldsize > 0) {
5329 memcpy(ret, ptr, oldsize); /* Preserve existing data. */
5330 }
5331
5332 /* TODO(haberman): ASAN unpoison. */
5333
5334 a->bytes_allocated += size;
5335 return ret;
5336 }
5337
5338 /* Public Arena API ***********************************************************/
5339
5340 void upb_arena_init(upb_arena *a) {
5341 a->alloc.func = &upb_arena_doalloc;
5342 a->block_alloc = &upb_alloc_global;
5343 a->bytes_allocated = 0;
5344 a->next_block_size = 256;
5345 a->max_block_size = 16384;
5346 a->cleanup_head = NULL;
5347 a->block_head = NULL;
5348 }
5349
5350 void upb_arena_init2(upb_arena *a, void *mem, size_t size, upb_alloc *alloc) {
5351 upb_arena_init(a);
5352
5353 if (size > sizeof(mem_block)) {
5354 upb_arena_addblock(a, mem, size, false);
5355 }
5356
5357 if (alloc) {
5358 a->block_alloc = alloc;
5359 }
5360 }
5361
5362 void upb_arena_uninit(upb_arena *a) {
5363 cleanup_ent *ent = a->cleanup_head;
5364 mem_block *block = a->block_head;
5365
5366 while (ent) {
5367 ent->cleanup(ent->ud);
5368 ent = ent->next;
5369 }
5370
5371 /* Must do this after running cleanup functions, because this will delete
5372 * the memory we store our cleanup entries in! */
5373 while (block) {
5374 mem_block *next = block->next;
5375
5376 if (block->owned) {
5377 upb_free(a->block_alloc, block);
5378 }
5379
5380 block = next;
5381 }
5382 }
5383
5384 bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud) {
5385 cleanup_ent *ent = upb_malloc(&a->alloc, sizeof(cleanup_ent));
5386 if (!ent) {
5387 return false; /* Out of memory. */
5388 }
5389
5390 ent->cleanup = func;
5391 ent->ud = ud;
5392 ent->next = a->cleanup_head;
5393 a->cleanup_head = ent;
5394
5395 return true;
5396 }
5397
5398 size_t upb_arena_bytesallocated(const upb_arena *a) {
5399 return a->bytes_allocated;
5400 }
5401
5402
5403 /* Standard error functions ***************************************************/
5404
5405 static bool default_err(void *ud, const upb_status *status) {
5406 UPB_UNUSED(ud);
5407 UPB_UNUSED(status);
5408 return false;
5409 }
5410
5411 static bool write_err_to(void *ud, const upb_status *status) {
5412 upb_status *copy_to = ud;
5413 upb_status_copy(copy_to, status);
5414 return false;
5415 }
5416
5417
5418 /* upb_env ********************************************************************/
5419
5420 void upb_env_initonly(upb_env *e) {
5421 e->ok_ = true;
5422 e->error_func_ = &default_err;
5423 e->error_ud_ = NULL;
5424 }
5425
5426 void upb_env_init(upb_env *e) {
5427 upb_arena_init(&e->arena_);
5428 upb_env_initonly(e);
5429 }
5430
5431 void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc) {
5432 upb_arena_init2(&e->arena_, mem, n, alloc);
5433 upb_env_initonly(e);
5434 }
5435
5436 void upb_env_uninit(upb_env *e) {
5437 upb_arena_uninit(&e->arena_);
5438 }
5439
5440 void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud) {
5441 e->error_func_ = func;
5442 e->error_ud_ = ud;
5443 }
5444
5445 void upb_env_reporterrorsto(upb_env *e, upb_status *s) {
5446 e->error_func_ = &write_err_to;
5447 e->error_ud_ = s;
5448 }
5449
5450 bool upb_env_reporterror(upb_env *e, const upb_status *status) {
5451 e->ok_ = false;
5452 return e->error_func_(e->error_ud_, status);
5453 }
5454
5455 void *upb_env_malloc(upb_env *e, size_t size) {
5456 return upb_malloc(&e->arena_.alloc, size);
5457 }
5458
5459 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) {
5460 return upb_realloc(&e->arena_.alloc, ptr, oldsize, size);
5461 }
5462
5463 void upb_env_free(upb_env *e, void *ptr) {
5464 upb_free(&e->arena_.alloc, ptr);
5465 }
5466
5467 bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud) {
5468 return upb_arena_addcleanup(&e->arena_, func, ud);
5469 }
5470
5471 size_t upb_env_bytesallocated(const upb_env *e) {
5472 return upb_arena_bytesallocated(&e->arena_);
5473 }
5474 /* This file was generated by upbc (the upb compiler) from the input
5475 * file:
5476 *
5477 * upb/descriptor/descriptor.proto
5478 *
4977 * Do not edit -- your changes will be discarded when the file is 5479 * Do not edit -- your changes will be discarded when the file is
4978 * regenerated. */ 5480 * regenerated. */
4979 5481
4980 5482 #include <assert.h>
4981 static const upb_msgdef msgs[20]; 5483
4982 static const upb_fielddef fields[81]; 5484
4983 static const upb_enumdef enums[4]; 5485 static const upb_msgdef msgs[22];
5486 static const upb_fielddef fields[105];
5487 static const upb_enumdef enums[5];
4984 static const upb_tabent strentries[236]; 5488 static const upb_tabent strentries[236];
4985 static const upb_tabent intentries[14]; 5489 static const upb_tabent intentries[18];
4986 static const upb_tabval arrays[232]; 5490 static const upb_tabval arrays[184];
4987 5491
4988 #ifdef UPB_DEBUG_REFS 5492 #ifdef UPB_DEBUG_REFS
4989 static upb_inttable reftables[212]; 5493 static upb_inttable reftables[264];
4990 #endif 5494 #endif
4991 5495
4992 static const upb_msgdef msgs[20] = { 5496 static const upb_msgdef msgs[22] = {
4993 UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 27, 6, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 8, 7), UPB_STRTABLE_INIT(7, 15, UPB_CTYP E_PTR, 4, &strentries[0]),&reftables[0], &reftables[1]), 5497 UPB_MSGDEF_INIT("google.protobuf.DescriptorProto", 40, 8, UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[0], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_C TYPE_PTR, 4, &strentries[0]), false, UPB_SYNTAX_PROTO2, &reftables[0], &reftable s[1]),
4994 UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 0, UPB_IN TTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[8], 3, 2), UPB_STRTABLE_INIT(2 , 3, UPB_CTYPE_PTR, 2, &strentries[16]),&reftables[2], &reftables[3]), 5498 UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ExtensionRange", 4, 0, UPB_IN TTABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 3, 2), UPB_STRTABLE_INIT( 2, 3, UPB_CTYPE_PTR, 2, &strentries[16]), false, UPB_SYNTAX_PROTO2, &reftables[2 ], &reftables[3]),
4995 UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 2, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[11], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_ CTYPE_PTR, 2, &strentries[20]),&reftables[4], &reftables[5]), 5499 UPB_MSGDEF_INIT("google.protobuf.DescriptorProto.ReservedRange", 4, 0, UPB_INT TABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[14], 3, 2), UPB_STRTABLE_INIT(2 , 3, UPB_CTYPE_PTR, 2, &strentries[20]), false, UPB_SYNTAX_PROTO2, &reftables[4] , &reftables[5]),
4996 UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 7, 1, UPB_INTTABLE_INIT(1, 1, U PB_CTYPE_PTR, 1, &intentries[0], &arrays[15], 8, 1), UPB_STRTABLE_INIT(2, 3, UPB _CTYPE_PTR, 2, &strentries[24]),&reftables[6], &reftables[7]), 5500 UPB_MSGDEF_INIT("google.protobuf.EnumDescriptorProto", 11, 2, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[17], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_ CTYPE_PTR, 2, &strentries[24]), false, UPB_SYNTAX_PROTO2, &reftables[6], &reftab les[7]),
4997 UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 1, UPB_INTTABLE _INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[23], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[28]),&reftables[8], &reftables[9]), 5501 UPB_MSGDEF_INIT("google.protobuf.EnumOptions", 8, 1, UPB_INTTABLE_INIT(1, 1, U PB_CTYPE_PTR, 1, &intentries[0], &arrays[21], 4, 2), UPB_STRTABLE_INIT(3, 3, UPB _CTYPE_PTR, 2, &strentries[28]), false, UPB_SYNTAX_PROTO2, &reftables[8], &refta bles[9]),
4998 UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 6, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[27], 4, 0), UPB_STRTABLE_INIT(1, 3 , UPB_CTYPE_PTR, 2, &strentries[32]),&reftables[10], &reftables[11]), 5502 UPB_MSGDEF_INIT("google.protobuf.EnumValueDescriptorProto", 8, 1, UPB_INTTABLE _INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[25], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[32]), false, UPB_SYNTAX_PROTO2, &reftables[10], &r eftables[11]),
4999 UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 19, 1, UPB_INTTABLE_IN IT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 9, 8), UPB_STRTABLE_INIT(8, 15, UP B_CTYPE_PTR, 4, &strentries[36]),&reftables[12], &reftables[13]), 5503 UPB_MSGDEF_INIT("google.protobuf.EnumValueOptions", 7, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[2], &arrays[29], 2, 1), UPB_STRTABLE_INIT(2, 3 , UPB_CTYPE_PTR, 2, &strentries[36]), false, UPB_SYNTAX_PROTO2, &reftables[12], &reftables[13]),
5000 UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 14, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[40], 32, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[52]),&reftables[14], &reftables[15]), 5504 UPB_MSGDEF_INIT("google.protobuf.FieldDescriptorProto", 23, 1, UPB_INTTABLE_IN IT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[31], 11, 10), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[40]), false, UPB_SYNTAX_PROTO2, &reftables[14], & reftables[15]),
5001 UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 39, 6, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[72], 12, 11), UPB_STRTABLE_INIT(11, 15, UPB_CTYPE_PTR, 4, &strentries[68]),&reftables[16], &reftables[17]), 5505 UPB_MSGDEF_INIT("google.protobuf.FieldOptions", 12, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[4], &arrays[42], 11, 6), UPB_STRTABLE_INIT(7, 15, UPB_CTYPE_PTR, 4, &strentries[56]), false, UPB_SYNTAX_PROTO2, &reftables[16], & reftables[17]),
5002 UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 1, UPB_INTTABLE_INIT(0 , 0, UPB_CTYPE_PTR, 0, NULL, &arrays[84], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTY PE_PTR, 2, &strentries[84]),&reftables[18], &reftables[19]), 5506 UPB_MSGDEF_INIT("google.protobuf.FileDescriptorProto", 42, 6, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[53], 13, 12), UPB_STRTABLE_INIT(12, 15, UPB_CTYPE_PTR, 4, &strentries[72]), false, UPB_SYNTAX_PROTO2, &reftables[18], &r eftables[19]),
5003 UPB_MSGDEF_INIT("google.protobuf.FileOptions", 21, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[86], 64, 9), UPB_STRTABLE_INIT(10, 15, UPB_CTYPE_PTR, 4, &strentries[88]),&reftables[20], &reftables[21]), 5507 UPB_MSGDEF_INIT("google.protobuf.FileDescriptorSet", 6, 1, UPB_INTTABLE_INIT(0 , 0, UPB_CTYPE_PTR, 0, NULL, &arrays[66], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTY PE_PTR, 2, &strentries[88]), false, UPB_SYNTAX_PROTO2, &reftables[20], &reftable s[21]),
5004 UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 8, 1, UPB_INTTABLE_INIT(1, 1 , UPB_CTYPE_PTR, 1, &intentries[8], &arrays[150], 16, 2), UPB_STRTABLE_INIT(3, 3 , UPB_CTYPE_PTR, 2, &strentries[104]),&reftables[22], &reftables[23]), 5508 UPB_MSGDEF_INIT("google.protobuf.FileOptions", 31, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[6], &arrays[68], 39, 15), UPB_STRTABLE_INIT(16, 31 , UPB_CTYPE_PTR, 5, &strentries[92]), false, UPB_SYNTAX_PROTO2, &reftables[22], &reftables[23]),
5005 UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 13, 1, UPB_INTTABLE_I NIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[166], 5, 4), UPB_STRTABLE_INIT(4, 7, U PB_CTYPE_PTR, 3, &strentries[108]),&reftables[24], &reftables[25]), 5509 UPB_MSGDEF_INIT("google.protobuf.MessageOptions", 10, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[8], &arrays[107], 8, 4), UPB_STRTABLE_INIT(5, 7 , UPB_CTYPE_PTR, 3, &strentries[124]), false, UPB_SYNTAX_PROTO2, &reftables[24], &reftables[25]),
5006 UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 6, 1, UPB_INTTABLE_INIT(1, 1, UPB_CTYPE_PTR, 1, &intentries[10], &arrays[171], 4, 0), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE_PTR, 2, &strentries[116]),&reftables[26], &reftables[27]), 5510 UPB_MSGDEF_INIT("google.protobuf.MethodDescriptorProto", 15, 1, UPB_INTTABLE_I NIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[115], 7, 6), UPB_STRTABLE_INIT(6, 7, U PB_CTYPE_PTR, 3, &strentries[132]), false, UPB_SYNTAX_PROTO2, &reftables[26], &r eftables[27]),
5007 UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_ INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[175], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[120]),&reftables[28], &reftables[29]), 5511 UPB_MSGDEF_INIT("google.protobuf.MethodOptions", 7, 1, UPB_INTTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &intentries[10], &arrays[122], 1, 0), UPB_STRTABLE_INIT(2, 3, UPB_CTYPE_PTR, 2, &strentries[140]), false, UPB_SYNTAX_PROTO2, &reftables[28], &reftables[29]),
5008 UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 6, 1, UPB_INTTABLE_INIT(1, 1 , UPB_CTYPE_PTR, 1, &intentries[12], &arrays[179], 4, 0), UPB_STRTABLE_INIT(1, 3 , UPB_CTYPE_PTR, 2, &strentries[124]),&reftables[30], &reftables[31]), 5512 UPB_MSGDEF_INIT("google.protobuf.OneofDescriptorProto", 5, 0, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[123], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB _CTYPE_PTR, 2, &strentries[144]), false, UPB_SYNTAX_PROTO2, &reftables[30], &ref tables[31]),
5009 UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0 , UPB_CTYPE_PTR, 0, NULL, &arrays[183], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE _PTR, 2, &strentries[128]),&reftables[32], &reftables[33]), 5513 UPB_MSGDEF_INIT("google.protobuf.ServiceDescriptorProto", 11, 2, UPB_INTTABLE_ INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[125], 4, 3), UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_PTR, 2, &strentries[148]), false, UPB_SYNTAX_PROTO2, &reftables[32], & reftables[33]),
5010 UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 14, 0, UPB_INTTABLE _INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[185], 5, 4), UPB_STRTABLE_INIT(4, 7, UPB_CTYPE_PTR, 3, &strentries[132]),&reftables[34], &reftables[35]), 5514 UPB_MSGDEF_INIT("google.protobuf.ServiceOptions", 7, 1, UPB_INTTABLE_INIT(2, 3 , UPB_CTYPE_PTR, 2, &intentries[14], &arrays[129], 1, 0), UPB_STRTABLE_INIT(2, 3 , UPB_CTYPE_PTR, 2, &strentries[152]), false, UPB_SYNTAX_PROTO2, &reftables[34], &reftables[35]),
5011 UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[190], 9, 7), UPB_STRTABLE_INIT(7, 15, UP B_CTYPE_PTR, 4, &strentries[140]),&reftables[36], &reftables[37]), 5515 UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo", 6, 1, UPB_INTTABLE_INIT(0, 0 , UPB_CTYPE_PTR, 0, NULL, &arrays[130], 2, 1), UPB_STRTABLE_INIT(1, 3, UPB_CTYPE _PTR, 2, &strentries[156]), false, UPB_SYNTAX_PROTO2, &reftables[36], &reftables [37]),
5012 UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTT ABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[199], 3, 2), UPB_STRTABLE_INIT(2 , 3, UPB_CTYPE_PTR, 2, &strentries[156]),&reftables[38], &reftables[39]), 5516 UPB_MSGDEF_INIT("google.protobuf.SourceCodeInfo.Location", 19, 0, UPB_INTTABLE _INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[132], 7, 5), UPB_STRTABLE_INIT(5, 7, UPB_CTYPE_PTR, 3, &strentries[160]), false, UPB_SYNTAX_PROTO2, &reftables[38], &reftables[39]),
5517 UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption", 18, 1, UPB_INTTABLE_INI T(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[139], 9, 7), UPB_STRTABLE_INIT(7, 15, UP B_CTYPE_PTR, 4, &strentries[168]), false, UPB_SYNTAX_PROTO2, &reftables[40], &re ftables[41]),
5518 UPB_MSGDEF_INIT("google.protobuf.UninterpretedOption.NamePart", 6, 0, UPB_INTT ABLE_INIT(0, 0, UPB_CTYPE_PTR, 0, NULL, &arrays[148], 3, 2), UPB_STRTABLE_INIT(2 , 3, UPB_CTYPE_PTR, 2, &strentries[184]), false, UPB_SYNTAX_PROTO2, &reftables[4 2], &reftables[43]),
5013 }; 5519 };
5014 5520
5015 static const upb_fielddef fields[81] = { 5521 static const upb_fielddef fields[105] = {
5016 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[18], NULL, 15, 6, {0},&reftables[40], &refta bles[41]), 5522 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "aggregate_value", 8, &msgs[20], NULL, 15, 6, {0},&reftables[44], &refta bles[45]),
5017 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "allow_alias", 2, &msgs[3], NULL, 6, 1, {0},&reftables[42], &reftables[43] ), 5523 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "allow_alias", 2, &msgs[4], NULL, 6, 1, {0},&reftables[46], &reftables[47] ),
5018 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "cc_generic_services", 16, &msgs[10], NULL, 17, 6, {0},&reftables[44], &re ftables[45]), 5524 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "cc_enable_arenas", 31, &msgs[11], NULL, 23, 12, {0},&reftables[48], &reft ables[49]),
5019 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "ctype", 1, &msgs[7], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[46 ], &reftables[47]), 5525 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "cc_generic_services", 16, &msgs[11], NULL, 17, 6, {0},&reftables[50], &re ftables[51]),
5020 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[6], NULL, 16, 7, {0},&reftables[48], &reftable s[49]), 5526 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "client_streaming", 5, &msgs[13], NULL, 13, 4, {0},&reftables[52], &reftab les[53]),
5021 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[8], NULL, 30, 8, {0},&reftables[50], &reftables[5 1]), 5527 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "csharp_namespace", 37, &msgs[11], NULL, 27, 14, {0},&reftables[54], &re ftables[55]),
5022 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 3, &msgs[7], NULL, 8, 3, {0},&reftables[52], &reftables[53]) , 5528 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "ctype", 1, &msgs[8], (const upb_def*)(&enums[2]), 6, 1, {0},&reftables[56 ], &reftables[57]),
5023 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[18], NULL, 11, 4, {0},&reftables[54], &reftable s[55]), 5529 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "default_value", 7, &msgs[7], NULL, 16, 7, {0},&reftables[58], &reftable s[59]),
5024 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[56], &re ftables[57]), 5530 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "dependency", 3, &msgs[9], NULL, 30, 8, {0},&reftables[60], &reftables[6 1]),
5025 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[2]), 16, 2, {0},&refta bles[58], &reftables[59]), 5531 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 3, &msgs[12], NULL, 8, 3, {0},&reftables[62], &reftables[63] ),
5026 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "enum_type", 5, &msgs[8], (const upb_def*)(&msgs[2]), 13, 1, {0},&refta bles[60], &reftables[61]), 5532 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 3, &msgs[8], NULL, 8, 3, {0},&reftables[64], &reftables[65]) ,
5027 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "experimental_map_key", 9, &msgs[7], NULL, 10, 5, {0},&reftables[62], &r eftables[63]), 5533 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 33, &msgs[14], NULL, 6, 1, {0},&reftables[66], &reftables[67 ]),
5028 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[6], NULL, 7, 2, {0},&reftables[64], &reftables[65]) , 5534 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 23, &msgs[11], NULL, 21, 10, {0},&reftables[68], &reftables[ 69]),
5029 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "extension", 7, &msgs[8], (const upb_def*)(&msgs[6]), 19, 3, {0},&refta bles[66], &reftables[67]), 5535 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 3, &msgs[4], NULL, 7, 2, {0},&reftables[70], &reftables[71]) ,
5030 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[6]), 22, 4, {0},&refta bles[68], &reftables[69]), 5536 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 33, &msgs[17], NULL, 6, 1, {0},&reftables[72], &reftables[73 ]),
5031 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 19, 3, {0}, &reftables[70], &reftables[71]), 5537 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "deprecated", 1, &msgs[6], NULL, 6, 1, {0},&reftables[74], &reftables[75]) ,
5032 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "field", 2, &msgs[0], (const upb_def*)(&msgs[6]), 10, 0, {0},&reftables [72], &reftables[73]), 5538 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_DOUBLE, 0, false, false, false, false, "double_value", 6, &msgs[20], NULL, 11, 4, {0},&reftables[76], &reftable s[77]),
5033 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "file", 1, &msgs[9], (const upb_def*)(&msgs[8]), 5, 0, {0},&reftables[7 4], &reftables[75]), 5539 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "end", 2, &msgs[2], NULL, 3, 1, {0},&reftables[78], &re ftables[79]),
5034 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[10], NULL, 14, 5, {0},&reftables[76], &reftables [77]), 5540 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "end", 2, &msgs[1], NULL, 3, 1, {0},&reftables[80], &re ftables[81]),
5035 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[18], NULL, 6, 1, {0},&reftables[78], &refta bles[79]), 5541 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "enum_type", 4, &msgs[0], (const upb_def*)(&msgs[3]), 18, 2, {0},&refta bles[82], &reftables[83]),
5036 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[12], NULL, 7, 2, {0},&reftables[80], &reftables[8 1]), 5542 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "enum_type", 5, &msgs[9], (const upb_def*)(&msgs[3]), 13, 1, {0},&refta bles[84], &reftables[85]),
5037 UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, f alse, "is_extension", 2, &msgs[19], NULL, 5, 1, {0},&reftables[82], &reftables[8 3]), 5543 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "extendee", 2, &msgs[7], NULL, 7, 2, {0},&reftables[86], &reftables[87]) ,
5038 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_generate_equals_and_hash", 20, &msgs[10], NULL, 20, 9, {0},&reftable s[84], &reftables[85]), 5544 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "extension", 6, &msgs[0], (const upb_def*)(&msgs[7]), 24, 4, {0},&refta bles[88], &reftables[89]),
5039 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_generic_services", 17, &msgs[10], NULL, 18, 7, {0},&reftables[86], & reftables[87]), 5545 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "extension", 7, &msgs[9], (const upb_def*)(&msgs[7]), 19, 3, {0},&refta bles[90], &reftables[91]),
5040 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_multiple_files", 10, &msgs[10], NULL, 13, 4, {0},&reftables[88], &re ftables[89]), 5546 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "extension_range", 5, &msgs[0], (const upb_def*)(&msgs[1]), 21, 3, {0}, &reftables[92], &reftables[93]),
5041 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[10], NULL, 9, 2, {0},&reftables[90], &r eftables[91]), 5547 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "field", 2, &msgs[0], (const upb_def*)(&msgs[7]), 12, 0, {0},&reftables [94], &reftables[95]),
5042 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[10], NULL, 6, 1, {0},&reftables[92], &reftables [93]), 5548 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "file", 1, &msgs[10], (const upb_def*)(&msgs[9]), 5, 0, {0},&reftables[ 96], &reftables[97]),
5043 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "label", 4, &msgs[6], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[9 4], &reftables[95]), 5549 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "go_package", 11, &msgs[11], NULL, 14, 5, {0},&reftables[98], &reftables [99]),
5044 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "lazy", 5, &msgs[7], NULL, 9, 4, {0},&reftables[96], &reftables[97]), 5550 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "identifier_value", 3, &msgs[20], NULL, 6, 1, {0},&reftables[100], &reft ables[101]),
5045 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[17], NULL, 8, 2, {0},&reftables[98], &refta bles[99]), 5551 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "input_type", 2, &msgs[13], NULL, 7, 2, {0},&reftables[102], &reftables[ 103]),
5046 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "location", 1, &msgs[16], (const upb_def*)(&msgs[17]), 5, 0, {0},&refta bles[100], &reftables[101]), 5552 UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_BOOL, 0, false, false, false, f alse, "is_extension", 2, &msgs[21], NULL, 5, 1, {0},&reftables[104], &reftables[ 105]),
5047 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "message_set_wire_format", 1, &msgs[11], NULL, 6, 1, {0},&reftables[102], &reftables[103]), 5553 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_generate_equals_and_hash", 20, &msgs[11], NULL, 20, 9, {0},&reftable s[106], &reftables[107]),
5048 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "message_type", 4, &msgs[8], (const upb_def*)(&msgs[0]), 10, 0, {0},&re ftables[104], &reftables[105]), 5554 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_generic_services", 17, &msgs[11], NULL, 18, 7, {0},&reftables[108], &reftables[109]),
5049 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "method", 2, &msgs[14], (const upb_def*)(&msgs[12]), 6, 0, {0},&reftabl es[106], &reftables[107]), 5555 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_multiple_files", 10, &msgs[11], NULL, 13, 4, {0},&reftables[110], &r eftables[111]),
5050 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[8], NULL, 22, 6, {0},&reftables[108], &reftables[109]), 5556 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_outer_classname", 8, &msgs[11], NULL, 9, 2, {0},&reftables[112], & reftables[113]),
5051 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[14], NULL, 8, 2, {0},&reftables[110], &reftables[111]), 5557 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "java_package", 1, &msgs[11], NULL, 6, 1, {0},&reftables[114], &reftable s[115]),
5052 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "name", 2, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&reftables [112], &reftables[113]), 5558 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "java_string_check_utf8", 27, &msgs[11], NULL, 22, 11, {0},&reftables[116] , &reftables[117]),
5053 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[4], NULL, 4, 1, {0},&reftables[114], &reftables[115]), 5559 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "javanano_use_deprecated_package", 38, &msgs[11], NULL, 30, 15, {0},&refta bles[118], &reftables[119]),
5054 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 24, 6, {0},&reftables[116], &reftables[117]), 5560 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "json_name", 10, &msgs[7], NULL, 20, 9, {0},&reftables[120], &reftables[ 121]),
5055 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[12], NULL, 4, 1, {0},&reftables[118], &reftables[119]), 5561 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "jstype", 6, &msgs[8], (const upb_def*)(&enums[3]), 10, 5, {0},&reftables[ 122], &reftables[123]),
5056 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[2], NULL, 8, 2, {0},&reftables[120], &reftables[121]), 5562 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "label", 4, &msgs[7], (const upb_def*)(&enums[0]), 11, 4, {0},&reftables[1 24], &reftables[125]),
5057 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[6], NULL, 4, 1, {0},&reftables[122], &reftables[123]), 5563 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "lazy", 5, &msgs[8], NULL, 9, 4, {0},&reftables[126], &reftables[127]),
5058 UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[19], NULL, 2, 0, {0},&reftables[124], &reftables[1 25]), 5564 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "leading_comments", 3, &msgs[19], NULL, 8, 2, {0},&reftables[128], &reft ables[129]),
5059 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, fal se, false, false, false, "negative_int_value", 5, &msgs[18], NULL, 10, 3, {0},&r eftables[126], &reftables[127]), 5565 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "leading_detached_comments", 6, &msgs[19], NULL, 16, 4, {0},&reftables[1 30], &reftables[131]),
5060 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 13, 1, {0},&ref tables[128], &reftables[129]), 5566 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "location", 1, &msgs[18], (const upb_def*)(&msgs[19]), 5, 0, {0},&refta bles[132], &reftables[133]),
5061 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "no_standard_descriptor_accessor", 2, &msgs[11], NULL, 7, 2, {0},&reftable s[130], &reftables[131]), 5567 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "map_entry", 7, &msgs[12], NULL, 9, 4, {0},&reftables[134], &reftables[135 ]),
5062 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "number", 3, &msgs[6], NULL, 10, 3, {0},&reftables[132] , &reftables[133]), 5568 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "message_set_wire_format", 1, &msgs[12], NULL, 6, 1, {0},&reftables[136], &reftables[137]),
5063 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "number", 2, &msgs[4], NULL, 7, 2, {0},&reftables[134], &reftables[135]), 5569 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "message_type", 4, &msgs[9], (const upb_def*)(&msgs[0]), 10, 0, {0},&re ftables[138], &reftables[139]),
5064 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "optimize_for", 9, &msgs[10], (const upb_def*)(&enums[3]), 12, 3, {0},&ref tables[136], &reftables[137]), 5570 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "method", 2, &msgs[16], (const upb_def*)(&msgs[13]), 6, 0, {0},&reftabl es[140], &reftables[141]),
5065 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 7, &msgs[0], (const upb_def*)(&msgs[11]), 23, 5, {0},&reftab les[138], &reftables[139]), 5571 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[3], NULL, 8, 2, {0},&reftables[142], &reftables[143]),
5066 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 3, &msgs[2], (const upb_def*)(&msgs[3]), 7, 1, {0},&reftable s[140], &reftables[141]), 5572 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[15], NULL, 2, 0, {0},&reftables[144], &reftables[145]),
5067 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 8, &msgs[6], (const upb_def*)(&msgs[7]), 3, 0, {0},&reftable s[142], &reftables[143]), 5573 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "name", 2, &msgs[20], (const upb_def*)(&msgs[21]), 5, 0, {0},&reftables [146], &reftables[147]),
5068 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 3, &msgs[4], (const upb_def*)(&msgs[5]), 3, 0, {0},&reftable s[144], &reftables[145]), 5574 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[0], NULL, 32, 8, {0},&reftables[148], &reftables[149]),
5069 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 8, &msgs[8], (const upb_def*)(&msgs[10]), 20, 4, {0},&reftab les[146], &reftables[147]), 5575 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[5], NULL, 4, 1, {0},&reftables[150], &reftables[151]),
5070 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 3, &msgs[14], (const upb_def*)(&msgs[15]), 7, 1, {0},&reftab les[148], &reftables[149]), 5576 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[9], NULL, 22, 6, {0},&reftables[152], &reftables[153]),
5071 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 4, &msgs[12], (const upb_def*)(&msgs[13]), 3, 0, {0},&reftab les[150], &reftables[151]), 5577 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[7], NULL, 4, 1, {0},&reftables[154], &reftables[155]),
5072 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[12], NULL, 10, 3, {0},&reftables[152], &reftable s[153]), 5578 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[13], NULL, 4, 1, {0},&reftables[156], &reftables[157]),
5073 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[8], NULL, 25, 7, {0},&reftables[154], &reftables[155 ]), 5579 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "name", 1, &msgs[16], NULL, 8, 2, {0},&reftables[158], &reftables[159]),
5074 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "packed", 2, &msgs[7], NULL, 7, 2, {0},&reftables[156], &reftables[157]), 5580 UPB_FIELDDEF_INIT(UPB_LABEL_REQUIRED, UPB_TYPE_STRING, 0, false, false, false, false, "name_part", 1, &msgs[21], NULL, 2, 0, {0},&reftables[160], &reftables[1 61]),
5075 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, true, "path", 1, &msgs[17], NULL, 4, 0, {0},&reftables[158], & reftables[159]), 5581 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT64, UPB_INTFMT_VARIABLE, fal se, false, false, false, "negative_int_value", 5, &msgs[20], NULL, 10, 3, {0},&r eftables[162], &reftables[163]),
5076 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, fa lse, false, false, false, "positive_int_value", 4, &msgs[18], NULL, 9, 2, {0},&r eftables[160], &reftables[161]), 5582 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "nested_type", 3, &msgs[0], (const upb_def*)(&msgs[0]), 15, 1, {0},&ref tables[164], &reftables[165]),
5077 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "public_dependency", 10, &msgs[8], NULL, 35, 9, {0},&re ftables[162], &reftables[163]), 5583 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "no_standard_descriptor_accessor", 2, &msgs[12], NULL, 7, 2, {0},&reftable s[166], &reftables[167]),
5078 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "py_generic_services", 18, &msgs[10], NULL, 19, 8, {0},&reftables[164], &r eftables[165]), 5584 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "number", 2, &msgs[5], NULL, 7, 2, {0},&reftables[168], &reftables[169]),
5079 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "service", 6, &msgs[8], (const upb_def*)(&msgs[14]), 16, 2, {0},&reftab les[166], &reftables[167]), 5585 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "number", 3, &msgs[7], NULL, 10, 3, {0},&reftables[170] , &reftables[171]),
5080 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "source_code_info", 9, &msgs[8], (const upb_def*)(&msgs[16]), 21, 5, {0 },&reftables[168], &reftables[169]), 5586 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "objc_class_prefix", 36, &msgs[11], NULL, 24, 13, {0},&reftables[172], & reftables[173]),
5081 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, true, "span", 2, &msgs[17], NULL, 7, 1, {0},&reftables[170], & reftables[171]), 5587 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "oneof_decl", 8, &msgs[0], (const upb_def*)(&msgs[15]), 28, 6, {0},&ref tables[174], &reftables[175]),
5082 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[172], &reftables[173]), 5588 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "oneof_index", 9, &msgs[7], NULL, 19, 8, {0},&reftables [176], &reftables[177]),
5083 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[18], NULL, 12, 5, {0},&reftables[174], &reftable s[175]), 5589 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "optimize_for", 9, &msgs[11], (const upb_def*)(&enums[4]), 12, 3, {0},&ref tables[178], &reftables[179]),
5084 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[17], NULL, 11, 3, {0},&reftables[176], &re ftables[177]), 5590 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 7, &msgs[0], (const upb_def*)(&msgs[12]), 25, 5, {0},&reftab les[180], &reftables[181]),
5085 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "type", 5, &msgs[6], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[17 8], &reftables[179]), 5591 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 8, &msgs[9], (const upb_def*)(&msgs[11]), 20, 4, {0},&reftab les[182], &reftables[183]),
5086 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[6], NULL, 13, 6, {0},&reftables[180], &reftables[1 81]), 5592 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 4, &msgs[13], (const upb_def*)(&msgs[14]), 3, 0, {0},&reftab les[184], &reftables[185]),
5087 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[5], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[182], &reftables[183]), 5593 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 8, &msgs[7], (const upb_def*)(&msgs[8]), 3, 0, {0},&reftable s[186], &reftables[187]),
5088 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[15], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[184], &reftables[185]), 5594 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 3, &msgs[16], (const upb_def*)(&msgs[17]), 7, 1, {0},&reftab les[188], &reftables[189]),
5089 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[3], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[186], &reftables[187]), 5595 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 3, &msgs[5], (const upb_def*)(&msgs[6]), 3, 0, {0},&reftable s[190], &reftables[191]),
5090 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[13], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[188], &reftables[189]), 5596 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "options", 3, &msgs[3], (const upb_def*)(&msgs[4]), 7, 1, {0},&reftable s[192], &reftables[193]),
5091 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[10], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[190], &reftables[191]), 5597 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "output_type", 3, &msgs[13], NULL, 10, 3, {0},&reftables[194], &reftable s[195]),
5092 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[192], &reftables[193]), 5598 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "package", 2, &msgs[9], NULL, 25, 7, {0},&reftables[196], &reftables[197 ]),
5093 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[7], (const upb_def*)(&msgs[18]), 5, 0, {0},&reftables[194], &reftables[195]), 5599 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "packed", 2, &msgs[8], NULL, 7, 2, {0},&reftables[198], &reftables[199]),
5094 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "value", 2, &msgs[2], (const upb_def*)(&msgs[4]), 6, 0, {0},&reftables[ 196], &reftables[197]), 5600 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, true, "path", 1, &msgs[19], NULL, 4, 0, {0},&reftables[200], & reftables[201]),
5095 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "weak", 10, &msgs[7], NULL, 13, 6, {0},&reftables[198], &reftables[199]), 5601 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_UINT64, UPB_INTFMT_VARIABLE, fa lse, false, false, false, "positive_int_value", 4, &msgs[20], NULL, 9, 2, {0},&r eftables[202], &reftables[203]),
5096 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "weak_dependency", 11, &msgs[8], NULL, 38, 10, {0},&ref tables[200], &reftables[201]), 5602 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "public_dependency", 10, &msgs[9], NULL, 35, 9, {0},&re ftables[204], &reftables[205]),
5603 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "py_generic_services", 18, &msgs[11], NULL, 19, 8, {0},&reftables[206], &r eftables[207]),
5604 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_STRING, 0, false, false, false, false, "reserved_name", 10, &msgs[0], NULL, 37, 9, {0},&reftables[208], &reftab les[209]),
5605 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "reserved_range", 9, &msgs[0], (const upb_def*)(&msgs[2]), 31, 7, {0},& reftables[210], &reftables[211]),
5606 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "server_streaming", 6, &msgs[13], NULL, 14, 5, {0},&reftables[212], &refta bles[213]),
5607 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "service", 6, &msgs[9], (const upb_def*)(&msgs[16]), 16, 2, {0},&reftab les[214], &reftables[215]),
5608 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_MESSAGE, 0, false, false, false , false, "source_code_info", 9, &msgs[9], (const upb_def*)(&msgs[18]), 21, 5, {0 },&reftables[216], &reftables[217]),
5609 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, true, "span", 2, &msgs[19], NULL, 7, 1, {0},&reftables[218], & reftables[219]),
5610 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "start", 1, &msgs[2], NULL, 2, 0, {0},&reftables[220], &reftables[221]),
5611 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "start", 1, &msgs[1], NULL, 2, 0, {0},&reftables[222], &reftables[223]),
5612 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BYTES, 0, false, false, false, false, "string_value", 7, &msgs[20], NULL, 12, 5, {0},&reftables[224], &reftable s[225]),
5613 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "syntax", 12, &msgs[9], NULL, 39, 11, {0},&reftables[226], &reftables[22 7]),
5614 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "trailing_comments", 4, &msgs[19], NULL, 11, 3, {0},&reftables[228], &re ftables[229]),
5615 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_ENUM, 0, false, false, false, f alse, "type", 5, &msgs[7], (const upb_def*)(&enums[1]), 12, 5, {0},&reftables[23 0], &reftables[231]),
5616 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_STRING, 0, false, false, false, false, "type_name", 6, &msgs[7], NULL, 13, 6, {0},&reftables[232], &reftables[2 33]),
5617 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[11], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[234], &reftables[235]),
5618 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[12], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[236], &reftables[237]),
5619 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[6], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[238], &reftables[239]),
5620 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[4], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[240], &reftables[241]),
5621 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[8], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[242], &reftables[243]),
5622 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[14], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[244], &reftables[245]),
5623 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "uninterpreted_option", 999, &msgs[17], (const upb_def*)(&msgs[20]), 5, 0, {0},&reftables[246], &reftables[247]),
5624 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_MESSAGE, 0, false, false, false , false, "value", 2, &msgs[3], (const upb_def*)(&msgs[5]), 6, 0, {0},&reftables[ 248], &reftables[249]),
5625 UPB_FIELDDEF_INIT(UPB_LABEL_OPTIONAL, UPB_TYPE_BOOL, 0, false, false, false, f alse, "weak", 10, &msgs[8], NULL, 11, 6, {0},&reftables[250], &reftables[251]),
5626 UPB_FIELDDEF_INIT(UPB_LABEL_REPEATED, UPB_TYPE_INT32, UPB_INTFMT_VARIABLE, fal se, false, false, false, "weak_dependency", 11, &msgs[9], NULL, 38, 10, {0},&ref tables[252], &reftables[253]),
5097 }; 5627 };
5098 5628
5099 static const upb_enumdef enums[4] = { 5629 static const upb_enumdef enums[5] = {
5100 UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Label", UPB_STRTABLE_IN IT(3, 3, UPB_CTYPE_INT32, 2, &strentries[160]), UPB_INTTABLE_INIT(0, 0, UPB_CTYP E_CSTR, 0, NULL, &arrays[202], 4, 3), 0, &reftables[202], &reftables[203]), 5630 UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Label", UPB_STRTABLE_IN IT(3, 3, UPB_CTYPE_INT32, 2, &strentries[188]), UPB_INTTABLE_INIT(0, 0, UPB_CTYP E_CSTR, 0, NULL, &arrays[151], 4, 3), 0, &reftables[254], &reftables[255]),
5101 UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Type", UPB_STRTABLE_INI T(18, 31, UPB_CTYPE_INT32, 5, &strentries[164]), UPB_INTTABLE_INIT(0, 0, UPB_CTY PE_CSTR, 0, NULL, &arrays[206], 19, 18), 0, &reftables[204], &reftables[205]), 5631 UPB_ENUMDEF_INIT("google.protobuf.FieldDescriptorProto.Type", UPB_STRTABLE_INI T(18, 31, UPB_CTYPE_INT32, 5, &strentries[192]), UPB_INTTABLE_INIT(0, 0, UPB_CTY PE_CSTR, 0, NULL, &arrays[155], 19, 18), 0, &reftables[256], &reftables[257]),
5102 UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.CType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[196]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[225], 3, 3), 0, &reftables[206], &reftables[207]), 5632 UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.CType", UPB_STRTABLE_INIT(3, 3, UPB_CTYPE_INT32, 2, &strentries[224]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[174], 3, 3), 0, &reftables[258], &reftables[259]),
5103 UPB_ENUMDEF_INIT("google.protobuf.FileOptions.OptimizeMode", UPB_STRTABLE_INIT (3, 3, UPB_CTYPE_INT32, 2, &strentries[200]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_ CSTR, 0, NULL, &arrays[228], 4, 3), 0, &reftables[208], &reftables[209]), 5633 UPB_ENUMDEF_INIT("google.protobuf.FieldOptions.JSType", UPB_STRTABLE_INIT(3, 3 , UPB_CTYPE_INT32, 2, &strentries[228]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_CSTR, 0, NULL, &arrays[177], 3, 3), 0, &reftables[260], &reftables[261]),
5634 UPB_ENUMDEF_INIT("google.protobuf.FileOptions.OptimizeMode", UPB_STRTABLE_INIT (3, 3, UPB_CTYPE_INT32, 2, &strentries[232]), UPB_INTTABLE_INIT(0, 0, UPB_CTYPE_ CSTR, 0, NULL, &arrays[180], 4, 3), 0, &reftables[262], &reftables[263]),
5104 }; 5635 };
5105 5636
5106 static const upb_tabent strentries[236] = { 5637 static const upb_tabent strentries[236] = {
5107 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR _INIT(&fields[14]), NULL}, 5638 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR _INIT(&fields[22]), NULL},
5108 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5639 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5109 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5640 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "reserved_name"), UPB_TABVALUE _PTR_INIT(&fields[82]), NULL},
5110 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[38]), NULL}, 5641 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[52]), NULL},
5111 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5642 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5112 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5643 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5113 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5644 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5114 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INI T(&fields[16]), NULL}, 5645 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INI T(&fields[25]), &strentries[12]},
5115 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVAL UE_PTR_INIT(&fields[15]), NULL}, 5646 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVAL UE_PTR_INIT(&fields[24]), &strentries[14]},
5116 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5647 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5117 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_P TR_INIT(&fields[44]), NULL}, 5648 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_P TR_INIT(&fields[60]), NULL},
5118 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5649 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5119 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5650 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "reserved_range"), UPB_TABVALU E_PTR_INIT(&fields[83]), NULL},
5120 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5651 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[68]), NULL},
5121 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[49]), NULL}, 5652 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "oneof_decl"), UPB_TABVALUE_PT R_INIT(&fields[65]), NULL},
5122 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR _INIT(&fields[9]), &strentries[14]}, 5653 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR _INIT(&fields[19]), &strentries[13]},
5123 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INI T(&fields[66]), NULL}, 5654 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INI T(&fields[89]), NULL},
5124 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT( &fields[8]), NULL}, 5655 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT( &fields[18]), NULL},
5125 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5656 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5126 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5657 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5127 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5658 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INI T(&fields[88]), NULL},
5128 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INI T(&fields[78]), NULL}, 5659 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT( &fields[17]), NULL},
5129 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[50]), NULL}, 5660 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5130 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[40]), &strentries[22]}, 5661 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5131 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[73]), NULL}, 5662 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5132 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5663 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INI T(&fields[102]), NULL},
5664 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[74]), NULL},
5665 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[49]), &strentries[26]},
5666 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[98]), NULL},
5667 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[13]), NULL},
5133 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_P TR_INIT(&fields[1]), NULL}, 5668 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_P TR_INIT(&fields[1]), NULL},
5134 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5669 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5135 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN IT(&fields[47]), NULL}, 5670 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN IT(&fields[62]), NULL},
5136 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5671 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5137 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[52]), NULL}, 5672 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[73]), NULL},
5138 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[37]), &strentries[30]}, 5673 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[53]), &strentries[34]},
5139 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[71]), NULL}, 5674 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[97]), NULL},
5140 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5675 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[15]), NULL},
5141 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5676 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5142 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5677 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5143 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5678 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "oneof_index"), UPB_TABVALUE_P TR_INIT(&fields[66]), NULL},
5144 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INI T(&fields[27]), NULL}, 5679 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INI T(&fields[40]), NULL},
5145 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5680 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5146 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[41]), NULL}, 5681 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[55]), NULL},
5147 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5682 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5148 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5683 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5149 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5684 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5150 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5685 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5151 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN IT(&fields[46]), &strentries[49]}, 5686 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN IT(&fields[63]), &strentries[53]},
5152 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5687 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5153 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5688 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_ INIT(&fields[21]), NULL},
5154 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR _INIT(&fields[70]), NULL}, 5689 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR _INIT(&fields[94]), NULL},
5155 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_ INIT(&fields[12]), NULL}, 5690 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "json_name"), UPB_TABVALUE_PTR _INIT(&fields[38]), NULL},
5156 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT (&fields[69]), &strentries[48]}, 5691 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT (&fields[93]), &strentries[50]},
5157 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE _PTR_INIT(&fields[4]), NULL}, 5692 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE _PTR_INIT(&fields[7]), NULL},
5158 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[51]), NULL}, 5693 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[71]), NULL},
5159 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "experimental_map_key"), UPB_T ABVALUE_PTR_INIT(&fields[11]), &strentries[67]}, 5694 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[99]), NULL},
5160 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5695 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5161 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT (&fields[79]), NULL}, 5696 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT (&fields[103]), NULL},
5162 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5697 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5163 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5698 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5164 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5699 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5165 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5700 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5166 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_IN IT(&fields[58]), NULL}, 5701 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_IN IT(&fields[77]), NULL},
5167 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT (&fields[28]), NULL}, 5702 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT (&fields[41]), NULL},
5168 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5703 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5169 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INI T(&fields[3]), NULL}, 5704 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INI T(&fields[6]), NULL},
5170 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5705 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5171 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5706 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "jstype"), UPB_TABVALUE_PTR_IN IT(&fields[39]), NULL},
5172 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[6]), NULL}, 5707 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[10]), NULL},
5173 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5708 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5174 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[77]), NULL}, 5709 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5175 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR _INIT(&fields[13]), NULL}, 5710 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR _INIT(&fields[23]), NULL},
5176 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVAL UE_PTR_INIT(&fields[80]), NULL}, 5711 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVAL UE_PTR_INIT(&fields[104]), NULL},
5177 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5712 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5178 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[34]), NULL}, 5713 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[54]), NULL},
5179 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_I NIT(&fields[63]), NULL}, 5714 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_I NIT(&fields[85]), NULL},
5180 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5715 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5181 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVA LUE_PTR_INIT(&fields[64]), NULL}, 5716 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVA LUE_PTR_INIT(&fields[86]), NULL},
5182 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5717 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5183 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5718 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5184 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5719 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "syntax"), UPB_TABVALUE_PTR_IN IT(&fields[91]), NULL},
5185 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PT R_INIT(&fields[5]), NULL}, 5720 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PT R_INIT(&fields[8]), NULL},
5186 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_ PTR_INIT(&fields[32]), NULL}, 5721 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_ PTR_INIT(&fields[47]), NULL},
5187 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_I NIT(&fields[57]), NULL}, 5722 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_I NIT(&fields[76]), NULL},
5188 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[53]), &strentries[82]}, 5723 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[69]), &strentries[86]},
5189 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR _INIT(&fields[10]), NULL}, 5724 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR _INIT(&fields[20]), NULL},
5190 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABV ALUE_PTR_INIT(&fields[61]), &strentries[81]}, 5725 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABV ALUE_PTR_INIT(&fields[80]), &strentries[85]},
5191 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5726 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5192 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT (&fields[17]), NULL}, 5727 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT (&fields[26]), NULL},
5193 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5728 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5194 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5729 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5195 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[75]), NULL}, 5730 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5196 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5731 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5197 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TA BVALUE_PTR_INIT(&fields[2]), NULL}, 5732 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TA BVALUE_PTR_INIT(&fields[3]), NULL},
5198 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5733 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "csharp_namespace"), UPB_TABVA LUE_PTR_INIT(&fields[5]), NULL},
5199 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TA BVALUE_PTR_INIT(&fields[24]), NULL}, 5734 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5200 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5735 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5201 {UPB_TABKEY_STR("\025", "\000", "\000", "\000", "java_generic_services"), UPB_ TABVALUE_PTR_INIT(&fields[23]), &strentries[102]}, 5736 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5202 {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash "), UPB_TABVALUE_PTR_INIT(&fields[22]), NULL}, 5737 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5203 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5738 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5204 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5739 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5205 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5740 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5206 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PT R_INIT(&fields[18]), NULL}, 5741 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PT R_INIT(&fields[27]), NULL},
5207 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_ PTR_INIT(&fields[26]), NULL}, 5742 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_ PTR_INIT(&fields[35]), &strentries[120]},
5208 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_ PTR_INIT(&fields[48]), NULL}, 5743 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5209 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TA BVALUE_PTR_INIT(&fields[62]), NULL}, 5744 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5210 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_T ABVALUE_PTR_INIT(&fields[25]), NULL}, 5745 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_T ABVALUE_PTR_INIT(&fields[34]), NULL},
5211 {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UP B_TABVALUE_PTR_INIT(&fields[31]), &strentries[106]}, 5746 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[95]), NULL},
5212 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5747 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5213 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[76]), NULL}, 5748 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5214 {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "no_standard_descriptor_access or"), UPB_TABVALUE_PTR_INIT(&fields[45]), NULL}, 5749 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5215 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5750 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TA BVALUE_PTR_INIT(&fields[33]), &strentries[117]},
5216 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5751 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5217 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5752 {UPB_TABKEY_STR("\025", "\000", "\000", "\000", "java_generic_services"), UPB_ TABVALUE_PTR_INIT(&fields[32]), &strentries[118]},
5218 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[39]), NULL}, 5753 {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash "), UPB_TABVALUE_PTR_INIT(&fields[31]), NULL},
5219 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PT R_INIT(&fields[20]), NULL}, 5754 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5220 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5755 {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "javanano_use_deprecated_packa ge"), UPB_TABVALUE_PTR_INIT(&fields[37]), &strentries[123]},
5221 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_P TR_INIT(&fields[56]), NULL}, 5756 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TA BVALUE_PTR_INIT(&fields[81]), NULL},
5222 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[55]), NULL}, 5757 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_ PTR_INIT(&fields[67]), NULL},
5223 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[74]), NULL}, 5758 {UPB_TABKEY_STR("\026", "\000", "\000", "\000", "java_string_check_utf8"), UPB _TABVALUE_PTR_INIT(&fields[36]), NULL},
5224 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5759 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[12]), &strentries[119]},
5225 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5760 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "objc_class_prefix"), UPB_TABV ALUE_PTR_INIT(&fields[64]), NULL},
5226 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5761 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "cc_enable_arenas"), UPB_TABVA LUE_PTR_INIT(&fields[2]), NULL},
5227 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5762 {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UP B_TABVALUE_PTR_INIT(&fields[46]), &strentries[128]},
5228 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[54]), &strentries[122]}, 5763 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5229 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "method"), UPB_TABVALUE_PTR_IN IT(&fields[33]), NULL}, 5764 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5230 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[35]), &strentries[121]}, 5765 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5231 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[72]), NULL}, 5766 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[96]), NULL},
5232 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5767 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[9]), NULL},
5233 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5768 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "map_entry"), UPB_TABVALUE_PTR _INIT(&fields[45]), NULL},
5234 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5769 {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "no_standard_descriptor_access or"), UPB_TABVALUE_PTR_INIT(&fields[61]), NULL},
5235 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5770 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5236 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5771 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "client_streaming"), UPB_TABVA LUE_PTR_INIT(&fields[4]), NULL},
5237 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_ INIT(&fields[30]), NULL}, 5772 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "server_streaming"), UPB_TABVA LUE_PTR_INIT(&fields[84]), NULL},
5238 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5773 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[56]), NULL},
5239 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5774 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PT R_INIT(&fields[29]), NULL},
5240 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5775 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5241 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5776 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_P TR_INIT(&fields[75]), NULL},
5242 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT (&fields[65]), &strentries[139]}, 5777 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[70]), NULL},
5243 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5778 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[100]), NULL},
5244 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABV ALUE_PTR_INIT(&fields[68]), NULL}, 5779 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[11]), NULL},
5245 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVA LUE_PTR_INIT(&fields[29]), &strentries[137]}, 5780 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5246 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT (&fields[59]), NULL}, 5781 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5247 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_ PTR_INIT(&fields[7]), NULL}, 5782 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5248 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5783 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5249 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5784 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5250 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[36]), NULL}, 5785 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[50]), NULL},
5251 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5786 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5252 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5787 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I NIT(&fields[72]), &strentries[150]},
5253 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5788 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "method"), UPB_TABVALUE_PTR_IN IT(&fields[48]), NULL},
5254 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TAB VALUE_PTR_INIT(&fields[43]), NULL}, 5789 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[57]), &strentries[149]},
5790 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T ABVALUE_PTR_INIT(&fields[101]), NULL},
5791 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT R_INIT(&fields[14]), NULL},
5792 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5793 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5794 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5795 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5796 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_ INIT(&fields[44]), NULL},
5797 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5798 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5799 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5800 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5801 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT (&fields[87]), &strentries[167]},
5802 {UPB_TABKEY_STR("\031", "\000", "\000", "\000", "leading_detached_comments"), UPB_TABVALUE_PTR_INIT(&fields[43]), &strentries[165]},
5803 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABV ALUE_PTR_INIT(&fields[92]), NULL},
5804 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVA LUE_PTR_INIT(&fields[42]), &strentries[164]},
5805 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT (&fields[78]), NULL},
5806 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_ PTR_INIT(&fields[16]), NULL},
5807 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5808 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5809 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT (&fields[51]), NULL},
5810 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5811 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5812 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5813 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TAB VALUE_PTR_INIT(&fields[59]), NULL},
5255 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVAL UE_PTR_INIT(&fields[0]), NULL}, 5814 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVAL UE_PTR_INIT(&fields[0]), NULL},
5256 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5815 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5257 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5816 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5258 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5817 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5259 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5818 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5260 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TAB VALUE_PTR_INIT(&fields[60]), NULL}, 5819 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TAB VALUE_PTR_INIT(&fields[79]), NULL},
5261 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVA LUE_PTR_INIT(&fields[19]), NULL}, 5820 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVA LUE_PTR_INIT(&fields[28]), NULL},
5262 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_ PTR_INIT(&fields[67]), &strentries[154]}, 5821 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_ PTR_INIT(&fields[90]), &strentries[182]},
5263 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5822 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5264 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5823 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5265 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_ PTR_INIT(&fields[21]), NULL}, 5824 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_ PTR_INIT(&fields[30]), NULL},
5266 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR _INIT(&fields[42]), NULL}, 5825 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR _INIT(&fields[58]), NULL},
5267 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALU E_INT_INIT(2), &strentries[162]}, 5826 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALU E_INT_INIT(2), &strentries[190]},
5268 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5827 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5269 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALU E_INT_INIT(3), NULL}, 5828 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALU E_INT_INIT(3), NULL},
5270 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALU E_INT_INIT(1), NULL}, 5829 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALU E_INT_INIT(1), NULL},
5271 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_ INT_INIT(6), NULL}, 5830 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_ INT_INIT(6), NULL},
5272 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5831 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5273 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5832 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5274 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5833 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5275 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5834 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5276 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_I NT_INIT(9), NULL}, 5835 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_I NT_INIT(9), NULL},
5277 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_IN T_INIT(2), &strentries[193]}, 5836 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_IN T_INIT(2), &strentries[221]},
5278 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_I NT_INIT(1), NULL}, 5837 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_I NT_INIT(1), NULL},
5279 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5838 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5280 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_IN T_INIT(5), NULL}, 5839 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_IN T_INIT(5), NULL},
5281 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE _INT_INIT(15), NULL}, 5840 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE _INT_INIT(15), NULL},
5282 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_ INT_INIT(7), NULL}, 5841 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_ INT_INIT(7), NULL},
5283 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5842 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5284 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_ INT_INIT(11), &strentries[194]}, 5843 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_ INT_INIT(11), &strentries[222]},
5285 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5844 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5286 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5845 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5287 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_IN T_INIT(3), &strentries[191]}, 5846 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_IN T_INIT(3), &strentries[219]},
5288 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5847 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5289 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5848 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5290 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5849 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5291 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5850 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5292 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT _INIT(14), NULL}, 5851 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT _INIT(14), NULL},
5293 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_I NT_INIT(13), NULL}, 5852 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_I NT_INIT(13), NULL},
5294 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5853 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5295 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_I NT_INIT(4), &strentries[190]}, 5854 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_I NT_INIT(4), &strentries[218]},
5296 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5855 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5297 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE _INT_INIT(16), NULL}, 5856 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE _INT_INIT(16), NULL},
5298 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_IN T_INIT(12), NULL}, 5857 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_IN T_INIT(12), NULL},
5299 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT64"), UPB_TABVALUE_I NT_INIT(18), NULL}, 5858 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT64"), UPB_TABVALUE_I NT_INIT(18), NULL},
5300 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_BOOL"), UPB_TABVALUE_INT _INIT(8), NULL}, 5859 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_BOOL"), UPB_TABVALUE_INT _INIT(8), NULL},
5301 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_GROUP"), UPB_TABVALUE_IN T_INIT(10), NULL}, 5860 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_GROUP"), UPB_TABVALUE_IN T_INIT(10), NULL},
5302 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_I NT_INIT(17), NULL}, 5861 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_I NT_INIT(17), NULL},
5303 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5862 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5304 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT (1), NULL}, 5863 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT (1), NULL},
5305 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_IN IT(0), &strentries[197]}, 5864 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_IN IT(0), &strentries[225]},
5306 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_ INT_INIT(2), NULL}, 5865 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_ INT_INIT(2), NULL},
5866 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5867 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NORMAL"), UPB_TABVALUE_INT _INIT(0), NULL},
5868 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NUMBER"), UPB_TABVALUE_INT _INIT(2), NULL},
5869 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_STRING"), UPB_TABVALUE_INT _INIT(1), NULL},
5307 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT _INIT(2), NULL}, 5870 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT _INIT(2), NULL},
5308 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INI T(1), &strentries[203]}, 5871 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INI T(1), &strentries[235]},
5309 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5872 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5310 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_ INT_INIT(3), NULL}, 5873 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_ INT_INIT(3), NULL},
5311 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5312 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5313 {UPB_TABKEY_STR("\047", "\000", "\000", "\000", "google.protobuf.SourceCodeInf o.Location"), UPB_TABVALUE_PTR_INIT(&msgs[17]), NULL},
5314 {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.Uninterpreted Option"), UPB_TABVALUE_PTR_INIT(&msgs[18]), NULL},
5315 {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.FileDescripto rProto"), UPB_TABVALUE_PTR_INIT(&msgs[8]), NULL},
5316 {UPB_TABKEY_STR("\045", "\000", "\000", "\000", "google.protobuf.MethodDescrip torProto"), UPB_TABVALUE_PTR_INIT(&msgs[12]), NULL},
5317 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5318 {UPB_TABKEY_STR("\040", "\000", "\000", "\000", "google.protobuf.EnumValueOpti ons"), UPB_TABVALUE_PTR_INIT(&msgs[5]), NULL},
5319 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5320 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5321 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5322 {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "google.protobuf.DescriptorPro to"), UPB_TABVALUE_PTR_INIT(&msgs[0]), &strentries[228]},
5323 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5324 {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.SourceCodeInf o"), UPB_TABVALUE_PTR_INIT(&msgs[16]), NULL},
5325 {UPB_TABKEY_STR("\051", "\000", "\000", "\000", "google.protobuf.FieldDescript orProto.Type"), UPB_TABVALUE_PTR_INIT(&enums[1]), NULL},
5326 {UPB_TABKEY_STR("\056", "\000", "\000", "\000", "google.protobuf.DescriptorPro to.ExtensionRange"), UPB_TABVALUE_PTR_INIT(&msgs[1]), NULL},
5327 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5328 {UPB_TABKEY_STR("\050", "\000", "\000", "\000", "google.protobuf.EnumValueDesc riptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[4]), NULL},
5329 {UPB_TABKEY_STR("\034", "\000", "\000", "\000", "google.protobuf.FieldOptions" ), UPB_TABVALUE_PTR_INIT(&msgs[7]), NULL},
5330 {UPB_TABKEY_STR("\033", "\000", "\000", "\000", "google.protobuf.FileOptions") , UPB_TABVALUE_PTR_INIT(&msgs[10]), NULL},
5331 {UPB_TABKEY_STR("\043", "\000", "\000", "\000", "google.protobuf.EnumDescripto rProto"), UPB_TABVALUE_PTR_INIT(&msgs[2]), &strentries[233]},
5332 {UPB_TABKEY_STR("\052", "\000", "\000", "\000", "google.protobuf.FieldDescript orProto.Label"), UPB_TABVALUE_PTR_INIT(&enums[0]), NULL},
5333 {UPB_TABKEY_STR("\046", "\000", "\000", "\000", "google.protobuf.ServiceDescri ptorProto"), UPB_TABVALUE_PTR_INIT(&msgs[14]), NULL},
5334 {UPB_TABKEY_STR("\042", "\000", "\000", "\000", "google.protobuf.FieldOptions. CType"), UPB_TABVALUE_PTR_INIT(&enums[2]), &strentries[229]},
5335 {UPB_TABKEY_STR("\041", "\000", "\000", "\000", "google.protobuf.FileDescripto rSet"), UPB_TABVALUE_PTR_INIT(&msgs[9]), &strentries[235]},
5336 {UPB_TABKEY_STR("\033", "\000", "\000", "\000", "google.protobuf.EnumOptions") , UPB_TABVALUE_PTR_INIT(&msgs[3]), NULL},
5337 {UPB_TABKEY_STR("\044", "\000", "\000", "\000", "google.protobuf.FieldDescript orProto"), UPB_TABVALUE_PTR_INIT(&msgs[6]), NULL},
5338 {UPB_TABKEY_STR("\050", "\000", "\000", "\000", "google.protobuf.FileOptions.O ptimizeMode"), UPB_TABVALUE_PTR_INIT(&enums[3]), &strentries[221]},
5339 {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.ServiceOption s"), UPB_TABVALUE_PTR_INIT(&msgs[15]), NULL},
5340 {UPB_TABKEY_STR("\036", "\000", "\000", "\000", "google.protobuf.MessageOption s"), UPB_TABVALUE_PTR_INIT(&msgs[11]), NULL},
5341 {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "google.protobuf.MethodOptions "), UPB_TABVALUE_PTR_INIT(&msgs[13]), &strentries[226]},
5342 {UPB_TABKEY_STR("\054", "\000", "\000", "\000", "google.protobuf.Uninterpreted Option.NamePart"), UPB_TABVALUE_PTR_INIT(&msgs[19]), NULL},
5343 }; 5874 };
5344 5875
5345 static const upb_tabent intentries[14] = { 5876 static const upb_tabent intentries[18] = {
5346 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5877 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5347 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[73]), NULL}, 5878 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL},
5348 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5879 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5349 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL}, 5880 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL},
5350 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5881 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5351 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL}, 5882 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL},
5352 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5883 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5353 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL}, 5884 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL},
5354 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5885 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5355 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL}, 5886 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL},
5356 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5887 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5357 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL}, 5888 {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL},
5358 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, 5889 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5359 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[72]), NULL}, 5890 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL},
5891 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5892 {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL},
5893 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL},
5894 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL},
5360 }; 5895 };
5361 5896
5362 static const upb_tabval arrays[232] = { 5897 static const upb_tabval arrays[184] = {
5363 UPB_TABVALUE_EMPTY_INIT, 5898 UPB_TABVALUE_EMPTY_INIT,
5899 UPB_TABVALUE_PTR_INIT(&fields[52]),
5900 UPB_TABVALUE_PTR_INIT(&fields[25]),
5901 UPB_TABVALUE_PTR_INIT(&fields[60]),
5902 UPB_TABVALUE_PTR_INIT(&fields[19]),
5903 UPB_TABVALUE_PTR_INIT(&fields[24]),
5904 UPB_TABVALUE_PTR_INIT(&fields[22]),
5905 UPB_TABVALUE_PTR_INIT(&fields[68]),
5906 UPB_TABVALUE_PTR_INIT(&fields[65]),
5907 UPB_TABVALUE_PTR_INIT(&fields[83]),
5908 UPB_TABVALUE_PTR_INIT(&fields[82]),
5909 UPB_TABVALUE_EMPTY_INIT,
5910 UPB_TABVALUE_PTR_INIT(&fields[89]),
5911 UPB_TABVALUE_PTR_INIT(&fields[18]),
5912 UPB_TABVALUE_EMPTY_INIT,
5913 UPB_TABVALUE_PTR_INIT(&fields[88]),
5914 UPB_TABVALUE_PTR_INIT(&fields[17]),
5915 UPB_TABVALUE_EMPTY_INIT,
5916 UPB_TABVALUE_PTR_INIT(&fields[49]),
5917 UPB_TABVALUE_PTR_INIT(&fields[102]),
5918 UPB_TABVALUE_PTR_INIT(&fields[74]),
5919 UPB_TABVALUE_EMPTY_INIT,
5920 UPB_TABVALUE_EMPTY_INIT,
5921 UPB_TABVALUE_PTR_INIT(&fields[1]),
5922 UPB_TABVALUE_PTR_INIT(&fields[13]),
5923 UPB_TABVALUE_EMPTY_INIT,
5924 UPB_TABVALUE_PTR_INIT(&fields[53]),
5925 UPB_TABVALUE_PTR_INIT(&fields[62]),
5926 UPB_TABVALUE_PTR_INIT(&fields[73]),
5927 UPB_TABVALUE_EMPTY_INIT,
5928 UPB_TABVALUE_PTR_INIT(&fields[15]),
5929 UPB_TABVALUE_EMPTY_INIT,
5930 UPB_TABVALUE_PTR_INIT(&fields[55]),
5931 UPB_TABVALUE_PTR_INIT(&fields[21]),
5932 UPB_TABVALUE_PTR_INIT(&fields[63]),
5933 UPB_TABVALUE_PTR_INIT(&fields[40]),
5934 UPB_TABVALUE_PTR_INIT(&fields[93]),
5935 UPB_TABVALUE_PTR_INIT(&fields[94]),
5936 UPB_TABVALUE_PTR_INIT(&fields[7]),
5937 UPB_TABVALUE_PTR_INIT(&fields[71]),
5938 UPB_TABVALUE_PTR_INIT(&fields[66]),
5364 UPB_TABVALUE_PTR_INIT(&fields[38]), 5939 UPB_TABVALUE_PTR_INIT(&fields[38]),
5365 UPB_TABVALUE_PTR_INIT(&fields[16]), 5940 UPB_TABVALUE_EMPTY_INIT,
5366 UPB_TABVALUE_PTR_INIT(&fields[44]), 5941 UPB_TABVALUE_PTR_INIT(&fields[6]),
5942 UPB_TABVALUE_PTR_INIT(&fields[77]),
5943 UPB_TABVALUE_PTR_INIT(&fields[10]),
5944 UPB_TABVALUE_EMPTY_INIT,
5945 UPB_TABVALUE_PTR_INIT(&fields[41]),
5946 UPB_TABVALUE_PTR_INIT(&fields[39]),
5947 UPB_TABVALUE_EMPTY_INIT,
5948 UPB_TABVALUE_EMPTY_INIT,
5949 UPB_TABVALUE_EMPTY_INIT,
5950 UPB_TABVALUE_PTR_INIT(&fields[103]),
5951 UPB_TABVALUE_EMPTY_INIT,
5952 UPB_TABVALUE_PTR_INIT(&fields[54]),
5953 UPB_TABVALUE_PTR_INIT(&fields[76]),
5954 UPB_TABVALUE_PTR_INIT(&fields[8]),
5955 UPB_TABVALUE_PTR_INIT(&fields[47]),
5956 UPB_TABVALUE_PTR_INIT(&fields[20]),
5957 UPB_TABVALUE_PTR_INIT(&fields[85]),
5958 UPB_TABVALUE_PTR_INIT(&fields[23]),
5959 UPB_TABVALUE_PTR_INIT(&fields[69]),
5960 UPB_TABVALUE_PTR_INIT(&fields[86]),
5961 UPB_TABVALUE_PTR_INIT(&fields[80]),
5962 UPB_TABVALUE_PTR_INIT(&fields[104]),
5963 UPB_TABVALUE_PTR_INIT(&fields[91]),
5964 UPB_TABVALUE_EMPTY_INIT,
5965 UPB_TABVALUE_PTR_INIT(&fields[26]),
5966 UPB_TABVALUE_EMPTY_INIT,
5967 UPB_TABVALUE_PTR_INIT(&fields[35]),
5968 UPB_TABVALUE_EMPTY_INIT,
5969 UPB_TABVALUE_EMPTY_INIT,
5970 UPB_TABVALUE_EMPTY_INIT,
5971 UPB_TABVALUE_EMPTY_INIT,
5972 UPB_TABVALUE_EMPTY_INIT,
5973 UPB_TABVALUE_EMPTY_INIT,
5974 UPB_TABVALUE_PTR_INIT(&fields[34]),
5975 UPB_TABVALUE_PTR_INIT(&fields[67]),
5976 UPB_TABVALUE_PTR_INIT(&fields[33]),
5977 UPB_TABVALUE_PTR_INIT(&fields[27]),
5978 UPB_TABVALUE_EMPTY_INIT,
5979 UPB_TABVALUE_EMPTY_INIT,
5980 UPB_TABVALUE_EMPTY_INIT,
5981 UPB_TABVALUE_EMPTY_INIT,
5982 UPB_TABVALUE_PTR_INIT(&fields[3]),
5983 UPB_TABVALUE_PTR_INIT(&fields[32]),
5984 UPB_TABVALUE_PTR_INIT(&fields[81]),
5985 UPB_TABVALUE_EMPTY_INIT,
5986 UPB_TABVALUE_PTR_INIT(&fields[31]),
5987 UPB_TABVALUE_EMPTY_INIT,
5988 UPB_TABVALUE_EMPTY_INIT,
5989 UPB_TABVALUE_PTR_INIT(&fields[12]),
5990 UPB_TABVALUE_EMPTY_INIT,
5991 UPB_TABVALUE_EMPTY_INIT,
5992 UPB_TABVALUE_EMPTY_INIT,
5993 UPB_TABVALUE_PTR_INIT(&fields[36]),
5994 UPB_TABVALUE_EMPTY_INIT,
5995 UPB_TABVALUE_EMPTY_INIT,
5996 UPB_TABVALUE_EMPTY_INIT,
5997 UPB_TABVALUE_PTR_INIT(&fields[2]),
5998 UPB_TABVALUE_EMPTY_INIT,
5999 UPB_TABVALUE_EMPTY_INIT,
6000 UPB_TABVALUE_EMPTY_INIT,
6001 UPB_TABVALUE_EMPTY_INIT,
6002 UPB_TABVALUE_PTR_INIT(&fields[64]),
6003 UPB_TABVALUE_PTR_INIT(&fields[5]),
6004 UPB_TABVALUE_PTR_INIT(&fields[37]),
6005 UPB_TABVALUE_EMPTY_INIT,
6006 UPB_TABVALUE_PTR_INIT(&fields[46]),
6007 UPB_TABVALUE_PTR_INIT(&fields[61]),
5367 UPB_TABVALUE_PTR_INIT(&fields[9]), 6008 UPB_TABVALUE_PTR_INIT(&fields[9]),
5368 UPB_TABVALUE_PTR_INIT(&fields[15]), 6009 UPB_TABVALUE_EMPTY_INIT,
5369 UPB_TABVALUE_PTR_INIT(&fields[14]), 6010 UPB_TABVALUE_EMPTY_INIT,
5370 UPB_TABVALUE_PTR_INIT(&fields[49]), 6011 UPB_TABVALUE_EMPTY_INIT,
5371 UPB_TABVALUE_EMPTY_INIT, 6012 UPB_TABVALUE_PTR_INIT(&fields[45]),
5372 UPB_TABVALUE_PTR_INIT(&fields[66]), 6013 UPB_TABVALUE_EMPTY_INIT,
5373 UPB_TABVALUE_PTR_INIT(&fields[8]), 6014 UPB_TABVALUE_PTR_INIT(&fields[56]),
5374 UPB_TABVALUE_EMPTY_INIT, 6015 UPB_TABVALUE_PTR_INIT(&fields[29]),
5375 UPB_TABVALUE_PTR_INIT(&fields[40]), 6016 UPB_TABVALUE_PTR_INIT(&fields[75]),
5376 UPB_TABVALUE_PTR_INIT(&fields[78]),
5377 UPB_TABVALUE_PTR_INIT(&fields[50]),
5378 UPB_TABVALUE_EMPTY_INIT,
5379 UPB_TABVALUE_EMPTY_INIT,
5380 UPB_TABVALUE_PTR_INIT(&fields[1]),
5381 UPB_TABVALUE_EMPTY_INIT,
5382 UPB_TABVALUE_EMPTY_INIT,
5383 UPB_TABVALUE_EMPTY_INIT,
5384 UPB_TABVALUE_EMPTY_INIT,
5385 UPB_TABVALUE_EMPTY_INIT,
5386 UPB_TABVALUE_EMPTY_INIT,
5387 UPB_TABVALUE_PTR_INIT(&fields[37]),
5388 UPB_TABVALUE_PTR_INIT(&fields[47]),
5389 UPB_TABVALUE_PTR_INIT(&fields[52]),
5390 UPB_TABVALUE_EMPTY_INIT,
5391 UPB_TABVALUE_EMPTY_INIT,
5392 UPB_TABVALUE_EMPTY_INIT,
5393 UPB_TABVALUE_EMPTY_INIT,
5394 UPB_TABVALUE_EMPTY_INIT,
5395 UPB_TABVALUE_PTR_INIT(&fields[41]),
5396 UPB_TABVALUE_PTR_INIT(&fields[12]),
5397 UPB_TABVALUE_PTR_INIT(&fields[46]),
5398 UPB_TABVALUE_PTR_INIT(&fields[27]),
5399 UPB_TABVALUE_PTR_INIT(&fields[69]),
5400 UPB_TABVALUE_PTR_INIT(&fields[70]), 6017 UPB_TABVALUE_PTR_INIT(&fields[70]),
5401 UPB_TABVALUE_PTR_INIT(&fields[4]), 6018 UPB_TABVALUE_PTR_INIT(&fields[4]),
6019 UPB_TABVALUE_PTR_INIT(&fields[84]),
6020 UPB_TABVALUE_EMPTY_INIT,
6021 UPB_TABVALUE_EMPTY_INIT,
6022 UPB_TABVALUE_PTR_INIT(&fields[50]),
6023 UPB_TABVALUE_EMPTY_INIT,
6024 UPB_TABVALUE_PTR_INIT(&fields[57]),
6025 UPB_TABVALUE_PTR_INIT(&fields[48]),
6026 UPB_TABVALUE_PTR_INIT(&fields[72]),
6027 UPB_TABVALUE_EMPTY_INIT,
6028 UPB_TABVALUE_EMPTY_INIT,
6029 UPB_TABVALUE_PTR_INIT(&fields[44]),
6030 UPB_TABVALUE_EMPTY_INIT,
6031 UPB_TABVALUE_PTR_INIT(&fields[78]),
6032 UPB_TABVALUE_PTR_INIT(&fields[87]),
6033 UPB_TABVALUE_PTR_INIT(&fields[42]),
6034 UPB_TABVALUE_PTR_INIT(&fields[92]),
6035 UPB_TABVALUE_EMPTY_INIT,
6036 UPB_TABVALUE_PTR_INIT(&fields[43]),
6037 UPB_TABVALUE_EMPTY_INIT,
6038 UPB_TABVALUE_EMPTY_INIT,
5402 UPB_TABVALUE_PTR_INIT(&fields[51]), 6039 UPB_TABVALUE_PTR_INIT(&fields[51]),
5403 UPB_TABVALUE_EMPTY_INIT, 6040 UPB_TABVALUE_PTR_INIT(&fields[28]),
5404 UPB_TABVALUE_PTR_INIT(&fields[3]), 6041 UPB_TABVALUE_PTR_INIT(&fields[79]),
6042 UPB_TABVALUE_PTR_INIT(&fields[59]),
6043 UPB_TABVALUE_PTR_INIT(&fields[16]),
6044 UPB_TABVALUE_PTR_INIT(&fields[90]),
6045 UPB_TABVALUE_PTR_INIT(&fields[0]),
6046 UPB_TABVALUE_EMPTY_INIT,
5405 UPB_TABVALUE_PTR_INIT(&fields[58]), 6047 UPB_TABVALUE_PTR_INIT(&fields[58]),
5406 UPB_TABVALUE_PTR_INIT(&fields[6]),
5407 UPB_TABVALUE_EMPTY_INIT,
5408 UPB_TABVALUE_PTR_INIT(&fields[28]),
5409 UPB_TABVALUE_EMPTY_INIT,
5410 UPB_TABVALUE_EMPTY_INIT,
5411 UPB_TABVALUE_EMPTY_INIT,
5412 UPB_TABVALUE_PTR_INIT(&fields[11]),
5413 UPB_TABVALUE_PTR_INIT(&fields[79]),
5414 UPB_TABVALUE_EMPTY_INIT,
5415 UPB_TABVALUE_EMPTY_INIT,
5416 UPB_TABVALUE_EMPTY_INIT,
5417 UPB_TABVALUE_EMPTY_INIT,
5418 UPB_TABVALUE_EMPTY_INIT,
5419 UPB_TABVALUE_EMPTY_INIT,
5420 UPB_TABVALUE_EMPTY_INIT,
5421 UPB_TABVALUE_EMPTY_INIT,
5422 UPB_TABVALUE_EMPTY_INIT,
5423 UPB_TABVALUE_EMPTY_INIT,
5424 UPB_TABVALUE_EMPTY_INIT,
5425 UPB_TABVALUE_EMPTY_INIT,
5426 UPB_TABVALUE_EMPTY_INIT,
5427 UPB_TABVALUE_EMPTY_INIT,
5428 UPB_TABVALUE_EMPTY_INIT,
5429 UPB_TABVALUE_EMPTY_INIT,
5430 UPB_TABVALUE_EMPTY_INIT,
5431 UPB_TABVALUE_EMPTY_INIT,
5432 UPB_TABVALUE_EMPTY_INIT,
5433 UPB_TABVALUE_EMPTY_INIT,
5434 UPB_TABVALUE_EMPTY_INIT,
5435 UPB_TABVALUE_EMPTY_INIT,
5436 UPB_TABVALUE_PTR_INIT(&fields[34]),
5437 UPB_TABVALUE_PTR_INIT(&fields[57]),
5438 UPB_TABVALUE_PTR_INIT(&fields[5]),
5439 UPB_TABVALUE_PTR_INIT(&fields[32]),
5440 UPB_TABVALUE_PTR_INIT(&fields[10]),
5441 UPB_TABVALUE_PTR_INIT(&fields[63]),
5442 UPB_TABVALUE_PTR_INIT(&fields[13]),
5443 UPB_TABVALUE_PTR_INIT(&fields[53]),
5444 UPB_TABVALUE_PTR_INIT(&fields[64]),
5445 UPB_TABVALUE_PTR_INIT(&fields[61]),
5446 UPB_TABVALUE_PTR_INIT(&fields[80]),
5447 UPB_TABVALUE_EMPTY_INIT,
5448 UPB_TABVALUE_PTR_INIT(&fields[17]),
5449 UPB_TABVALUE_EMPTY_INIT,
5450 UPB_TABVALUE_PTR_INIT(&fields[26]),
5451 UPB_TABVALUE_EMPTY_INIT,
5452 UPB_TABVALUE_EMPTY_INIT,
5453 UPB_TABVALUE_EMPTY_INIT,
5454 UPB_TABVALUE_EMPTY_INIT,
5455 UPB_TABVALUE_EMPTY_INIT,
5456 UPB_TABVALUE_EMPTY_INIT,
5457 UPB_TABVALUE_PTR_INIT(&fields[25]),
5458 UPB_TABVALUE_PTR_INIT(&fields[48]),
5459 UPB_TABVALUE_PTR_INIT(&fields[24]),
5460 UPB_TABVALUE_PTR_INIT(&fields[18]),
5461 UPB_TABVALUE_EMPTY_INIT,
5462 UPB_TABVALUE_EMPTY_INIT,
5463 UPB_TABVALUE_EMPTY_INIT,
5464 UPB_TABVALUE_EMPTY_INIT,
5465 UPB_TABVALUE_PTR_INIT(&fields[2]),
5466 UPB_TABVALUE_PTR_INIT(&fields[23]),
5467 UPB_TABVALUE_PTR_INIT(&fields[62]),
5468 UPB_TABVALUE_EMPTY_INIT,
5469 UPB_TABVALUE_PTR_INIT(&fields[22]),
5470 UPB_TABVALUE_EMPTY_INIT,
5471 UPB_TABVALUE_EMPTY_INIT,
5472 UPB_TABVALUE_EMPTY_INIT,
5473 UPB_TABVALUE_EMPTY_INIT,
5474 UPB_TABVALUE_EMPTY_INIT,
5475 UPB_TABVALUE_EMPTY_INIT,
5476 UPB_TABVALUE_EMPTY_INIT,
5477 UPB_TABVALUE_EMPTY_INIT,
5478 UPB_TABVALUE_EMPTY_INIT,
5479 UPB_TABVALUE_EMPTY_INIT,
5480 UPB_TABVALUE_EMPTY_INIT,
5481 UPB_TABVALUE_EMPTY_INIT,
5482 UPB_TABVALUE_EMPTY_INIT,
5483 UPB_TABVALUE_EMPTY_INIT,
5484 UPB_TABVALUE_EMPTY_INIT,
5485 UPB_TABVALUE_EMPTY_INIT,
5486 UPB_TABVALUE_EMPTY_INIT,
5487 UPB_TABVALUE_EMPTY_INIT,
5488 UPB_TABVALUE_EMPTY_INIT,
5489 UPB_TABVALUE_EMPTY_INIT,
5490 UPB_TABVALUE_EMPTY_INIT,
5491 UPB_TABVALUE_EMPTY_INIT,
5492 UPB_TABVALUE_EMPTY_INIT,
5493 UPB_TABVALUE_EMPTY_INIT,
5494 UPB_TABVALUE_EMPTY_INIT,
5495 UPB_TABVALUE_EMPTY_INIT,
5496 UPB_TABVALUE_EMPTY_INIT,
5497 UPB_TABVALUE_EMPTY_INIT,
5498 UPB_TABVALUE_EMPTY_INIT,
5499 UPB_TABVALUE_EMPTY_INIT,
5500 UPB_TABVALUE_EMPTY_INIT,
5501 UPB_TABVALUE_EMPTY_INIT,
5502 UPB_TABVALUE_EMPTY_INIT,
5503 UPB_TABVALUE_EMPTY_INIT,
5504 UPB_TABVALUE_EMPTY_INIT,
5505 UPB_TABVALUE_EMPTY_INIT,
5506 UPB_TABVALUE_EMPTY_INIT,
5507 UPB_TABVALUE_EMPTY_INIT,
5508 UPB_TABVALUE_EMPTY_INIT,
5509 UPB_TABVALUE_EMPTY_INIT,
5510 UPB_TABVALUE_EMPTY_INIT,
5511 UPB_TABVALUE_EMPTY_INIT,
5512 UPB_TABVALUE_EMPTY_INIT,
5513 UPB_TABVALUE_EMPTY_INIT,
5514 UPB_TABVALUE_PTR_INIT(&fields[31]),
5515 UPB_TABVALUE_PTR_INIT(&fields[45]),
5516 UPB_TABVALUE_EMPTY_INIT,
5517 UPB_TABVALUE_EMPTY_INIT,
5518 UPB_TABVALUE_EMPTY_INIT,
5519 UPB_TABVALUE_EMPTY_INIT,
5520 UPB_TABVALUE_EMPTY_INIT,
5521 UPB_TABVALUE_EMPTY_INIT,
5522 UPB_TABVALUE_EMPTY_INIT,
5523 UPB_TABVALUE_EMPTY_INIT,
5524 UPB_TABVALUE_EMPTY_INIT,
5525 UPB_TABVALUE_EMPTY_INIT,
5526 UPB_TABVALUE_EMPTY_INIT,
5527 UPB_TABVALUE_EMPTY_INIT,
5528 UPB_TABVALUE_EMPTY_INIT,
5529 UPB_TABVALUE_EMPTY_INIT,
5530 UPB_TABVALUE_PTR_INIT(&fields[39]),
5531 UPB_TABVALUE_PTR_INIT(&fields[20]),
5532 UPB_TABVALUE_PTR_INIT(&fields[56]),
5533 UPB_TABVALUE_PTR_INIT(&fields[55]),
5534 UPB_TABVALUE_EMPTY_INIT,
5535 UPB_TABVALUE_EMPTY_INIT,
5536 UPB_TABVALUE_EMPTY_INIT,
5537 UPB_TABVALUE_EMPTY_INIT,
5538 UPB_TABVALUE_EMPTY_INIT,
5539 UPB_TABVALUE_PTR_INIT(&fields[35]),
5540 UPB_TABVALUE_PTR_INIT(&fields[33]),
5541 UPB_TABVALUE_PTR_INIT(&fields[54]),
5542 UPB_TABVALUE_EMPTY_INIT,
5543 UPB_TABVALUE_EMPTY_INIT,
5544 UPB_TABVALUE_EMPTY_INIT,
5545 UPB_TABVALUE_EMPTY_INIT,
5546 UPB_TABVALUE_EMPTY_INIT,
5547 UPB_TABVALUE_PTR_INIT(&fields[30]), 6048 UPB_TABVALUE_PTR_INIT(&fields[30]),
5548 UPB_TABVALUE_EMPTY_INIT, 6049 UPB_TABVALUE_EMPTY_INIT,
5549 UPB_TABVALUE_PTR_INIT(&fields[59]),
5550 UPB_TABVALUE_PTR_INIT(&fields[65]),
5551 UPB_TABVALUE_PTR_INIT(&fields[29]),
5552 UPB_TABVALUE_PTR_INIT(&fields[68]),
5553 UPB_TABVALUE_EMPTY_INIT,
5554 UPB_TABVALUE_EMPTY_INIT,
5555 UPB_TABVALUE_PTR_INIT(&fields[36]),
5556 UPB_TABVALUE_PTR_INIT(&fields[19]),
5557 UPB_TABVALUE_PTR_INIT(&fields[60]),
5558 UPB_TABVALUE_PTR_INIT(&fields[43]),
5559 UPB_TABVALUE_PTR_INIT(&fields[7]),
5560 UPB_TABVALUE_PTR_INIT(&fields[67]),
5561 UPB_TABVALUE_PTR_INIT(&fields[0]),
5562 UPB_TABVALUE_EMPTY_INIT,
5563 UPB_TABVALUE_PTR_INIT(&fields[42]),
5564 UPB_TABVALUE_PTR_INIT(&fields[21]),
5565 UPB_TABVALUE_EMPTY_INIT,
5566 UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"), 6050 UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"),
5567 UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"), 6051 UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"),
5568 UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"), 6052 UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"),
5569 UPB_TABVALUE_EMPTY_INIT, 6053 UPB_TABVALUE_EMPTY_INIT,
5570 UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"), 6054 UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"),
5571 UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"), 6055 UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"),
5572 UPB_TABVALUE_PTR_INIT("TYPE_INT64"), 6056 UPB_TABVALUE_PTR_INIT("TYPE_INT64"),
5573 UPB_TABVALUE_PTR_INIT("TYPE_UINT64"), 6057 UPB_TABVALUE_PTR_INIT("TYPE_UINT64"),
5574 UPB_TABVALUE_PTR_INIT("TYPE_INT32"), 6058 UPB_TABVALUE_PTR_INIT("TYPE_INT32"),
5575 UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"), 6059 UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"),
5576 UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"), 6060 UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"),
5577 UPB_TABVALUE_PTR_INIT("TYPE_BOOL"), 6061 UPB_TABVALUE_PTR_INIT("TYPE_BOOL"),
5578 UPB_TABVALUE_PTR_INIT("TYPE_STRING"), 6062 UPB_TABVALUE_PTR_INIT("TYPE_STRING"),
5579 UPB_TABVALUE_PTR_INIT("TYPE_GROUP"), 6063 UPB_TABVALUE_PTR_INIT("TYPE_GROUP"),
5580 UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"), 6064 UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"),
5581 UPB_TABVALUE_PTR_INIT("TYPE_BYTES"), 6065 UPB_TABVALUE_PTR_INIT("TYPE_BYTES"),
5582 UPB_TABVALUE_PTR_INIT("TYPE_UINT32"), 6066 UPB_TABVALUE_PTR_INIT("TYPE_UINT32"),
5583 UPB_TABVALUE_PTR_INIT("TYPE_ENUM"), 6067 UPB_TABVALUE_PTR_INIT("TYPE_ENUM"),
5584 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"), 6068 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"),
5585 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"), 6069 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"),
5586 UPB_TABVALUE_PTR_INIT("TYPE_SINT32"), 6070 UPB_TABVALUE_PTR_INIT("TYPE_SINT32"),
5587 UPB_TABVALUE_PTR_INIT("TYPE_SINT64"), 6071 UPB_TABVALUE_PTR_INIT("TYPE_SINT64"),
5588 UPB_TABVALUE_PTR_INIT("STRING"), 6072 UPB_TABVALUE_PTR_INIT("STRING"),
5589 UPB_TABVALUE_PTR_INIT("CORD"), 6073 UPB_TABVALUE_PTR_INIT("CORD"),
5590 UPB_TABVALUE_PTR_INIT("STRING_PIECE"), 6074 UPB_TABVALUE_PTR_INIT("STRING_PIECE"),
6075 UPB_TABVALUE_PTR_INIT("JS_NORMAL"),
6076 UPB_TABVALUE_PTR_INIT("JS_STRING"),
6077 UPB_TABVALUE_PTR_INIT("JS_NUMBER"),
5591 UPB_TABVALUE_EMPTY_INIT, 6078 UPB_TABVALUE_EMPTY_INIT,
5592 UPB_TABVALUE_PTR_INIT("SPEED"), 6079 UPB_TABVALUE_PTR_INIT("SPEED"),
5593 UPB_TABVALUE_PTR_INIT("CODE_SIZE"), 6080 UPB_TABVALUE_PTR_INIT("CODE_SIZE"),
5594 UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"), 6081 UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"),
5595 }; 6082 };
5596 6083
5597 static const upb_symtab symtab = UPB_SYMTAB_INIT(UPB_STRTABLE_INIT(24, 31, UPB_C TYPE_PTR, 5, &strentries[204]), &reftables[210], &reftables[211]);
5598
5599 const upb_symtab *upbdefs_google_protobuf_descriptor(const void *owner) {
5600 upb_symtab_ref(&symtab, owner);
5601 return &symtab;
5602 }
5603
5604 #ifdef UPB_DEBUG_REFS 6084 #ifdef UPB_DEBUG_REFS
5605 static upb_inttable reftables[212] = { 6085 static upb_inttable reftables[264] = {
5606 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6086 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5607 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6087 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5608 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6088 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6089 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6090 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6091 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6092 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6093 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6094 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6095 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6096 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6097 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6098 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6099 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6100 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6101 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6102 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6103 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6104 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6105 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6106 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6107 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6108 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6109 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6110 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6111 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6112 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6113 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6114 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6115 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6116 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6117 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6118 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6119 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6120 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6121 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6122 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6123 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6124 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6125 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6126 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6127 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6128 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6129 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6130 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6131 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6132 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6133 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6134 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6135 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6136 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6137 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6138 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6139 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
6140 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5609 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6141 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5610 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6142 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5611 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6143 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5612 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6144 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5613 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6145 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5614 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6146 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5615 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6147 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5616 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6148 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5617 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6149 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5618 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6150 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
5811 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6343 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5812 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6344 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5813 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6345 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5814 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6346 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5815 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6347 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5816 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6348 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5817 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), 6349 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR),
5818 }; 6350 };
5819 #endif 6351 #endif
5820 6352
6353 static const upb_msgdef *refm(const upb_msgdef *m, const void *owner) {
6354 upb_msgdef_ref(m, owner);
6355 return m;
6356 }
6357
6358 static const upb_enumdef *refe(const upb_enumdef *e, const void *owner) {
6359 upb_enumdef_ref(e, owner);
6360 return e;
6361 }
6362
6363 /* Public API. */
6364 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner) { return refm(&msgs[0], owner); }
6365 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(con st void *owner) { return refm(&msgs[1], owner); }
6366 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(cons t void *owner) { return refm(&msgs[2], owner); }
6367 const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *ow ner) { return refm(&msgs[3], owner); }
6368 const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner) { r eturn refm(&msgs[4], owner); }
6369 const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const voi d *owner) { return refm(&msgs[5], owner); }
6370 const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner ) { return refm(&msgs[6], owner); }
6371 const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *o wner) { return refm(&msgs[7], owner); }
6372 const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner) { return refm(&msgs[8], owner); }
6373 const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *ow ner) { return refm(&msgs[9], owner); }
6374 const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owne r) { return refm(&msgs[10], owner); }
6375 const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner) { r eturn refm(&msgs[11], owner); }
6376 const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner) { return refm(&msgs[12], owner); }
6377 const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void * owner) { return refm(&msgs[13], owner); }
6378 const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner) { return refm(&msgs[14], owner); }
6379 const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *o wner) { return refm(&msgs[15], owner); }
6380 const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void *owner) { return refm(&msgs[16], owner); }
6381 const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner) { return refm(&msgs[17], owner); }
6382 const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner) { return refm(&msgs[18], owner); }
6383 const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void *owner) { return refm(&msgs[19], owner); }
6384 const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *ow ner) { return refm(&msgs[20], owner); }
6385 const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const void *owner) { return refm(&msgs[21], owner); }
6386
6387 const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const void *owner) { return refe(&enums[0], owner); }
6388 const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const v oid *owner) { return refe(&enums[1], owner); }
6389 const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *ow ner) { return refe(&enums[2], owner); }
6390 const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *o wner) { return refe(&enums[3], owner); }
6391 const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const vo id *owner) { return refe(&enums[4], owner); }
5821 /* 6392 /*
5822 ** XXX: The routines in this file that consume a string do not currently 6393 ** XXX: The routines in this file that consume a string do not currently
5823 ** support having the string span buffers. In the future, as upb_sink and 6394 ** support having the string span buffers. In the future, as upb_sink and
5824 ** its buffering/sharing functionality evolve there should be an easy and 6395 ** its buffering/sharing functionality evolve there should be an easy and
5825 ** idiomatic way of correctly handling this case. For now, we accept this 6396 ** idiomatic way of correctly handling this case. For now, we accept this
5826 ** limitation since we currently only parse descriptors from single strings. 6397 ** limitation since we currently only parse descriptors from single strings.
5827 */ 6398 */
5828 6399
5829 6400
5830 #include <errno.h> 6401 #include <errno.h>
5831 #include <stdlib.h> 6402 #include <stdlib.h>
5832 #include <string.h> 6403 #include <string.h>
5833 6404
5834 /* upb_deflist is an internal-only dynamic array for storing a growing list of 6405 /* Compares a NULL-terminated string with a non-NULL-terminated string. */
5835 * upb_defs. */ 6406 static bool upb_streq(const char *str, const char *buf, size_t n) {
5836 typedef struct { 6407 return strlen(str) == n && memcmp(str, buf, n) == 0;
5837 upb_def **defs; 6408 }
5838 size_t len;
5839 size_t size;
5840 bool owned;
5841 } upb_deflist;
5842 6409
5843 /* We keep a stack of all the messages scopes we are currently in, as well as 6410 /* We keep a stack of all the messages scopes we are currently in, as well as
5844 * the top-level file scope. This is necessary to correctly qualify the 6411 * the top-level file scope. This is necessary to correctly qualify the
5845 * definitions that are contained inside. "name" tracks the name of the 6412 * definitions that are contained inside. "name" tracks the name of the
5846 * message or package (a bare name -- not qualified by any enclosing scopes). */ 6413 * message or package (a bare name -- not qualified by any enclosing scopes). */
5847 typedef struct { 6414 typedef struct {
5848 char *name; 6415 char *name;
5849 /* Index of the first def that is under this scope. For msgdefs, the 6416 /* Index of the first def that is under this scope. For msgdefs, the
5850 * msgdef itself is at start-1. */ 6417 * msgdef itself is at start-1. */
5851 int start; 6418 int start;
5852 } upb_descreader_frame; 6419 } upb_descreader_frame;
5853 6420
5854 /* The maximum number of nested declarations that are allowed, ie. 6421 /* The maximum number of nested declarations that are allowed, ie.
5855 * message Foo { 6422 * message Foo {
5856 * message Bar { 6423 * message Bar {
5857 * message Baz { 6424 * message Baz {
5858 * } 6425 * }
5859 * } 6426 * }
5860 * } 6427 * }
5861 * 6428 *
5862 * This is a resource limit that affects how big our runtime stack can grow. 6429 * This is a resource limit that affects how big our runtime stack can grow.
5863 * TODO: make this a runtime-settable property of the Reader instance. */ 6430 * TODO: make this a runtime-settable property of the Reader instance. */
5864 #define UPB_MAX_MESSAGE_NESTING 64 6431 #define UPB_MAX_MESSAGE_NESTING 64
5865 6432
5866 struct upb_descreader { 6433 struct upb_descreader {
5867 upb_sink sink; 6434 upb_sink sink;
5868 upb_deflist defs; 6435 upb_inttable files;
6436 upb_filedef *file; /* The last file in files. */
5869 upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; 6437 upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING];
5870 int stack_len; 6438 int stack_len;
5871 6439
5872 uint32_t number; 6440 uint32_t number;
5873 char *name; 6441 char *name;
5874 bool saw_number; 6442 bool saw_number;
5875 bool saw_name; 6443 bool saw_name;
5876 6444
5877 char *default_string; 6445 char *default_string;
5878 6446
5879 upb_fielddef *f; 6447 upb_fielddef *f;
5880 }; 6448 };
5881 6449
5882 static char *upb_strndup(const char *buf, size_t n) { 6450 static char *upb_strndup(const char *buf, size_t n) {
5883 char *ret = malloc(n + 1); 6451 char *ret = upb_gmalloc(n + 1);
5884 if (!ret) return NULL; 6452 if (!ret) return NULL;
5885 memcpy(ret, buf, n); 6453 memcpy(ret, buf, n);
5886 ret[n] = '\0'; 6454 ret[n] = '\0';
5887 return ret; 6455 return ret;
5888 } 6456 }
5889 6457
5890 /* Returns a newly allocated string that joins input strings together, for 6458 /* Returns a newly allocated string that joins input strings together, for
5891 * example: 6459 * example:
5892 * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz" 6460 * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz"
5893 * join("", "Baz") -> "Baz" 6461 * join("", "Baz") -> "Baz"
5894 * Caller owns a ref on the returned string. */ 6462 * Caller owns a ref on the returned string. */
5895 static char *upb_join(const char *base, const char *name) { 6463 static char *upb_join(const char *base, const char *name) {
5896 if (!base || strlen(base) == 0) { 6464 if (!base || strlen(base) == 0) {
5897 return upb_strdup(name); 6465 return upb_gstrdup(name);
5898 } else { 6466 } else {
5899 char *ret = malloc(strlen(base) + strlen(name) + 2); 6467 char *ret = upb_gmalloc(strlen(base) + strlen(name) + 2);
6468 if (!ret) {
6469 return NULL;
6470 }
5900 ret[0] = '\0'; 6471 ret[0] = '\0';
5901 strcat(ret, base); 6472 strcat(ret, base);
5902 strcat(ret, "."); 6473 strcat(ret, ".");
5903 strcat(ret, name); 6474 strcat(ret, name);
5904 return ret; 6475 return ret;
5905 } 6476 }
5906 } 6477 }
5907 6478
5908 6479 /* Qualify the defname for all defs starting with offset "start" with "str". */
5909 /* upb_deflist ****************************************************************/ 6480 static bool upb_descreader_qualify(upb_filedef *f, char *str, int32_t start) {
5910
5911 void upb_deflist_init(upb_deflist *l) {
5912 l->size = 0;
5913 l->defs = NULL;
5914 l->len = 0;
5915 l->owned = true;
5916 }
5917
5918 void upb_deflist_uninit(upb_deflist *l) {
5919 size_t i; 6481 size_t i;
5920 if (l->owned) 6482 for (i = start; i < upb_filedef_defcount(f); i++) {
5921 for(i = 0; i < l->len; i++) 6483 upb_def *def = upb_filedef_mutabledef(f, i);
5922 upb_def_unref(l->defs[i], l); 6484 char *name = upb_join(str, upb_def_fullname(def));
5923 free(l->defs); 6485 if (!name) {
5924 } 6486 /* Need better logic here; at this point we've qualified some names but
5925 6487 * not others. */
5926 bool upb_deflist_push(upb_deflist *l, upb_def *d) { 6488 return false;
5927 if(++l->len >= l->size) { 6489 }
5928 size_t new_size = UPB_MAX(l->size, 4); 6490 upb_def_setfullname(def, name, NULL);
5929 new_size *= 2; 6491 upb_gfree(name);
5930 l->defs = realloc(l->defs, new_size * sizeof(void *));
5931 if (!l->defs) return false;
5932 l->size = new_size;
5933 } 6492 }
5934 l->defs[l->len - 1] = d;
5935 return true; 6493 return true;
5936 } 6494 }
5937 6495
5938 void upb_deflist_donaterefs(upb_deflist *l, void *owner) {
5939 size_t i;
5940 assert(l->owned);
5941 for (i = 0; i < l->len; i++)
5942 upb_def_donateref(l->defs[i], l, owner);
5943 l->owned = false;
5944 }
5945 6496
5946 static upb_def *upb_deflist_last(upb_deflist *l) {
5947 return l->defs[l->len-1];
5948 }
5949
5950 /* Qualify the defname for all defs starting with offset "start" with "str". */
5951 static void upb_deflist_qualify(upb_deflist *l, char *str, int32_t start) {
5952 uint32_t i;
5953 for (i = start; i < l->len; i++) {
5954 upb_def *def = l->defs[i];
5955 char *name = upb_join(str, upb_def_fullname(def));
5956 upb_def_setfullname(def, name, NULL);
5957 free(name);
5958 }
5959 }
5960
5961
5962 /* upb_descreader ************************************************************/ 6497 /* upb_descreader ************************************************************/
5963 6498
5964 static upb_msgdef *upb_descreader_top(upb_descreader *r) { 6499 static upb_msgdef *upb_descreader_top(upb_descreader *r) {
5965 int index; 6500 int index;
5966 assert(r->stack_len > 1); 6501 assert(r->stack_len > 1);
5967 index = r->stack[r->stack_len-1].start - 1; 6502 index = r->stack[r->stack_len-1].start - 1;
5968 assert(index >= 0); 6503 assert(index >= 0);
5969 return upb_downcast_msgdef_mutable(r->defs.defs[index]); 6504 return upb_downcast_msgdef_mutable(upb_filedef_mutabledef(r->file, index));
5970 } 6505 }
5971 6506
5972 static upb_def *upb_descreader_last(upb_descreader *r) { 6507 static upb_def *upb_descreader_last(upb_descreader *r) {
5973 return upb_deflist_last(&r->defs); 6508 return upb_filedef_mutabledef(r->file, upb_filedef_defcount(r->file) - 1);
5974 } 6509 }
5975 6510
5976 /* Start/end handlers for FileDescriptorProto and DescriptorProto (the two 6511 /* Start/end handlers for FileDescriptorProto and DescriptorProto (the two
5977 * entities that have names and can contain sub-definitions. */ 6512 * entities that have names and can contain sub-definitions. */
5978 void upb_descreader_startcontainer(upb_descreader *r) { 6513 void upb_descreader_startcontainer(upb_descreader *r) {
5979 upb_descreader_frame *f = &r->stack[r->stack_len++]; 6514 upb_descreader_frame *f = &r->stack[r->stack_len++];
5980 f->start = r->defs.len; 6515 f->start = upb_filedef_defcount(r->file);
5981 f->name = NULL; 6516 f->name = NULL;
5982 } 6517 }
5983 6518
5984 void upb_descreader_endcontainer(upb_descreader *r) { 6519 bool upb_descreader_endcontainer(upb_descreader *r) {
5985 upb_descreader_frame *f = &r->stack[--r->stack_len]; 6520 upb_descreader_frame *f = &r->stack[--r->stack_len];
5986 upb_deflist_qualify(&r->defs, f->name, f->start); 6521 if (!upb_descreader_qualify(r->file, f->name, f->start)) {
5987 free(f->name); 6522 return false;
6523 }
6524 upb_gfree(f->name);
5988 f->name = NULL; 6525 f->name = NULL;
6526 return true;
5989 } 6527 }
5990 6528
5991 void upb_descreader_setscopename(upb_descreader *r, char *str) { 6529 void upb_descreader_setscopename(upb_descreader *r, char *str) {
5992 upb_descreader_frame *f = &r->stack[r->stack_len-1]; 6530 upb_descreader_frame *f = &r->stack[r->stack_len-1];
5993 free(f->name); 6531 upb_gfree(f->name);
5994 f->name = str; 6532 f->name = str;
5995 } 6533 }
5996 6534
5997 /* Handlers for google.protobuf.FileDescriptorProto. */ 6535 /** Handlers for google.protobuf.FileDescriptorSet. ***************************/
5998 static bool file_startmsg(void *r, const void *hd) { 6536
6537 static void *fileset_startfile(void *closure, const void *hd) {
6538 upb_descreader *r = closure;
6539 UPB_UNUSED(hd);
6540 r->file = upb_filedef_new(&r->files);
6541 upb_inttable_push(&r->files, upb_value_ptr(r->file));
6542 return r;
6543 }
6544
6545 /** Handlers for google.protobuf.FileDescriptorProto. *************************/
6546
6547 static bool file_start(void *closure, const void *hd) {
6548 upb_descreader *r = closure;
5999 UPB_UNUSED(hd); 6549 UPB_UNUSED(hd);
6000 upb_descreader_startcontainer(r); 6550 upb_descreader_startcontainer(r);
6001 return true; 6551 return true;
6002 } 6552 }
6003 6553
6004 static bool file_endmsg(void *closure, const void *hd, upb_status *status) { 6554 static bool file_end(void *closure, const void *hd, upb_status *status) {
6005 upb_descreader *r = closure; 6555 upb_descreader *r = closure;
6006 UPB_UNUSED(hd); 6556 UPB_UNUSED(hd);
6007 UPB_UNUSED(status); 6557 UPB_UNUSED(status);
6008 upb_descreader_endcontainer(r); 6558 return upb_descreader_endcontainer(r);
6009 return true; 6559 }
6560
6561 static size_t file_onname(void *closure, const void *hd, const char *buf,
6562 size_t n, const upb_bufhandle *handle) {
6563 upb_descreader *r = closure;
6564 char *name;
6565 bool ok;
6566 UPB_UNUSED(hd);
6567 UPB_UNUSED(handle);
6568
6569 name = upb_strndup(buf, n);
6570 /* XXX: see comment at the top of the file. */
6571 ok = upb_filedef_setname(r->file, name, NULL);
6572 upb_gfree(name);
6573 UPB_ASSERT_VAR(ok, ok);
6574 return n;
6010 } 6575 }
6011 6576
6012 static size_t file_onpackage(void *closure, const void *hd, const char *buf, 6577 static size_t file_onpackage(void *closure, const void *hd, const char *buf,
6013 size_t n, const upb_bufhandle *handle) { 6578 size_t n, const upb_bufhandle *handle) {
6014 upb_descreader *r = closure; 6579 upb_descreader *r = closure;
6580 char *package;
6581 bool ok;
6582 UPB_UNUSED(hd);
6583 UPB_UNUSED(handle);
6584
6585 package = upb_strndup(buf, n);
6586 /* XXX: see comment at the top of the file. */
6587 upb_descreader_setscopename(r, package);
6588 ok = upb_filedef_setpackage(r->file, package, NULL);
6589 UPB_ASSERT_VAR(ok, ok);
6590 return n;
6591 }
6592
6593 static size_t file_onsyntax(void *closure, const void *hd, const char *buf,
6594 size_t n, const upb_bufhandle *handle) {
6595 upb_descreader *r = closure;
6596 bool ok;
6015 UPB_UNUSED(hd); 6597 UPB_UNUSED(hd);
6016 UPB_UNUSED(handle); 6598 UPB_UNUSED(handle);
6017 /* XXX: see comment at the top of the file. */ 6599 /* XXX: see comment at the top of the file. */
6018 upb_descreader_setscopename(r, upb_strndup(buf, n)); 6600 if (upb_streq("proto2", buf, n)) {
6601 ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO2, NULL);
6602 } else if (upb_streq("proto3", buf, n)) {
6603 ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO3, NULL);
6604 } else {
6605 ok = false;
6606 }
6607
6608 UPB_ASSERT_VAR(ok, ok);
6019 return n; 6609 return n;
6020 } 6610 }
6021 6611
6022 /* Handlers for google.protobuf.EnumValueDescriptorProto. */ 6612 static void *file_startmsg(void *closure, const void *hd) {
6613 upb_descreader *r = closure;
6614 upb_msgdef *m = upb_msgdef_new(&m);
6615 bool ok = upb_filedef_addmsg(r->file, m, &m, NULL);
6616 UPB_UNUSED(hd);
6617 UPB_ASSERT_VAR(ok, ok);
6618 return r;
6619 }
6620
6621 static void *file_startenum(void *closure, const void *hd) {
6622 upb_descreader *r = closure;
6623 upb_enumdef *e = upb_enumdef_new(&e);
6624 bool ok = upb_filedef_addenum(r->file, e, &e, NULL);
6625 UPB_UNUSED(hd);
6626 UPB_ASSERT_VAR(ok, ok);
6627 return r;
6628 }
6629
6630 static void *file_startext(void *closure, const void *hd) {
6631 upb_descreader *r = closure;
6632 bool ok;
6633 r->f = upb_fielddef_new(r);
6634 ok = upb_filedef_addext(r->file, r->f, r, NULL);
6635 UPB_UNUSED(hd);
6636 UPB_ASSERT_VAR(ok, ok);
6637 return r;
6638 }
6639
6640 /** Handlers for google.protobuf.EnumValueDescriptorProto. ********************* /
6641
6023 static bool enumval_startmsg(void *closure, const void *hd) { 6642 static bool enumval_startmsg(void *closure, const void *hd) {
6024 upb_descreader *r = closure; 6643 upb_descreader *r = closure;
6025 UPB_UNUSED(hd); 6644 UPB_UNUSED(hd);
6026 r->saw_number = false; 6645 r->saw_number = false;
6027 r->saw_name = false; 6646 r->saw_name = false;
6028 return true; 6647 return true;
6029 } 6648 }
6030 6649
6031 static size_t enumval_onname(void *closure, const void *hd, const char *buf, 6650 static size_t enumval_onname(void *closure, const void *hd, const char *buf,
6032 size_t n, const upb_bufhandle *handle) { 6651 size_t n, const upb_bufhandle *handle) {
6033 upb_descreader *r = closure; 6652 upb_descreader *r = closure;
6034 UPB_UNUSED(hd); 6653 UPB_UNUSED(hd);
6035 UPB_UNUSED(handle); 6654 UPB_UNUSED(handle);
6036 /* XXX: see comment at the top of the file. */ 6655 /* XXX: see comment at the top of the file. */
6037 free(r->name); 6656 upb_gfree(r->name);
6038 r->name = upb_strndup(buf, n); 6657 r->name = upb_strndup(buf, n);
6039 r->saw_name = true; 6658 r->saw_name = true;
6040 return n; 6659 return n;
6041 } 6660 }
6042 6661
6043 static bool enumval_onnumber(void *closure, const void *hd, int32_t val) { 6662 static bool enumval_onnumber(void *closure, const void *hd, int32_t val) {
6044 upb_descreader *r = closure; 6663 upb_descreader *r = closure;
6045 UPB_UNUSED(hd); 6664 UPB_UNUSED(hd);
6046 r->number = val; 6665 r->number = val;
6047 r->saw_number = true; 6666 r->saw_number = true;
6048 return true; 6667 return true;
6049 } 6668 }
6050 6669
6051 static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) { 6670 static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) {
6052 upb_descreader *r = closure; 6671 upb_descreader *r = closure;
6053 upb_enumdef *e; 6672 upb_enumdef *e;
6054 UPB_UNUSED(hd); 6673 UPB_UNUSED(hd);
6055 6674
6056 if(!r->saw_number || !r->saw_name) { 6675 if(!r->saw_number || !r->saw_name) {
6057 upb_status_seterrmsg(status, "Enum value missing name or number."); 6676 upb_status_seterrmsg(status, "Enum value missing name or number.");
6058 return false; 6677 return false;
6059 } 6678 }
6060 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); 6679 e = upb_downcast_enumdef_mutable(upb_descreader_last(r));
6061 upb_enumdef_addval(e, r->name, r->number, status); 6680 upb_enumdef_addval(e, r->name, r->number, status);
6062 free(r->name); 6681 upb_gfree(r->name);
6063 r->name = NULL; 6682 r->name = NULL;
6064 return true; 6683 return true;
6065 } 6684 }
6066 6685
6067 6686 /** Handlers for google.protobuf.EnumDescriptorProto. *************************/
6068 /* Handlers for google.protobuf.EnumDescriptorProto. */
6069 static bool enum_startmsg(void *closure, const void *hd) {
6070 upb_descreader *r = closure;
6071 UPB_UNUSED(hd);
6072 upb_deflist_push(&r->defs,
6073 upb_enumdef_upcast_mutable(upb_enumdef_new(&r->defs)));
6074 return true;
6075 }
6076 6687
6077 static bool enum_endmsg(void *closure, const void *hd, upb_status *status) { 6688 static bool enum_endmsg(void *closure, const void *hd, upb_status *status) {
6078 upb_descreader *r = closure; 6689 upb_descreader *r = closure;
6079 upb_enumdef *e; 6690 upb_enumdef *e;
6080 UPB_UNUSED(hd); 6691 UPB_UNUSED(hd);
6081 6692
6082 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); 6693 e = upb_downcast_enumdef_mutable(upb_descreader_last(r));
6083 if (upb_def_fullname(upb_descreader_last(r)) == NULL) { 6694 if (upb_def_fullname(upb_descreader_last(r)) == NULL) {
6084 upb_status_seterrmsg(status, "Enum had no name."); 6695 upb_status_seterrmsg(status, "Enum had no name.");
6085 return false; 6696 return false;
6086 } 6697 }
6087 if (upb_enumdef_numvals(e) == 0) { 6698 if (upb_enumdef_numvals(e) == 0) {
6088 upb_status_seterrmsg(status, "Enum had no values."); 6699 upb_status_seterrmsg(status, "Enum had no values.");
6089 return false; 6700 return false;
6090 } 6701 }
6091 return true; 6702 return true;
6092 } 6703 }
6093 6704
6094 static size_t enum_onname(void *closure, const void *hd, const char *buf, 6705 static size_t enum_onname(void *closure, const void *hd, const char *buf,
6095 size_t n, const upb_bufhandle *handle) { 6706 size_t n, const upb_bufhandle *handle) {
6096 upb_descreader *r = closure; 6707 upb_descreader *r = closure;
6097 char *fullname = upb_strndup(buf, n); 6708 char *fullname = upb_strndup(buf, n);
6098 UPB_UNUSED(hd); 6709 UPB_UNUSED(hd);
6099 UPB_UNUSED(handle); 6710 UPB_UNUSED(handle);
6100 /* XXX: see comment at the top of the file. */ 6711 /* XXX: see comment at the top of the file. */
6101 upb_def_setfullname(upb_descreader_last(r), fullname, NULL); 6712 upb_def_setfullname(upb_descreader_last(r), fullname, NULL);
6102 free(fullname); 6713 upb_gfree(fullname);
6103 return n; 6714 return n;
6104 } 6715 }
6105 6716
6106 /* Handlers for google.protobuf.FieldDescriptorProto */ 6717 /** Handlers for google.protobuf.FieldDescriptorProto *************************/
6718
6107 static bool field_startmsg(void *closure, const void *hd) { 6719 static bool field_startmsg(void *closure, const void *hd) {
6108 upb_descreader *r = closure; 6720 upb_descreader *r = closure;
6109 UPB_UNUSED(hd); 6721 UPB_UNUSED(hd);
6110 r->f = upb_fielddef_new(&r->defs); 6722 assert(r->f);
6111 free(r->default_string); 6723 upb_gfree(r->default_string);
6112 r->default_string = NULL; 6724 r->default_string = NULL;
6113 6725
6114 /* fielddefs default to packed, but descriptors default to non-packed. */ 6726 /* fielddefs default to packed, but descriptors default to non-packed. */
6115 upb_fielddef_setpacked(r->f, false); 6727 upb_fielddef_setpacked(r->f, false);
6116 return true; 6728 return true;
6117 } 6729 }
6118 6730
6119 /* Converts the default value in string "str" into "d". Passes a ref on str. 6731 /* Converts the default value in string "str" into "d". Passes a ref on str.
6120 * Returns true on success. */ 6732 * Returns true on success. */
6121 static bool parse_default(char *str, upb_fielddef *f) { 6733 static bool parse_default(char *str, upb_fielddef *f) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
6243 static bool field_onlabel(void *closure, const void *hd, int32_t val) { 6855 static bool field_onlabel(void *closure, const void *hd, int32_t val) {
6244 upb_descreader *r = closure; 6856 upb_descreader *r = closure;
6245 UPB_UNUSED(hd); 6857 UPB_UNUSED(hd);
6246 6858
6247 upb_fielddef_setlabel(r->f, val); 6859 upb_fielddef_setlabel(r->f, val);
6248 return true; 6860 return true;
6249 } 6861 }
6250 6862
6251 static bool field_onnumber(void *closure, const void *hd, int32_t val) { 6863 static bool field_onnumber(void *closure, const void *hd, int32_t val) {
6252 upb_descreader *r = closure; 6864 upb_descreader *r = closure;
6253 bool ok = upb_fielddef_setnumber(r->f, val, NULL); 6865 bool ok;
6254 UPB_UNUSED(hd); 6866 UPB_UNUSED(hd);
6255 6867
6868 ok = upb_fielddef_setnumber(r->f, val, NULL);
6256 UPB_ASSERT_VAR(ok, ok); 6869 UPB_ASSERT_VAR(ok, ok);
6257 return true; 6870 return true;
6258 } 6871 }
6259 6872
6260 static size_t field_onname(void *closure, const void *hd, const char *buf, 6873 static size_t field_onname(void *closure, const void *hd, const char *buf,
6261 size_t n, const upb_bufhandle *handle) { 6874 size_t n, const upb_bufhandle *handle) {
6262 upb_descreader *r = closure; 6875 upb_descreader *r = closure;
6263 char *name = upb_strndup(buf, n); 6876 char *name = upb_strndup(buf, n);
6264 UPB_UNUSED(hd); 6877 UPB_UNUSED(hd);
6265 UPB_UNUSED(handle); 6878 UPB_UNUSED(handle);
6266 6879
6267 /* XXX: see comment at the top of the file. */ 6880 /* XXX: see comment at the top of the file. */
6268 upb_fielddef_setname(r->f, name, NULL); 6881 upb_fielddef_setname(r->f, name, NULL);
6269 free(name); 6882 upb_gfree(name);
6270 return n; 6883 return n;
6271 } 6884 }
6272 6885
6273 static size_t field_ontypename(void *closure, const void *hd, const char *buf, 6886 static size_t field_ontypename(void *closure, const void *hd, const char *buf,
6274 size_t n, const upb_bufhandle *handle) { 6887 size_t n, const upb_bufhandle *handle) {
6275 upb_descreader *r = closure; 6888 upb_descreader *r = closure;
6276 char *name = upb_strndup(buf, n); 6889 char *name = upb_strndup(buf, n);
6277 UPB_UNUSED(hd); 6890 UPB_UNUSED(hd);
6278 UPB_UNUSED(handle); 6891 UPB_UNUSED(handle);
6279 6892
6280 /* XXX: see comment at the top of the file. */ 6893 /* XXX: see comment at the top of the file. */
6281 upb_fielddef_setsubdefname(r->f, name, NULL); 6894 upb_fielddef_setsubdefname(r->f, name, NULL);
6282 free(name); 6895 upb_gfree(name);
6283 return n; 6896 return n;
6284 } 6897 }
6285 6898
6286 static size_t field_onextendee(void *closure, const void *hd, const char *buf, 6899 static size_t field_onextendee(void *closure, const void *hd, const char *buf,
6287 size_t n, const upb_bufhandle *handle) { 6900 size_t n, const upb_bufhandle *handle) {
6288 upb_descreader *r = closure; 6901 upb_descreader *r = closure;
6289 char *name = upb_strndup(buf, n); 6902 char *name = upb_strndup(buf, n);
6290 UPB_UNUSED(hd); 6903 UPB_UNUSED(hd);
6291 UPB_UNUSED(handle); 6904 UPB_UNUSED(handle);
6292 6905
6293 /* XXX: see comment at the top of the file. */ 6906 /* XXX: see comment at the top of the file. */
6294 upb_fielddef_setcontainingtypename(r->f, name, NULL); 6907 upb_fielddef_setcontainingtypename(r->f, name, NULL);
6295 free(name); 6908 upb_gfree(name);
6296 return n; 6909 return n;
6297 } 6910 }
6298 6911
6299 static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, 6912 static size_t field_ondefaultval(void *closure, const void *hd, const char *buf,
6300 size_t n, const upb_bufhandle *handle) { 6913 size_t n, const upb_bufhandle *handle) {
6301 upb_descreader *r = closure; 6914 upb_descreader *r = closure;
6302 UPB_UNUSED(hd); 6915 UPB_UNUSED(hd);
6303 UPB_UNUSED(handle); 6916 UPB_UNUSED(handle);
6304 6917
6305 /* Have to convert from string to the correct type, but we might not know the 6918 /* Have to convert from string to the correct type, but we might not know the
6306 * type yet, so we save it as a string until the end of the field. 6919 * type yet, so we save it as a string until the end of the field.
6307 * XXX: see comment at the top of the file. */ 6920 * XXX: see comment at the top of the file. */
6308 free(r->default_string); 6921 upb_gfree(r->default_string);
6309 r->default_string = upb_strndup(buf, n); 6922 r->default_string = upb_strndup(buf, n);
6310 return n; 6923 return n;
6311 } 6924 }
6312 6925
6313 /* Handlers for google.protobuf.DescriptorProto (representing a message). */ 6926 /** Handlers for google.protobuf.DescriptorProto ******************************/
6314 static bool msg_startmsg(void *closure, const void *hd) { 6927
6928 static bool msg_start(void *closure, const void *hd) {
6315 upb_descreader *r = closure; 6929 upb_descreader *r = closure;
6316 UPB_UNUSED(hd); 6930 UPB_UNUSED(hd);
6317 6931
6318 upb_deflist_push(&r->defs,
6319 upb_msgdef_upcast_mutable(upb_msgdef_new(&r->defs)));
6320 upb_descreader_startcontainer(r); 6932 upb_descreader_startcontainer(r);
6321 return true; 6933 return true;
6322 } 6934 }
6323 6935
6324 static bool msg_endmsg(void *closure, const void *hd, upb_status *status) { 6936 static bool msg_end(void *closure, const void *hd, upb_status *status) {
6325 upb_descreader *r = closure; 6937 upb_descreader *r = closure;
6326 upb_msgdef *m = upb_descreader_top(r); 6938 upb_msgdef *m = upb_descreader_top(r);
6327 UPB_UNUSED(hd); 6939 UPB_UNUSED(hd);
6328 6940
6329 if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) { 6941 if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) {
6330 upb_status_seterrmsg(status, "Encountered message with no name."); 6942 upb_status_seterrmsg(status, "Encountered message with no name.");
6331 return false; 6943 return false;
6332 } 6944 }
6333 upb_descreader_endcontainer(r); 6945 return upb_descreader_endcontainer(r);
6334 return true;
6335 } 6946 }
6336 6947
6337 static size_t msg_onname(void *closure, const void *hd, const char *buf, 6948 static size_t msg_name(void *closure, const void *hd, const char *buf,
6338 size_t n, const upb_bufhandle *handle) { 6949 size_t n, const upb_bufhandle *handle) {
6339 upb_descreader *r = closure; 6950 upb_descreader *r = closure;
6340 upb_msgdef *m = upb_descreader_top(r); 6951 upb_msgdef *m = upb_descreader_top(r);
6341 /* XXX: see comment at the top of the file. */ 6952 /* XXX: see comment at the top of the file. */
6342 char *name = upb_strndup(buf, n); 6953 char *name = upb_strndup(buf, n);
6343 UPB_UNUSED(hd); 6954 UPB_UNUSED(hd);
6344 UPB_UNUSED(handle); 6955 UPB_UNUSED(handle);
6345 6956
6346 upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); 6957 upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL);
6347 upb_descreader_setscopename(r, name); /* Passes ownership of name. */ 6958 upb_descreader_setscopename(r, name); /* Passes ownership of name. */
6348 return n; 6959 return n;
6349 } 6960 }
6350 6961
6351 static bool msg_onendfield(void *closure, const void *hd) { 6962 static void *msg_startmsg(void *closure, const void *hd) {
6963 upb_descreader *r = closure;
6964 upb_msgdef *m = upb_msgdef_new(&m);
6965 bool ok = upb_filedef_addmsg(r->file, m, &m, NULL);
6966 UPB_UNUSED(hd);
6967 UPB_ASSERT_VAR(ok, ok);
6968 return r;
6969 }
6970
6971 static void *msg_startext(void *closure, const void *hd) {
6972 upb_descreader *r = closure;
6973 upb_fielddef *f = upb_fielddef_new(&f);
6974 bool ok = upb_filedef_addext(r->file, f, &f, NULL);
6975 UPB_UNUSED(hd);
6976 UPB_ASSERT_VAR(ok, ok);
6977 return r;
6978 }
6979
6980 static void *msg_startfield(void *closure, const void *hd) {
6981 upb_descreader *r = closure;
6982 r->f = upb_fielddef_new(&r->f);
6983 /* We can't add the new field to the message until its name/number are
6984 * filled in. */
6985 UPB_UNUSED(hd);
6986 return r;
6987 }
6988
6989 static bool msg_endfield(void *closure, const void *hd) {
6352 upb_descreader *r = closure; 6990 upb_descreader *r = closure;
6353 upb_msgdef *m = upb_descreader_top(r); 6991 upb_msgdef *m = upb_descreader_top(r);
6354 UPB_UNUSED(hd); 6992 UPB_UNUSED(hd);
6355 6993
6356 upb_msgdef_addfield(m, r->f, &r->defs, NULL); 6994 upb_msgdef_addfield(m, r->f, &r->f, NULL);
6357 r->f = NULL; 6995 r->f = NULL;
6358 return true; 6996 return true;
6359 } 6997 }
6360 6998
6361 static bool pushextension(void *closure, const void *hd) { 6999 static bool msg_onmapentry(void *closure, const void *hd, bool mapentry) {
6362 upb_descreader *r = closure; 7000 upb_descreader *r = closure;
7001 upb_msgdef *m = upb_descreader_top(r);
6363 UPB_UNUSED(hd); 7002 UPB_UNUSED(hd);
6364 7003
6365 assert(upb_fielddef_containingtypename(r->f)); 7004 upb_msgdef_setmapentry(m, mapentry);
6366 upb_fielddef_setisextension(r->f, true);
6367 upb_deflist_push(&r->defs, upb_fielddef_upcast_mutable(r->f));
6368 r->f = NULL; 7005 r->f = NULL;
6369 return true; 7006 return true;
6370 } 7007 }
6371 7008
6372 #define D(name) upbdefs_google_protobuf_ ## name(s) 7009
7010
7011 /** Code to register handlers *************************************************/
7012
7013 #define F(msg, field) upbdefs_google_protobuf_ ## msg ## _f_ ## field(m)
6373 7014
6374 static void reghandlers(const void *closure, upb_handlers *h) { 7015 static void reghandlers(const void *closure, upb_handlers *h) {
6375 const upb_symtab *s = closure;
6376 const upb_msgdef *m = upb_handlers_msgdef(h); 7016 const upb_msgdef *m = upb_handlers_msgdef(h);
7017 UPB_UNUSED(closure);
6377 7018
6378 if (m == D(DescriptorProto)) { 7019 if (upbdefs_google_protobuf_FileDescriptorSet_is(m)) {
6379 upb_handlers_setstartmsg(h, &msg_startmsg, NULL); 7020 upb_handlers_setstartsubmsg(h, F(FileDescriptorSet, file),
6380 upb_handlers_setendmsg(h, &msg_endmsg, NULL); 7021 &fileset_startfile, NULL);
6381 upb_handlers_setstring(h, D(DescriptorProto_name), &msg_onname, NULL); 7022 } else if (upbdefs_google_protobuf_DescriptorProto_is(m)) {
6382 upb_handlers_setendsubmsg(h, D(DescriptorProto_field), &msg_onendfield, 7023 upb_handlers_setstartmsg(h, &msg_start, NULL);
6383 NULL); 7024 upb_handlers_setendmsg(h, &msg_end, NULL);
6384 upb_handlers_setendsubmsg(h, D(DescriptorProto_extension), &pushextension, 7025 upb_handlers_setstring(h, F(DescriptorProto, name), &msg_name, NULL);
6385 NULL); 7026 upb_handlers_setstartsubmsg(h, F(DescriptorProto, extension), &msg_startext,
6386 } else if (m == D(FileDescriptorProto)) { 7027 NULL);
6387 upb_handlers_setstartmsg(h, &file_startmsg, NULL); 7028 upb_handlers_setstartsubmsg(h, F(DescriptorProto, nested_type),
6388 upb_handlers_setendmsg(h, &file_endmsg, NULL); 7029 &msg_startmsg, NULL);
6389 upb_handlers_setstring(h, D(FileDescriptorProto_package), &file_onpackage, 7030 upb_handlers_setstartsubmsg(h, F(DescriptorProto, field),
7031 &msg_startfield, NULL);
7032 upb_handlers_setendsubmsg(h, F(DescriptorProto, field),
7033 &msg_endfield, NULL);
7034 upb_handlers_setstartsubmsg(h, F(DescriptorProto, enum_type),
7035 &file_startenum, NULL);
7036 } else if (upbdefs_google_protobuf_FileDescriptorProto_is(m)) {
7037 upb_handlers_setstartmsg(h, &file_start, NULL);
7038 upb_handlers_setendmsg(h, &file_end, NULL);
7039 upb_handlers_setstring(h, F(FileDescriptorProto, name), &file_onname,
6390 NULL); 7040 NULL);
6391 upb_handlers_setendsubmsg(h, D(FileDescriptorProto_extension), &pushextensio n, 7041 upb_handlers_setstring(h, F(FileDescriptorProto, package), &file_onpackage,
6392 NULL); 7042 NULL);
6393 } else if (m == D(EnumValueDescriptorProto)) { 7043 upb_handlers_setstring(h, F(FileDescriptorProto, syntax), &file_onsyntax,
7044 NULL);
7045 upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, message_type),
7046 &file_startmsg, NULL);
7047 upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, enum_type),
7048 &file_startenum, NULL);
7049 upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension),
7050 &file_startext, NULL);
7051 } else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) {
6394 upb_handlers_setstartmsg(h, &enumval_startmsg, NULL); 7052 upb_handlers_setstartmsg(h, &enumval_startmsg, NULL);
6395 upb_handlers_setendmsg(h, &enumval_endmsg, NULL); 7053 upb_handlers_setendmsg(h, &enumval_endmsg, NULL);
6396 upb_handlers_setstring(h, D(EnumValueDescriptorProto_name), &enumval_onname, NULL); 7054 upb_handlers_setstring(h, F(EnumValueDescriptorProto, name), &enumval_onname , NULL);
6397 upb_handlers_setint32(h, D(EnumValueDescriptorProto_number), &enumval_onnumb er, 7055 upb_handlers_setint32(h, F(EnumValueDescriptorProto, number), &enumval_onnum ber,
6398 NULL); 7056 NULL);
6399 } else if (m == D(EnumDescriptorProto)) { 7057 } else if (upbdefs_google_protobuf_EnumDescriptorProto_is(m)) {
6400 upb_handlers_setstartmsg(h, &enum_startmsg, NULL);
6401 upb_handlers_setendmsg(h, &enum_endmsg, NULL); 7058 upb_handlers_setendmsg(h, &enum_endmsg, NULL);
6402 upb_handlers_setstring(h, D(EnumDescriptorProto_name), &enum_onname, NULL); 7059 upb_handlers_setstring(h, F(EnumDescriptorProto, name), &enum_onname, NULL);
6403 } else if (m == D(FieldDescriptorProto)) { 7060 } else if (upbdefs_google_protobuf_FieldDescriptorProto_is(m)) {
6404 upb_handlers_setstartmsg(h, &field_startmsg, NULL); 7061 upb_handlers_setstartmsg(h, &field_startmsg, NULL);
6405 upb_handlers_setendmsg(h, &field_endmsg, NULL); 7062 upb_handlers_setendmsg(h, &field_endmsg, NULL);
6406 upb_handlers_setint32(h, D(FieldDescriptorProto_type), &field_ontype, 7063 upb_handlers_setint32(h, F(FieldDescriptorProto, type), &field_ontype,
6407 NULL); 7064 NULL);
6408 upb_handlers_setint32(h, D(FieldDescriptorProto_label), &field_onlabel, 7065 upb_handlers_setint32(h, F(FieldDescriptorProto, label), &field_onlabel,
6409 NULL); 7066 NULL);
6410 upb_handlers_setint32(h, D(FieldDescriptorProto_number), &field_onnumber, 7067 upb_handlers_setint32(h, F(FieldDescriptorProto, number), &field_onnumber,
6411 NULL); 7068 NULL);
6412 upb_handlers_setstring(h, D(FieldDescriptorProto_name), &field_onname, 7069 upb_handlers_setstring(h, F(FieldDescriptorProto, name), &field_onname,
6413 NULL); 7070 NULL);
6414 upb_handlers_setstring(h, D(FieldDescriptorProto_type_name), 7071 upb_handlers_setstring(h, F(FieldDescriptorProto, type_name),
6415 &field_ontypename, NULL); 7072 &field_ontypename, NULL);
6416 upb_handlers_setstring(h, D(FieldDescriptorProto_extendee), 7073 upb_handlers_setstring(h, F(FieldDescriptorProto, extendee),
6417 &field_onextendee, NULL); 7074 &field_onextendee, NULL);
6418 upb_handlers_setstring(h, D(FieldDescriptorProto_default_value), 7075 upb_handlers_setstring(h, F(FieldDescriptorProto, default_value),
6419 &field_ondefaultval, NULL); 7076 &field_ondefaultval, NULL);
6420 } else if (m == D(FieldOptions)) { 7077 } else if (upbdefs_google_protobuf_FieldOptions_is(m)) {
6421 upb_handlers_setbool(h, D(FieldOptions_lazy), &field_onlazy, NULL); 7078 upb_handlers_setbool(h, F(FieldOptions, lazy), &field_onlazy, NULL);
6422 upb_handlers_setbool(h, D(FieldOptions_packed), &field_onpacked, NULL); 7079 upb_handlers_setbool(h, F(FieldOptions, packed), &field_onpacked, NULL);
7080 } else if (upbdefs_google_protobuf_MessageOptions_is(m)) {
7081 upb_handlers_setbool(h, F(MessageOptions, map_entry), &msg_onmapentry, NULL) ;
7082 }
7083
7084 assert(upb_ok(upb_handlers_status(h)));
7085 }
7086
7087 #undef F
7088
7089 void descreader_cleanup(void *_r) {
7090 upb_descreader *r = _r;
7091 size_t i;
7092
7093 for (i = 0; i < upb_descreader_filecount(r); i++) {
7094 upb_filedef_unref(upb_descreader_file(r, i), &r->files);
7095 }
7096
7097 upb_gfree(r->name);
7098 upb_inttable_uninit(&r->files);
7099 upb_gfree(r->default_string);
7100 while (r->stack_len > 0) {
7101 upb_descreader_frame *f = &r->stack[--r->stack_len];
7102 upb_gfree(f->name);
6423 } 7103 }
6424 } 7104 }
6425 7105
6426 #undef D
6427
6428 void descreader_cleanup(void *_r) {
6429 upb_descreader *r = _r;
6430 free(r->name);
6431 upb_deflist_uninit(&r->defs);
6432 free(r->default_string);
6433 while (r->stack_len > 0) {
6434 upb_descreader_frame *f = &r->stack[--r->stack_len];
6435 free(f->name);
6436 }
6437 }
6438
6439 7106
6440 /* Public API ****************************************************************/ 7107 /* Public API ****************************************************************/
6441 7108
6442 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) { 7109 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) {
6443 upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader)); 7110 upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader));
6444 if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) { 7111 if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) {
6445 return NULL; 7112 return NULL;
6446 } 7113 }
6447 7114
6448 upb_deflist_init(&r->defs); 7115 upb_inttable_init(&r->files, UPB_CTYPE_PTR);
6449 upb_sink_reset(upb_descreader_input(r), h, r); 7116 upb_sink_reset(upb_descreader_input(r), h, r);
6450 r->stack_len = 0; 7117 r->stack_len = 0;
6451 r->name = NULL; 7118 r->name = NULL;
6452 r->default_string = NULL; 7119 r->default_string = NULL;
6453 7120
6454 return r; 7121 return r;
6455 } 7122 }
6456 7123
6457 upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n) { 7124 size_t upb_descreader_filecount(const upb_descreader *r) {
6458 *n = r->defs.len; 7125 return upb_inttable_count(&r->files);
6459 upb_deflist_donaterefs(&r->defs, owner); 7126 }
6460 return r->defs.defs; 7127
7128 upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i) {
7129 upb_value v;
7130 if (upb_inttable_lookup(&r->files, i, &v)) {
7131 return upb_value_getptr(v);
7132 } else {
7133 return NULL;
7134 }
6461 } 7135 }
6462 7136
6463 upb_sink *upb_descreader_input(upb_descreader *r) { 7137 upb_sink *upb_descreader_input(upb_descreader *r) {
6464 return &r->sink; 7138 return &r->sink;
6465 } 7139 }
6466 7140
6467 const upb_handlers *upb_descreader_newhandlers(const void *owner) { 7141 const upb_handlers *upb_descreader_newhandlers(const void *owner) {
6468 const upb_symtab *s = upbdefs_google_protobuf_descriptor(&s); 7142 const upb_msgdef *m = upbdefs_google_protobuf_FileDescriptorSet_get(&m);
6469 const upb_handlers *h = upb_handlers_newfrozen( 7143 const upb_handlers *h = upb_handlers_newfrozen(m, owner, reghandlers, NULL);
6470 upbdefs_google_protobuf_FileDescriptorSet(s), owner, reghandlers, s); 7144 upb_msgdef_unref(m, &m);
6471 upb_symtab_unref(s, &s);
6472 return h; 7145 return h;
6473 } 7146 }
6474 /* 7147 /*
6475 ** protobuf decoder bytecode compiler 7148 ** protobuf decoder bytecode compiler
6476 ** 7149 **
6477 ** Code to compile a upb::Handlers into bytecode for decoding a protobuf 7150 ** Code to compile a upb::Handlers into bytecode for decoding a protobuf
6478 ** according to that specific schema and destination handlers. 7151 ** according to that specific schema and destination handlers.
6479 ** 7152 **
6480 ** Compiling to bytecode is always the first step. If we are using the 7153 ** Compiling to bytecode is always the first step. If we are using the
6481 ** interpreted decoder we leave it as bytecode and interpret that. If we are 7154 ** interpreted decoder we leave it as bytecode and interpret that. If we are
(...skipping 13 matching lines...) Expand all
6495 #define EMPTYLABEL -1 7168 #define EMPTYLABEL -1
6496 7169
6497 /* mgroup *********************************************************************/ 7170 /* mgroup *********************************************************************/
6498 7171
6499 static void freegroup(upb_refcounted *r) { 7172 static void freegroup(upb_refcounted *r) {
6500 mgroup *g = (mgroup*)r; 7173 mgroup *g = (mgroup*)r;
6501 upb_inttable_uninit(&g->methods); 7174 upb_inttable_uninit(&g->methods);
6502 #ifdef UPB_USE_JIT_X64 7175 #ifdef UPB_USE_JIT_X64
6503 upb_pbdecoder_freejit(g); 7176 upb_pbdecoder_freejit(g);
6504 #endif 7177 #endif
6505 free(g->bytecode); 7178 upb_gfree(g->bytecode);
6506 free(g); 7179 upb_gfree(g);
6507 } 7180 }
6508 7181
6509 static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit, 7182 static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit,
6510 void *closure) { 7183 void *closure) {
6511 const mgroup *g = (const mgroup*)r; 7184 const mgroup *g = (const mgroup*)r;
6512 upb_inttable_iter i; 7185 upb_inttable_iter i;
6513 upb_inttable_begin(&i, &g->methods); 7186 upb_inttable_begin(&i, &g->methods);
6514 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { 7187 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
6515 upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i)); 7188 upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i));
6516 visit(r, upb_pbdecodermethod_upcast(method), closure); 7189 visit(r, upb_pbdecodermethod_upcast(method), closure);
6517 } 7190 }
6518 } 7191 }
6519 7192
6520 mgroup *newgroup(const void *owner) { 7193 mgroup *newgroup(const void *owner) {
6521 mgroup *g = malloc(sizeof(*g)); 7194 mgroup *g = upb_gmalloc(sizeof(*g));
6522 static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup}; 7195 static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup};
6523 upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner); 7196 upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner);
6524 upb_inttable_init(&g->methods, UPB_CTYPE_PTR); 7197 upb_inttable_init(&g->methods, UPB_CTYPE_PTR);
6525 g->bytecode = NULL; 7198 g->bytecode = NULL;
6526 g->bytecode_end = NULL; 7199 g->bytecode_end = NULL;
6527 return g; 7200 return g;
6528 } 7201 }
6529 7202
6530 7203
6531 /* upb_pbdecodermethod ********************************************************/ 7204 /* upb_pbdecodermethod ********************************************************/
6532 7205
6533 static void freemethod(upb_refcounted *r) { 7206 static void freemethod(upb_refcounted *r) {
6534 upb_pbdecodermethod *method = (upb_pbdecodermethod*)r; 7207 upb_pbdecodermethod *method = (upb_pbdecodermethod*)r;
6535 7208
6536 if (method->dest_handlers_) { 7209 if (method->dest_handlers_) {
6537 upb_handlers_unref(method->dest_handlers_, method); 7210 upb_handlers_unref(method->dest_handlers_, method);
6538 } 7211 }
6539 7212
6540 upb_inttable_uninit(&method->dispatch); 7213 upb_inttable_uninit(&method->dispatch);
6541 free(method); 7214 upb_gfree(method);
6542 } 7215 }
6543 7216
6544 static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit, 7217 static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit,
6545 void *closure) { 7218 void *closure) {
6546 const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r; 7219 const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r;
6547 visit(r, m->group, closure); 7220 visit(r, m->group, closure);
6548 } 7221 }
6549 7222
6550 static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers, 7223 static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers,
6551 mgroup *group) { 7224 mgroup *group) {
6552 static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod}; 7225 static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod};
6553 upb_pbdecodermethod *ret = malloc(sizeof(*ret)); 7226 upb_pbdecodermethod *ret = upb_gmalloc(sizeof(*ret));
6554 upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret); 7227 upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret);
6555 upb_byteshandler_init(&ret->input_handler_); 7228 upb_byteshandler_init(&ret->input_handler_);
6556 7229
6557 /* The method references the group and vice-versa, in a circular reference. */ 7230 /* The method references the group and vice-versa, in a circular reference. */
6558 upb_ref2(ret, group); 7231 upb_ref2(ret, group);
6559 upb_ref2(group, ret); 7232 upb_ref2(group, ret);
6560 upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret)); 7233 upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret));
6561 upb_pbdecodermethod_unref(ret, &ret); 7234 upb_pbdecodermethod_unref(ret, &ret);
6562 7235
6563 ret->group = mgroup_upcast_mutable(group); 7236 ret->group = mgroup_upcast_mutable(group);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6606 7279
6607 uint32_t *pc; 7280 uint32_t *pc;
6608 int fwd_labels[MAXLABEL]; 7281 int fwd_labels[MAXLABEL];
6609 int back_labels[MAXLABEL]; 7282 int back_labels[MAXLABEL];
6610 7283
6611 /* For fields marked "lazy", parse them lazily or eagerly? */ 7284 /* For fields marked "lazy", parse them lazily or eagerly? */
6612 bool lazy; 7285 bool lazy;
6613 } compiler; 7286 } compiler;
6614 7287
6615 static compiler *newcompiler(mgroup *group, bool lazy) { 7288 static compiler *newcompiler(mgroup *group, bool lazy) {
6616 compiler *ret = malloc(sizeof(*ret)); 7289 compiler *ret = upb_gmalloc(sizeof(*ret));
6617 int i; 7290 int i;
6618 7291
6619 ret->group = group; 7292 ret->group = group;
6620 ret->lazy = lazy; 7293 ret->lazy = lazy;
6621 for (i = 0; i < MAXLABEL; i++) { 7294 for (i = 0; i < MAXLABEL; i++) {
6622 ret->fwd_labels[i] = EMPTYLABEL; 7295 ret->fwd_labels[i] = EMPTYLABEL;
6623 ret->back_labels[i] = EMPTYLABEL; 7296 ret->back_labels[i] = EMPTYLABEL;
6624 } 7297 }
6625 return ret; 7298 return ret;
6626 } 7299 }
6627 7300
6628 static void freecompiler(compiler *c) { 7301 static void freecompiler(compiler *c) {
6629 free(c); 7302 upb_gfree(c);
6630 } 7303 }
6631 7304
6632 const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); 7305 const size_t ptr_words = sizeof(void*) / sizeof(uint32_t);
6633 7306
6634 /* How many words an instruction is. */ 7307 /* How many words an instruction is. */
6635 static int instruction_len(uint32_t instr) { 7308 static int instruction_len(uint32_t instr) {
6636 switch (getop(instr)) { 7309 switch (getop(instr)) {
6637 case OP_SETDISPATCH: return 1 + ptr_words; 7310 case OP_SETDISPATCH: return 1 + ptr_words;
6638 case OP_TAGN: return 3; 7311 case OP_TAGN: return 3;
6639 case OP_SETBIGGROUPNUM: return 2; 7312 case OP_SETBIGGROUPNUM: return 2;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
6723 } 7396 }
6724 } 7397 }
6725 7398
6726 static void put32(compiler *c, uint32_t v) { 7399 static void put32(compiler *c, uint32_t v) {
6727 mgroup *g = c->group; 7400 mgroup *g = c->group;
6728 if (c->pc == g->bytecode_end) { 7401 if (c->pc == g->bytecode_end) {
6729 int ofs = pcofs(c); 7402 int ofs = pcofs(c);
6730 size_t oldsize = g->bytecode_end - g->bytecode; 7403 size_t oldsize = g->bytecode_end - g->bytecode;
6731 size_t newsize = UPB_MAX(oldsize * 2, 64); 7404 size_t newsize = UPB_MAX(oldsize * 2, 64);
6732 /* TODO(haberman): handle OOM. */ 7405 /* TODO(haberman): handle OOM. */
6733 g->bytecode = realloc(g->bytecode, newsize * sizeof(uint32_t)); 7406 g->bytecode = upb_grealloc(g->bytecode, oldsize * sizeof(uint32_t),
7407 newsize * sizeof(uint32_t));
6734 g->bytecode_end = g->bytecode + newsize; 7408 g->bytecode_end = g->bytecode + newsize;
6735 c->pc = g->bytecode + ofs; 7409 c->pc = g->bytecode + ofs;
6736 } 7410 }
6737 *c->pc++ = v; 7411 *c->pc++ = v;
6738 } 7412 }
6739 7413
6740 static void putop(compiler *c, opcode op, ...) { 7414 static void putop(compiler *c, opcode op, ...) {
6741 va_list ap; 7415 va_list ap;
6742 va_start(ap, op); 7416 va_start(ap, op);
6743 7417
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
7060 7734
7061 /* Generates bytecode to parse a single non-lazy message field. */ 7735 /* Generates bytecode to parse a single non-lazy message field. */
7062 static void generate_msgfield(compiler *c, const upb_fielddef *f, 7736 static void generate_msgfield(compiler *c, const upb_fielddef *f,
7063 upb_pbdecodermethod *method) { 7737 upb_pbdecodermethod *method) {
7064 const upb_handlers *h = upb_pbdecodermethod_desthandlers(method); 7738 const upb_handlers *h = upb_pbdecodermethod_desthandlers(method);
7065 const upb_pbdecodermethod *sub_m = find_submethod(c, method, f); 7739 const upb_pbdecodermethod *sub_m = find_submethod(c, method, f);
7066 int wire_type; 7740 int wire_type;
7067 7741
7068 if (!sub_m) { 7742 if (!sub_m) {
7069 /* Don't emit any code for this field at all; it will be parsed as an 7743 /* Don't emit any code for this field at all; it will be parsed as an
7070 * unknown field. */ 7744 * unknown field.
7745 *
7746 * TODO(haberman): we should change this to parse it as a string field
7747 * instead. It will probably be faster, but more importantly, once we
7748 * start vending unknown fields, a field shouldn't be treated as unknown
7749 * just because it doesn't have subhandlers registered. */
7071 return; 7750 return;
7072 } 7751 }
7073 7752
7074 label(c, LABEL_FIELD); 7753 label(c, LABEL_FIELD);
7075 7754
7076 wire_type = 7755 wire_type =
7077 (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) 7756 (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE)
7078 ? UPB_WIRE_TYPE_DELIMITED 7757 ? UPB_WIRE_TYPE_DELIMITED
7079 : UPB_WIRE_TYPE_START_GROUP; 7758 : UPB_WIRE_TYPE_START_GROUP;
7080 7759
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
7377 * offsets have been previously assigned. 8056 * offsets have been previously assigned.
7378 * 8057 *
7379 * Could avoid the second pass by linking OP_CALL instructions somehow. */ 8058 * Could avoid the second pass by linking OP_CALL instructions somehow. */
7380 compile_methods(c); 8059 compile_methods(c);
7381 compile_methods(c); 8060 compile_methods(c);
7382 g->bytecode_end = c->pc; 8061 g->bytecode_end = c->pc;
7383 freecompiler(c); 8062 freecompiler(c);
7384 8063
7385 #ifdef UPB_DUMP_BYTECODE 8064 #ifdef UPB_DUMP_BYTECODE
7386 { 8065 {
7387 FILE *f = fopen("/tmp/upb-bytecode", "wb"); 8066 FILE *f = fopen("/tmp/upb-bytecode", "w");
7388 assert(f); 8067 assert(f);
7389 dumpbc(g->bytecode, g->bytecode_end, stderr); 8068 dumpbc(g->bytecode, g->bytecode_end, stderr);
7390 dumpbc(g->bytecode, g->bytecode_end, f); 8069 dumpbc(g->bytecode, g->bytecode_end, f);
7391 fclose(f); 8070 fclose(f);
8071
8072 f = fopen("/tmp/upb-bytecode.bin", "wb");
8073 assert(f);
8074 fwrite(g->bytecode, 1, g->bytecode_end - g->bytecode, f);
8075 fclose(f);
7392 } 8076 }
7393 #endif 8077 #endif
7394 8078
7395 sethandlers(g, allowjit); 8079 sethandlers(g, allowjit);
7396 return g; 8080 return g;
7397 } 8081 }
7398 8082
7399 8083
7400 /* upb_pbcodecache ************************************************************/ 8084 /* upb_pbcodecache ************************************************************/
7401 8085
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
7481 const char *kPbDecoderSubmessageTooLong = 8165 const char *kPbDecoderSubmessageTooLong =
7482 "Submessage end extends past enclosing submessage."; 8166 "Submessage end extends past enclosing submessage.";
7483 8167
7484 /* Error messages shared within this file. */ 8168 /* Error messages shared within this file. */
7485 static const char *kUnterminatedVarint = "Unterminated varint."; 8169 static const char *kUnterminatedVarint = "Unterminated varint.";
7486 8170
7487 /* upb_pbdecoder **************************************************************/ 8171 /* upb_pbdecoder **************************************************************/
7488 8172
7489 static opcode halt = OP_HALT; 8173 static opcode halt = OP_HALT;
7490 8174
8175 /* A dummy character we can point to when the user passes us a NULL buffer.
8176 * We need this because in C (NULL + 0) and (NULL - NULL) are undefined
8177 * behavior, which would invalidate functions like curbufleft(). */
8178 static const char dummy_char;
8179
7491 /* Whether an op consumes any of the input buffer. */ 8180 /* Whether an op consumes any of the input buffer. */
7492 static bool consumes_input(opcode op) { 8181 static bool consumes_input(opcode op) {
7493 switch (op) { 8182 switch (op) {
7494 case OP_SETDISPATCH: 8183 case OP_SETDISPATCH:
7495 case OP_STARTMSG: 8184 case OP_STARTMSG:
7496 case OP_ENDMSG: 8185 case OP_ENDMSG:
7497 case OP_STARTSEQ: 8186 case OP_STARTSEQ:
7498 case OP_ENDSEQ: 8187 case OP_ENDSEQ:
7499 case OP_STARTSUBMSG: 8188 case OP_STARTSUBMSG:
7500 case OP_ENDSUBMSG: 8189 case OP_ENDSUBMSG:
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
7636 * indicating how many bytes can be skipped over before passing actual data 8325 * indicating how many bytes can be skipped over before passing actual data
7637 * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they 8326 * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they
7638 * won't actually be read. 8327 * won't actually be read.
7639 */ 8328 */
7640 static int32_t skip(upb_pbdecoder *d, size_t bytes) { 8329 static int32_t skip(upb_pbdecoder *d, size_t bytes) {
7641 assert(!in_residual_buf(d, d->ptr) || d->size_param == 0); 8330 assert(!in_residual_buf(d, d->ptr) || d->size_param == 0);
7642 assert(d->skip == 0); 8331 assert(d->skip == 0);
7643 if (bytes > delim_remaining(d)) { 8332 if (bytes > delim_remaining(d)) {
7644 seterr(d, "Skipped value extended beyond enclosing submessage."); 8333 seterr(d, "Skipped value extended beyond enclosing submessage.");
7645 return upb_pbdecoder_suspend(d); 8334 return upb_pbdecoder_suspend(d);
7646 } else if (bufleft(d) > bytes) { 8335 } else if (bufleft(d) >= bytes) {
7647 /* Skipped data is all in current buffer, and more is still available. */ 8336 /* Skipped data is all in current buffer, and more is still available. */
7648 advance(d, bytes); 8337 advance(d, bytes);
7649 d->skip = 0; 8338 d->skip = 0;
7650 return DECODE_OK; 8339 return DECODE_OK;
7651 } else { 8340 } else {
7652 /* Skipped data extends beyond currently available buffers. */ 8341 /* Skipped data extends beyond currently available buffers. */
7653 d->pc = d->last; 8342 d->pc = d->last;
7654 d->skip = bytes - curbufleft(d); 8343 d->skip = bytes - curbufleft(d);
7655 d->bufstart_ofs += (d->end - d->buf); 8344 d->bufstart_ofs += (d->end - d->buf);
7656 d->residual_end = d->residual; 8345 d->residual_end = d->residual;
7657 switchtobuf(d, d->residual, d->residual_end); 8346 switchtobuf(d, d->residual, d->residual_end);
7658 return d->size_param + d->skip; 8347 return d->size_param + d->skip;
7659 } 8348 }
7660 } 8349 }
7661 8350
7662 8351
7663 /* Resumes the decoder from an initial state or from a previous suspend. */ 8352 /* Resumes the decoder from an initial state or from a previous suspend. */
7664 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, 8353 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf,
7665 size_t size, const upb_bufhandle *handle) { 8354 size_t size, const upb_bufhandle *handle) {
7666 UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */ 8355 UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */
7667 8356
7668 d->buf_param = buf; 8357 /* d->skip and d->residual_end could probably elegantly be represented
8358 * as a single variable, to more easily represent this invariant. */
8359 assert(!(d->skip && d->residual_end > d->residual));
8360
8361 /* We need to remember the original size_param, so that the value we return
8362 * is relative to it, even if we do some skipping first. */
7669 d->size_param = size; 8363 d->size_param = size;
7670 d->handle = handle; 8364 d->handle = handle;
7671 8365
8366 /* Have to handle this case specially (ie. not with skip()) because the user
8367 * is allowed to pass a NULL buffer here, which won't allow us to safely
8368 * calculate a d->end or use our normal functions like curbufleft(). */
8369 if (d->skip && d->skip >= size) {
8370 d->skip -= size;
8371 d->bufstart_ofs += size;
8372 buf = &dummy_char;
8373 size = 0;
8374
8375 /* We can't just return now, because we might need to execute some ops
8376 * like CHECKDELIM, which could call some callbacks and pop the stack. */
8377 }
8378
8379 /* We need to pretend that this was the actual buffer param, since some of the
8380 * calculations assume that d->ptr/d->buf is relative to this. */
8381 d->buf_param = buf;
8382
8383 if (!buf) {
8384 /* NULL buf is ok if its entire span is covered by the "skip" above, but
8385 * by this point we know that "skip" doesn't cover the buffer. */
8386 seterr(d, "Passed NULL buffer over non-skippable region.");
8387 return upb_pbdecoder_suspend(d);
8388 }
8389
7672 if (d->residual_end > d->residual) { 8390 if (d->residual_end > d->residual) {
7673 /* We have residual bytes from the last buffer. */ 8391 /* We have residual bytes from the last buffer. */
7674 assert(d->ptr == d->residual); 8392 assert(d->ptr == d->residual);
7675 } else { 8393 } else {
7676 switchtobuf(d, buf, buf + size); 8394 switchtobuf(d, buf, buf + size);
7677 } 8395 }
7678 8396
7679 d->checkpoint = d->ptr; 8397 d->checkpoint = d->ptr;
7680 8398
8399 /* Handle skips that don't cover the whole buffer (as above). */
7681 if (d->skip) { 8400 if (d->skip) {
7682 size_t skip_bytes = d->skip; 8401 size_t skip_bytes = d->skip;
7683 d->skip = 0; 8402 d->skip = 0;
7684 CHECK_RETURN(skip(d, skip_bytes)); 8403 CHECK_RETURN(skip(d, skip_bytes));
7685 d->checkpoint = d->ptr; 8404 checkpoint(d);
7686 } 8405 }
7687 8406
7688 if (!buf) { 8407 /* If we're inside an unknown group, continue to parse unknown values. */
7689 /* NULL buf is ok if its entire span is covered by the "skip" above, but
7690 * by this point we know that "skip" doesn't cover the buffer. */
7691 seterr(d, "Passed NULL buffer over non-skippable region.");
7692 return upb_pbdecoder_suspend(d);
7693 }
7694
7695 if (d->top->groupnum < 0) { 8408 if (d->top->groupnum < 0) {
7696 CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0)); 8409 CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0));
7697 d->checkpoint = d->ptr; 8410 checkpoint(d);
7698 } 8411 }
7699 8412
7700 return DECODE_OK; 8413 return DECODE_OK;
7701 } 8414 }
7702 8415
7703 /* Suspends the decoder at the last checkpoint, without saving any residual 8416 /* Suspends the decoder at the last checkpoint, without saving any residual
7704 * bytes. If there are any unconsumed bytes, returns a short byte count. */ 8417 * bytes. If there are any unconsumed bytes, returns a short byte count. */
7705 size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { 8418 size_t upb_pbdecoder_suspend(upb_pbdecoder *d) {
7706 d->pc = d->last; 8419 d->pc = d->last;
7707 if (d->checkpoint == d->residual) { 8420 if (d->checkpoint == d->residual) {
7708 /* Checkpoint was in residual buf; no user bytes were consumed. */ 8421 /* Checkpoint was in residual buf; no user bytes were consumed. */
7709 d->ptr = d->residual; 8422 d->ptr = d->residual;
7710 return 0; 8423 return 0;
7711 } else { 8424 } else {
7712 size_t consumed; 8425 size_t ret = d->size_param - (d->end - d->checkpoint);
7713 assert(!in_residual_buf(d, d->checkpoint)); 8426 assert(!in_residual_buf(d, d->checkpoint));
7714 assert(d->buf == d->buf_param); 8427 assert(d->buf == d->buf_param || d->buf == &dummy_char);
7715 8428
7716 consumed = d->checkpoint - d->buf; 8429 d->bufstart_ofs += (d->checkpoint - d->buf);
7717 d->bufstart_ofs += consumed;
7718 d->residual_end = d->residual; 8430 d->residual_end = d->residual;
7719 switchtobuf(d, d->residual, d->residual_end); 8431 switchtobuf(d, d->residual, d->residual_end);
7720 return consumed; 8432 return ret;
7721 } 8433 }
7722 } 8434 }
7723 8435
7724 /* Suspends the decoder at the last checkpoint, and saves any unconsumed 8436 /* Suspends the decoder at the last checkpoint, and saves any unconsumed
7725 * bytes in our residual buffer. This is necessary if we need more user 8437 * bytes in our residual buffer. This is necessary if we need more user
7726 * bytes to form a complete value, which might not be contiguous in the 8438 * bytes to form a complete value, which might not be contiguous in the
7727 * user's buffers. Always consumes all user bytes. */ 8439 * user's buffers. Always consumes all user bytes. */
7728 static size_t suspend_save(upb_pbdecoder *d) { 8440 static size_t suspend_save(upb_pbdecoder *d) {
7729 /* We hit end-of-buffer before we could parse a full value. 8441 /* We hit end-of-buffer before we could parse a full value.
7730 * Save any unconsumed bytes (if any) to the residual buffer. */ 8442 * Save any unconsumed bytes (if any) to the residual buffer. */
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
7828 /* Decoding of wire types *****************************************************/ 8540 /* Decoding of wire types *****************************************************/
7829 8541
7830 /* Slow path for decoding a varint from the current buffer position. 8542 /* Slow path for decoding a varint from the current buffer position.
7831 * Returns a status code as described in decoder.int.h. */ 8543 * Returns a status code as described in decoder.int.h. */
7832 UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, 8544 UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d,
7833 uint64_t *u64) { 8545 uint64_t *u64) {
7834 uint8_t byte = 0x80; 8546 uint8_t byte = 0x80;
7835 int bitpos; 8547 int bitpos;
7836 *u64 = 0; 8548 *u64 = 0;
7837 for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { 8549 for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) {
7838 int32_t ret = getbytes(d, &byte, 1); 8550 CHECK_RETURN(getbytes(d, &byte, 1));
7839 if (ret >= 0) return ret;
7840 *u64 |= (uint64_t)(byte & 0x7F) << bitpos; 8551 *u64 |= (uint64_t)(byte & 0x7F) << bitpos;
7841 } 8552 }
7842 if(bitpos == 70 && (byte & 0x80)) { 8553 if(bitpos == 70 && (byte & 0x80)) {
7843 seterr(d, kUnterminatedVarint); 8554 seterr(d, kUnterminatedVarint);
7844 return upb_pbdecoder_suspend(d); 8555 return upb_pbdecoder_suspend(d);
7845 } 8556 }
7846 return DECODE_OK; 8557 return DECODE_OK;
7847 } 8558 }
7848 8559
7849 /* Decodes a varint from the current buffer position. 8560 /* Decodes a varint from the current buffer position.
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
8429 d->method_ = m; 9140 d->method_ = m;
8430 d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting)); 9141 d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting));
8431 d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting)); 9142 d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting));
8432 if (!d->stack || !d->callstack) { 9143 if (!d->stack || !d->callstack) {
8433 return NULL; 9144 return NULL;
8434 } 9145 }
8435 9146
8436 d->env = e; 9147 d->env = e;
8437 d->limit = d->stack + default_max_nesting - 1; 9148 d->limit = d->stack + default_max_nesting - 1;
8438 d->stack_size = default_max_nesting; 9149 d->stack_size = default_max_nesting;
9150 d->status = NULL;
8439 9151
8440 upb_pbdecoder_reset(d); 9152 upb_pbdecoder_reset(d);
8441 upb_bytessink_reset(&d->input_, &m->input_handler_, d); 9153 upb_bytessink_reset(&d->input_, &m->input_handler_, d);
8442 9154
8443 assert(sink); 9155 assert(sink);
8444 if (d->method_->dest_handlers_) { 9156 if (d->method_->dest_handlers_) {
8445 if (sink->handlers != d->method_->dest_handlers_) 9157 if (sink->handlers != d->method_->dest_handlers_)
8446 return NULL; 9158 return NULL;
8447 } 9159 }
8448 upb_sink_reset(&d->top->sink, sink->handlers, sink->closure); 9160 upb_sink_reset(&d->top->sink, sink->handlers, sink->closure);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
8550 ** be able to do it without affecting users. 9262 ** be able to do it without affecting users.
8551 ** 9263 **
8552 ** The strategy is to buffer the segments of data that do *not* depend on 9264 ** The strategy is to buffer the segments of data that do *not* depend on
8553 ** unknown lengths in one buffer, and keep a separate buffer of segment pointers 9265 ** unknown lengths in one buffer, and keep a separate buffer of segment pointers
8554 ** and lengths. When the top-level submessage ends, we can go beginning to end, 9266 ** and lengths. When the top-level submessage ends, we can go beginning to end,
8555 ** alternating the writing of lengths with memcpy() of the rest of the data. 9267 ** alternating the writing of lengths with memcpy() of the rest of the data.
8556 ** At the top level though, no buffering is required. 9268 ** At the top level though, no buffering is required.
8557 */ 9269 */
8558 9270
8559 9271
8560 #include <stdlib.h>
8561 9272
8562 /* The output buffer is divided into segments; a segment is a string of data 9273 /* The output buffer is divided into segments; a segment is a string of data
8563 * that is "ready to go" -- it does not need any varint lengths inserted into 9274 * that is "ready to go" -- it does not need any varint lengths inserted into
8564 * the middle. The seams between segments are where varints will be inserted 9275 * the middle. The seams between segments are where varints will be inserted
8565 * once they are known. 9276 * once they are known.
8566 * 9277 *
8567 * We also use the concept of a "run", which is a range of encoded bytes that 9278 * We also use the concept of a "run", which is a range of encoded bytes that
8568 * occur at a single submessage level. Every segment contains one or more runs. 9279 * occur at a single submessage level. Every segment contains one or more runs.
8569 * 9280 *
8570 * A segment can span messages. Consider: 9281 * A segment can span messages. Consider:
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
8795 typedef struct { 9506 typedef struct {
8796 uint8_t bytes; 9507 uint8_t bytes;
8797 char tag[7]; 9508 char tag[7];
8798 } tag_t; 9509 } tag_t;
8799 9510
8800 /* Allocates a new tag for this field, and sets it in these handlerattr. */ 9511 /* Allocates a new tag for this field, and sets it in these handlerattr. */
8801 static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt, 9512 static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt,
8802 upb_handlerattr *attr) { 9513 upb_handlerattr *attr) {
8803 uint32_t n = upb_fielddef_number(f); 9514 uint32_t n = upb_fielddef_number(f);
8804 9515
8805 tag_t *tag = malloc(sizeof(tag_t)); 9516 tag_t *tag = upb_gmalloc(sizeof(tag_t));
8806 tag->bytes = upb_vencode64((n << 3) | wt, tag->tag); 9517 tag->bytes = upb_vencode64((n << 3) | wt, tag->tag);
8807 9518
8808 upb_handlerattr_init(attr); 9519 upb_handlerattr_init(attr);
8809 upb_handlerattr_sethandlerdata(attr, tag); 9520 upb_handlerattr_sethandlerdata(attr, tag);
8810 upb_handlers_addcleanup(h, tag, free); 9521 upb_handlers_addcleanup(h, tag, upb_gfree);
8811 } 9522 }
8812 9523
8813 static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) { 9524 static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) {
8814 return encode_bytes(e, tag->tag, tag->bytes); 9525 return encode_bytes(e, tag->tag, tag->bytes);
8815 } 9526 }
8816 9527
8817 9528
8818 /* encoding of wire types *****************************************************/ 9529 /* encoding of wire types *****************************************************/
8819 9530
8820 static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) { 9531 static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
9059 e->ptr = e->buf; 9770 e->ptr = e->buf;
9060 9771
9061 /* If this fails, increase the value in encoder.h. */ 9772 /* If this fails, increase the value in encoder.h. */
9062 assert(upb_env_bytesallocated(env) - size_before <= UPB_PB_ENCODER_SIZE); 9773 assert(upb_env_bytesallocated(env) - size_before <= UPB_PB_ENCODER_SIZE);
9063 return e; 9774 return e;
9064 } 9775 }
9065 9776
9066 upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } 9777 upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; }
9067 9778
9068 9779
9069 #include <stdio.h>
9070 #include <stdlib.h>
9071 #include <string.h>
9072 9780
9073 upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n, 9781 upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner,
9074 void *owner, upb_status *status) { 9782 upb_status *status) {
9075 /* Create handlers. */ 9783 /* Create handlers. */
9076 const upb_pbdecodermethod *decoder_m; 9784 const upb_pbdecodermethod *decoder_m;
9077 const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h); 9785 const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h);
9078 upb_env env; 9786 upb_env env;
9079 upb_pbdecodermethodopts opts; 9787 upb_pbdecodermethodopts opts;
9080 upb_pbdecoder *decoder; 9788 upb_pbdecoder *decoder;
9081 upb_descreader *reader; 9789 upb_descreader *reader;
9082 bool ok; 9790 bool ok;
9083 upb_def **ret = NULL; 9791 size_t i;
9084 upb_def **defs; 9792 upb_filedef **ret = NULL;
9085 9793
9086 upb_pbdecodermethodopts_init(&opts, reader_h); 9794 upb_pbdecodermethodopts_init(&opts, reader_h);
9087 decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m); 9795 decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m);
9088 9796
9089 upb_env_init(&env); 9797 upb_env_init(&env);
9090 upb_env_reporterrorsto(&env, status); 9798 upb_env_reporterrorsto(&env, status);
9091 9799
9092 reader = upb_descreader_create(&env, reader_h); 9800 reader = upb_descreader_create(&env, reader_h);
9093 decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader)); 9801 decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader));
9094 9802
9095 /* Push input data. */ 9803 /* Push input data. */
9096 ok = upb_bufsrc_putbuf(str, len, upb_pbdecoder_input(decoder)); 9804 ok = upb_bufsrc_putbuf(buf, n, upb_pbdecoder_input(decoder));
9097 9805
9098 if (!ok) goto cleanup; 9806 if (!ok) {
9099 defs = upb_descreader_getdefs(reader, owner, n); 9807 goto cleanup;
9100 ret = malloc(sizeof(upb_def*) * (*n)); 9808 }
9101 memcpy(ret, defs, sizeof(upb_def*) * (*n)); 9809
9810 ret = upb_gmalloc(sizeof (*ret) * (upb_descreader_filecount(reader) + 1));
9811
9812 if (!ret) {
9813 goto cleanup;
9814 }
9815
9816 for (i = 0; i < upb_descreader_filecount(reader); i++) {
9817 ret[i] = upb_descreader_file(reader, i);
9818 upb_filedef_ref(ret[i], owner);
9819 }
9820
9821 ret[i] = NULL;
9102 9822
9103 cleanup: 9823 cleanup:
9104 upb_env_uninit(&env); 9824 upb_env_uninit(&env);
9105 upb_handlers_unref(reader_h, &reader_h); 9825 upb_handlers_unref(reader_h, &reader_h);
9106 upb_pbdecodermethod_unref(decoder_m, &decoder_m); 9826 upb_pbdecodermethod_unref(decoder_m, &decoder_m);
9107 return ret; 9827 return ret;
9108 } 9828 }
9109
9110 bool upb_load_descriptor_into_symtab(upb_symtab *s, const char *str, size_t len,
9111 upb_status *status) {
9112 int n;
9113 bool success;
9114 upb_def **defs = upb_load_defs_from_descriptor(str, len, &n, &defs, status);
9115 if (!defs) return false;
9116 success = upb_symtab_add(s, defs, n, &defs, status);
9117 free(defs);
9118 return success;
9119 }
9120
9121 char *upb_readfile(const char *filename, size_t *len) {
9122 long size;
9123 char *buf;
9124 FILE *f = fopen(filename, "rb");
9125 if(!f) return NULL;
9126 if(fseek(f, 0, SEEK_END) != 0) goto error;
9127 size = ftell(f);
9128 if(size < 0) goto error;
9129 if(fseek(f, 0, SEEK_SET) != 0) goto error;
9130 buf = malloc(size + 1);
9131 if(size && fread(buf, size, 1, f) != 1) goto error;
9132 fclose(f);
9133 if (len) *len = size;
9134 return buf;
9135
9136 error:
9137 fclose(f);
9138 return NULL;
9139 }
9140
9141 bool upb_load_descriptor_file_into_symtab(upb_symtab *symtab, const char *fname,
9142 upb_status *status) {
9143 size_t len;
9144 bool success;
9145 char *data = upb_readfile(fname, &len);
9146 if (!data) {
9147 if (status) upb_status_seterrf(status, "Couldn't read file: %s", fname);
9148 return false;
9149 }
9150 success = upb_load_descriptor_into_symtab(symtab, data, len, status);
9151 free(data);
9152 return success;
9153 }
9154 /* 9829 /*
9155 * upb::pb::TextPrinter 9830 * upb::pb::TextPrinter
9156 * 9831 *
9157 * OPT: This is not optimized at all. It uses printf() which parses the format 9832 * OPT: This is not optimized at all. It uses printf() which parses the format
9158 * string every time, and it allocates memory for every put. 9833 * string every time, and it allocates memory for every put.
9159 */ 9834 */
9160 9835
9161 9836
9162 #include <ctype.h> 9837 #include <ctype.h>
9163 #include <float.h> 9838 #include <float.h>
9164 #include <inttypes.h> 9839 #include <inttypes.h>
9165 #include <stdarg.h> 9840 #include <stdarg.h>
9166 #include <stdio.h> 9841 #include <stdio.h>
9167 #include <stdlib.h>
9168 #include <string.h> 9842 #include <string.h>
9169 9843
9170 9844
9171 struct upb_textprinter { 9845 struct upb_textprinter {
9172 upb_sink input_; 9846 upb_sink input_;
9173 upb_bytessink *output_; 9847 upb_bytessink *output_;
9174 int indent_depth_; 9848 int indent_depth_;
9175 bool single_line_; 9849 bool single_line_;
9176 void *subc; 9850 void *subc;
9177 }; 9851 };
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
9253 bool ok; 9927 bool ok;
9254 9928
9255 va_start(args, fmt); 9929 va_start(args, fmt);
9256 9930
9257 /* Run once to get the length of the string. */ 9931 /* Run once to get the length of the string. */
9258 _upb_va_copy(args_copy, args); 9932 _upb_va_copy(args_copy, args);
9259 len = _upb_vsnprintf(NULL, 0, fmt, args_copy); 9933 len = _upb_vsnprintf(NULL, 0, fmt, args_copy);
9260 va_end(args_copy); 9934 va_end(args_copy);
9261 9935
9262 /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */ 9936 /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */
9263 str = malloc(len + 1); 9937 str = upb_gmalloc(len + 1);
9264 if (!str) return false; 9938 if (!str) return false;
9265 written = vsprintf(str, fmt, args); 9939 written = vsprintf(str, fmt, args);
9266 va_end(args); 9940 va_end(args);
9267 UPB_ASSERT_VAR(written, written == len); 9941 UPB_ASSERT_VAR(written, written == len);
9268 9942
9269 ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL); 9943 ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL);
9270 free(str); 9944 upb_gfree(str);
9271 return ok; 9945 return ok;
9272 } 9946 }
9273 9947
9274 9948
9275 /* handlers *******************************************************************/ 9949 /* handlers *******************************************************************/
9276 9950
9277 static bool textprinter_startmsg(void *c, const void *hd) { 9951 static bool textprinter_startmsg(void *c, const void *hd) {
9278 upb_textprinter *p = c; 9952 upb_textprinter *p = c;
9279 UPB_UNUSED(hd); 9953 UPB_UNUSED(hd);
9280 if (p->indent_depth_ == 0) { 9954 if (p->indent_depth_ == 0) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
9629 ** out: 10303 ** out:
9630 ** 10304 **
9631 ** - handling of unicode escape sequences (including high surrogate pairs). 10305 ** - handling of unicode escape sequences (including high surrogate pairs).
9632 ** - properly check and report errors for unknown fields, stack overflow, 10306 ** - properly check and report errors for unknown fields, stack overflow,
9633 ** improper array nesting (or lack of nesting). 10307 ** improper array nesting (or lack of nesting).
9634 ** - handling of base64 sequences with padding characters. 10308 ** - handling of base64 sequences with padding characters.
9635 ** - handling of push-back (non-success returns from sink functions). 10309 ** - handling of push-back (non-success returns from sink functions).
9636 ** - handling of keys/escape-sequences/etc that span input buffers. 10310 ** - handling of keys/escape-sequences/etc that span input buffers.
9637 */ 10311 */
9638 10312
9639 #include <stdio.h> 10313 #include <assert.h>
10314 #include <errno.h>
9640 #include <stdint.h> 10315 #include <stdint.h>
9641 #include <assert.h> 10316 #include <stdlib.h>
9642 #include <string.h> 10317 #include <string.h>
9643 #include <stdlib.h>
9644 #include <errno.h>
9645 10318
9646 10319
9647 #define UPB_JSON_MAX_DEPTH 64 10320 #define UPB_JSON_MAX_DEPTH 64
9648 10321
9649 typedef struct { 10322 typedef struct {
9650 upb_sink sink; 10323 upb_sink sink;
9651 10324
9652 /* The current message in which we're parsing, and the field whose value we're 10325 /* The current message in which we're parsing, and the field whose value we're
9653 * expecting next. */ 10326 * expecting next. */
9654 const upb_msgdef *m; 10327 const upb_msgdef *m;
9655 const upb_fielddef *f; 10328 const upb_fielddef *f;
9656 10329
10330 /* The table mapping json name to fielddef for this message. */
10331 upb_strtable *name_table;
10332
9657 /* We are in a repeated-field context, ready to emit mapentries as 10333 /* We are in a repeated-field context, ready to emit mapentries as
9658 * submessages. This flag alters the start-of-object (open-brace) behavior to 10334 * submessages. This flag alters the start-of-object (open-brace) behavior to
9659 * begin a sequence of mapentry messages rather than a single submessage. */ 10335 * begin a sequence of mapentry messages rather than a single submessage. */
9660 bool is_map; 10336 bool is_map;
9661 10337
9662 /* We are in a map-entry message context. This flag is set when parsing the 10338 /* We are in a map-entry message context. This flag is set when parsing the
9663 * value field of a single map entry and indicates to all value-field parsers 10339 * value field of a single map entry and indicates to all value-field parsers
9664 * (subobjects, strings, numbers, and bools) that the map-entry submessage 10340 * (subobjects, strings, numbers, and bools) that the map-entry submessage
9665 * should end as soon as the value is parsed. */ 10341 * should end as soon as the value is parsed. */
9666 bool is_mapentry; 10342 bool is_mapentry;
9667 10343
9668 /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent 10344 /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent
9669 * message's map field that we're currently parsing. This differs from |f| 10345 * message's map field that we're currently parsing. This differs from |f|
9670 * because |f| is the field in the *current* message (i.e., the map-entry 10346 * because |f| is the field in the *current* message (i.e., the map-entry
9671 * message itself), not the parent's field that leads to this map. */ 10347 * message itself), not the parent's field that leads to this map. */
9672 const upb_fielddef *mapfield; 10348 const upb_fielddef *mapfield;
9673 } upb_jsonparser_frame; 10349 } upb_jsonparser_frame;
9674 10350
9675 struct upb_json_parser { 10351 struct upb_json_parser {
9676 upb_env *env; 10352 upb_env *env;
9677 upb_byteshandler input_handler_; 10353 const upb_json_parsermethod *method;
9678 upb_bytessink input_; 10354 upb_bytessink input_;
9679 10355
9680 /* Stack to track the JSON scopes we are in. */ 10356 /* Stack to track the JSON scopes we are in. */
9681 upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH]; 10357 upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH];
9682 upb_jsonparser_frame *top; 10358 upb_jsonparser_frame *top;
9683 upb_jsonparser_frame *limit; 10359 upb_jsonparser_frame *limit;
9684 10360
9685 upb_status status; 10361 upb_status status;
9686 10362
9687 /* Ragel's internal parsing stack for the parsing state machine. */ 10363 /* Ragel's internal parsing stack for the parsing state machine. */
(...skipping 14 matching lines...) Expand all
9702 int multipart_state; 10378 int multipart_state;
9703 upb_selector_t string_selector; 10379 upb_selector_t string_selector;
9704 10380
9705 /* Input capture. See details in parser.rl. */ 10381 /* Input capture. See details in parser.rl. */
9706 const char *capture; 10382 const char *capture;
9707 10383
9708 /* Intermediate result of parsing a unicode escape sequence. */ 10384 /* Intermediate result of parsing a unicode escape sequence. */
9709 uint32_t digit; 10385 uint32_t digit;
9710 }; 10386 };
9711 10387
10388 struct upb_json_parsermethod {
10389 upb_refcounted base;
10390
10391 upb_byteshandler input_handler_;
10392
10393 /* Mainly for the purposes of refcounting, so all the fielddefs we point
10394 * to stay alive. */
10395 const upb_msgdef *msg;
10396
10397 /* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */
10398 upb_inttable name_tables;
10399 };
10400
9712 #define PARSER_CHECK_RETURN(x) if (!(x)) return false 10401 #define PARSER_CHECK_RETURN(x) if (!(x)) return false
9713 10402
9714 /* Used to signal that a capture has been suspended. */ 10403 /* Used to signal that a capture has been suspended. */
9715 static char suspend_capture; 10404 static char suspend_capture;
9716 10405
9717 static upb_selector_t getsel_for_handlertype(upb_json_parser *p, 10406 static upb_selector_t getsel_for_handlertype(upb_json_parser *p,
9718 upb_handlertype_t type) { 10407 upb_handlertype_t type) {
9719 upb_selector_t sel; 10408 upb_selector_t sel;
9720 bool ok = upb_handlers_getselector(p->top->f, type, &sel); 10409 bool ok = upb_handlers_getselector(p->top->f, type, &sel);
9721 UPB_ASSERT_VAR(ok, ok); 10410 UPB_ASSERT_VAR(ok, ok);
9722 return sel; 10411 return sel;
9723 } 10412 }
9724 10413
9725 static upb_selector_t parser_getsel(upb_json_parser *p) { 10414 static upb_selector_t parser_getsel(upb_json_parser *p) {
9726 return getsel_for_handlertype( 10415 return getsel_for_handlertype(
9727 p, upb_handlers_getprimitivehandlertype(p->top->f)); 10416 p, upb_handlers_getprimitivehandlertype(p->top->f));
9728 } 10417 }
9729 10418
9730 static bool check_stack(upb_json_parser *p) { 10419 static bool check_stack(upb_json_parser *p) {
9731 if ((p->top + 1) == p->limit) { 10420 if ((p->top + 1) == p->limit) {
9732 upb_status_seterrmsg(&p->status, "Nesting too deep"); 10421 upb_status_seterrmsg(&p->status, "Nesting too deep");
9733 upb_env_reporterror(p->env, &p->status); 10422 upb_env_reporterror(p->env, &p->status);
9734 return false; 10423 return false;
9735 } 10424 }
9736 10425
9737 return true; 10426 return true;
9738 } 10427 }
9739 10428
10429 static void set_name_table(upb_json_parser *p, upb_jsonparser_frame *frame) {
10430 upb_value v;
10431 bool ok = upb_inttable_lookupptr(&p->method->name_tables, frame->m, &v);
10432 UPB_ASSERT_VAR(ok, ok);
10433 frame->name_table = upb_value_getptr(v);
10434 }
10435
9740 /* There are GCC/Clang built-ins for overflow checking which we could start 10436 /* There are GCC/Clang built-ins for overflow checking which we could start
9741 * using if there was any performance benefit to it. */ 10437 * using if there was any performance benefit to it. */
9742 10438
9743 static bool checked_add(size_t a, size_t b, size_t *c) { 10439 static bool checked_add(size_t a, size_t b, size_t *c) {
9744 if (SIZE_MAX - a < b) return false; 10440 if (SIZE_MAX - a < b) return false;
9745 *c = a + b; 10441 *c = a + b;
9746 return true; 10442 return true;
9747 } 10443 }
9748 10444
9749 static size_t saturating_multiply(size_t a, size_t b) { 10445 static size_t saturating_multiply(size_t a, size_t b) {
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
10326 11022
10327 if (!check_stack(p)) return false; 11023 if (!check_stack(p)) return false;
10328 11024
10329 /* Start a new parser frame: parser frames correspond one-to-one with 11025 /* Start a new parser frame: parser frames correspond one-to-one with
10330 * handler frames, and string events occur in a sub-frame. */ 11026 * handler frames, and string events occur in a sub-frame. */
10331 inner = p->top + 1; 11027 inner = p->top + 1;
10332 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); 11028 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR);
10333 upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); 11029 upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink);
10334 inner->m = p->top->m; 11030 inner->m = p->top->m;
10335 inner->f = p->top->f; 11031 inner->f = p->top->f;
11032 inner->name_table = NULL;
10336 inner->is_map = false; 11033 inner->is_map = false;
10337 inner->is_mapentry = false; 11034 inner->is_mapentry = false;
10338 p->top = inner; 11035 p->top = inner;
10339 11036
10340 if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { 11037 if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) {
10341 /* For STRING fields we push data directly to the handlers as it is 11038 /* For STRING fields we push data directly to the handlers as it is
10342 * parsed. We don't do this yet for BYTES fields, because our base64 11039 * parsed. We don't do this yet for BYTES fields, because our base64
10343 * decoder is not streaming. 11040 * decoder is not streaming.
10344 * 11041 *
10345 * TODO(haberman): make base64 decoding streaming also. */ 11042 * TODO(haberman): make base64 decoding streaming also. */
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
10512 if (!check_stack(p)) return false; 11209 if (!check_stack(p)) return false;
10513 11210
10514 mapfield = p->top->mapfield; 11211 mapfield = p->top->mapfield;
10515 mapentrymsg = upb_fielddef_msgsubdef(mapfield); 11212 mapentrymsg = upb_fielddef_msgsubdef(mapfield);
10516 11213
10517 inner = p->top + 1; 11214 inner = p->top + 1;
10518 p->top->f = mapfield; 11215 p->top->f = mapfield;
10519 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); 11216 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
10520 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); 11217 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
10521 inner->m = mapentrymsg; 11218 inner->m = mapentrymsg;
11219 inner->name_table = NULL;
10522 inner->mapfield = mapfield; 11220 inner->mapfield = mapfield;
10523 inner->is_map = false; 11221 inner->is_map = false;
10524 11222
10525 /* Don't set this to true *yet* -- we reuse parsing handlers below to push 11223 /* Don't set this to true *yet* -- we reuse parsing handlers below to push
10526 * the key field value to the sink, and these handlers will pop the frame 11224 * the key field value to the sink, and these handlers will pop the frame
10527 * if they see is_mapentry (when invoked by the parser state machine, they 11225 * if they see is_mapentry (when invoked by the parser state machine, they
10528 * would have just seen the map-entry value, not key). */ 11226 * would have just seen the map-entry value, not key). */
10529 inner->is_mapentry = false; 11227 inner->is_mapentry = false;
10530 p->top = inner; 11228 p->top = inner;
10531 11229
(...skipping 16 matching lines...) Expand all
10548 } 11246 }
10549 11247
10550 static bool end_membername(upb_json_parser *p) { 11248 static bool end_membername(upb_json_parser *p) {
10551 assert(!p->top->f); 11249 assert(!p->top->f);
10552 11250
10553 if (p->top->is_map) { 11251 if (p->top->is_map) {
10554 return handle_mapentry(p); 11252 return handle_mapentry(p);
10555 } else { 11253 } else {
10556 size_t len; 11254 size_t len;
10557 const char *buf = accumulate_getptr(p, &len); 11255 const char *buf = accumulate_getptr(p, &len);
10558 const upb_fielddef *f = upb_msgdef_ntof(p->top->m, buf, len); 11256 upb_value v;
10559 11257
10560 if (!f) { 11258 if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) {
11259 p->top->f = upb_value_getconstptr(v);
11260 multipart_end(p);
11261
11262 return true;
11263 } else {
10561 /* TODO(haberman): Ignore unknown fields if requested/configured to do 11264 /* TODO(haberman): Ignore unknown fields if requested/configured to do
10562 * so. */ 11265 * so. */
10563 upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); 11266 upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf);
10564 upb_env_reporterror(p->env, &p->status); 11267 upb_env_reporterror(p->env, &p->status);
10565 return false; 11268 return false;
10566 } 11269 }
10567
10568 p->top->f = f;
10569 multipart_end(p);
10570
10571 return true;
10572 } 11270 }
10573 } 11271 }
10574 11272
10575 static void end_member(upb_json_parser *p) { 11273 static void end_member(upb_json_parser *p) {
10576 /* If we just parsed a map-entry value, end that frame too. */ 11274 /* If we just parsed a map-entry value, end that frame too. */
10577 if (p->top->is_mapentry) { 11275 if (p->top->is_mapentry) {
10578 upb_status s = UPB_STATUS_INIT; 11276 upb_status s = UPB_STATUS_INIT;
10579 upb_selector_t sel; 11277 upb_selector_t sel;
10580 bool ok; 11278 bool ok;
10581 const upb_fielddef *mapfield; 11279 const upb_fielddef *mapfield;
(...skipping 21 matching lines...) Expand all
10603 upb_selector_t sel; 11301 upb_selector_t sel;
10604 11302
10605 /* Beginning of a map. Start a new parser frame in a repeated-field 11303 /* Beginning of a map. Start a new parser frame in a repeated-field
10606 * context. */ 11304 * context. */
10607 if (!check_stack(p)) return false; 11305 if (!check_stack(p)) return false;
10608 11306
10609 inner = p->top + 1; 11307 inner = p->top + 1;
10610 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); 11308 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
10611 upb_sink_startseq(&p->top->sink, sel, &inner->sink); 11309 upb_sink_startseq(&p->top->sink, sel, &inner->sink);
10612 inner->m = upb_fielddef_msgsubdef(p->top->f); 11310 inner->m = upb_fielddef_msgsubdef(p->top->f);
11311 inner->name_table = NULL;
10613 inner->mapfield = p->top->f; 11312 inner->mapfield = p->top->f;
10614 inner->f = NULL; 11313 inner->f = NULL;
10615 inner->is_map = true; 11314 inner->is_map = true;
10616 inner->is_mapentry = false; 11315 inner->is_mapentry = false;
10617 p->top = inner; 11316 p->top = inner;
10618 11317
10619 return true; 11318 return true;
10620 } else if (upb_fielddef_issubmsg(p->top->f)) { 11319 } else if (upb_fielddef_issubmsg(p->top->f)) {
10621 upb_jsonparser_frame *inner; 11320 upb_jsonparser_frame *inner;
10622 upb_selector_t sel; 11321 upb_selector_t sel;
10623 11322
10624 /* Beginning of a subobject. Start a new parser frame in the submsg 11323 /* Beginning of a subobject. Start a new parser frame in the submsg
10625 * context. */ 11324 * context. */
10626 if (!check_stack(p)) return false; 11325 if (!check_stack(p)) return false;
10627 11326
10628 inner = p->top + 1; 11327 inner = p->top + 1;
10629 11328
10630 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); 11329 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG);
10631 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); 11330 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink);
10632 inner->m = upb_fielddef_msgsubdef(p->top->f); 11331 inner->m = upb_fielddef_msgsubdef(p->top->f);
11332 set_name_table(p, inner);
10633 inner->f = NULL; 11333 inner->f = NULL;
10634 inner->is_map = false; 11334 inner->is_map = false;
10635 inner->is_mapentry = false; 11335 inner->is_mapentry = false;
10636 p->top = inner; 11336 p->top = inner;
10637 11337
10638 return true; 11338 return true;
10639 } else { 11339 } else {
10640 upb_status_seterrf(&p->status, 11340 upb_status_seterrf(&p->status,
10641 "Object specified for non-message/group field: %s", 11341 "Object specified for non-message/group field: %s",
10642 upb_fielddef_name(p->top->f)); 11342 upb_fielddef_name(p->top->f));
(...skipping 29 matching lines...) Expand all
10672 upb_env_reporterror(p->env, &p->status); 11372 upb_env_reporterror(p->env, &p->status);
10673 return false; 11373 return false;
10674 } 11374 }
10675 11375
10676 if (!check_stack(p)) return false; 11376 if (!check_stack(p)) return false;
10677 11377
10678 inner = p->top + 1; 11378 inner = p->top + 1;
10679 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); 11379 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ);
10680 upb_sink_startseq(&p->top->sink, sel, &inner->sink); 11380 upb_sink_startseq(&p->top->sink, sel, &inner->sink);
10681 inner->m = p->top->m; 11381 inner->m = p->top->m;
11382 inner->name_table = NULL;
10682 inner->f = p->top->f; 11383 inner->f = p->top->f;
10683 inner->is_map = false; 11384 inner->is_map = false;
10684 inner->is_mapentry = false; 11385 inner->is_mapentry = false;
10685 p->top = inner; 11386 p->top = inner;
10686 11387
10687 return true; 11388 return true;
10688 } 11389 }
10689 11390
10690 static void end_array(upb_json_parser *p) { 11391 static void end_array(upb_json_parser *p) {
10691 upb_selector_t sel; 11392 upb_selector_t sel;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
10729 * ">" -- transition into a machine 11430 * ">" -- transition into a machine
10730 * "%" -- transition out of a machine 11431 * "%" -- transition out of a machine
10731 * "@" -- transition into a final state of a machine. 11432 * "@" -- transition into a final state of a machine.
10732 * 11433 *
10733 * "@" transitions are tricky because a machine can transition into a final 11434 * "@" transitions are tricky because a machine can transition into a final
10734 * state repeatedly. But in some cases we know this can't happen, for example 11435 * state repeatedly. But in some cases we know this can't happen, for example
10735 * a string which is delimited by a final '"' can only transition into its 11436 * a string which is delimited by a final '"' can only transition into its
10736 * final state once, when the closing '"' is seen. */ 11437 * final state once, when the closing '"' is seen. */
10737 11438
10738 11439
10739 #line 1218 "upb/json/parser.rl" 11440 #line 1245 "upb/json/parser.rl"
10740 11441
10741 11442
10742 11443
10743 #line 1130 "upb/json/parser.c" 11444 #line 1157 "upb/json/parser.c"
10744 static const char _json_actions[] = { 11445 static const char _json_actions[] = {
10745 0, 1, 0, 1, 2, 1, 3, 1, 11446 0, 1, 0, 1, 2, 1, 3, 1,
10746 5, 1, 6, 1, 7, 1, 8, 1, 11447 5, 1, 6, 1, 7, 1, 8, 1,
10747 10, 1, 12, 1, 13, 1, 14, 1, 11448 10, 1, 12, 1, 13, 1, 14, 1,
10748 15, 1, 16, 1, 17, 1, 21, 1, 11449 15, 1, 16, 1, 17, 1, 21, 1,
10749 25, 1, 27, 2, 3, 8, 2, 4, 11450 25, 1, 27, 2, 3, 8, 2, 4,
10750 5, 2, 6, 2, 2, 6, 8, 2, 11451 5, 2, 6, 2, 2, 6, 8, 2,
10751 11, 9, 2, 13, 15, 2, 14, 15, 11452 11, 9, 2, 13, 15, 2, 14, 15,
10752 2, 18, 1, 2, 19, 27, 2, 20, 11453 2, 18, 1, 2, 19, 27, 2, 20,
10753 9, 2, 22, 27, 2, 23, 27, 2, 11454 9, 2, 22, 27, 2, 23, 27, 2,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
10882 }; 11583 };
10883 11584
10884 static const int json_start = 1; 11585 static const int json_start = 1;
10885 11586
10886 static const int json_en_number_machine = 10; 11587 static const int json_en_number_machine = 10;
10887 static const int json_en_string_machine = 19; 11588 static const int json_en_string_machine = 19;
10888 static const int json_en_value_machine = 27; 11589 static const int json_en_value_machine = 27;
10889 static const int json_en_main = 1; 11590 static const int json_en_main = 1;
10890 11591
10891 11592
10892 #line 1221 "upb/json/parser.rl" 11593 #line 1248 "upb/json/parser.rl"
10893 11594
10894 size_t parse(void *closure, const void *hd, const char *buf, size_t size, 11595 size_t parse(void *closure, const void *hd, const char *buf, size_t size,
10895 const upb_bufhandle *handle) { 11596 const upb_bufhandle *handle) {
10896 upb_json_parser *parser = closure; 11597 upb_json_parser *parser = closure;
10897 11598
10898 /* Variables used by Ragel's generated code. */ 11599 /* Variables used by Ragel's generated code. */
10899 int cs = parser->current_state; 11600 int cs = parser->current_state;
10900 int *stack = parser->parser_stack; 11601 int *stack = parser->parser_stack;
10901 int top = parser->parser_top; 11602 int top = parser->parser_top;
10902 11603
10903 const char *p = buf; 11604 const char *p = buf;
10904 const char *pe = buf + size; 11605 const char *pe = buf + size;
10905 11606
10906 parser->handle = handle; 11607 parser->handle = handle;
10907 11608
10908 UPB_UNUSED(hd); 11609 UPB_UNUSED(hd);
10909 UPB_UNUSED(handle); 11610 UPB_UNUSED(handle);
10910 11611
10911 capture_resume(parser, buf); 11612 capture_resume(parser, buf);
10912 11613
10913 11614
10914 #line 1301 "upb/json/parser.c" 11615 #line 1328 "upb/json/parser.c"
10915 { 11616 {
10916 int _klen; 11617 int _klen;
10917 unsigned int _trans; 11618 unsigned int _trans;
10918 const char *_acts; 11619 const char *_acts;
10919 unsigned int _nacts; 11620 unsigned int _nacts;
10920 const char *_keys; 11621 const char *_keys;
10921 11622
10922 if ( p == pe ) 11623 if ( p == pe )
10923 goto _test_eof; 11624 goto _test_eof;
10924 if ( cs == 0 ) 11625 if ( cs == 0 )
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
10979 if ( _json_trans_actions[_trans] == 0 ) 11680 if ( _json_trans_actions[_trans] == 0 )
10980 goto _again; 11681 goto _again;
10981 11682
10982 _acts = _json_actions + _json_trans_actions[_trans]; 11683 _acts = _json_actions + _json_trans_actions[_trans];
10983 _nacts = (unsigned int) *_acts++; 11684 _nacts = (unsigned int) *_acts++;
10984 while ( _nacts-- > 0 ) 11685 while ( _nacts-- > 0 )
10985 { 11686 {
10986 switch ( *_acts++ ) 11687 switch ( *_acts++ )
10987 { 11688 {
10988 case 0: 11689 case 0:
10989 #line 1133 "upb/json/parser.rl" 11690 #line 1160 "upb/json/parser.rl"
10990 { p--; {cs = stack[--top]; goto _again;} } 11691 { p--; {cs = stack[--top]; goto _again;} }
10991 break; 11692 break;
10992 case 1: 11693 case 1:
10993 #line 1134 "upb/json/parser.rl" 11694 #line 1161 "upb/json/parser.rl"
10994 { p--; {stack[top++] = cs; cs = 10; goto _again;} } 11695 { p--; {stack[top++] = cs; cs = 10; goto _again;} }
10995 break; 11696 break;
10996 case 2: 11697 case 2:
10997 #line 1138 "upb/json/parser.rl" 11698 #line 1165 "upb/json/parser.rl"
10998 { start_text(parser, p); } 11699 { start_text(parser, p); }
10999 break; 11700 break;
11000 case 3: 11701 case 3:
11001 #line 1139 "upb/json/parser.rl" 11702 #line 1166 "upb/json/parser.rl"
11002 { CHECK_RETURN_TOP(end_text(parser, p)); } 11703 { CHECK_RETURN_TOP(end_text(parser, p)); }
11003 break; 11704 break;
11004 case 4: 11705 case 4:
11005 #line 1145 "upb/json/parser.rl" 11706 #line 1172 "upb/json/parser.rl"
11006 { start_hex(parser); } 11707 { start_hex(parser); }
11007 break; 11708 break;
11008 case 5: 11709 case 5:
11009 #line 1146 "upb/json/parser.rl" 11710 #line 1173 "upb/json/parser.rl"
11010 { hexdigit(parser, p); } 11711 { hexdigit(parser, p); }
11011 break; 11712 break;
11012 case 6: 11713 case 6:
11013 #line 1147 "upb/json/parser.rl" 11714 #line 1174 "upb/json/parser.rl"
11014 { CHECK_RETURN_TOP(end_hex(parser)); } 11715 { CHECK_RETURN_TOP(end_hex(parser)); }
11015 break; 11716 break;
11016 case 7: 11717 case 7:
11017 #line 1153 "upb/json/parser.rl" 11718 #line 1180 "upb/json/parser.rl"
11018 { CHECK_RETURN_TOP(escape(parser, p)); } 11719 { CHECK_RETURN_TOP(escape(parser, p)); }
11019 break; 11720 break;
11020 case 8: 11721 case 8:
11021 #line 1159 "upb/json/parser.rl" 11722 #line 1186 "upb/json/parser.rl"
11022 { p--; {cs = stack[--top]; goto _again;} } 11723 { p--; {cs = stack[--top]; goto _again;} }
11023 break; 11724 break;
11024 case 9: 11725 case 9:
11025 #line 1162 "upb/json/parser.rl" 11726 #line 1189 "upb/json/parser.rl"
11026 { {stack[top++] = cs; cs = 19; goto _again;} } 11727 { {stack[top++] = cs; cs = 19; goto _again;} }
11027 break; 11728 break;
11028 case 10: 11729 case 10:
11029 #line 1164 "upb/json/parser.rl" 11730 #line 1191 "upb/json/parser.rl"
11030 { p--; {stack[top++] = cs; cs = 27; goto _again;} } 11731 { p--; {stack[top++] = cs; cs = 27; goto _again;} }
11031 break; 11732 break;
11032 case 11: 11733 case 11:
11033 #line 1169 "upb/json/parser.rl" 11734 #line 1196 "upb/json/parser.rl"
11034 { start_member(parser); } 11735 { start_member(parser); }
11035 break; 11736 break;
11036 case 12: 11737 case 12:
11037 #line 1170 "upb/json/parser.rl" 11738 #line 1197 "upb/json/parser.rl"
11038 { CHECK_RETURN_TOP(end_membername(parser)); } 11739 { CHECK_RETURN_TOP(end_membername(parser)); }
11039 break; 11740 break;
11040 case 13: 11741 case 13:
11041 #line 1173 "upb/json/parser.rl" 11742 #line 1200 "upb/json/parser.rl"
11042 { end_member(parser); } 11743 { end_member(parser); }
11043 break; 11744 break;
11044 case 14: 11745 case 14:
11045 #line 1179 "upb/json/parser.rl" 11746 #line 1206 "upb/json/parser.rl"
11046 { start_object(parser); } 11747 { start_object(parser); }
11047 break; 11748 break;
11048 case 15: 11749 case 15:
11049 #line 1182 "upb/json/parser.rl" 11750 #line 1209 "upb/json/parser.rl"
11050 { end_object(parser); } 11751 { end_object(parser); }
11051 break; 11752 break;
11052 case 16: 11753 case 16:
11053 #line 1188 "upb/json/parser.rl" 11754 #line 1215 "upb/json/parser.rl"
11054 { CHECK_RETURN_TOP(start_array(parser)); } 11755 { CHECK_RETURN_TOP(start_array(parser)); }
11055 break; 11756 break;
11056 case 17: 11757 case 17:
11057 #line 1192 "upb/json/parser.rl" 11758 #line 1219 "upb/json/parser.rl"
11058 { end_array(parser); } 11759 { end_array(parser); }
11059 break; 11760 break;
11060 case 18: 11761 case 18:
11061 #line 1197 "upb/json/parser.rl" 11762 #line 1224 "upb/json/parser.rl"
11062 { start_number(parser, p); } 11763 { start_number(parser, p); }
11063 break; 11764 break;
11064 case 19: 11765 case 19:
11065 #line 1198 "upb/json/parser.rl" 11766 #line 1225 "upb/json/parser.rl"
11066 { CHECK_RETURN_TOP(end_number(parser, p)); } 11767 { CHECK_RETURN_TOP(end_number(parser, p)); }
11067 break; 11768 break;
11068 case 20: 11769 case 20:
11069 #line 1200 "upb/json/parser.rl" 11770 #line 1227 "upb/json/parser.rl"
11070 { CHECK_RETURN_TOP(start_stringval(parser)); } 11771 { CHECK_RETURN_TOP(start_stringval(parser)); }
11071 break; 11772 break;
11072 case 21: 11773 case 21:
11073 #line 1201 "upb/json/parser.rl" 11774 #line 1228 "upb/json/parser.rl"
11074 { CHECK_RETURN_TOP(end_stringval(parser)); } 11775 { CHECK_RETURN_TOP(end_stringval(parser)); }
11075 break; 11776 break;
11076 case 22: 11777 case 22:
11077 #line 1203 "upb/json/parser.rl" 11778 #line 1230 "upb/json/parser.rl"
11078 { CHECK_RETURN_TOP(parser_putbool(parser, true)); } 11779 { CHECK_RETURN_TOP(parser_putbool(parser, true)); }
11079 break; 11780 break;
11080 case 23: 11781 case 23:
11081 #line 1205 "upb/json/parser.rl" 11782 #line 1232 "upb/json/parser.rl"
11082 { CHECK_RETURN_TOP(parser_putbool(parser, false)); } 11783 { CHECK_RETURN_TOP(parser_putbool(parser, false)); }
11083 break; 11784 break;
11084 case 24: 11785 case 24:
11085 #line 1207 "upb/json/parser.rl" 11786 #line 1234 "upb/json/parser.rl"
11086 { /* null value */ } 11787 { /* null value */ }
11087 break; 11788 break;
11088 case 25: 11789 case 25:
11089 #line 1209 "upb/json/parser.rl" 11790 #line 1236 "upb/json/parser.rl"
11090 { CHECK_RETURN_TOP(start_subobject(parser)); } 11791 { CHECK_RETURN_TOP(start_subobject(parser)); }
11091 break; 11792 break;
11092 case 26: 11793 case 26:
11093 #line 1210 "upb/json/parser.rl" 11794 #line 1237 "upb/json/parser.rl"
11094 { end_subobject(parser); } 11795 { end_subobject(parser); }
11095 break; 11796 break;
11096 case 27: 11797 case 27:
11097 #line 1215 "upb/json/parser.rl" 11798 #line 1242 "upb/json/parser.rl"
11098 { p--; {cs = stack[--top]; goto _again;} } 11799 { p--; {cs = stack[--top]; goto _again;} }
11099 break; 11800 break;
11100 #line 1487 "upb/json/parser.c" 11801 #line 1514 "upb/json/parser.c"
11101 } 11802 }
11102 } 11803 }
11103 11804
11104 _again: 11805 _again:
11105 if ( cs == 0 ) 11806 if ( cs == 0 )
11106 goto _out; 11807 goto _out;
11107 if ( ++p != pe ) 11808 if ( ++p != pe )
11108 goto _resume; 11809 goto _resume;
11109 _test_eof: {} 11810 _test_eof: {}
11110 _out: {} 11811 _out: {}
11111 } 11812 }
11112 11813
11113 #line 1242 "upb/json/parser.rl" 11814 #line 1269 "upb/json/parser.rl"
11114 11815
11115 if (p != pe) { 11816 if (p != pe) {
11116 upb_status_seterrf(&parser->status, "Parse error at %s\n", p); 11817 upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
11117 upb_env_reporterror(parser->env, &parser->status); 11818 upb_env_reporterror(parser->env, &parser->status);
11118 } else { 11819 } else {
11119 capture_suspend(parser, &p); 11820 capture_suspend(parser, &p);
11120 } 11821 }
11121 11822
11122 error: 11823 error:
11123 /* Save parsing state back to parser. */ 11824 /* Save parsing state back to parser. */
11124 parser->current_state = cs; 11825 parser->current_state = cs;
11125 parser->parser_top = top; 11826 parser->parser_top = top;
11126 11827
(...skipping 17 matching lines...) Expand all
11144 int cs; 11845 int cs;
11145 int top; 11846 int top;
11146 11847
11147 p->top = p->stack; 11848 p->top = p->stack;
11148 p->top->f = NULL; 11849 p->top->f = NULL;
11149 p->top->is_map = false; 11850 p->top->is_map = false;
11150 p->top->is_mapentry = false; 11851 p->top->is_mapentry = false;
11151 11852
11152 /* Emit Ragel initialization of the parser. */ 11853 /* Emit Ragel initialization of the parser. */
11153 11854
11154 #line 1541 "upb/json/parser.c" 11855 #line 1568 "upb/json/parser.c"
11155 { 11856 {
11156 cs = json_start; 11857 cs = json_start;
11157 top = 0; 11858 top = 0;
11158 } 11859 }
11159 11860
11160 #line 1282 "upb/json/parser.rl" 11861 #line 1309 "upb/json/parser.rl"
11161 p->current_state = cs; 11862 p->current_state = cs;
11162 p->parser_top = top; 11863 p->parser_top = top;
11163 accumulate_clear(p); 11864 accumulate_clear(p);
11164 p->multipart_state = MULTIPART_INACTIVE; 11865 p->multipart_state = MULTIPART_INACTIVE;
11165 p->capture = NULL; 11866 p->capture = NULL;
11166 p->accumulated = NULL; 11867 p->accumulated = NULL;
11167 upb_status_clear(&p->status); 11868 upb_status_clear(&p->status);
11168 } 11869 }
11169 11870
11871 static void visit_json_parsermethod(const upb_refcounted *r,
11872 upb_refcounted_visit *visit,
11873 void *closure) {
11874 const upb_json_parsermethod *method = (upb_json_parsermethod*)r;
11875 visit(r, upb_msgdef_upcast2(method->msg), closure);
11876 }
11877
11878 static void free_json_parsermethod(upb_refcounted *r) {
11879 upb_json_parsermethod *method = (upb_json_parsermethod*)r;
11880
11881 upb_inttable_iter i;
11882 upb_inttable_begin(&i, &method->name_tables);
11883 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) {
11884 upb_value val = upb_inttable_iter_value(&i);
11885 upb_strtable *t = upb_value_getptr(val);
11886 upb_strtable_uninit(t);
11887 upb_gfree(t);
11888 }
11889
11890 upb_inttable_uninit(&method->name_tables);
11891
11892 upb_gfree(r);
11893 }
11894
11895 static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) {
11896 upb_msg_field_iter i;
11897 upb_strtable *t;
11898
11899 /* It would be nice to stack-allocate this, but protobufs do not limit the
11900 * length of fields to any reasonable limit. */
11901 char *buf = NULL;
11902 size_t len = 0;
11903
11904 if (upb_inttable_lookupptr(&m->name_tables, md, NULL)) {
11905 return;
11906 }
11907
11908 /* TODO(haberman): handle malloc failure. */
11909 t = upb_gmalloc(sizeof(*t));
11910 upb_strtable_init(t, UPB_CTYPE_CONSTPTR);
11911 upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t));
11912
11913 for(upb_msg_field_begin(&i, md);
11914 !upb_msg_field_done(&i);
11915 upb_msg_field_next(&i)) {
11916 const upb_fielddef *f = upb_msg_iter_field(&i);
11917
11918 /* Add an entry for the JSON name. */
11919 size_t field_len = upb_fielddef_getjsonname(f, buf, len);
11920 if (field_len > len) {
11921 size_t len2;
11922 buf = upb_grealloc(buf, 0, field_len);
11923 len = field_len;
11924 len2 = upb_fielddef_getjsonname(f, buf, len);
11925 UPB_ASSERT_VAR(len2, len == len2);
11926 }
11927 upb_strtable_insert(t, buf, upb_value_constptr(f));
11928
11929 if (strcmp(buf, upb_fielddef_name(f)) != 0) {
11930 /* Since the JSON name is different from the regular field name, add an
11931 * entry for the raw name (compliant proto3 JSON parsers must accept
11932 * both). */
11933 upb_strtable_insert(t, upb_fielddef_name(f), upb_value_constptr(f));
11934 }
11935
11936 if (upb_fielddef_issubmsg(f)) {
11937 add_jsonname_table(m, upb_fielddef_msgsubdef(f));
11938 }
11939 }
11940
11941 upb_gfree(buf);
11942 }
11170 11943
11171 /* Public API *****************************************************************/ 11944 /* Public API *****************************************************************/
11172 11945
11173 upb_json_parser *upb_json_parser_create(upb_env *env, upb_sink *output) { 11946 upb_json_parser *upb_json_parser_create(upb_env *env,
11947 const upb_json_parsermethod *method,
11948 upb_sink *output) {
11174 #ifndef NDEBUG 11949 #ifndef NDEBUG
11175 const size_t size_before = upb_env_bytesallocated(env); 11950 const size_t size_before = upb_env_bytesallocated(env);
11176 #endif 11951 #endif
11177 upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser)); 11952 upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser));
11178 if (!p) return false; 11953 if (!p) return false;
11179 11954
11180 p->env = env; 11955 p->env = env;
11956 p->method = method;
11181 p->limit = p->stack + UPB_JSON_MAX_DEPTH; 11957 p->limit = p->stack + UPB_JSON_MAX_DEPTH;
11182 p->accumulate_buf = NULL; 11958 p->accumulate_buf = NULL;
11183 p->accumulate_buf_size = 0; 11959 p->accumulate_buf_size = 0;
11184 upb_byteshandler_init(&p->input_handler_); 11960 upb_bytessink_reset(&p->input_, &method->input_handler_, p);
11185 upb_byteshandler_setstring(&p->input_handler_, parse, NULL);
11186 upb_byteshandler_setendstr(&p->input_handler_, end, NULL);
11187 upb_bytessink_reset(&p->input_, &p->input_handler_, p);
11188 11961
11189 json_parser_reset(p); 11962 json_parser_reset(p);
11190 upb_sink_reset(&p->top->sink, output->handlers, output->closure); 11963 upb_sink_reset(&p->top->sink, output->handlers, output->closure);
11191 p->top->m = upb_handlers_msgdef(output->handlers); 11964 p->top->m = upb_handlers_msgdef(output->handlers);
11965 set_name_table(p, p->top);
11192 11966
11193 /* If this fails, uncomment and increase the value in parser.h. */ 11967 /* If this fails, uncomment and increase the value in parser.h. */
11194 /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ 11968 /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */
11195 assert(upb_env_bytesallocated(env) - size_before <= UPB_JSON_PARSER_SIZE); 11969 assert(upb_env_bytesallocated(env) - size_before <= UPB_JSON_PARSER_SIZE);
11196 return p; 11970 return p;
11197 } 11971 }
11198 11972
11199 upb_bytessink *upb_json_parser_input(upb_json_parser *p) { 11973 upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
11200 return &p->input_; 11974 return &p->input_;
11201 } 11975 }
11976
11977 upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md,
11978 const void* owner) {
11979 static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod,
11980 free_json_parsermethod};
11981 upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret));
11982 upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner);
11983
11984 ret->msg = md;
11985 upb_ref2(md, ret);
11986
11987 upb_byteshandler_init(&ret->input_handler_);
11988 upb_byteshandler_setstring(&ret->input_handler_, parse, ret);
11989 upb_byteshandler_setendstr(&ret->input_handler_, end, ret);
11990
11991 upb_inttable_init(&ret->name_tables, UPB_CTYPE_PTR);
11992
11993 add_jsonname_table(ret, md);
11994
11995 return ret;
11996 }
11997
11998 const upb_byteshandler *upb_json_parsermethod_inputhandler(
11999 const upb_json_parsermethod *m) {
12000 return &m->input_handler_;
12001 }
11202 /* 12002 /*
11203 ** This currently uses snprintf() to format primitives, and could be optimized 12003 ** This currently uses snprintf() to format primitives, and could be optimized
11204 ** further. 12004 ** further.
11205 */ 12005 */
11206 12006
11207 12007
11208 #include <stdlib.h>
11209 #include <stdio.h>
11210 #include <string.h> 12008 #include <string.h>
11211 #include <stdint.h> 12009 #include <stdint.h>
11212 12010
11213 struct upb_json_printer { 12011 struct upb_json_printer {
11214 upb_sink input_; 12012 upb_sink input_;
11215 /* BytesSink closure. */ 12013 /* BytesSink closure. */
11216 void *subc_; 12014 void *subc_;
11217 upb_bytessink *output_; 12015 upb_bytessink *output_;
11218 12016
11219 /* We track the depth so that we know when to emit startstr/endstr on the 12017 /* We track the depth so that we know when to emit startstr/endstr on the
11220 * output. */ 12018 * output. */
11221 int depth_; 12019 int depth_;
11222 12020
11223 /* Have we emitted the first element? This state is necessary to emit commas 12021 /* Have we emitted the first element? This state is necessary to emit commas
11224 * without leaving a trailing comma in arrays/maps. We keep this state per 12022 * without leaving a trailing comma in arrays/maps. We keep this state per
11225 * frame depth. 12023 * frame depth.
11226 * 12024 *
11227 * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages. 12025 * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages.
11228 * We count frames (contexts in which we separate elements by commas) as both 12026 * We count frames (contexts in which we separate elements by commas) as both
11229 * repeated fields and messages (maps), and the worst case is a 12027 * repeated fields and messages (maps), and the worst case is a
11230 * message->repeated field->submessage->repeated field->... nesting. */ 12028 * message->repeated field->submessage->repeated field->... nesting. */
11231 bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; 12029 bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2];
11232 }; 12030 };
11233 12031
11234 /* StringPiece; a pointer plus a length. */ 12032 /* StringPiece; a pointer plus a length. */
11235 typedef struct { 12033 typedef struct {
11236 const char *ptr; 12034 char *ptr;
11237 size_t len; 12035 size_t len;
11238 } strpc; 12036 } strpc;
11239 12037
11240 strpc *newstrpc(upb_handlers *h, const upb_fielddef *f) { 12038 void freestrpc(void *ptr) {
11241 strpc *ret = malloc(sizeof(*ret)); 12039 strpc *pc = ptr;
11242 ret->ptr = upb_fielddef_name(f); 12040 upb_gfree(pc->ptr);
11243 ret->len = strlen(ret->ptr); 12041 upb_gfree(pc);
11244 upb_handlers_addcleanup(h, ret, free); 12042 }
12043
12044 /* Convert fielddef name to JSON name and return as a string piece. */
12045 strpc *newstrpc(upb_handlers *h, const upb_fielddef *f,
12046 bool preserve_fieldnames) {
12047 /* TODO(haberman): handle malloc failure. */
12048 strpc *ret = upb_gmalloc(sizeof(*ret));
12049 if (preserve_fieldnames) {
12050 ret->ptr = upb_gstrdup(upb_fielddef_name(f));
12051 ret->len = strlen(ret->ptr);
12052 } else {
12053 size_t len;
12054 ret->len = upb_fielddef_getjsonname(f, NULL, 0);
12055 ret->ptr = upb_gmalloc(ret->len);
12056 len = upb_fielddef_getjsonname(f, ret->ptr, ret->len);
12057 UPB_ASSERT_VAR(len, len == ret->len);
12058 ret->len--; /* NULL */
12059 }
12060
12061 upb_handlers_addcleanup(h, ret, freestrpc);
11245 return ret; 12062 return ret;
11246 } 12063 }
11247 12064
11248 /* ------------ JSON string printing: values, maps, arrays ------------------ */ 12065 /* ------------ JSON string printing: values, maps, arrays ------------------ */
11249 12066
11250 static void print_data( 12067 static void print_data(
11251 upb_json_printer *p, const char *buf, unsigned int len) { 12068 upb_json_printer *p, const char *buf, unsigned int len) {
11252 /* TODO: Will need to change if we support pushback from the sink. */ 12069 /* TODO: Will need to change if we support pushback from the sink. */
11253 size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); 12070 size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL);
11254 UPB_ASSERT_VAR(n, n == len); 12071 UPB_ASSERT_VAR(n, n == len);
(...skipping 10 matching lines...) Expand all
11265 12082
11266 /* Used for escaping control chars in strings. */ 12083 /* Used for escaping control chars in strings. */
11267 static const char kControlCharLimit = 0x20; 12084 static const char kControlCharLimit = 0x20;
11268 12085
11269 UPB_INLINE bool is_json_escaped(char c) { 12086 UPB_INLINE bool is_json_escaped(char c) {
11270 /* See RFC 4627. */ 12087 /* See RFC 4627. */
11271 unsigned char uc = (unsigned char)c; 12088 unsigned char uc = (unsigned char)c;
11272 return uc < kControlCharLimit || uc == '"' || uc == '\\'; 12089 return uc < kControlCharLimit || uc == '"' || uc == '\\';
11273 } 12090 }
11274 12091
11275 UPB_INLINE char* json_nice_escape(char c) { 12092 UPB_INLINE const char* json_nice_escape(char c) {
11276 switch (c) { 12093 switch (c) {
11277 case '"': return "\\\""; 12094 case '"': return "\\\"";
11278 case '\\': return "\\\\"; 12095 case '\\': return "\\\\";
11279 case '\b': return "\\b"; 12096 case '\b': return "\\b";
11280 case '\f': return "\\f"; 12097 case '\f': return "\\f";
11281 case '\n': return "\\n"; 12098 case '\n': return "\\n";
11282 case '\r': return "\\r"; 12099 case '\r': return "\\r";
11283 case '\t': return "\\t"; 12100 case '\t': return "\\t";
11284 default: return NULL; 12101 default: return NULL;
11285 } 12102 }
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
11738 const char *str, size_t len, 12555 const char *str, size_t len,
11739 const upb_bufhandle *handle) { 12556 const upb_bufhandle *handle) {
11740 upb_json_printer *p = closure; 12557 upb_json_printer *p = closure;
11741 CHK(putbytes(closure, handler_data, str, len, handle)); 12558 CHK(putbytes(closure, handler_data, str, len, handle));
11742 print_data(p, ":", 1); 12559 print_data(p, ":", 1);
11743 return len; 12560 return len;
11744 } 12561 }
11745 12562
11746 static void set_enum_hd(upb_handlers *h, 12563 static void set_enum_hd(upb_handlers *h,
11747 const upb_fielddef *f, 12564 const upb_fielddef *f,
12565 bool preserve_fieldnames,
11748 upb_handlerattr *attr) { 12566 upb_handlerattr *attr) {
11749 EnumHandlerData *hd = malloc(sizeof(EnumHandlerData)); 12567 EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData));
11750 hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f); 12568 hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f);
11751 hd->keyname = newstrpc(h, f); 12569 hd->keyname = newstrpc(h, f, preserve_fieldnames);
11752 upb_handlers_addcleanup(h, hd, free); 12570 upb_handlers_addcleanup(h, hd, upb_gfree);
11753 upb_handlerattr_sethandlerdata(attr, hd); 12571 upb_handlerattr_sethandlerdata(attr, hd);
11754 } 12572 }
11755 12573
11756 /* Set up handlers for a mapentry submessage (i.e., an individual key/value pair 12574 /* Set up handlers for a mapentry submessage (i.e., an individual key/value pair
11757 * in a map). 12575 * in a map).
11758 * 12576 *
11759 * TODO: Handle missing key, missing value, out-of-order key/value, or repeated 12577 * TODO: Handle missing key, missing value, out-of-order key/value, or repeated
11760 * key or value cases properly. The right way to do this is to allocate a 12578 * key or value cases properly. The right way to do this is to allocate a
11761 * temporary structure at the start of a mapentry submessage, store key and 12579 * temporary structure at the start of a mapentry submessage, store key and
11762 * value data in it as key and value handlers are called, and then print the 12580 * value data in it as key and value handlers are called, and then print the
11763 * key/value pair once at the end of the submessage. If we don't do this, we 12581 * key/value pair once at the end of the submessage. If we don't do this, we
11764 * should at least detect the case and throw an error. However, so far all of 12582 * should at least detect the case and throw an error. However, so far all of
11765 * our sources that emit mapentry messages do so canonically (with one key 12583 * our sources that emit mapentry messages do so canonically (with one key
11766 * field, and then one value field), so this is not a pressing concern at the 12584 * field, and then one value field), so this is not a pressing concern at the
11767 * moment. */ 12585 * moment. */
11768 void printer_sethandlers_mapentry(const void *closure, upb_handlers *h) { 12586 void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames,
12587 upb_handlers *h) {
11769 const upb_msgdef *md = upb_handlers_msgdef(h); 12588 const upb_msgdef *md = upb_handlers_msgdef(h);
11770 12589
11771 /* A mapentry message is printed simply as '"key": value'. Rather than 12590 /* A mapentry message is printed simply as '"key": value'. Rather than
11772 * special-case key and value for every type below, we just handle both 12591 * special-case key and value for every type below, we just handle both
11773 * fields explicitly here. */ 12592 * fields explicitly here. */
11774 const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY); 12593 const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY);
11775 const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE); 12594 const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE);
11776 12595
11777 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; 12596 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
11778 12597
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
11832 case UPB_TYPE_STRING: 12651 case UPB_TYPE_STRING:
11833 upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr); 12652 upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr);
11834 upb_handlers_setstring(h, value_field, putstr, &empty_attr); 12653 upb_handlers_setstring(h, value_field, putstr, &empty_attr);
11835 upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr); 12654 upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr);
11836 break; 12655 break;
11837 case UPB_TYPE_BYTES: 12656 case UPB_TYPE_BYTES:
11838 upb_handlers_setstring(h, value_field, putbytes, &empty_attr); 12657 upb_handlers_setstring(h, value_field, putbytes, &empty_attr);
11839 break; 12658 break;
11840 case UPB_TYPE_ENUM: { 12659 case UPB_TYPE_ENUM: {
11841 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; 12660 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER;
11842 set_enum_hd(h, value_field, &enum_attr); 12661 set_enum_hd(h, value_field, preserve_fieldnames, &enum_attr);
11843 upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr); 12662 upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr);
11844 upb_handlerattr_uninit(&enum_attr); 12663 upb_handlerattr_uninit(&enum_attr);
11845 break; 12664 break;
11846 } 12665 }
11847 case UPB_TYPE_MESSAGE: 12666 case UPB_TYPE_MESSAGE:
11848 /* No handler necessary -- the submsg handlers will print the message 12667 /* No handler necessary -- the submsg handlers will print the message
11849 * as appropriate. */ 12668 * as appropriate. */
11850 break; 12669 break;
11851 } 12670 }
11852 12671
11853 upb_handlerattr_uninit(&empty_attr); 12672 upb_handlerattr_uninit(&empty_attr);
11854 } 12673 }
11855 12674
11856 void printer_sethandlers(const void *closure, upb_handlers *h) { 12675 void printer_sethandlers(const void *closure, upb_handlers *h) {
11857 const upb_msgdef *md = upb_handlers_msgdef(h); 12676 const upb_msgdef *md = upb_handlers_msgdef(h);
11858 bool is_mapentry = upb_msgdef_mapentry(md); 12677 bool is_mapentry = upb_msgdef_mapentry(md);
11859 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; 12678 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER;
11860 upb_msg_field_iter i; 12679 upb_msg_field_iter i;
11861 12680 const bool *preserve_fieldnames_ptr = closure;
11862 UPB_UNUSED(closure); 12681 const bool preserve_fieldnames = *preserve_fieldnames_ptr;
11863 12682
11864 if (is_mapentry) { 12683 if (is_mapentry) {
11865 /* mapentry messages are sufficiently different that we handle them 12684 /* mapentry messages are sufficiently different that we handle them
11866 * separately. */ 12685 * separately. */
11867 printer_sethandlers_mapentry(closure, h); 12686 printer_sethandlers_mapentry(closure, preserve_fieldnames, h);
11868 return; 12687 return;
11869 } 12688 }
11870 12689
11871 upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); 12690 upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr);
11872 upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); 12691 upb_handlers_setendmsg(h, printer_endmsg, &empty_attr);
11873 12692
11874 #define TYPE(type, name, ctype) \ 12693 #define TYPE(type, name, ctype) \
11875 case type: \ 12694 case type: \
11876 if (upb_fielddef_isseq(f)) { \ 12695 if (upb_fielddef_isseq(f)) { \
11877 upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \ 12696 upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \
11878 } else { \ 12697 } else { \
11879 upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \ 12698 upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \
11880 } \ 12699 } \
11881 break; 12700 break;
11882 12701
11883 upb_msg_field_begin(&i, md); 12702 upb_msg_field_begin(&i, md);
11884 for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { 12703 for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) {
11885 const upb_fielddef *f = upb_msg_iter_field(&i); 12704 const upb_fielddef *f = upb_msg_iter_field(&i);
11886 12705
11887 upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER; 12706 upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER;
11888 upb_handlerattr_sethandlerdata(&name_attr, newstrpc(h, f)); 12707 upb_handlerattr_sethandlerdata(&name_attr,
12708 newstrpc(h, f, preserve_fieldnames));
11889 12709
11890 if (upb_fielddef_ismap(f)) { 12710 if (upb_fielddef_ismap(f)) {
11891 upb_handlers_setstartseq(h, f, startmap, &name_attr); 12711 upb_handlers_setstartseq(h, f, startmap, &name_attr);
11892 upb_handlers_setendseq(h, f, endmap, &name_attr); 12712 upb_handlers_setendseq(h, f, endmap, &name_attr);
11893 } else if (upb_fielddef_isseq(f)) { 12713 } else if (upb_fielddef_isseq(f)) {
11894 upb_handlers_setstartseq(h, f, startseq, &name_attr); 12714 upb_handlers_setstartseq(h, f, startseq, &name_attr);
11895 upb_handlers_setendseq(h, f, endseq, &empty_attr); 12715 upb_handlers_setendseq(h, f, endseq, &empty_attr);
11896 } 12716 }
11897 12717
11898 switch (upb_fielddef_type(f)) { 12718 switch (upb_fielddef_type(f)) {
11899 TYPE(UPB_TYPE_FLOAT, float, float); 12719 TYPE(UPB_TYPE_FLOAT, float, float);
11900 TYPE(UPB_TYPE_DOUBLE, double, double); 12720 TYPE(UPB_TYPE_DOUBLE, double, double);
11901 TYPE(UPB_TYPE_BOOL, bool, bool); 12721 TYPE(UPB_TYPE_BOOL, bool, bool);
11902 TYPE(UPB_TYPE_INT32, int32, int32_t); 12722 TYPE(UPB_TYPE_INT32, int32, int32_t);
11903 TYPE(UPB_TYPE_UINT32, uint32, uint32_t); 12723 TYPE(UPB_TYPE_UINT32, uint32, uint32_t);
11904 TYPE(UPB_TYPE_INT64, int64, int64_t); 12724 TYPE(UPB_TYPE_INT64, int64, int64_t);
11905 TYPE(UPB_TYPE_UINT64, uint64, uint64_t); 12725 TYPE(UPB_TYPE_UINT64, uint64, uint64_t);
11906 case UPB_TYPE_ENUM: { 12726 case UPB_TYPE_ENUM: {
11907 /* For now, we always emit symbolic names for enums. We may want an 12727 /* For now, we always emit symbolic names for enums. We may want an
11908 * option later to control this behavior, but we will wait for a real 12728 * option later to control this behavior, but we will wait for a real
11909 * need first. */ 12729 * need first. */
11910 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; 12730 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER;
11911 set_enum_hd(h, f, &enum_attr); 12731 set_enum_hd(h, f, preserve_fieldnames, &enum_attr);
11912 12732
11913 if (upb_fielddef_isseq(f)) { 12733 if (upb_fielddef_isseq(f)) {
11914 upb_handlers_setint32(h, f, repeated_enum, &enum_attr); 12734 upb_handlers_setint32(h, f, repeated_enum, &enum_attr);
11915 } else { 12735 } else {
11916 upb_handlers_setint32(h, f, scalar_enum, &enum_attr); 12736 upb_handlers_setint32(h, f, scalar_enum, &enum_attr);
11917 } 12737 }
11918 12738
11919 upb_handlerattr_uninit(&enum_attr); 12739 upb_handlerattr_uninit(&enum_attr);
11920 break; 12740 break;
11921 } 12741 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
11978 /* If this fails, increase the value in printer.h. */ 12798 /* If this fails, increase the value in printer.h. */
11979 assert(upb_env_bytesallocated(e) - size_before <= UPB_JSON_PRINTER_SIZE); 12799 assert(upb_env_bytesallocated(e) - size_before <= UPB_JSON_PRINTER_SIZE);
11980 return p; 12800 return p;
11981 } 12801 }
11982 12802
11983 upb_sink *upb_json_printer_input(upb_json_printer *p) { 12803 upb_sink *upb_json_printer_input(upb_json_printer *p) {
11984 return &p->input_; 12804 return &p->input_;
11985 } 12805 }
11986 12806
11987 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, 12807 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md,
12808 bool preserve_fieldnames,
11988 const void *owner) { 12809 const void *owner) {
11989 return upb_handlers_newfrozen(md, owner, printer_sethandlers, NULL); 12810 return upb_handlers_newfrozen(
12811 md, owner, printer_sethandlers, &preserve_fieldnames);
11990 } 12812 }
OLDNEW
« no previous file with comments | « third_party/protobuf/ruby/ext/google/protobuf_c/upb.h ('k') | third_party/protobuf/ruby/google-protobuf.gemspec » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698