OLD | NEW |
1 // Amalgamated source file | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ |
| 4 // |
| 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are |
| 7 // met: |
| 8 // |
| 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the |
| 14 // distribution. |
| 15 // * Neither the name of Google Inc. nor the names of its |
| 16 // contributors may be used to endorse or promote products derived from |
| 17 // this software without specific prior written permission. |
| 18 // |
| 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 |
2 #include "upb.h" | 31 #include "upb.h" |
3 | 32 |
4 | 33 |
| 34 #include <ctype.h> |
5 #include <stdlib.h> | 35 #include <stdlib.h> |
6 #include <string.h> | 36 #include <string.h> |
7 | 37 |
8 typedef struct { | 38 typedef struct { |
9 size_t len; | 39 size_t len; |
10 char str[1]; /* Null-terminated string data follows. */ | 40 char str[1]; /* Null-terminated string data follows. */ |
11 } str_t; | 41 } str_t; |
12 | 42 |
13 static str_t *newstr(const char *data, size_t len) { | 43 static str_t *newstr(const char *data, size_t len) { |
14 str_t *ret = malloc(sizeof(*ret) + len); | 44 str_t *ret = upb_gmalloc(sizeof(*ret) + len); |
15 if (!ret) return NULL; | 45 if (!ret) return NULL; |
16 ret->len = len; | 46 ret->len = len; |
17 memcpy(ret->str, data, len); | 47 memcpy(ret->str, data, len); |
18 ret->str[len] = '\0'; | 48 ret->str[len] = '\0'; |
19 return ret; | 49 return ret; |
20 } | 50 } |
21 | 51 |
22 static void freestr(str_t *s) { free(s); } | 52 static void freestr(str_t *s) { upb_gfree(s); } |
23 | 53 |
24 /* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ | 54 /* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ |
25 static bool upb_isbetween(char c, char low, char high) { | 55 static bool upb_isbetween(char c, char low, char high) { |
26 return c >= low && c <= high; | 56 return c >= low && c <= high; |
27 } | 57 } |
28 | 58 |
29 static bool upb_isletter(char c) { | 59 static bool upb_isletter(char c) { |
30 return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_'; | 60 return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_'; |
31 } | 61 } |
32 | 62 |
(...skipping 24 matching lines...) Expand all Loading... |
57 if (!upb_isalphanum(c)) { | 87 if (!upb_isalphanum(c)) { |
58 upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)", | 88 upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)", |
59 str); | 89 str); |
60 return false; | 90 return false; |
61 } | 91 } |
62 } | 92 } |
63 } | 93 } |
64 return !start; | 94 return !start; |
65 } | 95 } |
66 | 96 |
| 97 static bool upb_isoneof(const upb_refcounted *def) { |
| 98 return def->vtbl == &upb_oneofdef_vtbl; |
| 99 } |
| 100 |
| 101 static bool upb_isfield(const upb_refcounted *def) { |
| 102 return def->vtbl == &upb_fielddef_vtbl; |
| 103 } |
| 104 |
| 105 static const upb_oneofdef *upb_trygetoneof(const upb_refcounted *def) { |
| 106 return upb_isoneof(def) ? (const upb_oneofdef*)def : NULL; |
| 107 } |
| 108 |
| 109 static const upb_fielddef *upb_trygetfield(const upb_refcounted *def) { |
| 110 return upb_isfield(def) ? (const upb_fielddef*)def : NULL; |
| 111 } |
| 112 |
67 | 113 |
68 /* upb_def ********************************************************************/ | 114 /* upb_def ********************************************************************/ |
69 | 115 |
70 upb_deftype_t upb_def_type(const upb_def *d) { return d->type; } | 116 upb_deftype_t upb_def_type(const upb_def *d) { return d->type; } |
71 | 117 |
72 const char *upb_def_fullname(const upb_def *d) { return d->fullname; } | 118 const char *upb_def_fullname(const upb_def *d) { return d->fullname; } |
73 | 119 |
| 120 const char *upb_def_name(const upb_def *d) { |
| 121 const char *p; |
| 122 |
| 123 if (d->fullname == NULL) { |
| 124 return NULL; |
| 125 } else if ((p = strrchr(d->fullname, '.')) == NULL) { |
| 126 /* No '.' in the name, return the full string. */ |
| 127 return d->fullname; |
| 128 } else { |
| 129 /* Return one past the last '.'. */ |
| 130 return p + 1; |
| 131 } |
| 132 } |
| 133 |
74 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) { | 134 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) { |
75 assert(!upb_def_isfrozen(def)); | 135 UPB_ASSERT(!upb_def_isfrozen(def)); |
76 if (!upb_isident(fullname, strlen(fullname), true, s)) return false; | 136 if (!upb_isident(fullname, strlen(fullname), true, s)) { |
77 free((void*)def->fullname); | 137 return false; |
78 def->fullname = upb_strdup(fullname); | 138 } |
| 139 |
| 140 fullname = upb_gstrdup(fullname); |
| 141 if (!fullname) { |
| 142 upb_upberr_setoom(s); |
| 143 return false; |
| 144 } |
| 145 |
| 146 upb_gfree((void*)def->fullname); |
| 147 def->fullname = fullname; |
79 return true; | 148 return true; |
80 } | 149 } |
81 | 150 |
| 151 const upb_filedef *upb_def_file(const upb_def *d) { return d->file; } |
| 152 |
82 upb_def *upb_def_dup(const upb_def *def, const void *o) { | 153 upb_def *upb_def_dup(const upb_def *def, const void *o) { |
83 switch (def->type) { | 154 switch (def->type) { |
84 case UPB_DEF_MSG: | 155 case UPB_DEF_MSG: |
85 return upb_msgdef_upcast_mutable( | 156 return upb_msgdef_upcast_mutable( |
86 upb_msgdef_dup(upb_downcast_msgdef(def), o)); | 157 upb_msgdef_dup(upb_downcast_msgdef(def), o)); |
87 case UPB_DEF_FIELD: | 158 case UPB_DEF_FIELD: |
88 return upb_fielddef_upcast_mutable( | 159 return upb_fielddef_upcast_mutable( |
89 upb_fielddef_dup(upb_downcast_fielddef(def), o)); | 160 upb_fielddef_dup(upb_downcast_fielddef(def), o)); |
90 case UPB_DEF_ENUM: | 161 case UPB_DEF_ENUM: |
91 return upb_enumdef_upcast_mutable( | 162 return upb_enumdef_upcast_mutable( |
92 upb_enumdef_dup(upb_downcast_enumdef(def), o)); | 163 upb_enumdef_dup(upb_downcast_enumdef(def), o)); |
93 default: assert(false); return NULL; | 164 default: UPB_ASSERT(false); return NULL; |
94 } | 165 } |
95 } | 166 } |
96 | 167 |
97 static bool upb_def_init(upb_def *def, upb_deftype_t type, | 168 static bool upb_def_init(upb_def *def, upb_deftype_t type, |
98 const struct upb_refcounted_vtbl *vtbl, | 169 const struct upb_refcounted_vtbl *vtbl, |
99 const void *owner) { | 170 const void *owner) { |
100 if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return fal
se; | 171 if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return fal
se; |
101 def->type = type; | 172 def->type = type; |
102 def->fullname = NULL; | 173 def->fullname = NULL; |
103 def->came_from_user = false; | 174 def->came_from_user = false; |
| 175 def->file = NULL; |
104 return true; | 176 return true; |
105 } | 177 } |
106 | 178 |
107 static void upb_def_uninit(upb_def *def) { | 179 static void upb_def_uninit(upb_def *def) { |
108 free((void*)def->fullname); | 180 upb_gfree((void*)def->fullname); |
109 } | 181 } |
110 | 182 |
111 static const char *msgdef_name(const upb_msgdef *m) { | 183 static const char *msgdef_name(const upb_msgdef *m) { |
112 const char *name = upb_def_fullname(upb_msgdef_upcast(m)); | 184 const char *name = upb_def_fullname(upb_msgdef_upcast(m)); |
113 return name ? name : "(anonymous)"; | 185 return name ? name : "(anonymous)"; |
114 } | 186 } |
115 | 187 |
116 static bool upb_validate_field(upb_fielddef *f, upb_status *s) { | 188 static bool upb_validate_field(upb_fielddef *f, upb_status *s) { |
117 if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { | 189 if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { |
118 upb_status_seterrmsg(s, "fielddef must have name and number set"); | 190 upb_status_seterrmsg(s, "fielddef must have name and number set"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 msgdef_name(f->msg.def), upb_fielddef_name(f)); | 225 msgdef_name(f->msg.def), upb_fielddef_name(f)); |
154 return false; | 226 return false; |
155 } | 227 } |
156 } | 228 } |
157 | 229 |
158 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 230 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
159 bool has_default_name = upb_fielddef_enumhasdefaultstr(f); | 231 bool has_default_name = upb_fielddef_enumhasdefaultstr(f); |
160 bool has_default_number = upb_fielddef_enumhasdefaultint32(f); | 232 bool has_default_number = upb_fielddef_enumhasdefaultint32(f); |
161 | 233 |
162 /* Previously verified by upb_validate_enumdef(). */ | 234 /* Previously verified by upb_validate_enumdef(). */ |
163 assert(upb_enumdef_numvals(upb_fielddef_enumsubdef(f)) > 0); | 235 UPB_ASSERT(upb_enumdef_numvals(upb_fielddef_enumsubdef(f)) > 0); |
164 | 236 |
165 /* We've already validated that we have an associated enumdef and that it | 237 /* We've already validated that we have an associated enumdef and that it |
166 * has at least one member, so at least one of these should be true. | 238 * has at least one member, so at least one of these should be true. |
167 * Because if the user didn't set anything, we'll pick up the enum's | 239 * Because if the user didn't set anything, we'll pick up the enum's |
168 * default, but if the user *did* set something we should at least pick up | 240 * default, but if the user *did* set something we should at least pick up |
169 * the one they set (int32 or string). */ | 241 * the one they set (int32 or string). */ |
170 assert(has_default_name || has_default_number); | 242 UPB_ASSERT(has_default_name || has_default_number); |
171 | 243 |
172 if (!has_default_name) { | 244 if (!has_default_name) { |
173 upb_status_seterrf(s, | 245 upb_status_seterrf(s, |
174 "enum default for field %s.%s (%d) is not in the enum", | 246 "enum default for field %s.%s (%d) is not in the enum", |
175 msgdef_name(f->msg.def), upb_fielddef_name(f), | 247 msgdef_name(f->msg.def), upb_fielddef_name(f), |
176 upb_fielddef_defaultint32(f)); | 248 upb_fielddef_defaultint32(f)); |
177 return false; | 249 return false; |
178 } | 250 } |
179 | 251 |
180 if (!has_default_number) { | 252 if (!has_default_number) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 288 } |
217 | 289 |
218 return true; | 290 return true; |
219 } | 291 } |
220 | 292 |
221 /* All submessage fields are lower than all other fields. | 293 /* All submessage fields are lower than all other fields. |
222 * Secondly, fields are increasing in order. */ | 294 * Secondly, fields are increasing in order. */ |
223 uint32_t field_rank(const upb_fielddef *f) { | 295 uint32_t field_rank(const upb_fielddef *f) { |
224 uint32_t ret = upb_fielddef_number(f); | 296 uint32_t ret = upb_fielddef_number(f); |
225 const uint32_t high_bit = 1 << 30; | 297 const uint32_t high_bit = 1 << 30; |
226 assert(ret < high_bit); | 298 UPB_ASSERT(ret < high_bit); |
227 if (!upb_fielddef_issubmsg(f)) | 299 if (!upb_fielddef_issubmsg(f)) |
228 ret |= high_bit; | 300 ret |= high_bit; |
229 return ret; | 301 return ret; |
230 } | 302 } |
231 | 303 |
232 int cmp_fields(const void *p1, const void *p2) { | 304 int cmp_fields(const void *p1, const void *p2) { |
233 const upb_fielddef *f1 = *(upb_fielddef*const*)p1; | 305 const upb_fielddef *f1 = *(upb_fielddef*const*)p1; |
234 const upb_fielddef *f2 = *(upb_fielddef*const*)p2; | 306 const upb_fielddef *f2 = *(upb_fielddef*const*)p2; |
235 return field_rank(f1) - field_rank(f2); | 307 return field_rank(f1) - field_rank(f2); |
236 } | 308 } |
237 | 309 |
238 static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { | 310 static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { |
239 /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the | 311 /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the |
240 * lowest indexes, but we do not publicly guarantee this. */ | 312 * lowest indexes, but we do not publicly guarantee this. */ |
241 upb_msg_field_iter j; | 313 upb_msg_field_iter j; |
242 int i; | 314 int i; |
243 uint32_t selector; | 315 uint32_t selector; |
244 int n = upb_msgdef_numfields(m); | 316 int n = upb_msgdef_numfields(m); |
245 upb_fielddef **fields = malloc(n * sizeof(*fields)); | 317 upb_fielddef **fields; |
246 if (!fields) return false; | 318 |
| 319 if (n == 0) { |
| 320 m->selector_count = UPB_STATIC_SELECTOR_COUNT; |
| 321 m->submsg_field_count = 0; |
| 322 return true; |
| 323 } |
| 324 |
| 325 fields = upb_gmalloc(n * sizeof(*fields)); |
| 326 if (!fields) { |
| 327 upb_upberr_setoom(s); |
| 328 return false; |
| 329 } |
247 | 330 |
248 m->submsg_field_count = 0; | 331 m->submsg_field_count = 0; |
249 for(i = 0, upb_msg_field_begin(&j, m); | 332 for(i = 0, upb_msg_field_begin(&j, m); |
250 !upb_msg_field_done(&j); | 333 !upb_msg_field_done(&j); |
251 upb_msg_field_next(&j), i++) { | 334 upb_msg_field_next(&j), i++) { |
252 upb_fielddef *f = upb_msg_iter_field(&j); | 335 upb_fielddef *f = upb_msg_iter_field(&j); |
253 assert(f->msg.def == m); | 336 UPB_ASSERT(f->msg.def == m); |
254 if (!upb_validate_field(f, s)) { | 337 if (!upb_validate_field(f, s)) { |
255 free(fields); | 338 upb_gfree(fields); |
256 return false; | 339 return false; |
257 } | 340 } |
258 if (upb_fielddef_issubmsg(f)) { | 341 if (upb_fielddef_issubmsg(f)) { |
259 m->submsg_field_count++; | 342 m->submsg_field_count++; |
260 } | 343 } |
261 fields[i] = f; | 344 fields[i] = f; |
262 } | 345 } |
263 | 346 |
264 qsort(fields, n, sizeof(*fields), cmp_fields); | 347 qsort(fields, n, sizeof(*fields), cmp_fields); |
265 | 348 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 TRY(UPB_HANDLER_STARTSUBMSG) | 388 TRY(UPB_HANDLER_STARTSUBMSG) |
306 TRY(UPB_HANDLER_ENDSUBMSG) | 389 TRY(UPB_HANDLER_ENDSUBMSG) |
307 TRY(UPB_HANDLER_STARTSEQ) | 390 TRY(UPB_HANDLER_STARTSEQ) |
308 TRY(UPB_HANDLER_ENDSEQ) | 391 TRY(UPB_HANDLER_ENDSEQ) |
309 } | 392 } |
310 upb_inttable_uninit(&t); | 393 upb_inttable_uninit(&t); |
311 } | 394 } |
312 #undef TRY | 395 #undef TRY |
313 #endif | 396 #endif |
314 | 397 |
315 free(fields); | 398 upb_gfree(fields); |
316 return true; | 399 return true; |
317 } | 400 } |
318 | 401 |
319 bool upb_def_freeze(upb_def *const* defs, int n, upb_status *s) { | 402 bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { |
320 int i; | 403 size_t i; |
321 int maxdepth; | |
322 bool ret; | |
323 upb_status_clear(s); | |
324 | 404 |
325 /* First perform validation, in two passes so we can check that we have a | 405 /* First perform validation, in two passes so we can check that we have a |
326 * transitive closure without needing to search. */ | 406 * transitive closure without needing to search. */ |
327 for (i = 0; i < n; i++) { | 407 for (i = 0; i < n; i++) { |
328 upb_def *def = defs[i]; | 408 upb_def *def = defs[i]; |
329 if (upb_def_isfrozen(def)) { | 409 if (upb_def_isfrozen(def)) { |
330 /* Could relax this requirement if it's annoying. */ | 410 /* Could relax this requirement if it's annoying. */ |
331 upb_status_seterrmsg(s, "def is already frozen"); | 411 upb_status_seterrmsg(s, "def is already frozen"); |
332 goto err; | 412 goto err; |
333 } else if (def->type == UPB_DEF_FIELD) { | 413 } else if (def->type == UPB_DEF_FIELD) { |
334 upb_status_seterrmsg(s, "standalone fielddefs can not be frozen"); | 414 upb_status_seterrmsg(s, "standalone fielddefs can not be frozen"); |
335 goto err; | 415 goto err; |
336 } else if (def->type == UPB_DEF_ENUM) { | 416 } else if (def->type == UPB_DEF_ENUM) { |
337 if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) { | 417 if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) { |
338 goto err; | 418 goto err; |
339 } | 419 } |
340 } else { | 420 } else { |
341 /* Set now to detect transitive closure in the second pass. */ | 421 /* Set now to detect transitive closure in the second pass. */ |
342 def->came_from_user = true; | 422 def->came_from_user = true; |
343 } | 423 } |
344 } | 424 } |
345 | 425 |
346 /* Second pass of validation. Also assign selector bases and indexes, and | 426 /* Second pass of validation. Also assign selector bases and indexes, and |
347 * compact tables. */ | 427 * compact tables. */ |
348 for (i = 0; i < n; i++) { | 428 for (i = 0; i < n; i++) { |
349 upb_msgdef *m = upb_dyncast_msgdef_mutable(defs[i]); | 429 upb_def *def = defs[i]; |
350 upb_enumdef *e = upb_dyncast_enumdef_mutable(defs[i]); | 430 upb_msgdef *m = upb_dyncast_msgdef_mutable(def); |
| 431 upb_enumdef *e = upb_dyncast_enumdef_mutable(def); |
351 if (m) { | 432 if (m) { |
352 upb_inttable_compact(&m->itof); | 433 upb_inttable_compact(&m->itof); |
353 if (!assign_msg_indices(m, s)) { | 434 if (!assign_msg_indices(m, s)) { |
354 goto err; | 435 goto err; |
355 } | 436 } |
356 } else if (e) { | 437 } else if (e) { |
357 upb_inttable_compact(&e->iton); | 438 upb_inttable_compact(&e->iton); |
358 } | 439 } |
359 } | 440 } |
360 | 441 |
361 /* Def graph contains FieldDefs between each MessageDef, so double the | 442 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 | 443 |
370 err: | 444 err: |
371 for (i = 0; i < n; i++) { | 445 for (i = 0; i < n; i++) { |
372 defs[i]->came_from_user = false; | 446 upb_def *def = defs[i]; |
| 447 def->came_from_user = false; |
373 } | 448 } |
374 assert(!(s && upb_ok(s))); | 449 UPB_ASSERT(!(s && upb_ok(s))); |
375 return false; | 450 return false; |
376 } | 451 } |
377 | 452 |
| 453 bool upb_def_freeze(upb_def *const* defs, size_t n, upb_status *s) { |
| 454 /* Def graph contains FieldDefs between each MessageDef, so double the |
| 455 * limit. */ |
| 456 const size_t maxdepth = UPB_MAX_MESSAGE_DEPTH * 2; |
| 457 |
| 458 if (!_upb_def_validate(defs, n, s)) { |
| 459 return false; |
| 460 } |
| 461 |
| 462 |
| 463 /* Validation all passed; freeze the objects. */ |
| 464 return upb_refcounted_freeze((upb_refcounted *const*)defs, n, s, maxdepth); |
| 465 } |
| 466 |
378 | 467 |
379 /* upb_enumdef ****************************************************************/ | 468 /* upb_enumdef ****************************************************************/ |
380 | 469 |
381 static void upb_enumdef_free(upb_refcounted *r) { | 470 static void visitenum(const upb_refcounted *r, upb_refcounted_visit *visit, |
| 471 void *closure) { |
| 472 const upb_enumdef *e = (const upb_enumdef*)r; |
| 473 const upb_def *def = upb_enumdef_upcast(e); |
| 474 if (upb_def_file(def)) { |
| 475 visit(r, upb_filedef_upcast(upb_def_file(def)), closure); |
| 476 } |
| 477 } |
| 478 |
| 479 static void freeenum(upb_refcounted *r) { |
382 upb_enumdef *e = (upb_enumdef*)r; | 480 upb_enumdef *e = (upb_enumdef*)r; |
383 upb_inttable_iter i; | 481 upb_inttable_iter i; |
384 upb_inttable_begin(&i, &e->iton); | 482 upb_inttable_begin(&i, &e->iton); |
385 for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 483 for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
386 /* To clean up the upb_strdup() from upb_enumdef_addval(). */ | 484 /* To clean up the upb_gstrdup() from upb_enumdef_addval(). */ |
387 free(upb_value_getcstr(upb_inttable_iter_value(&i))); | 485 upb_gfree(upb_value_getcstr(upb_inttable_iter_value(&i))); |
388 } | 486 } |
389 upb_strtable_uninit(&e->ntoi); | 487 upb_strtable_uninit(&e->ntoi); |
390 upb_inttable_uninit(&e->iton); | 488 upb_inttable_uninit(&e->iton); |
391 upb_def_uninit(upb_enumdef_upcast_mutable(e)); | 489 upb_def_uninit(upb_enumdef_upcast_mutable(e)); |
392 free(e); | 490 upb_gfree(e); |
393 } | 491 } |
394 | 492 |
| 493 const struct upb_refcounted_vtbl upb_enumdef_vtbl = {&visitenum, &freeenum}; |
| 494 |
395 upb_enumdef *upb_enumdef_new(const void *owner) { | 495 upb_enumdef *upb_enumdef_new(const void *owner) { |
396 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_enumdef_free}; | 496 upb_enumdef *e = upb_gmalloc(sizeof(*e)); |
397 upb_enumdef *e = malloc(sizeof(*e)); | |
398 if (!e) return NULL; | 497 if (!e) return NULL; |
399 if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM, &vtbl, owner)) | 498 |
| 499 if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM, |
| 500 &upb_enumdef_vtbl, owner)) { |
400 goto err2; | 501 goto err2; |
| 502 } |
| 503 |
401 if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2; | 504 if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2; |
402 if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1; | 505 if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1; |
403 return e; | 506 return e; |
404 | 507 |
405 err1: | 508 err1: |
406 upb_strtable_uninit(&e->ntoi); | 509 upb_strtable_uninit(&e->ntoi); |
407 err2: | 510 err2: |
408 free(e); | 511 upb_gfree(e); |
409 return NULL; | 512 return NULL; |
410 } | 513 } |
411 | 514 |
412 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner) { | 515 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner) { |
413 upb_enum_iter i; | 516 upb_enum_iter i; |
414 upb_enumdef *new_e = upb_enumdef_new(owner); | 517 upb_enumdef *new_e = upb_enumdef_new(owner); |
415 if (!new_e) return NULL; | 518 if (!new_e) return NULL; |
416 for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) { | 519 for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) { |
417 bool success = upb_enumdef_addval( | 520 bool success = upb_enumdef_addval( |
418 new_e, upb_enum_iter_name(&i),upb_enum_iter_number(&i), NULL); | 521 new_e, upb_enum_iter_name(&i),upb_enum_iter_number(&i), NULL); |
419 if (!success) { | 522 if (!success) { |
420 upb_enumdef_unref(new_e, owner); | 523 upb_enumdef_unref(new_e, owner); |
421 return NULL; | 524 return NULL; |
422 } | 525 } |
423 } | 526 } |
424 return new_e; | 527 return new_e; |
425 } | 528 } |
426 | 529 |
427 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) { | 530 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) { |
428 upb_def *d = upb_enumdef_upcast_mutable(e); | 531 upb_def *d = upb_enumdef_upcast_mutable(e); |
429 return upb_def_freeze(&d, 1, status); | 532 return upb_def_freeze(&d, 1, status); |
430 } | 533 } |
431 | 534 |
432 const char *upb_enumdef_fullname(const upb_enumdef *e) { | 535 const char *upb_enumdef_fullname(const upb_enumdef *e) { |
433 return upb_def_fullname(upb_enumdef_upcast(e)); | 536 return upb_def_fullname(upb_enumdef_upcast(e)); |
434 } | 537 } |
435 | 538 |
| 539 const char *upb_enumdef_name(const upb_enumdef *e) { |
| 540 return upb_def_name(upb_enumdef_upcast(e)); |
| 541 } |
| 542 |
436 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname, | 543 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname, |
437 upb_status *s) { | 544 upb_status *s) { |
438 return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s); | 545 return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s); |
439 } | 546 } |
440 | 547 |
441 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, | 548 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, |
442 upb_status *status) { | 549 upb_status *status) { |
| 550 char *name2; |
| 551 |
443 if (!upb_isident(name, strlen(name), false, status)) { | 552 if (!upb_isident(name, strlen(name), false, status)) { |
444 return false; | 553 return false; |
445 } | 554 } |
| 555 |
446 if (upb_enumdef_ntoiz(e, name, NULL)) { | 556 if (upb_enumdef_ntoiz(e, name, NULL)) { |
447 upb_status_seterrf(status, "name '%s' is already defined", name); | 557 upb_status_seterrf(status, "name '%s' is already defined", name); |
448 return false; | 558 return false; |
449 } | 559 } |
| 560 |
450 if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) { | 561 if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) { |
451 upb_status_seterrmsg(status, "out of memory"); | 562 upb_status_seterrmsg(status, "out of memory"); |
452 return false; | 563 return false; |
453 } | 564 } |
454 if (!upb_inttable_lookup(&e->iton, num, NULL) && | 565 |
455 !upb_inttable_insert(&e->iton, num, upb_value_cstr(upb_strdup(name)))) { | 566 if (!upb_inttable_lookup(&e->iton, num, NULL)) { |
456 upb_status_seterrmsg(status, "out of memory"); | 567 name2 = upb_gstrdup(name); |
457 upb_strtable_remove(&e->ntoi, name, NULL); | 568 if (!name2 || !upb_inttable_insert(&e->iton, num, upb_value_cstr(name2))) { |
458 return false; | 569 upb_status_seterrmsg(status, "out of memory"); |
| 570 upb_strtable_remove(&e->ntoi, name, NULL); |
| 571 return false; |
| 572 } |
459 } | 573 } |
| 574 |
460 if (upb_enumdef_numvals(e) == 1) { | 575 if (upb_enumdef_numvals(e) == 1) { |
461 bool ok = upb_enumdef_setdefault(e, num, NULL); | 576 bool ok = upb_enumdef_setdefault(e, num, NULL); |
462 UPB_ASSERT_VAR(ok, ok); | 577 UPB_ASSERT(ok); |
463 } | 578 } |
| 579 |
464 return true; | 580 return true; |
465 } | 581 } |
466 | 582 |
467 int32_t upb_enumdef_default(const upb_enumdef *e) { | 583 int32_t upb_enumdef_default(const upb_enumdef *e) { |
468 assert(upb_enumdef_iton(e, e->defaultval)); | 584 UPB_ASSERT(upb_enumdef_iton(e, e->defaultval)); |
469 return e->defaultval; | 585 return e->defaultval; |
470 } | 586 } |
471 | 587 |
472 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) { | 588 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) { |
473 assert(!upb_enumdef_isfrozen(e)); | 589 UPB_ASSERT(!upb_enumdef_isfrozen(e)); |
474 if (!upb_enumdef_iton(e, val)) { | 590 if (!upb_enumdef_iton(e, val)) { |
475 upb_status_seterrf(s, "number '%d' is not in the enum.", val); | 591 upb_status_seterrf(s, "number '%d' is not in the enum.", val); |
476 return false; | 592 return false; |
477 } | 593 } |
478 e->defaultval = val; | 594 e->defaultval = val; |
479 return true; | 595 return true; |
480 } | 596 } |
481 | 597 |
482 int upb_enumdef_numvals(const upb_enumdef *e) { | 598 int upb_enumdef_numvals(const upb_enumdef *e) { |
483 return upb_strtable_count(&e->ntoi); | 599 return upb_strtable_count(&e->ntoi); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 | 634 |
519 /* upb_fielddef ***************************************************************/ | 635 /* upb_fielddef ***************************************************************/ |
520 | 636 |
521 static void upb_fielddef_init_default(upb_fielddef *f); | 637 static void upb_fielddef_init_default(upb_fielddef *f); |
522 | 638 |
523 static void upb_fielddef_uninit_default(upb_fielddef *f) { | 639 static void upb_fielddef_uninit_default(upb_fielddef *f) { |
524 if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes) | 640 if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes) |
525 freestr(f->defaultval.bytes); | 641 freestr(f->defaultval.bytes); |
526 } | 642 } |
527 | 643 |
| 644 const char *upb_fielddef_fullname(const upb_fielddef *e) { |
| 645 return upb_def_fullname(upb_fielddef_upcast(e)); |
| 646 } |
| 647 |
528 static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit, | 648 static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit, |
529 void *closure) { | 649 void *closure) { |
530 const upb_fielddef *f = (const upb_fielddef*)r; | 650 const upb_fielddef *f = (const upb_fielddef*)r; |
| 651 const upb_def *def = upb_fielddef_upcast(f); |
531 if (upb_fielddef_containingtype(f)) { | 652 if (upb_fielddef_containingtype(f)) { |
532 visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure); | 653 visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure); |
533 } | 654 } |
534 if (upb_fielddef_containingoneof(f)) { | 655 if (upb_fielddef_containingoneof(f)) { |
535 visit(r, upb_oneofdef_upcast2(upb_fielddef_containingoneof(f)), closure); | 656 visit(r, upb_oneofdef_upcast(upb_fielddef_containingoneof(f)), closure); |
536 } | 657 } |
537 if (upb_fielddef_subdef(f)) { | 658 if (upb_fielddef_subdef(f)) { |
538 visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure); | 659 visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure); |
539 } | 660 } |
| 661 if (upb_def_file(def)) { |
| 662 visit(r, upb_filedef_upcast(upb_def_file(def)), closure); |
| 663 } |
540 } | 664 } |
541 | 665 |
542 static void freefield(upb_refcounted *r) { | 666 static void freefield(upb_refcounted *r) { |
543 upb_fielddef *f = (upb_fielddef*)r; | 667 upb_fielddef *f = (upb_fielddef*)r; |
544 upb_fielddef_uninit_default(f); | 668 upb_fielddef_uninit_default(f); |
545 if (f->subdef_is_symbolic) | 669 if (f->subdef_is_symbolic) |
546 free(f->sub.name); | 670 upb_gfree(f->sub.name); |
547 upb_def_uninit(upb_fielddef_upcast_mutable(f)); | 671 upb_def_uninit(upb_fielddef_upcast_mutable(f)); |
548 free(f); | 672 upb_gfree(f); |
549 } | 673 } |
550 | 674 |
551 static const char *enumdefaultstr(const upb_fielddef *f) { | 675 static const char *enumdefaultstr(const upb_fielddef *f) { |
552 const upb_enumdef *e; | 676 const upb_enumdef *e; |
553 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 677 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
554 e = upb_fielddef_enumsubdef(f); | 678 e = upb_fielddef_enumsubdef(f); |
555 if (f->default_is_string && f->defaultval.bytes) { | 679 if (f->default_is_string && f->defaultval.bytes) { |
556 /* Default was explicitly set as a string. */ | 680 /* Default was explicitly set as a string. */ |
557 str_t *s = f->defaultval.bytes; | 681 str_t *s = f->defaultval.bytes; |
558 return s->str; | 682 return s->str; |
559 } else if (e) { | 683 } else if (e) { |
560 if (!f->default_is_string) { | 684 if (!f->default_is_string) { |
561 /* Default was explicitly set as an integer; look it up in enumdef. */ | 685 /* Default was explicitly set as an integer; look it up in enumdef. */ |
562 const char *name = upb_enumdef_iton(e, f->defaultval.sint); | 686 const char *name = upb_enumdef_iton(e, f->defaultval.sint); |
563 if (name) { | 687 if (name) { |
564 return name; | 688 return name; |
565 } | 689 } |
566 } else { | 690 } else { |
567 /* Default is completely unset; pull enumdef default. */ | 691 /* Default is completely unset; pull enumdef default. */ |
568 if (upb_enumdef_numvals(e) > 0) { | 692 if (upb_enumdef_numvals(e) > 0) { |
569 const char *name = upb_enumdef_iton(e, upb_enumdef_default(e)); | 693 const char *name = upb_enumdef_iton(e, upb_enumdef_default(e)); |
570 assert(name); | 694 UPB_ASSERT(name); |
571 return name; | 695 return name; |
572 } | 696 } |
573 } | 697 } |
574 } | 698 } |
575 return NULL; | 699 return NULL; |
576 } | 700 } |
577 | 701 |
578 static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) { | 702 static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) { |
579 const upb_enumdef *e; | 703 const upb_enumdef *e; |
580 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 704 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
581 e = upb_fielddef_enumsubdef(f); | 705 e = upb_fielddef_enumsubdef(f); |
582 if (!f->default_is_string) { | 706 if (!f->default_is_string) { |
583 /* Default was explicitly set as an integer. */ | 707 /* Default was explicitly set as an integer. */ |
584 *val = f->defaultval.sint; | 708 *val = f->defaultval.sint; |
585 return true; | 709 return true; |
586 } else if (e) { | 710 } else if (e) { |
587 if (f->defaultval.bytes) { | 711 if (f->defaultval.bytes) { |
588 /* Default was explicitly set as a str; try to lookup corresponding int. *
/ | 712 /* Default was explicitly set as a str; try to lookup corresponding int. *
/ |
589 str_t *s = f->defaultval.bytes; | 713 str_t *s = f->defaultval.bytes; |
590 if (upb_enumdef_ntoiz(e, s->str, val)) { | 714 if (upb_enumdef_ntoiz(e, s->str, val)) { |
591 return true; | 715 return true; |
592 } | 716 } |
593 } else { | 717 } else { |
594 /* Default is unset; try to pull in enumdef default. */ | 718 /* Default is unset; try to pull in enumdef default. */ |
595 if (upb_enumdef_numvals(e) > 0) { | 719 if (upb_enumdef_numvals(e) > 0) { |
596 *val = upb_enumdef_default(e); | 720 *val = upb_enumdef_default(e); |
597 return true; | 721 return true; |
598 } | 722 } |
599 } | 723 } |
600 } | 724 } |
601 return false; | 725 return false; |
602 } | 726 } |
603 | 727 |
| 728 const struct upb_refcounted_vtbl upb_fielddef_vtbl = {visitfield, freefield}; |
| 729 |
604 upb_fielddef *upb_fielddef_new(const void *o) { | 730 upb_fielddef *upb_fielddef_new(const void *o) { |
605 static const struct upb_refcounted_vtbl vtbl = {visitfield, freefield}; | 731 upb_fielddef *f = upb_gmalloc(sizeof(*f)); |
606 upb_fielddef *f = malloc(sizeof(*f)); | |
607 if (!f) return NULL; | 732 if (!f) return NULL; |
608 if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD, &vtbl, o)) { | 733 if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD, |
609 free(f); | 734 &upb_fielddef_vtbl, o)) { |
| 735 upb_gfree(f); |
610 return NULL; | 736 return NULL; |
611 } | 737 } |
612 f->msg.def = NULL; | 738 f->msg.def = NULL; |
613 f->sub.def = NULL; | 739 f->sub.def = NULL; |
614 f->oneof = NULL; | 740 f->oneof = NULL; |
615 f->subdef_is_symbolic = false; | 741 f->subdef_is_symbolic = false; |
616 f->msg_is_symbolic = false; | 742 f->msg_is_symbolic = false; |
617 f->label_ = UPB_LABEL_OPTIONAL; | 743 f->label_ = UPB_LABEL_OPTIONAL; |
618 f->type_ = UPB_TYPE_INT32; | 744 f->type_ = UPB_TYPE_INT32; |
619 f->number_ = 0; | 745 f->number_ = 0; |
(...skipping 30 matching lines...) Expand all Loading... |
650 newf->default_is_string = f->default_is_string; | 776 newf->default_is_string = f->default_is_string; |
651 newf->defaultval = f->defaultval; | 777 newf->defaultval = f->defaultval; |
652 } | 778 } |
653 | 779 |
654 if (f->subdef_is_symbolic) { | 780 if (f->subdef_is_symbolic) { |
655 srcname = f->sub.name; /* Might be NULL. */ | 781 srcname = f->sub.name; /* Might be NULL. */ |
656 } else { | 782 } else { |
657 srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL; | 783 srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL; |
658 } | 784 } |
659 if (srcname) { | 785 if (srcname) { |
660 char *newname = malloc(strlen(f->sub.def->fullname) + 2); | 786 char *newname = upb_gmalloc(strlen(f->sub.def->fullname) + 2); |
661 if (!newname) { | 787 if (!newname) { |
662 upb_fielddef_unref(newf, owner); | 788 upb_fielddef_unref(newf, owner); |
663 return NULL; | 789 return NULL; |
664 } | 790 } |
665 strcpy(newname, "."); | 791 strcpy(newname, "."); |
666 strcat(newname, f->sub.def->fullname); | 792 strcat(newname, f->sub.def->fullname); |
667 upb_fielddef_setsubdefname(newf, newname, NULL); | 793 upb_fielddef_setsubdefname(newf, newname, NULL); |
668 free(newname); | 794 upb_gfree(newname); |
669 } | 795 } |
670 | 796 |
671 return newf; | 797 return newf; |
672 } | 798 } |
673 | 799 |
674 bool upb_fielddef_typeisset(const upb_fielddef *f) { | 800 bool upb_fielddef_typeisset(const upb_fielddef *f) { |
675 return f->type_is_set_; | 801 return f->type_is_set_; |
676 } | 802 } |
677 | 803 |
678 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) { | 804 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) { |
679 assert(f->type_is_set_); | 805 UPB_ASSERT(f->type_is_set_); |
680 return f->type_; | 806 return f->type_; |
681 } | 807 } |
682 | 808 |
683 uint32_t upb_fielddef_index(const upb_fielddef *f) { | 809 uint32_t upb_fielddef_index(const upb_fielddef *f) { |
684 return f->index_; | 810 return f->index_; |
685 } | 811 } |
686 | 812 |
687 upb_label_t upb_fielddef_label(const upb_fielddef *f) { | 813 upb_label_t upb_fielddef_label(const upb_fielddef *f) { |
688 return f->label_; | 814 return f->label_; |
689 } | 815 } |
(...skipping 19 matching lines...) Expand all Loading... |
709 } | 835 } |
710 | 836 |
711 bool upb_fielddef_packed(const upb_fielddef *f) { | 837 bool upb_fielddef_packed(const upb_fielddef *f) { |
712 return f->packed_; | 838 return f->packed_; |
713 } | 839 } |
714 | 840 |
715 const char *upb_fielddef_name(const upb_fielddef *f) { | 841 const char *upb_fielddef_name(const upb_fielddef *f) { |
716 return upb_def_fullname(upb_fielddef_upcast(f)); | 842 return upb_def_fullname(upb_fielddef_upcast(f)); |
717 } | 843 } |
718 | 844 |
| 845 size_t upb_fielddef_getjsonname(const upb_fielddef *f, char *buf, size_t len) { |
| 846 const char *name = upb_fielddef_name(f); |
| 847 size_t src, dst = 0; |
| 848 bool ucase_next = false; |
| 849 |
| 850 #define WRITE(byte) \ |
| 851 ++dst; \ |
| 852 if (dst < len) buf[dst - 1] = byte; \ |
| 853 else if (dst == len) buf[dst - 1] = '\0' |
| 854 |
| 855 if (!name) { |
| 856 WRITE('\0'); |
| 857 return 0; |
| 858 } |
| 859 |
| 860 /* Implement the transformation as described in the spec: |
| 861 * 1. upper case all letters after an underscore. |
| 862 * 2. remove all underscores. |
| 863 */ |
| 864 for (src = 0; name[src]; src++) { |
| 865 if (name[src] == '_') { |
| 866 ucase_next = true; |
| 867 continue; |
| 868 } |
| 869 |
| 870 if (ucase_next) { |
| 871 WRITE(toupper(name[src])); |
| 872 ucase_next = false; |
| 873 } else { |
| 874 WRITE(name[src]); |
| 875 } |
| 876 } |
| 877 |
| 878 WRITE('\0'); |
| 879 return dst; |
| 880 |
| 881 #undef WRITE |
| 882 } |
| 883 |
719 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { | 884 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { |
720 return f->msg_is_symbolic ? NULL : f->msg.def; | 885 return f->msg_is_symbolic ? NULL : f->msg.def; |
721 } | 886 } |
722 | 887 |
723 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { | 888 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { |
724 return f->oneof; | 889 return f->oneof; |
725 } | 890 } |
726 | 891 |
727 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) { | 892 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) { |
728 return (upb_msgdef*)upb_fielddef_containingtype(f); | 893 return (upb_msgdef*)upb_fielddef_containingtype(f); |
729 } | 894 } |
730 | 895 |
731 const char *upb_fielddef_containingtypename(upb_fielddef *f) { | 896 const char *upb_fielddef_containingtypename(upb_fielddef *f) { |
732 return f->msg_is_symbolic ? f->msg.name : NULL; | 897 return f->msg_is_symbolic ? f->msg.name : NULL; |
733 } | 898 } |
734 | 899 |
735 static void release_containingtype(upb_fielddef *f) { | 900 static void release_containingtype(upb_fielddef *f) { |
736 if (f->msg_is_symbolic) free(f->msg.name); | 901 if (f->msg_is_symbolic) upb_gfree(f->msg.name); |
737 } | 902 } |
738 | 903 |
739 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, | 904 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, |
740 upb_status *s) { | 905 upb_status *s) { |
741 assert(!upb_fielddef_isfrozen(f)); | 906 char *name_copy; |
| 907 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
742 if (upb_fielddef_containingtype(f)) { | 908 if (upb_fielddef_containingtype(f)) { |
743 upb_status_seterrmsg(s, "field has already been added to a message."); | 909 upb_status_seterrmsg(s, "field has already been added to a message."); |
744 return false; | 910 return false; |
745 } | 911 } |
746 /* TODO: validate name (upb_isident() doesn't quite work atm because this name | 912 /* TODO: validate name (upb_isident() doesn't quite work atm because this name |
747 * may have a leading "."). */ | 913 * may have a leading "."). */ |
| 914 |
| 915 name_copy = upb_gstrdup(name); |
| 916 if (!name_copy) { |
| 917 upb_upberr_setoom(s); |
| 918 return false; |
| 919 } |
| 920 |
748 release_containingtype(f); | 921 release_containingtype(f); |
749 f->msg.name = upb_strdup(name); | 922 f->msg.name = name_copy; |
750 f->msg_is_symbolic = true; | 923 f->msg_is_symbolic = true; |
751 return true; | 924 return true; |
752 } | 925 } |
753 | 926 |
754 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) { | 927 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) { |
755 if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) { | 928 if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) { |
756 upb_status_seterrmsg(s, "Already added to message or oneof"); | 929 upb_status_seterrmsg(s, "Already added to message or oneof"); |
757 return false; | 930 return false; |
758 } | 931 } |
759 return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s); | 932 return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s); |
760 } | 933 } |
761 | 934 |
762 static void chkdefaulttype(const upb_fielddef *f, upb_fieldtype_t type) { | 935 static void chkdefaulttype(const upb_fielddef *f, upb_fieldtype_t type) { |
763 UPB_UNUSED(f); | 936 UPB_UNUSED(f); |
764 UPB_UNUSED(type); | 937 UPB_UNUSED(type); |
765 assert(f->type_is_set_ && upb_fielddef_type(f) == type); | 938 UPB_ASSERT(f->type_is_set_ && upb_fielddef_type(f) == type); |
766 } | 939 } |
767 | 940 |
768 int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { | 941 int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { |
769 chkdefaulttype(f, UPB_TYPE_INT64); | 942 chkdefaulttype(f, UPB_TYPE_INT64); |
770 return f->defaultval.sint; | 943 return f->defaultval.sint; |
771 } | 944 } |
772 | 945 |
773 int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { | 946 int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { |
774 if (f->type_is_set_ && upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 947 if (f->type_is_set_ && upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
775 int32_t val; | 948 int32_t val; |
776 bool ok = enumdefaultint32(f, &val); | 949 bool ok = enumdefaultint32(f, &val); |
777 UPB_ASSERT_VAR(ok, ok); | 950 UPB_ASSERT(ok); |
778 return val; | 951 return val; |
779 } else { | 952 } else { |
780 chkdefaulttype(f, UPB_TYPE_INT32); | 953 chkdefaulttype(f, UPB_TYPE_INT32); |
781 return f->defaultval.sint; | 954 return f->defaultval.sint; |
782 } | 955 } |
783 } | 956 } |
784 | 957 |
785 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { | 958 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { |
786 chkdefaulttype(f, UPB_TYPE_UINT64); | 959 chkdefaulttype(f, UPB_TYPE_UINT64); |
787 return f->defaultval.uint; | 960 return f->defaultval.uint; |
(...skipping 13 matching lines...) Expand all Loading... |
801 chkdefaulttype(f, UPB_TYPE_FLOAT); | 974 chkdefaulttype(f, UPB_TYPE_FLOAT); |
802 return f->defaultval.flt; | 975 return f->defaultval.flt; |
803 } | 976 } |
804 | 977 |
805 double upb_fielddef_defaultdouble(const upb_fielddef *f) { | 978 double upb_fielddef_defaultdouble(const upb_fielddef *f) { |
806 chkdefaulttype(f, UPB_TYPE_DOUBLE); | 979 chkdefaulttype(f, UPB_TYPE_DOUBLE); |
807 return f->defaultval.dbl; | 980 return f->defaultval.dbl; |
808 } | 981 } |
809 | 982 |
810 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) { | 983 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) { |
811 assert(f->type_is_set_); | 984 UPB_ASSERT(f->type_is_set_); |
812 assert(upb_fielddef_type(f) == UPB_TYPE_STRING || | 985 UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_STRING || |
813 upb_fielddef_type(f) == UPB_TYPE_BYTES || | 986 upb_fielddef_type(f) == UPB_TYPE_BYTES || |
814 upb_fielddef_type(f) == UPB_TYPE_ENUM); | 987 upb_fielddef_type(f) == UPB_TYPE_ENUM); |
815 | 988 |
816 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 989 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
817 const char *ret = enumdefaultstr(f); | 990 const char *ret = enumdefaultstr(f); |
818 assert(ret); | 991 UPB_ASSERT(ret); |
819 /* Enum defaults can't have embedded NULLs. */ | 992 /* Enum defaults can't have embedded NULLs. */ |
820 if (len) *len = strlen(ret); | 993 if (len) *len = strlen(ret); |
821 return ret; | 994 return ret; |
822 } | 995 } |
823 | 996 |
824 if (f->default_is_string) { | 997 if (f->default_is_string) { |
825 str_t *str = f->defaultval.bytes; | 998 str_t *str = f->defaultval.bytes; |
826 if (len) *len = str->len; | 999 if (len) *len = str->len; |
827 return str->str; | 1000 return str->str; |
828 } | 1001 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 } | 1063 } |
891 if (number == 0 || number > UPB_MAX_FIELDNUMBER) { | 1064 if (number == 0 || number > UPB_MAX_FIELDNUMBER) { |
892 upb_status_seterrf(s, "invalid field number (%u)", number); | 1065 upb_status_seterrf(s, "invalid field number (%u)", number); |
893 return false; | 1066 return false; |
894 } | 1067 } |
895 f->number_ = number; | 1068 f->number_ = number; |
896 return true; | 1069 return true; |
897 } | 1070 } |
898 | 1071 |
899 void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type) { | 1072 void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type) { |
900 assert(!upb_fielddef_isfrozen(f)); | 1073 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
901 assert(upb_fielddef_checktype(type)); | 1074 UPB_ASSERT(upb_fielddef_checktype(type)); |
902 upb_fielddef_uninit_default(f); | 1075 upb_fielddef_uninit_default(f); |
903 f->type_ = type; | 1076 f->type_ = type; |
904 f->type_is_set_ = true; | 1077 f->type_is_set_ = true; |
905 upb_fielddef_init_default(f); | 1078 upb_fielddef_init_default(f); |
906 } | 1079 } |
907 | 1080 |
908 void upb_fielddef_setdescriptortype(upb_fielddef *f, int type) { | 1081 void upb_fielddef_setdescriptortype(upb_fielddef *f, int type) { |
909 assert(!upb_fielddef_isfrozen(f)); | 1082 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
910 switch (type) { | 1083 switch (type) { |
911 case UPB_DESCRIPTOR_TYPE_DOUBLE: | 1084 case UPB_DESCRIPTOR_TYPE_DOUBLE: |
912 upb_fielddef_settype(f, UPB_TYPE_DOUBLE); | 1085 upb_fielddef_settype(f, UPB_TYPE_DOUBLE); |
913 break; | 1086 break; |
914 case UPB_DESCRIPTOR_TYPE_FLOAT: | 1087 case UPB_DESCRIPTOR_TYPE_FLOAT: |
915 upb_fielddef_settype(f, UPB_TYPE_FLOAT); | 1088 upb_fielddef_settype(f, UPB_TYPE_FLOAT); |
916 break; | 1089 break; |
917 case UPB_DESCRIPTOR_TYPE_INT64: | 1090 case UPB_DESCRIPTOR_TYPE_INT64: |
918 case UPB_DESCRIPTOR_TYPE_SFIXED64: | 1091 case UPB_DESCRIPTOR_TYPE_SFIXED64: |
919 case UPB_DESCRIPTOR_TYPE_SINT64: | 1092 case UPB_DESCRIPTOR_TYPE_SINT64: |
(...skipping 21 matching lines...) Expand all Loading... |
941 case UPB_DESCRIPTOR_TYPE_BYTES: | 1114 case UPB_DESCRIPTOR_TYPE_BYTES: |
942 upb_fielddef_settype(f, UPB_TYPE_BYTES); | 1115 upb_fielddef_settype(f, UPB_TYPE_BYTES); |
943 break; | 1116 break; |
944 case UPB_DESCRIPTOR_TYPE_GROUP: | 1117 case UPB_DESCRIPTOR_TYPE_GROUP: |
945 case UPB_DESCRIPTOR_TYPE_MESSAGE: | 1118 case UPB_DESCRIPTOR_TYPE_MESSAGE: |
946 upb_fielddef_settype(f, UPB_TYPE_MESSAGE); | 1119 upb_fielddef_settype(f, UPB_TYPE_MESSAGE); |
947 break; | 1120 break; |
948 case UPB_DESCRIPTOR_TYPE_ENUM: | 1121 case UPB_DESCRIPTOR_TYPE_ENUM: |
949 upb_fielddef_settype(f, UPB_TYPE_ENUM); | 1122 upb_fielddef_settype(f, UPB_TYPE_ENUM); |
950 break; | 1123 break; |
951 default: assert(false); | 1124 default: UPB_ASSERT(false); |
952 } | 1125 } |
953 | 1126 |
954 if (type == UPB_DESCRIPTOR_TYPE_FIXED64 || | 1127 if (type == UPB_DESCRIPTOR_TYPE_FIXED64 || |
955 type == UPB_DESCRIPTOR_TYPE_FIXED32 || | 1128 type == UPB_DESCRIPTOR_TYPE_FIXED32 || |
956 type == UPB_DESCRIPTOR_TYPE_SFIXED64 || | 1129 type == UPB_DESCRIPTOR_TYPE_SFIXED64 || |
957 type == UPB_DESCRIPTOR_TYPE_SFIXED32) { | 1130 type == UPB_DESCRIPTOR_TYPE_SFIXED32) { |
958 upb_fielddef_setintfmt(f, UPB_INTFMT_FIXED); | 1131 upb_fielddef_setintfmt(f, UPB_INTFMT_FIXED); |
959 } else if (type == UPB_DESCRIPTOR_TYPE_SINT64 || | 1132 } else if (type == UPB_DESCRIPTOR_TYPE_SINT64 || |
960 type == UPB_DESCRIPTOR_TYPE_SINT32) { | 1133 type == UPB_DESCRIPTOR_TYPE_SINT32) { |
961 upb_fielddef_setintfmt(f, UPB_INTFMT_ZIGZAG); | 1134 upb_fielddef_setintfmt(f, UPB_INTFMT_ZIGZAG); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 case UPB_INTFMT_ZIGZAG: return -1; | 1172 case UPB_INTFMT_ZIGZAG: return -1; |
1000 } | 1173 } |
1001 case UPB_TYPE_MESSAGE: | 1174 case UPB_TYPE_MESSAGE: |
1002 return upb_fielddef_istagdelim(f) ? | 1175 return upb_fielddef_istagdelim(f) ? |
1003 UPB_DESCRIPTOR_TYPE_GROUP : UPB_DESCRIPTOR_TYPE_MESSAGE; | 1176 UPB_DESCRIPTOR_TYPE_GROUP : UPB_DESCRIPTOR_TYPE_MESSAGE; |
1004 } | 1177 } |
1005 return 0; | 1178 return 0; |
1006 } | 1179 } |
1007 | 1180 |
1008 void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension) { | 1181 void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension) { |
1009 assert(!upb_fielddef_isfrozen(f)); | 1182 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1010 f->is_extension_ = is_extension; | 1183 f->is_extension_ = is_extension; |
1011 } | 1184 } |
1012 | 1185 |
1013 void upb_fielddef_setlazy(upb_fielddef *f, bool lazy) { | 1186 void upb_fielddef_setlazy(upb_fielddef *f, bool lazy) { |
1014 assert(!upb_fielddef_isfrozen(f)); | 1187 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1015 f->lazy_ = lazy; | 1188 f->lazy_ = lazy; |
1016 } | 1189 } |
1017 | 1190 |
1018 void upb_fielddef_setpacked(upb_fielddef *f, bool packed) { | 1191 void upb_fielddef_setpacked(upb_fielddef *f, bool packed) { |
1019 assert(!upb_fielddef_isfrozen(f)); | 1192 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1020 f->packed_ = packed; | 1193 f->packed_ = packed; |
1021 } | 1194 } |
1022 | 1195 |
1023 void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label) { | 1196 void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label) { |
1024 assert(!upb_fielddef_isfrozen(f)); | 1197 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1025 assert(upb_fielddef_checklabel(label)); | 1198 UPB_ASSERT(upb_fielddef_checklabel(label)); |
1026 f->label_ = label; | 1199 f->label_ = label; |
1027 } | 1200 } |
1028 | 1201 |
1029 void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt) { | 1202 void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt) { |
1030 assert(!upb_fielddef_isfrozen(f)); | 1203 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1031 assert(upb_fielddef_checkintfmt(fmt)); | 1204 UPB_ASSERT(upb_fielddef_checkintfmt(fmt)); |
1032 f->intfmt = fmt; | 1205 f->intfmt = fmt; |
1033 } | 1206 } |
1034 | 1207 |
1035 void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim) { | 1208 void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim) { |
1036 assert(!upb_fielddef_isfrozen(f)); | 1209 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1037 f->tagdelim = tag_delim; | 1210 f->tagdelim = tag_delim; |
1038 f->tagdelim = tag_delim; | 1211 f->tagdelim = tag_delim; |
1039 } | 1212 } |
1040 | 1213 |
1041 static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) { | 1214 static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) { |
1042 if (!f->type_is_set_ || upb_fielddef_isfrozen(f) || | 1215 if (!f->type_is_set_ || upb_fielddef_isfrozen(f) || |
1043 upb_fielddef_type(f) != type) { | 1216 upb_fielddef_type(f) != type) { |
1044 assert(false); | 1217 UPB_ASSERT(false); |
1045 return false; | 1218 return false; |
1046 } | 1219 } |
1047 if (f->default_is_string) { | 1220 if (f->default_is_string) { |
1048 str_t *s = f->defaultval.bytes; | 1221 str_t *s = f->defaultval.bytes; |
1049 assert(s || type == UPB_TYPE_ENUM); | 1222 UPB_ASSERT(s || type == UPB_TYPE_ENUM); |
1050 if (s) freestr(s); | 1223 if (s) freestr(s); |
1051 } | 1224 } |
1052 f->default_is_string = false; | 1225 f->default_is_string = false; |
1053 return true; | 1226 return true; |
1054 } | 1227 } |
1055 | 1228 |
1056 void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t value) { | 1229 void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t value) { |
1057 if (checksetdefault(f, UPB_TYPE_INT64)) | 1230 if (checksetdefault(f, UPB_TYPE_INT64)) |
1058 f->defaultval.sint = value; | 1231 f->defaultval.sint = value; |
1059 } | 1232 } |
(...skipping 27 matching lines...) Expand all Loading... |
1087 } | 1260 } |
1088 | 1261 |
1089 void upb_fielddef_setdefaultdouble(upb_fielddef *f, double value) { | 1262 void upb_fielddef_setdefaultdouble(upb_fielddef *f, double value) { |
1090 if (checksetdefault(f, UPB_TYPE_DOUBLE)) | 1263 if (checksetdefault(f, UPB_TYPE_DOUBLE)) |
1091 f->defaultval.dbl = value; | 1264 f->defaultval.dbl = value; |
1092 } | 1265 } |
1093 | 1266 |
1094 bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len, | 1267 bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len, |
1095 upb_status *s) { | 1268 upb_status *s) { |
1096 str_t *str2; | 1269 str_t *str2; |
1097 assert(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM); | 1270 UPB_ASSERT(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM); |
1098 if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s)) | 1271 if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s)) |
1099 return false; | 1272 return false; |
1100 | 1273 |
1101 if (f->default_is_string) { | 1274 if (f->default_is_string) { |
1102 str_t *s = f->defaultval.bytes; | 1275 str_t *s = f->defaultval.bytes; |
1103 assert(s || f->type_ == UPB_TYPE_ENUM); | 1276 UPB_ASSERT(s || f->type_ == UPB_TYPE_ENUM); |
1104 if (s) freestr(s); | 1277 if (s) freestr(s); |
1105 } else { | 1278 } else { |
1106 assert(f->type_ == UPB_TYPE_ENUM); | 1279 UPB_ASSERT(f->type_ == UPB_TYPE_ENUM); |
1107 } | 1280 } |
1108 | 1281 |
1109 str2 = newstr(str, len); | 1282 str2 = newstr(str, len); |
1110 f->defaultval.bytes = str2; | 1283 f->defaultval.bytes = str2; |
1111 f->default_is_string = true; | 1284 f->default_is_string = true; |
1112 return true; | 1285 return true; |
1113 } | 1286 } |
1114 | 1287 |
1115 void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str, | 1288 void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str, |
1116 upb_status *s) { | 1289 upb_status *s) { |
1117 assert(f->type_is_set_); | 1290 UPB_ASSERT(f->type_is_set_); |
1118 upb_fielddef_setdefaultstr(f, str, str ? strlen(str) : 0, s); | 1291 upb_fielddef_setdefaultstr(f, str, str ? strlen(str) : 0, s); |
1119 } | 1292 } |
1120 | 1293 |
1121 bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f) { | 1294 bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f) { |
1122 int32_t val; | 1295 int32_t val; |
1123 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 1296 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
1124 return enumdefaultint32(f, &val); | 1297 return enumdefaultint32(f, &val); |
1125 } | 1298 } |
1126 | 1299 |
1127 bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f) { | 1300 bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f) { |
1128 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 1301 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
1129 return enumdefaultstr(f) != NULL; | 1302 return enumdefaultstr(f) != NULL; |
1130 } | 1303 } |
1131 | 1304 |
1132 static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef, | 1305 static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef, |
1133 upb_status *s) { | 1306 upb_status *s) { |
1134 if (f->type_ == UPB_TYPE_MESSAGE) { | 1307 if (f->type_ == UPB_TYPE_MESSAGE) { |
1135 if (upb_dyncast_msgdef(subdef)) return true; | 1308 if (upb_dyncast_msgdef(subdef)) return true; |
1136 upb_status_seterrmsg(s, "invalid subdef type for this submessage field"); | 1309 upb_status_seterrmsg(s, "invalid subdef type for this submessage field"); |
1137 return false; | 1310 return false; |
1138 } else if (f->type_ == UPB_TYPE_ENUM) { | 1311 } else if (f->type_ == UPB_TYPE_ENUM) { |
1139 if (upb_dyncast_enumdef(subdef)) return true; | 1312 if (upb_dyncast_enumdef(subdef)) return true; |
1140 upb_status_seterrmsg(s, "invalid subdef type for this enum field"); | 1313 upb_status_seterrmsg(s, "invalid subdef type for this enum field"); |
1141 return false; | 1314 return false; |
1142 } else { | 1315 } else { |
1143 upb_status_seterrmsg(s, "only message and enum fields can have a subdef"); | 1316 upb_status_seterrmsg(s, "only message and enum fields can have a subdef"); |
1144 return false; | 1317 return false; |
1145 } | 1318 } |
1146 } | 1319 } |
1147 | 1320 |
1148 static void release_subdef(upb_fielddef *f) { | 1321 static void release_subdef(upb_fielddef *f) { |
1149 if (f->subdef_is_symbolic) { | 1322 if (f->subdef_is_symbolic) { |
1150 free(f->sub.name); | 1323 upb_gfree(f->sub.name); |
1151 } else if (f->sub.def) { | 1324 } else if (f->sub.def) { |
1152 upb_unref2(f->sub.def, f); | 1325 upb_unref2(f->sub.def, f); |
1153 } | 1326 } |
1154 } | 1327 } |
1155 | 1328 |
1156 bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef, | 1329 bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef, |
1157 upb_status *s) { | 1330 upb_status *s) { |
1158 assert(!upb_fielddef_isfrozen(f)); | 1331 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1159 assert(upb_fielddef_hassubdef(f)); | 1332 UPB_ASSERT(upb_fielddef_hassubdef(f)); |
1160 if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false; | 1333 if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false; |
1161 release_subdef(f); | 1334 release_subdef(f); |
1162 f->sub.def = subdef; | 1335 f->sub.def = subdef; |
1163 f->subdef_is_symbolic = false; | 1336 f->subdef_is_symbolic = false; |
1164 if (f->sub.def) upb_ref2(f->sub.def, f); | 1337 if (f->sub.def) upb_ref2(f->sub.def, f); |
1165 return true; | 1338 return true; |
1166 } | 1339 } |
1167 | 1340 |
1168 bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef, | 1341 bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef, |
1169 upb_status *s) { | 1342 upb_status *s) { |
1170 return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s); | 1343 return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s); |
1171 } | 1344 } |
1172 | 1345 |
1173 bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef, | 1346 bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef, |
1174 upb_status *s) { | 1347 upb_status *s) { |
1175 return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s); | 1348 return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s); |
1176 } | 1349 } |
1177 | 1350 |
1178 bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name, | 1351 bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name, |
1179 upb_status *s) { | 1352 upb_status *s) { |
1180 assert(!upb_fielddef_isfrozen(f)); | 1353 char *name_copy; |
| 1354 UPB_ASSERT(!upb_fielddef_isfrozen(f)); |
1181 if (!upb_fielddef_hassubdef(f)) { | 1355 if (!upb_fielddef_hassubdef(f)) { |
1182 upb_status_seterrmsg(s, "field type does not accept a subdef"); | 1356 upb_status_seterrmsg(s, "field type does not accept a subdef"); |
1183 return false; | 1357 return false; |
1184 } | 1358 } |
| 1359 |
| 1360 name_copy = upb_gstrdup(name); |
| 1361 if (!name_copy) { |
| 1362 upb_upberr_setoom(s); |
| 1363 return false; |
| 1364 } |
| 1365 |
1185 /* TODO: validate name (upb_isident() doesn't quite work atm because this name | 1366 /* TODO: validate name (upb_isident() doesn't quite work atm because this name |
1186 * may have a leading "."). */ | 1367 * may have a leading "."). */ |
1187 release_subdef(f); | 1368 release_subdef(f); |
1188 f->sub.name = upb_strdup(name); | 1369 f->sub.name = name_copy; |
1189 f->subdef_is_symbolic = true; | 1370 f->subdef_is_symbolic = true; |
1190 return true; | 1371 return true; |
1191 } | 1372 } |
1192 | 1373 |
1193 bool upb_fielddef_issubmsg(const upb_fielddef *f) { | 1374 bool upb_fielddef_issubmsg(const upb_fielddef *f) { |
1194 return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; | 1375 return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; |
1195 } | 1376 } |
1196 | 1377 |
1197 bool upb_fielddef_isstring(const upb_fielddef *f) { | 1378 bool upb_fielddef_isstring(const upb_fielddef *f) { |
1198 return upb_fielddef_type(f) == UPB_TYPE_STRING || | 1379 return upb_fielddef_type(f) == UPB_TYPE_STRING || |
1199 upb_fielddef_type(f) == UPB_TYPE_BYTES; | 1380 upb_fielddef_type(f) == UPB_TYPE_BYTES; |
1200 } | 1381 } |
1201 | 1382 |
1202 bool upb_fielddef_isseq(const upb_fielddef *f) { | 1383 bool upb_fielddef_isseq(const upb_fielddef *f) { |
1203 return upb_fielddef_label(f) == UPB_LABEL_REPEATED; | 1384 return upb_fielddef_label(f) == UPB_LABEL_REPEATED; |
1204 } | 1385 } |
1205 | 1386 |
1206 bool upb_fielddef_isprimitive(const upb_fielddef *f) { | 1387 bool upb_fielddef_isprimitive(const upb_fielddef *f) { |
1207 return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f); | 1388 return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f); |
1208 } | 1389 } |
1209 | 1390 |
1210 bool upb_fielddef_ismap(const upb_fielddef *f) { | 1391 bool upb_fielddef_ismap(const upb_fielddef *f) { |
1211 return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) && | 1392 return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) && |
1212 upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); | 1393 upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); |
1213 } | 1394 } |
1214 | 1395 |
| 1396 bool upb_fielddef_haspresence(const upb_fielddef *f) { |
| 1397 if (upb_fielddef_isseq(f)) return false; |
| 1398 if (upb_fielddef_issubmsg(f)) return true; |
| 1399 |
| 1400 /* Primitive field: return true unless there is a message that specifies |
| 1401 * presence should not exist. */ |
| 1402 if (f->msg_is_symbolic || !f->msg.def) return true; |
| 1403 return f->msg.def->syntax == UPB_SYNTAX_PROTO2; |
| 1404 } |
| 1405 |
1215 bool upb_fielddef_hassubdef(const upb_fielddef *f) { | 1406 bool upb_fielddef_hassubdef(const upb_fielddef *f) { |
1216 return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; | 1407 return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; |
1217 } | 1408 } |
1218 | 1409 |
1219 static bool between(int32_t x, int32_t low, int32_t high) { | 1410 static bool between(int32_t x, int32_t low, int32_t high) { |
1220 return x >= low && x <= high; | 1411 return x >= low && x <= high; |
1221 } | 1412 } |
1222 | 1413 |
1223 bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); } | 1414 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); } | 1415 bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); } |
1225 bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } | 1416 bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } |
1226 | 1417 |
1227 bool upb_fielddef_checkdescriptortype(int32_t type) { | 1418 bool upb_fielddef_checkdescriptortype(int32_t type) { |
1228 return between(type, 1, 18); | 1419 return between(type, 1, 18); |
1229 } | 1420 } |
1230 | 1421 |
1231 /* upb_msgdef *****************************************************************/ | 1422 /* upb_msgdef *****************************************************************/ |
1232 | 1423 |
1233 static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit, | 1424 static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit, |
1234 void *closure) { | 1425 void *closure) { |
1235 upb_msg_oneof_iter o; | 1426 upb_msg_oneof_iter o; |
1236 const upb_msgdef *m = (const upb_msgdef*)r; | 1427 const upb_msgdef *m = (const upb_msgdef*)r; |
| 1428 const upb_def *def = upb_msgdef_upcast(m); |
1237 upb_msg_field_iter i; | 1429 upb_msg_field_iter i; |
1238 for(upb_msg_field_begin(&i, m); | 1430 for(upb_msg_field_begin(&i, m); |
1239 !upb_msg_field_done(&i); | 1431 !upb_msg_field_done(&i); |
1240 upb_msg_field_next(&i)) { | 1432 upb_msg_field_next(&i)) { |
1241 upb_fielddef *f = upb_msg_iter_field(&i); | 1433 upb_fielddef *f = upb_msg_iter_field(&i); |
1242 visit(r, upb_fielddef_upcast2(f), closure); | 1434 visit(r, upb_fielddef_upcast2(f), closure); |
1243 } | 1435 } |
1244 for(upb_msg_oneof_begin(&o, m); | 1436 for(upb_msg_oneof_begin(&o, m); |
1245 !upb_msg_oneof_done(&o); | 1437 !upb_msg_oneof_done(&o); |
1246 upb_msg_oneof_next(&o)) { | 1438 upb_msg_oneof_next(&o)) { |
1247 upb_oneofdef *f = upb_msg_iter_oneof(&o); | 1439 upb_oneofdef *f = upb_msg_iter_oneof(&o); |
1248 visit(r, upb_oneofdef_upcast2(f), closure); | 1440 visit(r, upb_oneofdef_upcast(f), closure); |
| 1441 } |
| 1442 if (upb_def_file(def)) { |
| 1443 visit(r, upb_filedef_upcast(upb_def_file(def)), closure); |
1249 } | 1444 } |
1250 } | 1445 } |
1251 | 1446 |
1252 static void freemsg(upb_refcounted *r) { | 1447 static void freemsg(upb_refcounted *r) { |
1253 upb_msgdef *m = (upb_msgdef*)r; | 1448 upb_msgdef *m = (upb_msgdef*)r; |
1254 upb_strtable_uninit(&m->ntoo); | |
1255 upb_strtable_uninit(&m->ntof); | 1449 upb_strtable_uninit(&m->ntof); |
1256 upb_inttable_uninit(&m->itof); | 1450 upb_inttable_uninit(&m->itof); |
1257 upb_def_uninit(upb_msgdef_upcast_mutable(m)); | 1451 upb_def_uninit(upb_msgdef_upcast_mutable(m)); |
1258 free(m); | 1452 upb_gfree(m); |
1259 } | 1453 } |
1260 | 1454 |
| 1455 const struct upb_refcounted_vtbl upb_msgdef_vtbl = {visitmsg, freemsg}; |
| 1456 |
1261 upb_msgdef *upb_msgdef_new(const void *owner) { | 1457 upb_msgdef *upb_msgdef_new(const void *owner) { |
1262 static const struct upb_refcounted_vtbl vtbl = {visitmsg, freemsg}; | 1458 upb_msgdef *m = upb_gmalloc(sizeof(*m)); |
1263 upb_msgdef *m = malloc(sizeof(*m)); | |
1264 if (!m) return NULL; | 1459 if (!m) return NULL; |
1265 if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &vtbl, owner)) | 1460 |
| 1461 if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &upb_msgdef_vtbl, |
| 1462 owner)) { |
1266 goto err2; | 1463 goto err2; |
1267 if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err3; | 1464 } |
1268 if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err2; | 1465 |
1269 if (!upb_strtable_init(&m->ntoo, UPB_CTYPE_PTR)) goto err1; | 1466 if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err2; |
| 1467 if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err1; |
1270 m->map_entry = false; | 1468 m->map_entry = false; |
| 1469 m->syntax = UPB_SYNTAX_PROTO2; |
1271 return m; | 1470 return m; |
1272 | 1471 |
1273 err1: | 1472 err1: |
1274 upb_strtable_uninit(&m->ntof); | 1473 upb_inttable_uninit(&m->itof); |
1275 err2: | 1474 err2: |
1276 upb_inttable_uninit(&m->itof); | 1475 upb_gfree(m); |
1277 err3: | |
1278 free(m); | |
1279 return NULL; | 1476 return NULL; |
1280 } | 1477 } |
1281 | 1478 |
1282 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) { | 1479 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) { |
1283 bool ok; | 1480 bool ok; |
1284 upb_msg_field_iter i; | 1481 upb_msg_field_iter i; |
1285 upb_msg_oneof_iter o; | 1482 upb_msg_oneof_iter o; |
1286 | 1483 |
1287 upb_msgdef *newm = upb_msgdef_new(owner); | 1484 upb_msgdef *newm = upb_msgdef_new(owner); |
1288 if (!newm) return NULL; | 1485 if (!newm) return NULL; |
1289 ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm), | 1486 ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm), |
1290 upb_def_fullname(upb_msgdef_upcast(m)), | 1487 upb_def_fullname(upb_msgdef_upcast(m)), |
1291 NULL); | 1488 NULL); |
1292 newm->map_entry = m->map_entry; | 1489 newm->map_entry = m->map_entry; |
1293 UPB_ASSERT_VAR(ok, ok); | 1490 newm->syntax = m->syntax; |
| 1491 UPB_ASSERT(ok); |
1294 for(upb_msg_field_begin(&i, m); | 1492 for(upb_msg_field_begin(&i, m); |
1295 !upb_msg_field_done(&i); | 1493 !upb_msg_field_done(&i); |
1296 upb_msg_field_next(&i)) { | 1494 upb_msg_field_next(&i)) { |
1297 upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f); | 1495 upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f); |
1298 /* Fields in oneofs are dup'd below. */ | 1496 /* Fields in oneofs are dup'd below. */ |
1299 if (upb_fielddef_containingoneof(f)) continue; | 1497 if (upb_fielddef_containingoneof(f)) continue; |
1300 if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) { | 1498 if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) { |
1301 upb_msgdef_unref(newm, owner); | 1499 upb_msgdef_unref(newm, owner); |
1302 return NULL; | 1500 return NULL; |
1303 } | 1501 } |
(...skipping 12 matching lines...) Expand all Loading... |
1316 | 1514 |
1317 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) { | 1515 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) { |
1318 upb_def *d = upb_msgdef_upcast_mutable(m); | 1516 upb_def *d = upb_msgdef_upcast_mutable(m); |
1319 return upb_def_freeze(&d, 1, status); | 1517 return upb_def_freeze(&d, 1, status); |
1320 } | 1518 } |
1321 | 1519 |
1322 const char *upb_msgdef_fullname(const upb_msgdef *m) { | 1520 const char *upb_msgdef_fullname(const upb_msgdef *m) { |
1323 return upb_def_fullname(upb_msgdef_upcast(m)); | 1521 return upb_def_fullname(upb_msgdef_upcast(m)); |
1324 } | 1522 } |
1325 | 1523 |
| 1524 const char *upb_msgdef_name(const upb_msgdef *m) { |
| 1525 return upb_def_name(upb_msgdef_upcast(m)); |
| 1526 } |
| 1527 |
1326 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, | 1528 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, |
1327 upb_status *s) { | 1529 upb_status *s) { |
1328 return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s); | 1530 return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s); |
1329 } | 1531 } |
1330 | 1532 |
| 1533 bool upb_msgdef_setsyntax(upb_msgdef *m, upb_syntax_t syntax) { |
| 1534 if (syntax != UPB_SYNTAX_PROTO2 && syntax != UPB_SYNTAX_PROTO3) { |
| 1535 return false; |
| 1536 } |
| 1537 |
| 1538 m->syntax = syntax; |
| 1539 return true; |
| 1540 } |
| 1541 |
| 1542 upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) { |
| 1543 return m->syntax; |
| 1544 } |
| 1545 |
1331 /* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error | 1546 /* 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. */ | 1547 * on status |s| and return false if not. */ |
1333 static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f, | 1548 static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f, |
1334 upb_status *s) { | 1549 upb_status *s) { |
1335 if (upb_fielddef_containingtype(f) != NULL) { | 1550 if (upb_fielddef_containingtype(f) != NULL) { |
1336 upb_status_seterrmsg(s, "fielddef already belongs to a message"); | 1551 upb_status_seterrmsg(s, "fielddef already belongs to a message"); |
1337 return false; | 1552 return false; |
1338 } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { | 1553 } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { |
1339 upb_status_seterrmsg(s, "field name or number were not set"); | 1554 upb_status_seterrmsg(s, "field name or number were not set"); |
1340 return false; | 1555 return false; |
1341 } else if (upb_msgdef_ntofz(m, upb_fielddef_name(f)) || | 1556 } else if (upb_msgdef_itof(m, upb_fielddef_number(f))) { |
1342 upb_msgdef_itof(m, upb_fielddef_number(f))) { | 1557 upb_status_seterrmsg(s, "duplicate field number"); |
1343 upb_status_seterrmsg(s, "duplicate field name or number for field"); | 1558 return false; |
| 1559 } else if (upb_strtable_lookup(&m->ntof, upb_fielddef_name(f), NULL)) { |
| 1560 upb_status_seterrmsg(s, "name conflicts with existing field or oneof"); |
1344 return false; | 1561 return false; |
1345 } | 1562 } |
1346 return true; | 1563 return true; |
1347 } | 1564 } |
1348 | 1565 |
1349 static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) { | 1566 static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) { |
1350 release_containingtype(f); | 1567 release_containingtype(f); |
1351 f->msg.def = m; | 1568 f->msg.def = m; |
1352 f->msg_is_symbolic = false; | 1569 f->msg_is_symbolic = false; |
1353 upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f)); | 1570 upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f)); |
(...skipping 12 matching lines...) Expand all Loading... |
1366 * This also implies that there needs to be a separate lookup-by-name method | 1583 * This also implies that there needs to be a separate lookup-by-name method |
1367 * for extensions. It seems desirable for iteration to return both extensions | 1584 * for extensions. It seems desirable for iteration to return both extensions |
1368 * and non-extensions though. | 1585 * and non-extensions though. |
1369 * | 1586 * |
1370 * We also need to validate that the field number is in an extension range iff | 1587 * We also need to validate that the field number is in an extension range iff |
1371 * it is an extension. | 1588 * it is an extension. |
1372 * | 1589 * |
1373 * This method is idempotent. Check if |f| is already part of this msgdef and | 1590 * This method is idempotent. Check if |f| is already part of this msgdef and |
1374 * return immediately if so. */ | 1591 * return immediately if so. */ |
1375 if (upb_fielddef_containingtype(f) == m) { | 1592 if (upb_fielddef_containingtype(f) == m) { |
| 1593 if (ref_donor) upb_fielddef_unref(f, ref_donor); |
1376 return true; | 1594 return true; |
1377 } | 1595 } |
1378 | 1596 |
1379 /* Check constraints for all fields before performing any action. */ | 1597 /* Check constraints for all fields before performing any action. */ |
1380 if (!check_field_add(m, f, s)) { | 1598 if (!check_field_add(m, f, s)) { |
1381 return false; | 1599 return false; |
1382 } else if (upb_fielddef_containingoneof(f) != NULL) { | 1600 } else if (upb_fielddef_containingoneof(f) != NULL) { |
1383 /* Fields in a oneof can only be added by adding the oneof to the msgdef. */ | 1601 /* Fields in a oneof can only be added by adding the oneof to the msgdef. */ |
1384 upb_status_seterrmsg(s, "fielddef is part of a oneof"); | 1602 upb_status_seterrmsg(s, "fielddef is part of a oneof"); |
1385 return false; | 1603 return false; |
1386 } | 1604 } |
1387 | 1605 |
1388 /* Constraint checks ok, perform the action. */ | 1606 /* Constraint checks ok, perform the action. */ |
1389 add_field(m, f, ref_donor); | 1607 add_field(m, f, ref_donor); |
1390 return true; | 1608 return true; |
1391 } | 1609 } |
1392 | 1610 |
1393 bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, | 1611 bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, |
1394 upb_status *s) { | 1612 upb_status *s) { |
1395 upb_oneof_iter it; | 1613 upb_oneof_iter it; |
1396 | 1614 |
1397 /* Check various conditions that would prevent this oneof from being added. */ | 1615 /* Check various conditions that would prevent this oneof from being added. */ |
1398 if (upb_oneofdef_containingtype(o)) { | 1616 if (upb_oneofdef_containingtype(o)) { |
1399 upb_status_seterrmsg(s, "oneofdef already belongs to a message"); | 1617 upb_status_seterrmsg(s, "oneofdef already belongs to a message"); |
1400 return false; | 1618 return false; |
1401 } else if (upb_oneofdef_name(o) == NULL) { | 1619 } else if (upb_oneofdef_name(o) == NULL) { |
1402 upb_status_seterrmsg(s, "oneofdef name was not set"); | 1620 upb_status_seterrmsg(s, "oneofdef name was not set"); |
1403 return false; | 1621 return false; |
1404 } else if (upb_msgdef_ntooz(m, upb_oneofdef_name(o))) { | 1622 } else if (upb_strtable_lookup(&m->ntof, upb_oneofdef_name(o), NULL)) { |
1405 upb_status_seterrmsg(s, "duplicate oneof name"); | 1623 upb_status_seterrmsg(s, "name conflicts with existing field or oneof"); |
1406 return false; | 1624 return false; |
1407 } | 1625 } |
1408 | 1626 |
1409 /* Check that all of the oneof's fields do not conflict with names or numbers | 1627 /* Check that all of the oneof's fields do not conflict with names or numbers |
1410 * of fields already in the message. */ | 1628 * of fields already in the message. */ |
1411 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { | 1629 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { |
1412 const upb_fielddef *f = upb_oneof_iter_field(&it); | 1630 const upb_fielddef *f = upb_oneof_iter_field(&it); |
1413 if (!check_field_add(m, f, s)) { | 1631 if (!check_field_add(m, f, s)) { |
1414 return false; | 1632 return false; |
1415 } | 1633 } |
1416 } | 1634 } |
1417 | 1635 |
1418 /* Everything checks out -- commit now. */ | 1636 /* Everything checks out -- commit now. */ |
1419 | 1637 |
1420 /* Add oneof itself first. */ | 1638 /* Add oneof itself first. */ |
1421 o->parent = m; | 1639 o->parent = m; |
1422 upb_strtable_insert(&m->ntoo, upb_oneofdef_name(o), upb_value_ptr(o)); | 1640 upb_strtable_insert(&m->ntof, upb_oneofdef_name(o), upb_value_ptr(o)); |
1423 upb_ref2(o, m); | 1641 upb_ref2(o, m); |
1424 upb_ref2(m, o); | 1642 upb_ref2(m, o); |
1425 | 1643 |
1426 /* Add each field of the oneof directly to the msgdef. */ | 1644 /* 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)) { | 1645 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { |
1428 upb_fielddef *f = upb_oneof_iter_field(&it); | 1646 upb_fielddef *f = upb_oneof_iter_field(&it); |
1429 add_field(m, f, NULL); | 1647 add_field(m, f, NULL); |
1430 } | 1648 } |
1431 | 1649 |
1432 if (ref_donor) upb_oneofdef_unref(o, ref_donor); | 1650 if (ref_donor) upb_oneofdef_unref(o, ref_donor); |
1433 | 1651 |
1434 return true; | 1652 return true; |
1435 } | 1653 } |
1436 | 1654 |
1437 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { | 1655 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { |
1438 upb_value val; | 1656 upb_value val; |
1439 return upb_inttable_lookup32(&m->itof, i, &val) ? | 1657 return upb_inttable_lookup32(&m->itof, i, &val) ? |
1440 upb_value_getptr(val) : NULL; | 1658 upb_value_getptr(val) : NULL; |
1441 } | 1659 } |
1442 | 1660 |
1443 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, | 1661 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, |
1444 size_t len) { | 1662 size_t len) { |
1445 upb_value val; | 1663 upb_value val; |
1446 return upb_strtable_lookup2(&m->ntof, name, len, &val) ? | 1664 |
1447 upb_value_getptr(val) : NULL; | 1665 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { |
| 1666 return NULL; |
| 1667 } |
| 1668 |
| 1669 return upb_trygetfield(upb_value_getptr(val)); |
1448 } | 1670 } |
1449 | 1671 |
1450 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, | 1672 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, |
1451 size_t len) { | 1673 size_t len) { |
1452 upb_value val; | 1674 upb_value val; |
1453 return upb_strtable_lookup2(&m->ntoo, name, len, &val) ? | 1675 |
1454 upb_value_getptr(val) : NULL; | 1676 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { |
| 1677 return NULL; |
| 1678 } |
| 1679 |
| 1680 return upb_trygetoneof(upb_value_getptr(val)); |
| 1681 } |
| 1682 |
| 1683 bool upb_msgdef_lookupname(const upb_msgdef *m, const char *name, size_t len, |
| 1684 const upb_fielddef **f, const upb_oneofdef **o) { |
| 1685 upb_value val; |
| 1686 |
| 1687 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { |
| 1688 return false; |
| 1689 } |
| 1690 |
| 1691 *o = upb_trygetoneof(upb_value_getptr(val)); |
| 1692 *f = upb_trygetfield(upb_value_getptr(val)); |
| 1693 UPB_ASSERT((*o != NULL) ^ (*f != NULL)); /* Exactly one of the two should be
set. */ |
| 1694 return true; |
1455 } | 1695 } |
1456 | 1696 |
1457 int upb_msgdef_numfields(const upb_msgdef *m) { | 1697 int upb_msgdef_numfields(const upb_msgdef *m) { |
1458 return upb_strtable_count(&m->ntof); | 1698 /* The number table contains only fields. */ |
| 1699 return upb_inttable_count(&m->itof); |
1459 } | 1700 } |
1460 | 1701 |
1461 int upb_msgdef_numoneofs(const upb_msgdef *m) { | 1702 int upb_msgdef_numoneofs(const upb_msgdef *m) { |
1462 return upb_strtable_count(&m->ntoo); | 1703 /* The name table includes oneofs, and the number table does not. */ |
| 1704 return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof); |
1463 } | 1705 } |
1464 | 1706 |
1465 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) { | 1707 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) { |
1466 assert(!upb_msgdef_isfrozen(m)); | 1708 UPB_ASSERT(!upb_msgdef_isfrozen(m)); |
1467 m->map_entry = map_entry; | 1709 m->map_entry = map_entry; |
1468 } | 1710 } |
1469 | 1711 |
1470 bool upb_msgdef_mapentry(const upb_msgdef *m) { | 1712 bool upb_msgdef_mapentry(const upb_msgdef *m) { |
1471 return m->map_entry; | 1713 return m->map_entry; |
1472 } | 1714 } |
1473 | 1715 |
1474 void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { | 1716 void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { |
1475 upb_inttable_begin(iter, &m->itof); | 1717 upb_inttable_begin(iter, &m->itof); |
1476 } | 1718 } |
1477 | 1719 |
1478 void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); } | 1720 void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); } |
1479 | 1721 |
1480 bool upb_msg_field_done(const upb_msg_field_iter *iter) { | 1722 bool upb_msg_field_done(const upb_msg_field_iter *iter) { |
1481 return upb_inttable_done(iter); | 1723 return upb_inttable_done(iter); |
1482 } | 1724 } |
1483 | 1725 |
1484 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) { | 1726 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) { |
1485 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); | 1727 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); |
1486 } | 1728 } |
1487 | 1729 |
1488 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) { | 1730 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) { |
1489 upb_inttable_iter_setdone(iter); | 1731 upb_inttable_iter_setdone(iter); |
1490 } | 1732 } |
1491 | 1733 |
1492 void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) { | 1734 void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) { |
1493 upb_strtable_begin(iter, &m->ntoo); | 1735 upb_strtable_begin(iter, &m->ntof); |
| 1736 /* We need to skip past any initial fields. */ |
| 1737 while (!upb_strtable_done(iter) && |
| 1738 !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter)))) { |
| 1739 upb_strtable_next(iter); |
| 1740 } |
1494 } | 1741 } |
1495 | 1742 |
1496 void upb_msg_oneof_next(upb_msg_oneof_iter *iter) { upb_strtable_next(iter); } | 1743 void upb_msg_oneof_next(upb_msg_oneof_iter *iter) { |
| 1744 /* We need to skip past fields to return only oneofs. */ |
| 1745 do { |
| 1746 upb_strtable_next(iter); |
| 1747 } while (!upb_strtable_done(iter) && |
| 1748 !upb_isoneof(upb_value_getptr(upb_strtable_iter_value(iter)))); |
| 1749 } |
1497 | 1750 |
1498 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) { | 1751 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) { |
1499 return upb_strtable_done(iter); | 1752 return upb_strtable_done(iter); |
1500 } | 1753 } |
1501 | 1754 |
1502 upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) { | 1755 upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) { |
1503 return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter)); | 1756 return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter)); |
1504 } | 1757 } |
1505 | 1758 |
1506 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) { | 1759 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) { |
(...skipping 12 matching lines...) Expand all Loading... |
1519 } | 1772 } |
1520 if (o->parent) { | 1773 if (o->parent) { |
1521 visit(r, upb_msgdef_upcast2(o->parent), closure); | 1774 visit(r, upb_msgdef_upcast2(o->parent), closure); |
1522 } | 1775 } |
1523 } | 1776 } |
1524 | 1777 |
1525 static void freeoneof(upb_refcounted *r) { | 1778 static void freeoneof(upb_refcounted *r) { |
1526 upb_oneofdef *o = (upb_oneofdef*)r; | 1779 upb_oneofdef *o = (upb_oneofdef*)r; |
1527 upb_strtable_uninit(&o->ntof); | 1780 upb_strtable_uninit(&o->ntof); |
1528 upb_inttable_uninit(&o->itof); | 1781 upb_inttable_uninit(&o->itof); |
1529 upb_def_uninit(upb_oneofdef_upcast_mutable(o)); | 1782 upb_gfree((void*)o->name); |
1530 free(o); | 1783 upb_gfree(o); |
1531 } | 1784 } |
1532 | 1785 |
| 1786 const struct upb_refcounted_vtbl upb_oneofdef_vtbl = {visitoneof, freeoneof}; |
| 1787 |
1533 upb_oneofdef *upb_oneofdef_new(const void *owner) { | 1788 upb_oneofdef *upb_oneofdef_new(const void *owner) { |
1534 static const struct upb_refcounted_vtbl vtbl = {visitoneof, freeoneof}; | 1789 upb_oneofdef *o = upb_gmalloc(sizeof(*o)); |
1535 upb_oneofdef *o = malloc(sizeof(*o)); | 1790 |
| 1791 if (!o) { |
| 1792 return NULL; |
| 1793 } |
| 1794 |
1536 o->parent = NULL; | 1795 o->parent = NULL; |
1537 if (!o) return NULL; | 1796 o->name = NULL; |
1538 if (!upb_def_init(upb_oneofdef_upcast_mutable(o), UPB_DEF_ONEOF, &vtbl, | 1797 |
1539 owner)) | 1798 if (!upb_refcounted_init(upb_oneofdef_upcast_mutable(o), &upb_oneofdef_vtbl, |
| 1799 owner)) { |
1540 goto err2; | 1800 goto err2; |
| 1801 } |
| 1802 |
1541 if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2; | 1803 if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2; |
1542 if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1; | 1804 if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1; |
| 1805 |
1543 return o; | 1806 return o; |
1544 | 1807 |
1545 err1: | 1808 err1: |
1546 upb_inttable_uninit(&o->itof); | 1809 upb_inttable_uninit(&o->itof); |
1547 err2: | 1810 err2: |
1548 free(o); | 1811 upb_gfree(o); |
1549 return NULL; | 1812 return NULL; |
1550 } | 1813 } |
1551 | 1814 |
1552 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner) { | 1815 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner) { |
1553 bool ok; | 1816 bool ok; |
1554 upb_oneof_iter i; | 1817 upb_oneof_iter i; |
1555 upb_oneofdef *newo = upb_oneofdef_new(owner); | 1818 upb_oneofdef *newo = upb_oneofdef_new(owner); |
1556 if (!newo) return NULL; | 1819 if (!newo) return NULL; |
1557 ok = upb_def_setfullname(upb_oneofdef_upcast_mutable(newo), | 1820 ok = upb_oneofdef_setname(newo, upb_oneofdef_name(o), NULL); |
1558 upb_def_fullname(upb_oneofdef_upcast(o)), NULL); | 1821 UPB_ASSERT(ok); |
1559 UPB_ASSERT_VAR(ok, ok); | |
1560 for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) { | 1822 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); | 1823 upb_fielddef *f = upb_fielddef_dup(upb_oneof_iter_field(&i), &f); |
1562 if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) { | 1824 if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) { |
1563 upb_oneofdef_unref(newo, owner); | 1825 upb_oneofdef_unref(newo, owner); |
1564 return NULL; | 1826 return NULL; |
1565 } | 1827 } |
1566 } | 1828 } |
1567 return newo; | 1829 return newo; |
1568 } | 1830 } |
1569 | 1831 |
1570 const char *upb_oneofdef_name(const upb_oneofdef *o) { | 1832 const char *upb_oneofdef_name(const upb_oneofdef *o) { return o->name; } |
1571 return upb_def_fullname(upb_oneofdef_upcast(o)); | |
1572 } | |
1573 | 1833 |
1574 bool upb_oneofdef_setname(upb_oneofdef *o, const char *fullname, | 1834 bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s) { |
1575 upb_status *s) { | 1835 UPB_ASSERT(!upb_oneofdef_isfrozen(o)); |
1576 if (upb_oneofdef_containingtype(o)) { | 1836 if (upb_oneofdef_containingtype(o)) { |
1577 upb_status_seterrmsg(s, "oneof already added to a message"); | 1837 upb_status_seterrmsg(s, "oneof already added to a message"); |
1578 return false; | 1838 return false; |
1579 } | 1839 } |
1580 return upb_def_setfullname(upb_oneofdef_upcast_mutable(o), fullname, s); | 1840 |
| 1841 if (!upb_isident(name, strlen(name), true, s)) { |
| 1842 return false; |
| 1843 } |
| 1844 |
| 1845 name = upb_gstrdup(name); |
| 1846 if (!name) { |
| 1847 upb_status_seterrmsg(s, "One of memory"); |
| 1848 return false; |
| 1849 } |
| 1850 |
| 1851 upb_gfree((void*)o->name); |
| 1852 o->name = name; |
| 1853 return true; |
1581 } | 1854 } |
1582 | 1855 |
1583 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { | 1856 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { |
1584 return o->parent; | 1857 return o->parent; |
1585 } | 1858 } |
1586 | 1859 |
1587 int upb_oneofdef_numfields(const upb_oneofdef *o) { | 1860 int upb_oneofdef_numfields(const upb_oneofdef *o) { |
1588 return upb_strtable_count(&o->ntof); | 1861 return upb_strtable_count(&o->ntof); |
1589 } | 1862 } |
1590 | 1863 |
1591 bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f, | 1864 bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f, |
1592 const void *ref_donor, | 1865 const void *ref_donor, |
1593 upb_status *s) { | 1866 upb_status *s) { |
1594 assert(!upb_oneofdef_isfrozen(o)); | 1867 UPB_ASSERT(!upb_oneofdef_isfrozen(o)); |
1595 assert(!o->parent || !upb_msgdef_isfrozen(o->parent)); | 1868 UPB_ASSERT(!o->parent || !upb_msgdef_isfrozen(o->parent)); |
1596 | 1869 |
1597 /* This method is idempotent. Check if |f| is already part of this oneofdef | 1870 /* This method is idempotent. Check if |f| is already part of this oneofdef |
1598 * and return immediately if so. */ | 1871 * and return immediately if so. */ |
1599 if (upb_fielddef_containingoneof(f) == o) { | 1872 if (upb_fielddef_containingoneof(f) == o) { |
1600 return true; | 1873 return true; |
1601 } | 1874 } |
1602 | 1875 |
1603 /* The field must have an OPTIONAL label. */ | 1876 /* The field must have an OPTIONAL label. */ |
1604 if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) { | 1877 if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) { |
1605 upb_status_seterrmsg(s, "fields in oneof must have OPTIONAL label"); | 1878 upb_status_seterrmsg(s, "fields in oneof must have OPTIONAL label"); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1689 } | 1962 } |
1690 | 1963 |
1691 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) { | 1964 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) { |
1692 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); | 1965 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); |
1693 } | 1966 } |
1694 | 1967 |
1695 void upb_oneof_iter_setdone(upb_oneof_iter *iter) { | 1968 void upb_oneof_iter_setdone(upb_oneof_iter *iter) { |
1696 upb_inttable_iter_setdone(iter); | 1969 upb_inttable_iter_setdone(iter); |
1697 } | 1970 } |
1698 | 1971 |
1699 | 1972 /* upb_filedef ****************************************************************/ |
1700 #include <stdlib.h> | 1973 |
1701 #include <stdio.h> | 1974 static void visitfiledef(const upb_refcounted *r, upb_refcounted_visit *visit, |
1702 #include <string.h> | 1975 void *closure) { |
1703 | 1976 const upb_filedef *f = (const upb_filedef*)r; |
1704 typedef struct cleanup_ent { | 1977 size_t i; |
1705 upb_cleanup_func *cleanup; | 1978 |
1706 void *ud; | 1979 for(i = 0; i < upb_filedef_defcount(f); i++) { |
1707 struct cleanup_ent *next; | 1980 visit(r, upb_def_upcast(upb_filedef_def(f, i)), closure); |
1708 } cleanup_ent; | 1981 } |
1709 | 1982 } |
1710 static void *seeded_alloc(void *ud, void *ptr, size_t oldsize, size_t size); | 1983 |
1711 | 1984 static void freefiledef(upb_refcounted *r) { |
1712 /* Default allocator **********************************************************/ | 1985 upb_filedef *f = (upb_filedef*)r; |
1713 | 1986 size_t i; |
1714 /* Just use realloc, keeping all allocated blocks in a linked list to destroy at | 1987 |
1715 * the end. */ | 1988 for(i = 0; i < upb_filedef_depcount(f); i++) { |
1716 | 1989 upb_filedef_unref(upb_filedef_dep(f, i), f); |
1717 typedef struct mem_block { | 1990 } |
1718 /* List is doubly-linked, because in cases where realloc() moves an existing | 1991 |
1719 * block, we need to be able to remove the old pointer from the list | 1992 upb_inttable_uninit(&f->defs); |
1720 * efficiently. */ | 1993 upb_inttable_uninit(&f->deps); |
1721 struct mem_block *prev, *next; | 1994 upb_gfree((void*)f->name); |
1722 #ifndef NDEBUG | 1995 upb_gfree((void*)f->package); |
1723 size_t size; /* Doesn't include mem_block structure. */ | 1996 upb_gfree(f); |
1724 #endif | 1997 } |
1725 } mem_block; | 1998 |
1726 | 1999 const struct upb_refcounted_vtbl upb_filedef_vtbl = {visitfiledef, freefiledef}; |
1727 typedef struct { | 2000 |
1728 mem_block *head; | 2001 upb_filedef *upb_filedef_new(const void *owner) { |
1729 } default_alloc_ud; | 2002 upb_filedef *f = upb_gmalloc(sizeof(*f)); |
1730 | 2003 |
1731 static void *default_alloc(void *_ud, void *ptr, size_t oldsize, size_t size) { | 2004 if (!f) { |
1732 default_alloc_ud *ud = _ud; | 2005 return NULL; |
1733 mem_block *from, *block; | 2006 } |
1734 void *ret; | 2007 |
1735 UPB_UNUSED(oldsize); | 2008 f->package = NULL; |
1736 | 2009 f->name = NULL; |
1737 from = ptr ? (void*)((char*)ptr - sizeof(mem_block)) : NULL; | 2010 f->syntax = UPB_SYNTAX_PROTO2; |
1738 | 2011 |
1739 #ifndef NDEBUG | 2012 if (!upb_refcounted_init(upb_filedef_upcast_mutable(f), &upb_filedef_vtbl, |
1740 if (from) { | 2013 owner)) { |
1741 assert(oldsize <= from->size); | 2014 goto err; |
1742 } | 2015 } |
1743 #endif | 2016 |
1744 | 2017 if (!upb_inttable_init(&f->defs, UPB_CTYPE_CONSTPTR)) { |
1745 /* TODO(haberman): we probably need to provide even better alignment here, | 2018 goto err; |
1746 * like 16-byte alignment of the returned data pointer. */ | 2019 } |
1747 block = realloc(from, size + sizeof(mem_block)); | 2020 |
1748 if (!block) return NULL; | 2021 if (!upb_inttable_init(&f->deps, UPB_CTYPE_CONSTPTR)) { |
1749 ret = (char*)block + sizeof(*block); | 2022 goto err2; |
1750 | 2023 } |
1751 #ifndef NDEBUG | 2024 |
1752 block->size = size; | 2025 return f; |
1753 #endif | 2026 |
1754 | 2027 |
1755 if (from) { | 2028 err2: |
1756 if (block != from) { | 2029 upb_inttable_uninit(&f->defs); |
1757 /* The block was moved, so pointers in next and prev blocks must be | 2030 |
1758 * updated to its new location. */ | 2031 err: |
1759 if (block->next) block->next->prev = block; | 2032 upb_gfree(f); |
1760 if (block->prev) block->prev->next = block; | 2033 return NULL; |
1761 if (ud->head == from) ud->head = block; | 2034 } |
| 2035 |
| 2036 const char *upb_filedef_name(const upb_filedef *f) { |
| 2037 return f->name; |
| 2038 } |
| 2039 |
| 2040 const char *upb_filedef_package(const upb_filedef *f) { |
| 2041 return f->package; |
| 2042 } |
| 2043 |
| 2044 upb_syntax_t upb_filedef_syntax(const upb_filedef *f) { |
| 2045 return f->syntax; |
| 2046 } |
| 2047 |
| 2048 size_t upb_filedef_defcount(const upb_filedef *f) { |
| 2049 return upb_inttable_count(&f->defs); |
| 2050 } |
| 2051 |
| 2052 size_t upb_filedef_depcount(const upb_filedef *f) { |
| 2053 return upb_inttable_count(&f->deps); |
| 2054 } |
| 2055 |
| 2056 const upb_def *upb_filedef_def(const upb_filedef *f, size_t i) { |
| 2057 upb_value v; |
| 2058 |
| 2059 if (upb_inttable_lookup32(&f->defs, i, &v)) { |
| 2060 return upb_value_getconstptr(v); |
| 2061 } else { |
| 2062 return NULL; |
| 2063 } |
| 2064 } |
| 2065 |
| 2066 const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) { |
| 2067 upb_value v; |
| 2068 |
| 2069 if (upb_inttable_lookup32(&f->deps, i, &v)) { |
| 2070 return upb_value_getconstptr(v); |
| 2071 } else { |
| 2072 return NULL; |
| 2073 } |
| 2074 } |
| 2075 |
| 2076 bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s) { |
| 2077 name = upb_gstrdup(name); |
| 2078 if (!name) { |
| 2079 upb_upberr_setoom(s); |
| 2080 return false; |
| 2081 } |
| 2082 upb_gfree((void*)f->name); |
| 2083 f->name = name; |
| 2084 return true; |
| 2085 } |
| 2086 |
| 2087 bool upb_filedef_setpackage(upb_filedef *f, const char *package, |
| 2088 upb_status *s) { |
| 2089 if (!upb_isident(package, strlen(package), true, s)) return false; |
| 2090 package = upb_gstrdup(package); |
| 2091 if (!package) { |
| 2092 upb_upberr_setoom(s); |
| 2093 return false; |
| 2094 } |
| 2095 upb_gfree((void*)f->package); |
| 2096 f->package = package; |
| 2097 return true; |
| 2098 } |
| 2099 |
| 2100 bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, |
| 2101 upb_status *s) { |
| 2102 UPB_UNUSED(s); |
| 2103 if (syntax != UPB_SYNTAX_PROTO2 && |
| 2104 syntax != UPB_SYNTAX_PROTO3) { |
| 2105 upb_status_seterrmsg(s, "Unknown syntax value."); |
| 2106 return false; |
| 2107 } |
| 2108 f->syntax = syntax; |
| 2109 |
| 2110 { |
| 2111 /* Set all messages in this file to match. */ |
| 2112 size_t i; |
| 2113 for (i = 0; i < upb_filedef_defcount(f); i++) { |
| 2114 /* Casting const away is safe since all defs in mutable filedef must |
| 2115 * also be mutable. */ |
| 2116 upb_def *def = (upb_def*)upb_filedef_def(f, i); |
| 2117 |
| 2118 upb_msgdef *m = upb_dyncast_msgdef_mutable(def); |
| 2119 if (m) { |
| 2120 m->syntax = syntax; |
| 2121 } |
1762 } | 2122 } |
1763 } else { | 2123 } |
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 | 2124 |
1866 return true; | 2125 return true; |
1867 } | 2126 } |
1868 | 2127 |
1869 void *upb_env_malloc(upb_env *e, size_t size) { | 2128 bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor, |
1870 e->bytes_allocated += size; | 2129 upb_status *s) { |
1871 if (e->alloc == seeded_alloc) { | 2130 if (def->file) { |
1872 /* This is equivalent to the next branch, but allows inlining for a | 2131 upb_status_seterrmsg(s, "Def is already part of another filedef."); |
1873 * measurable perf benefit. */ | 2132 return false; |
1874 return seeded_alloc(e->alloc_ud, NULL, 0, size); | 2133 } |
1875 } else { | 2134 |
1876 return e->alloc(e->alloc_ud, NULL, 0, size); | 2135 if (upb_inttable_push(&f->defs, upb_value_constptr(def))) { |
1877 } | 2136 def->file = f; |
1878 } | 2137 upb_ref2(def, f); |
1879 | 2138 upb_ref2(f, def); |
1880 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) { | 2139 if (ref_donor) upb_def_unref(def, ref_donor); |
1881 char *ret; | 2140 if (def->type == UPB_DEF_MSG) { |
1882 assert(oldsize <= size); | 2141 upb_downcast_msgdef_mutable(def)->syntax = f->syntax; |
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 } | 2142 } |
1936 } | 2143 return true; |
1937 } | 2144 } else { |
1938 | 2145 upb_upberr_setoom(s); |
1939 void upb_seededalloc_init(upb_seededalloc *a, void *mem, size_t len) { | 2146 return false; |
1940 default_alloc_ud *ud = (default_alloc_ud*)&a->default_alloc_ud; | 2147 } |
1941 a->mem_base = mem; | 2148 } |
1942 a->mem_ptr = mem; | 2149 |
1943 a->mem_limit = (char*)mem + len; | 2150 bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep) { |
1944 a->need_cleanup = false; | 2151 if (upb_inttable_push(&f->deps, upb_value_constptr(dep))) { |
1945 a->returned_allocfunc = false; | 2152 /* Regular ref instead of ref2 because files can't form cycles. */ |
1946 | 2153 upb_filedef_ref(dep, f); |
1947 ud->head = NULL; | 2154 return true; |
1948 | 2155 } else { |
1949 upb_seededalloc_setfallbackalloc(a, default_alloc, ud); | 2156 return false; |
1950 } | 2157 } |
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 } | 2158 } |
1970 /* | 2159 /* |
1971 ** TODO(haberman): it's unclear whether a lot of the consistency checks should | 2160 ** TODO(haberman): it's unclear whether a lot of the consistency checks should |
1972 ** assert() or return false. | 2161 ** UPB_ASSERT() or return false. |
1973 */ | 2162 */ |
1974 | 2163 |
1975 | 2164 |
1976 #include <stdlib.h> | |
1977 #include <string.h> | 2165 #include <string.h> |
1978 | 2166 |
1979 | 2167 |
| 2168 static void *upb_calloc(size_t size) { |
| 2169 void *mem = upb_gmalloc(size); |
| 2170 if (mem) { |
| 2171 memset(mem, 0, size); |
| 2172 } |
| 2173 return mem; |
| 2174 } |
1980 | 2175 |
1981 /* Defined for the sole purpose of having a unique pointer value for | 2176 /* Defined for the sole purpose of having a unique pointer value for |
1982 * UPB_NO_CLOSURE. */ | 2177 * UPB_NO_CLOSURE. */ |
1983 char _upb_noclosure; | 2178 char _upb_noclosure; |
1984 | 2179 |
1985 static void freehandlers(upb_refcounted *r) { | 2180 static void freehandlers(upb_refcounted *r) { |
1986 upb_handlers *h = (upb_handlers*)r; | 2181 upb_handlers *h = (upb_handlers*)r; |
1987 | 2182 |
1988 upb_inttable_iter i; | 2183 upb_inttable_iter i; |
1989 upb_inttable_begin(&i, &h->cleanup_); | 2184 upb_inttable_begin(&i, &h->cleanup_); |
1990 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 2185 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
1991 void *val = (void*)upb_inttable_iter_key(&i); | 2186 void *val = (void*)upb_inttable_iter_key(&i); |
1992 upb_value func_val = upb_inttable_iter_value(&i); | 2187 upb_value func_val = upb_inttable_iter_value(&i); |
1993 upb_handlerfree *func = upb_value_getfptr(func_val); | 2188 upb_handlerfree *func = upb_value_getfptr(func_val); |
1994 func(val); | 2189 func(val); |
1995 } | 2190 } |
1996 | 2191 |
1997 upb_inttable_uninit(&h->cleanup_); | 2192 upb_inttable_uninit(&h->cleanup_); |
1998 upb_msgdef_unref(h->msg, h); | 2193 upb_msgdef_unref(h->msg, h); |
1999 free(h->sub); | 2194 upb_gfree(h->sub); |
2000 free(h); | 2195 upb_gfree(h); |
2001 } | 2196 } |
2002 | 2197 |
2003 static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit, | 2198 static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit, |
2004 void *closure) { | 2199 void *closure) { |
2005 const upb_handlers *h = (const upb_handlers*)r; | 2200 const upb_handlers *h = (const upb_handlers*)r; |
2006 upb_msg_field_iter i; | 2201 upb_msg_field_iter i; |
2007 for(upb_msg_field_begin(&i, h->msg); | 2202 for(upb_msg_field_begin(&i, h->msg); |
2008 !upb_msg_field_done(&i); | 2203 !upb_msg_field_done(&i); |
2009 upb_msg_field_next(&i)) { | 2204 upb_msg_field_next(&i)) { |
2010 upb_fielddef *f = upb_msg_iter_field(&i); | 2205 upb_fielddef *f = upb_msg_iter_field(&i); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2066 /* Given a selector for a STARTSUBMSG handler, resolves to a pointer to the | 2261 /* Given a selector for a STARTSUBMSG handler, resolves to a pointer to the |
2067 * subhandlers for this submessage field. */ | 2262 * subhandlers for this submessage field. */ |
2068 #define SUBH(h, selector) (h->sub[selector]) | 2263 #define SUBH(h, selector) (h->sub[selector]) |
2069 | 2264 |
2070 /* The selector for a submessage field is the field index. */ | 2265 /* The selector for a submessage field is the field index. */ |
2071 #define SUBH_F(h, f) SUBH(h, f->index_) | 2266 #define SUBH_F(h, f) SUBH(h, f->index_) |
2072 | 2267 |
2073 static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f, | 2268 static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f, |
2074 upb_handlertype_t type) { | 2269 upb_handlertype_t type) { |
2075 upb_selector_t sel; | 2270 upb_selector_t sel; |
2076 assert(!upb_handlers_isfrozen(h)); | 2271 UPB_ASSERT(!upb_handlers_isfrozen(h)); |
2077 if (upb_handlers_msgdef(h) != upb_fielddef_containingtype(f)) { | 2272 if (upb_handlers_msgdef(h) != upb_fielddef_containingtype(f)) { |
2078 upb_status_seterrf( | 2273 upb_status_seterrf( |
2079 &h->status_, "type mismatch: field %s does not belong to message %s", | 2274 &h->status_, "type mismatch: field %s does not belong to message %s", |
2080 upb_fielddef_name(f), upb_msgdef_fullname(upb_handlers_msgdef(h))); | 2275 upb_fielddef_name(f), upb_msgdef_fullname(upb_handlers_msgdef(h))); |
2081 return -1; | 2276 return -1; |
2082 } | 2277 } |
2083 if (!upb_handlers_getselector(f, type, &sel)) { | 2278 if (!upb_handlers_getselector(f, type, &sel)) { |
2084 upb_status_seterrf( | 2279 upb_status_seterrf( |
2085 &h->status_, | 2280 &h->status_, |
2086 "type mismatch: cannot register handler type %d for field %s", | 2281 "type mismatch: cannot register handler type %d for field %s", |
2087 type, upb_fielddef_name(f)); | 2282 type, upb_fielddef_name(f)); |
2088 return -1; | 2283 return -1; |
2089 } | 2284 } |
2090 return sel; | 2285 return sel; |
2091 } | 2286 } |
2092 | 2287 |
2093 static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f, | 2288 static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f, |
2094 upb_handlertype_t type) { | 2289 upb_handlertype_t type) { |
2095 int32_t sel = trygetsel(h, f, type); | 2290 int32_t sel = trygetsel(h, f, type); |
2096 assert(sel >= 0); | 2291 UPB_ASSERT(sel >= 0); |
2097 return sel; | 2292 return sel; |
2098 } | 2293 } |
2099 | 2294 |
2100 static const void **returntype(upb_handlers *h, const upb_fielddef *f, | 2295 static const void **returntype(upb_handlers *h, const upb_fielddef *f, |
2101 upb_handlertype_t type) { | 2296 upb_handlertype_t type) { |
2102 return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_; | 2297 return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_; |
2103 } | 2298 } |
2104 | 2299 |
2105 static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f, | 2300 static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f, |
2106 upb_handlertype_t type, upb_func *func, | 2301 upb_handlertype_t type, upb_func *func, |
2107 upb_handlerattr *attr) { | 2302 upb_handlerattr *attr) { |
2108 upb_handlerattr set_attr = UPB_HANDLERATTR_INITIALIZER; | 2303 upb_handlerattr set_attr = UPB_HANDLERATTR_INITIALIZER; |
2109 const void *closure_type; | 2304 const void *closure_type; |
2110 const void **context_closure_type; | 2305 const void **context_closure_type; |
2111 | 2306 |
2112 assert(!upb_handlers_isfrozen(h)); | 2307 UPB_ASSERT(!upb_handlers_isfrozen(h)); |
2113 | 2308 |
2114 if (sel < 0) { | 2309 if (sel < 0) { |
2115 upb_status_seterrmsg(&h->status_, | 2310 upb_status_seterrmsg(&h->status_, |
2116 "incorrect handler type for this field."); | 2311 "incorrect handler type for this field."); |
2117 return false; | 2312 return false; |
2118 } | 2313 } |
2119 | 2314 |
2120 if (h->table[sel].func) { | 2315 if (h->table[sel].func) { |
2121 upb_status_seterrmsg(&h->status_, | 2316 upb_status_seterrmsg(&h->status_, |
2122 "cannot change handler once it has been set."); | 2317 "cannot change handler once it has been set."); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2182 * from outer frames if this frame has no START* handler). Not implemented for | 2377 * from outer frames if this frame has no START* handler). Not implemented for |
2183 * UPB_HANDLER_STRING at the moment since this is not needed. Returns NULL is | 2378 * UPB_HANDLER_STRING at the moment since this is not needed. Returns NULL is |
2184 * the effective closure type is unspecified (either no handler was registered | 2379 * the effective closure type is unspecified (either no handler was registered |
2185 * to specify it or the handler that was registered did not specify the closure | 2380 * to specify it or the handler that was registered did not specify the closure |
2186 * type). */ | 2381 * type). */ |
2187 const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f, | 2382 const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f, |
2188 upb_handlertype_t type) { | 2383 upb_handlertype_t type) { |
2189 const void *ret; | 2384 const void *ret; |
2190 upb_selector_t sel; | 2385 upb_selector_t sel; |
2191 | 2386 |
2192 assert(type != UPB_HANDLER_STRING); | 2387 UPB_ASSERT(type != UPB_HANDLER_STRING); |
2193 ret = h->top_closure_type; | 2388 ret = h->top_closure_type; |
2194 | 2389 |
2195 if (upb_fielddef_isseq(f) && | 2390 if (upb_fielddef_isseq(f) && |
2196 type != UPB_HANDLER_STARTSEQ && | 2391 type != UPB_HANDLER_STARTSEQ && |
2197 type != UPB_HANDLER_ENDSEQ && | 2392 type != UPB_HANDLER_ENDSEQ && |
2198 h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) { | 2393 h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) { |
2199 ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr); | 2394 ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr); |
2200 } | 2395 } |
2201 | 2396 |
2202 if (type == UPB_HANDLER_STRING && | 2397 if (type == UPB_HANDLER_STRING && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2237 } | 2432 } |
2238 return true; | 2433 return true; |
2239 } | 2434 } |
2240 | 2435 |
2241 /* Public interface ***********************************************************/ | 2436 /* Public interface ***********************************************************/ |
2242 | 2437 |
2243 upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) { | 2438 upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) { |
2244 int extra; | 2439 int extra; |
2245 upb_handlers *h; | 2440 upb_handlers *h; |
2246 | 2441 |
2247 assert(upb_msgdef_isfrozen(md)); | 2442 UPB_ASSERT(upb_msgdef_isfrozen(md)); |
2248 | 2443 |
2249 extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1); | 2444 extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1); |
2250 h = calloc(sizeof(*h) + extra, 1); | 2445 h = upb_calloc(sizeof(*h) + extra); |
2251 if (!h) return NULL; | 2446 if (!h) return NULL; |
2252 | 2447 |
2253 h->msg = md; | 2448 h->msg = md; |
2254 upb_msgdef_ref(h->msg, h); | 2449 upb_msgdef_ref(h->msg, h); |
2255 upb_status_clear(&h->status_); | 2450 upb_status_clear(&h->status_); |
2256 h->sub = calloc(md->submsg_field_count, sizeof(*h->sub)); | 2451 |
2257 if (!h->sub) goto oom; | 2452 if (md->submsg_field_count > 0) { |
| 2453 h->sub = upb_calloc(md->submsg_field_count * sizeof(*h->sub)); |
| 2454 if (!h->sub) goto oom; |
| 2455 } else { |
| 2456 h->sub = 0; |
| 2457 } |
| 2458 |
2258 if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner)) | 2459 if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner)) |
2259 goto oom; | 2460 goto oom; |
2260 if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom; | 2461 if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom; |
2261 | 2462 |
2262 /* calloc() above initialized all handlers to NULL. */ | 2463 /* calloc() above initialized all handlers to NULL. */ |
2263 return h; | 2464 return h; |
2264 | 2465 |
2265 oom: | 2466 oom: |
2266 freehandlers(upb_handlers_upcast_mutable(h)); | 2467 freehandlers(upb_handlers_upcast_mutable(h)); |
2267 return NULL; | 2468 return NULL; |
(...skipping 12 matching lines...) Expand all Loading... |
2280 state.closure = closure; | 2481 state.closure = closure; |
2281 if (!upb_inttable_init(&state.tab, UPB_CTYPE_PTR)) return NULL; | 2482 if (!upb_inttable_init(&state.tab, UPB_CTYPE_PTR)) return NULL; |
2282 | 2483 |
2283 ret = newformsg(m, owner, &state); | 2484 ret = newformsg(m, owner, &state); |
2284 | 2485 |
2285 upb_inttable_uninit(&state.tab); | 2486 upb_inttable_uninit(&state.tab); |
2286 if (!ret) return NULL; | 2487 if (!ret) return NULL; |
2287 | 2488 |
2288 r = upb_handlers_upcast_mutable(ret); | 2489 r = upb_handlers_upcast_mutable(ret); |
2289 ok = upb_refcounted_freeze(&r, 1, NULL, UPB_MAX_HANDLER_DEPTH); | 2490 ok = upb_refcounted_freeze(&r, 1, NULL, UPB_MAX_HANDLER_DEPTH); |
2290 UPB_ASSERT_VAR(ok, ok); | 2491 UPB_ASSERT(ok); |
2291 | 2492 |
2292 return ret; | 2493 return ret; |
2293 } | 2494 } |
2294 | 2495 |
2295 const upb_status *upb_handlers_status(upb_handlers *h) { | 2496 const upb_status *upb_handlers_status(upb_handlers *h) { |
2296 assert(!upb_handlers_isfrozen(h)); | 2497 UPB_ASSERT(!upb_handlers_isfrozen(h)); |
2297 return &h->status_; | 2498 return &h->status_; |
2298 } | 2499 } |
2299 | 2500 |
2300 void upb_handlers_clearerr(upb_handlers *h) { | 2501 void upb_handlers_clearerr(upb_handlers *h) { |
2301 assert(!upb_handlers_isfrozen(h)); | 2502 UPB_ASSERT(!upb_handlers_isfrozen(h)); |
2302 upb_status_clear(&h->status_); | 2503 upb_status_clear(&h->status_); |
2303 } | 2504 } |
2304 | 2505 |
2305 #define SETTER(name, handlerctype, handlertype) \ | 2506 #define SETTER(name, handlerctype, handlertype) \ |
2306 bool upb_handlers_set ## name(upb_handlers *h, const upb_fielddef *f, \ | 2507 bool upb_handlers_set ## name(upb_handlers *h, const upb_fielddef *f, \ |
2307 handlerctype func, upb_handlerattr *attr) { \ | 2508 handlerctype func, upb_handlerattr *attr) { \ |
2308 int32_t sel = trygetsel(h, f, handlertype); \ | 2509 int32_t sel = trygetsel(h, f, handlertype); \ |
2309 return doset(h, sel, f, handlertype, (upb_func*)func, attr); \ | 2510 return doset(h, sel, f, handlertype, (upb_func*)func, attr); \ |
2310 } | 2511 } |
2311 | 2512 |
(...skipping 15 matching lines...) Expand all Loading... |
2327 #undef SETTER | 2528 #undef SETTER |
2328 | 2529 |
2329 bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func, | 2530 bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func, |
2330 upb_handlerattr *attr) { | 2531 upb_handlerattr *attr) { |
2331 return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32, | 2532 return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32, |
2332 (upb_func *)func, attr); | 2533 (upb_func *)func, attr); |
2333 } | 2534 } |
2334 | 2535 |
2335 bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func, | 2536 bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func, |
2336 upb_handlerattr *attr) { | 2537 upb_handlerattr *attr) { |
2337 assert(!upb_handlers_isfrozen(h)); | 2538 UPB_ASSERT(!upb_handlers_isfrozen(h)); |
2338 return doset(h, UPB_ENDMSG_SELECTOR, NULL, UPB_HANDLER_INT32, | 2539 return doset(h, UPB_ENDMSG_SELECTOR, NULL, UPB_HANDLER_INT32, |
2339 (upb_func *)func, attr); | 2540 (upb_func *)func, attr); |
2340 } | 2541 } |
2341 | 2542 |
2342 bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f, | 2543 bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f, |
2343 const upb_handlers *sub) { | 2544 const upb_handlers *sub) { |
2344 assert(sub); | 2545 UPB_ASSERT(sub); |
2345 assert(!upb_handlers_isfrozen(h)); | 2546 UPB_ASSERT(!upb_handlers_isfrozen(h)); |
2346 assert(upb_fielddef_issubmsg(f)); | 2547 UPB_ASSERT(upb_fielddef_issubmsg(f)); |
2347 if (SUBH_F(h, f)) return false; /* Can't reset. */ | 2548 if (SUBH_F(h, f)) return false; /* Can't reset. */ |
2348 if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) { | 2549 if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) { |
2349 return false; | 2550 return false; |
2350 } | 2551 } |
2351 SUBH_F(h, f) = sub; | 2552 SUBH_F(h, f) = sub; |
2352 upb_ref2(sub, h); | 2553 upb_ref2(sub, h); |
2353 return true; | 2554 return true; |
2354 } | 2555 } |
2355 | 2556 |
2356 const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h, | 2557 const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h, |
2357 const upb_fielddef *f) { | 2558 const upb_fielddef *f) { |
2358 assert(upb_fielddef_issubmsg(f)); | 2559 UPB_ASSERT(upb_fielddef_issubmsg(f)); |
2359 return SUBH_F(h, f); | 2560 return SUBH_F(h, f); |
2360 } | 2561 } |
2361 | 2562 |
2362 bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t sel, | 2563 bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t sel, |
2363 upb_handlerattr *attr) { | 2564 upb_handlerattr *attr) { |
2364 if (!upb_handlers_gethandler(h, sel)) | 2565 if (!upb_handlers_gethandler(h, sel)) |
2365 return false; | 2566 return false; |
2366 *attr = h->table[sel].attr; | 2567 *attr = h->table[sel].attr; |
2367 return true; | 2568 return true; |
2368 } | 2569 } |
2369 | 2570 |
2370 const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h, | 2571 const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h, |
2371 upb_selector_t sel) { | 2572 upb_selector_t sel) { |
2372 /* STARTSUBMSG selector in sel is the field's selector base. */ | 2573 /* STARTSUBMSG selector in sel is the field's selector base. */ |
2373 return SUBH(h, sel - UPB_STATIC_SELECTOR_COUNT); | 2574 return SUBH(h, sel - UPB_STATIC_SELECTOR_COUNT); |
2374 } | 2575 } |
2375 | 2576 |
2376 const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h) { return h->msg; } | 2577 const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h) { return h->msg; } |
2377 | 2578 |
2378 bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func) { | 2579 bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func) { |
2379 bool ok; | 2580 bool ok; |
2380 if (upb_inttable_lookupptr(&h->cleanup_, p, NULL)) { | 2581 if (upb_inttable_lookupptr(&h->cleanup_, p, NULL)) { |
2381 return false; | 2582 return false; |
2382 } | 2583 } |
2383 ok = upb_inttable_insertptr(&h->cleanup_, p, upb_value_fptr(func)); | 2584 ok = upb_inttable_insertptr(&h->cleanup_, p, upb_value_fptr(func)); |
2384 UPB_ASSERT_VAR(ok, ok); | 2585 UPB_ASSERT(ok); |
2385 return true; | 2586 return true; |
2386 } | 2587 } |
2387 | 2588 |
2388 | 2589 |
2389 /* "Static" methods ***********************************************************/ | 2590 /* "Static" methods ***********************************************************/ |
2390 | 2591 |
2391 bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) { | 2592 bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) { |
2392 /* TODO: verify we have a transitive closure. */ | 2593 /* TODO: verify we have a transitive closure. */ |
2393 int i; | 2594 int i; |
2394 for (i = 0; i < n; i++) { | 2595 for (i = 0; i < n; i++) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f) { | 2676 upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f) { |
2476 switch (upb_fielddef_type(f)) { | 2677 switch (upb_fielddef_type(f)) { |
2477 case UPB_TYPE_INT32: | 2678 case UPB_TYPE_INT32: |
2478 case UPB_TYPE_ENUM: return UPB_HANDLER_INT32; | 2679 case UPB_TYPE_ENUM: return UPB_HANDLER_INT32; |
2479 case UPB_TYPE_INT64: return UPB_HANDLER_INT64; | 2680 case UPB_TYPE_INT64: return UPB_HANDLER_INT64; |
2480 case UPB_TYPE_UINT32: return UPB_HANDLER_UINT32; | 2681 case UPB_TYPE_UINT32: return UPB_HANDLER_UINT32; |
2481 case UPB_TYPE_UINT64: return UPB_HANDLER_UINT64; | 2682 case UPB_TYPE_UINT64: return UPB_HANDLER_UINT64; |
2482 case UPB_TYPE_FLOAT: return UPB_HANDLER_FLOAT; | 2683 case UPB_TYPE_FLOAT: return UPB_HANDLER_FLOAT; |
2483 case UPB_TYPE_DOUBLE: return UPB_HANDLER_DOUBLE; | 2684 case UPB_TYPE_DOUBLE: return UPB_HANDLER_DOUBLE; |
2484 case UPB_TYPE_BOOL: return UPB_HANDLER_BOOL; | 2685 case UPB_TYPE_BOOL: return UPB_HANDLER_BOOL; |
2485 default: assert(false); return -1; /* Invalid input. */ | 2686 default: UPB_ASSERT(false); return -1; /* Invalid input. */ |
2486 } | 2687 } |
2487 } | 2688 } |
2488 | 2689 |
2489 bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, | 2690 bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, |
2490 upb_selector_t *s) { | 2691 upb_selector_t *s) { |
2491 switch (type) { | 2692 switch (type) { |
2492 case UPB_HANDLER_INT32: | 2693 case UPB_HANDLER_INT32: |
2493 case UPB_HANDLER_INT64: | 2694 case UPB_HANDLER_INT64: |
2494 case UPB_HANDLER_UINT32: | 2695 case UPB_HANDLER_UINT32: |
2495 case UPB_HANDLER_UINT64: | 2696 case UPB_HANDLER_UINT64: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2538 * selector can also be used as an index into the "sub" array of | 2739 * selector can also be used as an index into the "sub" array of |
2539 * subhandlers. The indexes for the two into these two tables are the | 2740 * subhandlers. The indexes for the two into these two tables are the |
2540 * same, except that in the handler table the static selectors come first.
*/ | 2741 * same, except that in the handler table the static selectors come first.
*/ |
2541 *s = f->index_ + UPB_STATIC_SELECTOR_COUNT; | 2742 *s = f->index_ + UPB_STATIC_SELECTOR_COUNT; |
2542 break; | 2743 break; |
2543 case UPB_HANDLER_ENDSUBMSG: | 2744 case UPB_HANDLER_ENDSUBMSG: |
2544 if (!upb_fielddef_issubmsg(f)) return false; | 2745 if (!upb_fielddef_issubmsg(f)) return false; |
2545 *s = f->selector_base; | 2746 *s = f->selector_base; |
2546 break; | 2747 break; |
2547 } | 2748 } |
2548 assert((size_t)*s < upb_fielddef_containingtype(f)->selector_count); | 2749 UPB_ASSERT((size_t)*s < upb_fielddef_containingtype(f)->selector_count); |
2549 return true; | 2750 return true; |
2550 } | 2751 } |
2551 | 2752 |
2552 uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) { | 2753 uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) { |
2553 return upb_fielddef_isseq(f) ? 2 : 0; | 2754 return upb_fielddef_isseq(f) ? 2 : 0; |
2554 } | 2755 } |
2555 | 2756 |
2556 uint32_t upb_handlers_selectorcount(const upb_fielddef *f) { | 2757 uint32_t upb_handlers_selectorcount(const upb_fielddef *f) { |
2557 uint32_t ret = 1; | 2758 uint32_t ret = 1; |
2558 if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */ | 2759 if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2662 ** 3. for mutable objects "from" and "to", if there exists a ref2(to, from) | 2863 ** 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 | 2864 ** 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* | 2865 ** 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 | 2866 ** been a ref2(to, from), but all that is necessary for correctness is the |
2666 ** weaker one). | 2867 ** weaker one). |
2667 ** 4. mutable and immutable objects are never in the same group. | 2868 ** 4. mutable and immutable objects are never in the same group. |
2668 */ | 2869 */ |
2669 | 2870 |
2670 | 2871 |
2671 #include <setjmp.h> | 2872 #include <setjmp.h> |
2672 #include <stdlib.h> | |
2673 | 2873 |
2674 static void freeobj(upb_refcounted *o); | 2874 static void freeobj(upb_refcounted *o); |
2675 | 2875 |
2676 const char untracked_val; | 2876 const char untracked_val; |
2677 const void *UPB_UNTRACKED_REF = &untracked_val; | 2877 const void *UPB_UNTRACKED_REF = &untracked_val; |
2678 | 2878 |
2679 /* arch-specific atomic primitives *******************************************/ | 2879 /* arch-specific atomic primitives *******************************************/ |
2680 | 2880 |
2681 #ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/ | 2881 #ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/ |
2682 | 2882 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2738 /* User must define functions that lock/unlock a global mutex and link this | 2938 /* User must define functions that lock/unlock a global mutex and link this |
2739 * file against them. */ | 2939 * file against them. */ |
2740 void upb_lock(); | 2940 void upb_lock(); |
2741 void upb_unlock(); | 2941 void upb_unlock(); |
2742 | 2942 |
2743 #endif | 2943 #endif |
2744 | 2944 |
2745 /* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some | 2945 /* 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 | 2946 * 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 | 2947 * 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. */ | 2948 * 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); } | 2949 * immediately aborts on failure (avoiding the global allocator, which might |
| 2950 * inject failures). */ |
| 2951 |
| 2952 #include <stdlib.h> |
| 2953 |
| 2954 static void *upb_debugrefs_allocfunc(upb_alloc *alloc, void *ptr, |
| 2955 size_t oldsize, size_t size) { |
| 2956 UPB_UNUSED(alloc); |
| 2957 UPB_UNUSED(oldsize); |
| 2958 if (size == 0) { |
| 2959 free(ptr); |
| 2960 return NULL; |
| 2961 } else { |
| 2962 void *ret = realloc(ptr, size); |
| 2963 |
| 2964 if (!ret) { |
| 2965 abort(); |
| 2966 } |
| 2967 |
| 2968 return ret; |
| 2969 } |
| 2970 } |
| 2971 |
| 2972 upb_alloc upb_alloc_debugrefs = {&upb_debugrefs_allocfunc}; |
2750 | 2973 |
2751 typedef struct { | 2974 typedef struct { |
2752 int count; /* How many refs there are (duplicates only allowed for ref2). */ | 2975 int count; /* How many refs there are (duplicates only allowed for ref2). */ |
2753 bool is_ref2; | 2976 bool is_ref2; |
2754 } trackedref; | 2977 } trackedref; |
2755 | 2978 |
2756 static trackedref *trackedref_new(bool is_ref2) { | 2979 static trackedref *trackedref_new(bool is_ref2) { |
2757 trackedref *ret = malloc(sizeof(*ret)); | 2980 trackedref *ret = upb_malloc(&upb_alloc_debugrefs, sizeof(*ret)); |
2758 CHECK_OOM(ret); | |
2759 ret->count = 1; | 2981 ret->count = 1; |
2760 ret->is_ref2 = is_ref2; | 2982 ret->is_ref2 = is_ref2; |
2761 return ret; | 2983 return ret; |
2762 } | 2984 } |
2763 | 2985 |
2764 static void track(const upb_refcounted *r, const void *owner, bool ref2) { | 2986 static void track(const upb_refcounted *r, const void *owner, bool ref2) { |
2765 upb_value v; | 2987 upb_value v; |
2766 | 2988 |
2767 assert(owner); | 2989 UPB_ASSERT(owner); |
2768 if (owner == UPB_UNTRACKED_REF) return; | 2990 if (owner == UPB_UNTRACKED_REF) return; |
2769 | 2991 |
2770 upb_lock(); | 2992 upb_lock(); |
2771 if (upb_inttable_lookupptr(r->refs, owner, &v)) { | 2993 if (upb_inttable_lookupptr(r->refs, owner, &v)) { |
2772 trackedref *ref = upb_value_getptr(v); | 2994 trackedref *ref = upb_value_getptr(v); |
2773 /* Since we allow multiple ref2's for the same to/from pair without | 2995 /* 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 | 2996 * allocating separate memory for each one, we lose the fine-grained |
2775 * tracking behavior we get with regular refs. Since ref2s only happen | 2997 * 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 | 2998 * 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. */ | 2999 * difficult upb-internal bug that can't be figured out without it. */ |
2778 assert(ref2); | 3000 UPB_ASSERT(ref2); |
2779 assert(ref->is_ref2); | 3001 UPB_ASSERT(ref->is_ref2); |
2780 ref->count++; | 3002 ref->count++; |
2781 } else { | 3003 } else { |
2782 trackedref *ref = trackedref_new(ref2); | 3004 trackedref *ref = trackedref_new(ref2); |
2783 bool ok = upb_inttable_insertptr(r->refs, owner, upb_value_ptr(ref)); | 3005 upb_inttable_insertptr2(r->refs, owner, upb_value_ptr(ref), |
2784 CHECK_OOM(ok); | 3006 &upb_alloc_debugrefs); |
2785 if (ref2) { | 3007 if (ref2) { |
2786 /* We know this cast is safe when it is a ref2, because it's coming from | 3008 /* We know this cast is safe when it is a ref2, because it's coming from |
2787 * another refcounted object. */ | 3009 * another refcounted object. */ |
2788 const upb_refcounted *from = owner; | 3010 const upb_refcounted *from = owner; |
2789 assert(!upb_inttable_lookupptr(from->ref2s, r, NULL)); | 3011 UPB_ASSERT(!upb_inttable_lookupptr(from->ref2s, r, NULL)); |
2790 ok = upb_inttable_insertptr(from->ref2s, r, upb_value_ptr(NULL)); | 3012 upb_inttable_insertptr2(from->ref2s, r, upb_value_ptr(NULL), |
2791 CHECK_OOM(ok); | 3013 &upb_alloc_debugrefs); |
2792 } | 3014 } |
2793 } | 3015 } |
2794 upb_unlock(); | 3016 upb_unlock(); |
2795 } | 3017 } |
2796 | 3018 |
2797 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { | 3019 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { |
2798 upb_value v; | 3020 upb_value v; |
2799 bool found; | 3021 bool found; |
2800 trackedref *ref; | 3022 trackedref *ref; |
2801 | 3023 |
2802 assert(owner); | 3024 UPB_ASSERT(owner); |
2803 if (owner == UPB_UNTRACKED_REF) return; | 3025 if (owner == UPB_UNTRACKED_REF) return; |
2804 | 3026 |
2805 upb_lock(); | 3027 upb_lock(); |
2806 found = upb_inttable_lookupptr(r->refs, owner, &v); | 3028 found = upb_inttable_lookupptr(r->refs, owner, &v); |
2807 /* This assert will fail if an owner attempts to release a ref it didn't have.
*/ | 3029 /* This assert will fail if an owner attempts to release a ref it didn't have.
*/ |
2808 UPB_ASSERT_VAR(found, found); | 3030 UPB_ASSERT(found); |
2809 ref = upb_value_getptr(v); | 3031 ref = upb_value_getptr(v); |
2810 assert(ref->is_ref2 == ref2); | 3032 UPB_ASSERT(ref->is_ref2 == ref2); |
2811 if (--ref->count == 0) { | 3033 if (--ref->count == 0) { |
2812 free(ref); | 3034 free(ref); |
2813 upb_inttable_removeptr(r->refs, owner, NULL); | 3035 upb_inttable_removeptr(r->refs, owner, NULL); |
2814 if (ref2) { | 3036 if (ref2) { |
2815 /* We know this cast is safe when it is a ref2, because it's coming from | 3037 /* We know this cast is safe when it is a ref2, because it's coming from |
2816 * another refcounted object. */ | 3038 * another refcounted object. */ |
2817 const upb_refcounted *from = owner; | 3039 const upb_refcounted *from = owner; |
2818 bool removed = upb_inttable_removeptr(from->ref2s, r, NULL); | 3040 bool removed = upb_inttable_removeptr(from->ref2s, r, NULL); |
2819 assert(removed); | 3041 UPB_ASSERT(removed); |
2820 } | 3042 } |
2821 } | 3043 } |
2822 upb_unlock(); | 3044 upb_unlock(); |
2823 } | 3045 } |
2824 | 3046 |
2825 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { | 3047 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { |
2826 upb_value v; | 3048 upb_value v; |
2827 bool found; | 3049 bool found; |
2828 trackedref *ref; | 3050 trackedref *ref; |
2829 | 3051 |
2830 upb_lock(); | 3052 upb_lock(); |
2831 found = upb_inttable_lookupptr(r->refs, owner, &v); | 3053 found = upb_inttable_lookupptr(r->refs, owner, &v); |
2832 UPB_ASSERT_VAR(found, found); | 3054 UPB_ASSERT(found); |
2833 ref = upb_value_getptr(v); | 3055 ref = upb_value_getptr(v); |
2834 assert(ref->is_ref2 == ref2); | 3056 UPB_ASSERT(ref->is_ref2 == ref2); |
2835 upb_unlock(); | 3057 upb_unlock(); |
2836 } | 3058 } |
2837 | 3059 |
2838 /* Populates the given UPB_CTYPE_INT32 inttable with counts of ref2's that | 3060 /* Populates the given UPB_CTYPE_INT32 inttable with counts of ref2's that |
2839 * originate from the given owner. */ | 3061 * originate from the given owner. */ |
2840 static void getref2s(const upb_refcounted *owner, upb_inttable *tab) { | 3062 static void getref2s(const upb_refcounted *owner, upb_inttable *tab) { |
2841 upb_inttable_iter i; | 3063 upb_inttable_iter i; |
2842 | 3064 |
2843 upb_lock(); | 3065 upb_lock(); |
2844 upb_inttable_begin(&i, owner->ref2s); | 3066 upb_inttable_begin(&i, owner->ref2s); |
2845 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 3067 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
2846 upb_value v; | 3068 upb_value v; |
2847 upb_value count; | 3069 upb_value count; |
2848 trackedref *ref; | 3070 trackedref *ref; |
2849 bool ok; | |
2850 bool found; | 3071 bool found; |
2851 | 3072 |
2852 upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i); | 3073 upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i); |
2853 | 3074 |
2854 /* To get the count we need to look in the target's table. */ | 3075 /* To get the count we need to look in the target's table. */ |
2855 found = upb_inttable_lookupptr(to->refs, owner, &v); | 3076 found = upb_inttable_lookupptr(to->refs, owner, &v); |
2856 assert(found); | 3077 UPB_ASSERT(found); |
2857 ref = upb_value_getptr(v); | 3078 ref = upb_value_getptr(v); |
2858 count = upb_value_int32(ref->count); | 3079 count = upb_value_int32(ref->count); |
2859 | 3080 |
2860 ok = upb_inttable_insertptr(tab, to, count); | 3081 upb_inttable_insertptr2(tab, to, count, &upb_alloc_debugrefs); |
2861 CHECK_OOM(ok); | |
2862 } | 3082 } |
2863 upb_unlock(); | 3083 upb_unlock(); |
2864 } | 3084 } |
2865 | 3085 |
2866 typedef struct { | 3086 typedef struct { |
2867 upb_inttable ref2; | 3087 upb_inttable ref2; |
2868 const upb_refcounted *obj; | 3088 const upb_refcounted *obj; |
2869 } check_state; | 3089 } check_state; |
2870 | 3090 |
2871 static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj, | 3091 static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj, |
2872 void *closure) { | 3092 void *closure) { |
2873 check_state *s = closure; | 3093 check_state *s = closure; |
2874 upb_inttable *ref2 = &s->ref2; | 3094 upb_inttable *ref2 = &s->ref2; |
2875 upb_value v; | 3095 upb_value v; |
2876 bool removed; | 3096 bool removed; |
2877 int32_t newcount; | 3097 int32_t newcount; |
2878 | 3098 |
2879 assert(obj == s->obj); | 3099 UPB_ASSERT(obj == s->obj); |
2880 assert(subobj); | 3100 UPB_ASSERT(subobj); |
2881 removed = upb_inttable_removeptr(ref2, subobj, &v); | 3101 removed = upb_inttable_removeptr(ref2, subobj, &v); |
2882 /* The following assertion will fail if the visit() function visits a subobj | 3102 /* 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. *
/ | 3103 * that it did not have a ref2 on, or visits the same subobj too many times. *
/ |
2884 assert(removed); | 3104 UPB_ASSERT(removed); |
2885 newcount = upb_value_getint32(v) - 1; | 3105 newcount = upb_value_getint32(v) - 1; |
2886 if (newcount > 0) { | 3106 if (newcount > 0) { |
2887 upb_inttable_insert(ref2, (uintptr_t)subobj, upb_value_int32(newcount)); | 3107 upb_inttable_insert2(ref2, (uintptr_t)subobj, upb_value_int32(newcount), |
| 3108 &upb_alloc_debugrefs); |
2888 } | 3109 } |
2889 } | 3110 } |
2890 | 3111 |
2891 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, | 3112 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, |
2892 void *closure) { | 3113 void *closure) { |
2893 bool ok; | |
2894 | |
2895 /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know | 3114 /* 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 | 3115 * exactly the set of nodes that visit() should visit. So we verify visit()'s |
2897 * correctness here. */ | 3116 * correctness here. */ |
2898 check_state state; | 3117 check_state state; |
2899 state.obj = r; | 3118 state.obj = r; |
2900 ok = upb_inttable_init(&state.ref2, UPB_CTYPE_INT32); | 3119 upb_inttable_init2(&state.ref2, UPB_CTYPE_INT32, &upb_alloc_debugrefs); |
2901 CHECK_OOM(ok); | |
2902 getref2s(r, &state.ref2); | 3120 getref2s(r, &state.ref2); |
2903 | 3121 |
2904 /* This should visit any children in the ref2 table. */ | 3122 /* This should visit any children in the ref2 table. */ |
2905 if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state); | 3123 if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state); |
2906 | 3124 |
2907 /* This assertion will fail if the visit() function missed any children. */ | 3125 /* This assertion will fail if the visit() function missed any children. */ |
2908 assert(upb_inttable_count(&state.ref2) == 0); | 3126 UPB_ASSERT(upb_inttable_count(&state.ref2) == 0); |
2909 upb_inttable_uninit(&state.ref2); | 3127 upb_inttable_uninit2(&state.ref2, &upb_alloc_debugrefs); |
2910 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); | 3128 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); |
2911 } | 3129 } |
2912 | 3130 |
2913 static bool trackinit(upb_refcounted *r) { | 3131 static void trackinit(upb_refcounted *r) { |
2914 r->refs = malloc(sizeof(*r->refs)); | 3132 r->refs = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->refs)); |
2915 r->ref2s = malloc(sizeof(*r->ref2s)); | 3133 r->ref2s = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->ref2s)); |
2916 if (!r->refs || !r->ref2s) goto err1; | 3134 upb_inttable_init2(r->refs, UPB_CTYPE_PTR, &upb_alloc_debugrefs); |
2917 | 3135 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 } | 3136 } |
2929 | 3137 |
2930 static void trackfree(const upb_refcounted *r) { | 3138 static void trackfree(const upb_refcounted *r) { |
2931 upb_inttable_uninit(r->refs); | 3139 upb_inttable_uninit2(r->refs, &upb_alloc_debugrefs); |
2932 upb_inttable_uninit(r->ref2s); | 3140 upb_inttable_uninit2(r->ref2s, &upb_alloc_debugrefs); |
2933 free(r->refs); | 3141 upb_free(&upb_alloc_debugrefs, r->refs); |
2934 free(r->ref2s); | 3142 upb_free(&upb_alloc_debugrefs, r->ref2s); |
2935 } | 3143 } |
2936 | 3144 |
2937 #else | 3145 #else |
2938 | 3146 |
2939 static void track(const upb_refcounted *r, const void *owner, bool ref2) { | 3147 static void track(const upb_refcounted *r, const void *owner, bool ref2) { |
2940 UPB_UNUSED(r); | 3148 UPB_UNUSED(r); |
2941 UPB_UNUSED(owner); | 3149 UPB_UNUSED(owner); |
2942 UPB_UNUSED(ref2); | 3150 UPB_UNUSED(ref2); |
2943 } | 3151 } |
2944 | 3152 |
2945 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { | 3153 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { |
2946 UPB_UNUSED(r); | 3154 UPB_UNUSED(r); |
2947 UPB_UNUSED(owner); | 3155 UPB_UNUSED(owner); |
2948 UPB_UNUSED(ref2); | 3156 UPB_UNUSED(ref2); |
2949 } | 3157 } |
2950 | 3158 |
2951 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { | 3159 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { |
2952 UPB_UNUSED(r); | 3160 UPB_UNUSED(r); |
2953 UPB_UNUSED(owner); | 3161 UPB_UNUSED(owner); |
2954 UPB_UNUSED(ref2); | 3162 UPB_UNUSED(ref2); |
2955 } | 3163 } |
2956 | 3164 |
2957 static bool trackinit(upb_refcounted *r) { | 3165 static void trackinit(upb_refcounted *r) { |
2958 UPB_UNUSED(r); | 3166 UPB_UNUSED(r); |
2959 return true; | |
2960 } | 3167 } |
2961 | 3168 |
2962 static void trackfree(const upb_refcounted *r) { | 3169 static void trackfree(const upb_refcounted *r) { |
2963 UPB_UNUSED(r); | 3170 UPB_UNUSED(r); |
2964 } | 3171 } |
2965 | 3172 |
2966 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, | 3173 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, |
2967 void *closure) { | 3174 void *closure) { |
2968 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); | 3175 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); |
2969 } | 3176 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3016 | 3223 |
3017 static uint64_t trygetattr(const tarjan *t, const upb_refcounted *r) { | 3224 static uint64_t trygetattr(const tarjan *t, const upb_refcounted *r) { |
3018 upb_value v; | 3225 upb_value v; |
3019 return upb_inttable_lookupptr(&t->objattr, r, &v) ? | 3226 return upb_inttable_lookupptr(&t->objattr, r, &v) ? |
3020 upb_value_getuint64(v) : 0; | 3227 upb_value_getuint64(v) : 0; |
3021 } | 3228 } |
3022 | 3229 |
3023 static uint64_t getattr(const tarjan *t, const upb_refcounted *r) { | 3230 static uint64_t getattr(const tarjan *t, const upb_refcounted *r) { |
3024 upb_value v; | 3231 upb_value v; |
3025 bool found = upb_inttable_lookupptr(&t->objattr, r, &v); | 3232 bool found = upb_inttable_lookupptr(&t->objattr, r, &v); |
3026 UPB_ASSERT_VAR(found, found); | 3233 UPB_ASSERT(found); |
3027 return upb_value_getuint64(v); | 3234 return upb_value_getuint64(v); |
3028 } | 3235 } |
3029 | 3236 |
3030 static void setattr(tarjan *t, const upb_refcounted *r, uint64_t attr) { | 3237 static void setattr(tarjan *t, const upb_refcounted *r, uint64_t attr) { |
3031 upb_inttable_removeptr(&t->objattr, r, NULL); | 3238 upb_inttable_removeptr(&t->objattr, r, NULL); |
3032 upb_inttable_insertptr(&t->objattr, r, upb_value_uint64(attr)); | 3239 upb_inttable_insertptr(&t->objattr, r, upb_value_uint64(attr)); |
3033 } | 3240 } |
3034 | 3241 |
3035 static color_t color(tarjan *t, const upb_refcounted *r) { | 3242 static color_t color(tarjan *t, const upb_refcounted *r) { |
3036 return trygetattr(t, r) & 0x3; /* Color is always stored in the low 2 bits. *
/ | 3243 return trygetattr(t, r) & 0x3; /* Color is always stored in the low 2 bits. *
/ |
3037 } | 3244 } |
3038 | 3245 |
3039 static void set_gray(tarjan *t, const upb_refcounted *r) { | 3246 static void set_gray(tarjan *t, const upb_refcounted *r) { |
3040 assert(color(t, r) == BLACK); | 3247 UPB_ASSERT(color(t, r) == BLACK); |
3041 setattr(t, r, GRAY); | 3248 setattr(t, r, GRAY); |
3042 } | 3249 } |
3043 | 3250 |
3044 /* Pushes an obj onto the Tarjan stack and sets it to GREEN. */ | 3251 /* Pushes an obj onto the Tarjan stack and sets it to GREEN. */ |
3045 static void push(tarjan *t, const upb_refcounted *r) { | 3252 static void push(tarjan *t, const upb_refcounted *r) { |
3046 assert(color(t, r) == BLACK || color(t, r) == GRAY); | 3253 UPB_ASSERT(color(t, r) == BLACK || color(t, r) == GRAY); |
3047 /* This defines the attr layout for the GREEN state. "index" and "lowlink" | 3254 /* This defines the attr layout for the GREEN state. "index" and "lowlink" |
3048 * get 31 bits, which is plenty (limit of 2B objects frozen at a time). */ | 3255 * get 31 bits, which is plenty (limit of 2B objects frozen at a time). */ |
3049 setattr(t, r, GREEN | (t->index << 2) | (t->index << 33)); | 3256 setattr(t, r, GREEN | (t->index << 2) | (t->index << 33)); |
3050 if (++t->index == 0x80000000) { | 3257 if (++t->index == 0x80000000) { |
3051 upb_status_seterrmsg(t->status, "too many objects to freeze"); | 3258 upb_status_seterrmsg(t->status, "too many objects to freeze"); |
3052 err(t); | 3259 err(t); |
3053 } | 3260 } |
3054 upb_inttable_push(&t->stack, upb_value_ptr((void*)r)); | 3261 upb_inttable_push(&t->stack, upb_value_ptr((void*)r)); |
3055 } | 3262 } |
3056 | 3263 |
3057 /* Pops an obj from the Tarjan stack and sets it to WHITE, with a ptr to its | 3264 /* Pops an obj from the Tarjan stack and sets it to WHITE, with a ptr to its |
3058 * SCC group. */ | 3265 * SCC group. */ |
3059 static upb_refcounted *pop(tarjan *t) { | 3266 static upb_refcounted *pop(tarjan *t) { |
3060 upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack)); | 3267 upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack)); |
3061 assert(color(t, r) == GREEN); | 3268 UPB_ASSERT(color(t, r) == GREEN); |
3062 /* This defines the attr layout for nodes in the WHITE state. | 3269 /* This defines the attr layout for nodes in the WHITE state. |
3063 * Top of group stack is [group, NULL]; we point at group. */ | 3270 * Top of group stack is [group, NULL]; we point at group. */ |
3064 setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8); | 3271 setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8); |
3065 return r; | 3272 return r; |
3066 } | 3273 } |
3067 | 3274 |
3068 static void tarjan_newgroup(tarjan *t) { | 3275 static void tarjan_newgroup(tarjan *t) { |
3069 uint32_t *group = malloc(sizeof(*group)); | 3276 uint32_t *group = upb_gmalloc(sizeof(*group)); |
3070 if (!group) oom(t); | 3277 if (!group) oom(t); |
3071 /* Push group and empty group leader (we'll fill in leader later). */ | 3278 /* Push group and empty group leader (we'll fill in leader later). */ |
3072 if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) || | 3279 if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) || |
3073 !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) { | 3280 !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) { |
3074 free(group); | 3281 upb_gfree(group); |
3075 oom(t); | 3282 oom(t); |
3076 } | 3283 } |
3077 *group = 0; | 3284 *group = 0; |
3078 } | 3285 } |
3079 | 3286 |
3080 static uint32_t idx(tarjan *t, const upb_refcounted *r) { | 3287 static uint32_t idx(tarjan *t, const upb_refcounted *r) { |
3081 assert(color(t, r) == GREEN); | 3288 UPB_ASSERT(color(t, r) == GREEN); |
3082 return (getattr(t, r) >> 2) & 0x7FFFFFFF; | 3289 return (getattr(t, r) >> 2) & 0x7FFFFFFF; |
3083 } | 3290 } |
3084 | 3291 |
3085 static uint32_t lowlink(tarjan *t, const upb_refcounted *r) { | 3292 static uint32_t lowlink(tarjan *t, const upb_refcounted *r) { |
3086 if (color(t, r) == GREEN) { | 3293 if (color(t, r) == GREEN) { |
3087 return getattr(t, r) >> 33; | 3294 return getattr(t, r) >> 33; |
3088 } else { | 3295 } else { |
3089 return UINT32_MAX; | 3296 return UINT32_MAX; |
3090 } | 3297 } |
3091 } | 3298 } |
3092 | 3299 |
3093 static void set_lowlink(tarjan *t, const upb_refcounted *r, uint32_t lowlink) { | 3300 static void set_lowlink(tarjan *t, const upb_refcounted *r, uint32_t lowlink) { |
3094 assert(color(t, r) == GREEN); | 3301 UPB_ASSERT(color(t, r) == GREEN); |
3095 setattr(t, r, ((uint64_t)lowlink << 33) | (getattr(t, r) & 0x1FFFFFFFF)); | 3302 setattr(t, r, ((uint64_t)lowlink << 33) | (getattr(t, r) & 0x1FFFFFFFF)); |
3096 } | 3303 } |
3097 | 3304 |
3098 static uint32_t *group(tarjan *t, upb_refcounted *r) { | 3305 static uint32_t *group(tarjan *t, upb_refcounted *r) { |
3099 uint64_t groupnum; | 3306 uint64_t groupnum; |
3100 upb_value v; | 3307 upb_value v; |
3101 bool found; | 3308 bool found; |
3102 | 3309 |
3103 assert(color(t, r) == WHITE); | 3310 UPB_ASSERT(color(t, r) == WHITE); |
3104 groupnum = getattr(t, r) >> 8; | 3311 groupnum = getattr(t, r) >> 8; |
3105 found = upb_inttable_lookup(&t->groups, groupnum, &v); | 3312 found = upb_inttable_lookup(&t->groups, groupnum, &v); |
3106 UPB_ASSERT_VAR(found, found); | 3313 UPB_ASSERT(found); |
3107 return upb_value_getptr(v); | 3314 return upb_value_getptr(v); |
3108 } | 3315 } |
3109 | 3316 |
3110 /* If the group leader for this object's group has not previously been set, | 3317 /* If the group leader for this object's group has not previously been set, |
3111 * the given object is assigned to be its leader. */ | 3318 * the given object is assigned to be its leader. */ |
3112 static upb_refcounted *groupleader(tarjan *t, upb_refcounted *r) { | 3319 static upb_refcounted *groupleader(tarjan *t, upb_refcounted *r) { |
3113 uint64_t leader_slot; | 3320 uint64_t leader_slot; |
3114 upb_value v; | 3321 upb_value v; |
3115 bool found; | 3322 bool found; |
3116 | 3323 |
3117 assert(color(t, r) == WHITE); | 3324 UPB_ASSERT(color(t, r) == WHITE); |
3118 leader_slot = (getattr(t, r) >> 8) + 1; | 3325 leader_slot = (getattr(t, r) >> 8) + 1; |
3119 found = upb_inttable_lookup(&t->groups, leader_slot, &v); | 3326 found = upb_inttable_lookup(&t->groups, leader_slot, &v); |
3120 UPB_ASSERT_VAR(found, found); | 3327 UPB_ASSERT(found); |
3121 if (upb_value_getptr(v)) { | 3328 if (upb_value_getptr(v)) { |
3122 return upb_value_getptr(v); | 3329 return upb_value_getptr(v); |
3123 } else { | 3330 } else { |
3124 upb_inttable_remove(&t->groups, leader_slot, NULL); | 3331 upb_inttable_remove(&t->groups, leader_slot, NULL); |
3125 upb_inttable_insert(&t->groups, leader_slot, upb_value_ptr(r)); | 3332 upb_inttable_insert(&t->groups, leader_slot, upb_value_ptr(r)); |
3126 return r; | 3333 return r; |
3127 } | 3334 } |
3128 } | 3335 } |
3129 | 3336 |
3130 | 3337 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3170 ; | 3377 ; |
3171 } | 3378 } |
3172 } | 3379 } |
3173 | 3380 |
3174 | 3381 |
3175 /* freeze() ------------------------------------------------------------------*/ | 3382 /* freeze() ------------------------------------------------------------------*/ |
3176 | 3383 |
3177 static void crossref(const upb_refcounted *r, const upb_refcounted *subobj, | 3384 static void crossref(const upb_refcounted *r, const upb_refcounted *subobj, |
3178 void *_t) { | 3385 void *_t) { |
3179 tarjan *t = _t; | 3386 tarjan *t = _t; |
3180 assert(color(t, r) > BLACK); | 3387 UPB_ASSERT(color(t, r) > BLACK); |
3181 if (color(t, subobj) > BLACK && r->group != subobj->group) { | 3388 if (color(t, subobj) > BLACK && r->group != subobj->group) { |
3182 /* Previously this ref was not reflected in subobj->group because they | 3389 /* Previously this ref was not reflected in subobj->group because they |
3183 * were in the same group; now that they are split a ref must be taken. */ | 3390 * were in the same group; now that they are split a ref must be taken. */ |
3184 refgroup(subobj->group); | 3391 refgroup(subobj->group); |
3185 } | 3392 } |
3186 } | 3393 } |
3187 | 3394 |
3188 static bool freeze(upb_refcounted *const*roots, int n, upb_status *s, | 3395 static bool freeze(upb_refcounted *const*roots, int n, upb_status *s, |
3189 int maxdepth) { | 3396 int maxdepth) { |
3190 volatile bool ret = false; | 3397 volatile bool ret = false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3238 * change it to be the node we are currently operating on, so with a | 3445 * change it to be the node we are currently operating on, so with a |
3239 * while() loop we guarantee ourselves the chance to remove each node. *
/ | 3446 * while() loop we guarantee ourselves the chance to remove each node. *
/ |
3240 while (color(&t, obj->next) == WHITE && | 3447 while (color(&t, obj->next) == WHITE && |
3241 group(&t, obj->next) != obj->next->group) { | 3448 group(&t, obj->next) != obj->next->group) { |
3242 upb_refcounted *leader; | 3449 upb_refcounted *leader; |
3243 | 3450 |
3244 /* Remove from old group. */ | 3451 /* Remove from old group. */ |
3245 upb_refcounted *move = obj->next; | 3452 upb_refcounted *move = obj->next; |
3246 if (obj == move) { | 3453 if (obj == move) { |
3247 /* Removing the last object from a group. */ | 3454 /* Removing the last object from a group. */ |
3248 assert(*obj->group == obj->individual_count); | 3455 UPB_ASSERT(*obj->group == obj->individual_count); |
3249 free(obj->group); | 3456 upb_gfree(obj->group); |
3250 } else { | 3457 } else { |
3251 obj->next = move->next; | 3458 obj->next = move->next; |
3252 /* This may decrease to zero; we'll collect GRAY objects (if any) that | 3459 /* This may decrease to zero; we'll collect GRAY objects (if any) that |
3253 * remain in the group in the third pass. */ | 3460 * remain in the group in the third pass. */ |
3254 assert(*move->group >= move->individual_count); | 3461 UPB_ASSERT(*move->group >= move->individual_count); |
3255 *move->group -= move->individual_count; | 3462 *move->group -= move->individual_count; |
3256 } | 3463 } |
3257 | 3464 |
3258 /* Add to new group. */ | 3465 /* Add to new group. */ |
3259 leader = groupleader(&t, move); | 3466 leader = groupleader(&t, move); |
3260 if (move == leader) { | 3467 if (move == leader) { |
3261 /* First object added to new group is its leader. */ | 3468 /* First object added to new group is its leader. */ |
3262 move->group = group(&t, move); | 3469 move->group = group(&t, move); |
3263 move->next = move; | 3470 move->next = move; |
3264 *move->group = move->individual_count; | 3471 *move->group = move->individual_count; |
3265 } else { | 3472 } else { |
3266 /* Group already has at least one object in it. */ | 3473 /* Group already has at least one object in it. */ |
3267 assert(leader->group == group(&t, move)); | 3474 UPB_ASSERT(leader->group == group(&t, move)); |
3268 move->group = group(&t, move); | 3475 move->group = group(&t, move); |
3269 move->next = leader->next; | 3476 move->next = leader->next; |
3270 leader->next = move; | 3477 leader->next = move; |
3271 *move->group += move->individual_count; | 3478 *move->group += move->individual_count; |
3272 } | 3479 } |
3273 | 3480 |
3274 move->is_frozen = true; | 3481 move->is_frozen = true; |
3275 } | 3482 } |
3276 } | 3483 } |
3277 | 3484 |
(...skipping 17 matching lines...) Expand all Loading... |
3295 upb_inttable_begin(&iter, &t.objattr); | 3502 upb_inttable_begin(&iter, &t.objattr); |
3296 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) { | 3503 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) { |
3297 upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter); | 3504 upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter); |
3298 if (obj->group == NULL || *obj->group == 0) { | 3505 if (obj->group == NULL || *obj->group == 0) { |
3299 if (obj->group) { | 3506 if (obj->group) { |
3300 upb_refcounted *o; | 3507 upb_refcounted *o; |
3301 | 3508 |
3302 /* We eagerly free() the group's count (since we can't easily determine | 3509 /* 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 | 3510 * the group's remaining size it's the easiest way to ensure it gets |
3304 * done). */ | 3511 * done). */ |
3305 free(obj->group); | 3512 upb_gfree(obj->group); |
3306 | 3513 |
3307 /* Visit to release ref2's (done in a separate pass since release_ref2 | 3514 /* 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()). */ | 3515 * depends on o->group being unmodified so it can test merged()). */ |
3309 o = obj; | 3516 o = obj; |
3310 do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj); | 3517 do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj); |
3311 | 3518 |
3312 /* Mark "group" fields as NULL so we know to free the objects later in | 3519 /* 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. */ | 3520 * this loop, but also don't try to delete the group twice. */ |
3314 o = obj; | 3521 o = obj; |
3315 do { o->group = NULL; } while ((o = o->next) != obj); | 3522 do { o->group = NULL; } while ((o = o->next) != obj); |
3316 } | 3523 } |
3317 freeobj(obj); | 3524 freeobj(obj); |
3318 } | 3525 } |
3319 } | 3526 } |
3320 | 3527 |
3321 err4: | 3528 err4: |
3322 if (!ret) { | 3529 if (!ret) { |
3323 upb_inttable_begin(&iter, &t.groups); | 3530 upb_inttable_begin(&iter, &t.groups); |
3324 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) | 3531 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) |
3325 free(upb_value_getptr(upb_inttable_iter_value(&iter))); | 3532 upb_gfree(upb_value_getptr(upb_inttable_iter_value(&iter))); |
3326 } | 3533 } |
3327 upb_inttable_uninit(&t.groups); | 3534 upb_inttable_uninit(&t.groups); |
3328 err3: | 3535 err3: |
3329 upb_inttable_uninit(&t.stack); | 3536 upb_inttable_uninit(&t.stack); |
3330 err2: | 3537 err2: |
3331 upb_inttable_uninit(&t.objattr); | 3538 upb_inttable_uninit(&t.objattr); |
3332 err1: | 3539 err1: |
3333 return ret; | 3540 return ret; |
3334 } | 3541 } |
3335 | 3542 |
3336 | 3543 |
3337 /* Misc internal functions ***************************************************/ | 3544 /* Misc internal functions ***************************************************/ |
3338 | 3545 |
3339 static bool merged(const upb_refcounted *r, const upb_refcounted *r2) { | 3546 static bool merged(const upb_refcounted *r, const upb_refcounted *r2) { |
3340 return r->group == r2->group; | 3547 return r->group == r2->group; |
3341 } | 3548 } |
3342 | 3549 |
3343 static void merge(upb_refcounted *r, upb_refcounted *from) { | 3550 static void merge(upb_refcounted *r, upb_refcounted *from) { |
3344 upb_refcounted *base; | 3551 upb_refcounted *base; |
3345 upb_refcounted *tmp; | 3552 upb_refcounted *tmp; |
3346 | 3553 |
3347 if (merged(r, from)) return; | 3554 if (merged(r, from)) return; |
3348 *r->group += *from->group; | 3555 *r->group += *from->group; |
3349 free(from->group); | 3556 upb_gfree(from->group); |
3350 base = from; | 3557 base = from; |
3351 | 3558 |
3352 /* Set all refcount pointers in the "from" chain to the merged refcount. | 3559 /* Set all refcount pointers in the "from" chain to the merged refcount. |
3353 * | 3560 * |
3354 * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound | 3561 * 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 | 3562 * if the user continuously extends a group by one object. Prevent this by |
3356 * using one of the techniques in this paper: | 3563 * using one of the techniques in this paper: |
3357 * ftp://www.ncedc.org/outgoing/geomorph/dino/orals/p245-tarjan.pdf */ | 3564 * http://bioinfo.ict.ac.cn/~dbu/AlgorithmCourses/Lectures/Union-Find-Tarj
an.pdf */ |
3358 do { from->group = r->group; } while ((from = from->next) != base); | 3565 do { from->group = r->group; } while ((from = from->next) != base); |
3359 | 3566 |
3360 /* Merge the two circularly linked lists by swapping their next pointers. */ | 3567 /* Merge the two circularly linked lists by swapping their next pointers. */ |
3361 tmp = r->next; | 3568 tmp = r->next; |
3362 r->next = base->next; | 3569 r->next = base->next; |
3363 base->next = tmp; | 3570 base->next = tmp; |
3364 } | 3571 } |
3365 | 3572 |
3366 static void unref(const upb_refcounted *r); | 3573 static void unref(const upb_refcounted *r); |
3367 | 3574 |
3368 static void release_ref2(const upb_refcounted *obj, | 3575 static void release_ref2(const upb_refcounted *obj, |
3369 const upb_refcounted *subobj, | 3576 const upb_refcounted *subobj, |
3370 void *closure) { | 3577 void *closure) { |
3371 UPB_UNUSED(closure); | 3578 UPB_UNUSED(closure); |
3372 untrack(subobj, obj, true); | 3579 untrack(subobj, obj, true); |
3373 if (!merged(obj, subobj)) { | 3580 if (!merged(obj, subobj)) { |
3374 assert(subobj->is_frozen); | 3581 UPB_ASSERT(subobj->is_frozen); |
3375 unref(subobj); | 3582 unref(subobj); |
3376 } | 3583 } |
3377 } | 3584 } |
3378 | 3585 |
3379 static void unref(const upb_refcounted *r) { | 3586 static void unref(const upb_refcounted *r) { |
3380 if (unrefgroup(r->group)) { | 3587 if (unrefgroup(r->group)) { |
3381 const upb_refcounted *o; | 3588 const upb_refcounted *o; |
3382 | 3589 |
3383 free(r->group); | 3590 upb_gfree(r->group); |
3384 | 3591 |
3385 /* In two passes, since release_ref2 needs a guarantee that any subobjs | 3592 /* In two passes, since release_ref2 needs a guarantee that any subobjs |
3386 * are alive. */ | 3593 * are alive. */ |
3387 o = r; | 3594 o = r; |
3388 do { visit(o, release_ref2, NULL); } while((o = o->next) != r); | 3595 do { visit(o, release_ref2, NULL); } while((o = o->next) != r); |
3389 | 3596 |
3390 o = r; | 3597 o = r; |
3391 do { | 3598 do { |
3392 const upb_refcounted *next = o->next; | 3599 const upb_refcounted *next = o->next; |
3393 assert(o->is_frozen || o->individual_count == 0); | 3600 UPB_ASSERT(o->is_frozen || o->individual_count == 0); |
3394 freeobj((upb_refcounted*)o); | 3601 freeobj((upb_refcounted*)o); |
3395 o = next; | 3602 o = next; |
3396 } while(o != r); | 3603 } while(o != r); |
3397 } | 3604 } |
3398 } | 3605 } |
3399 | 3606 |
3400 static void freeobj(upb_refcounted *o) { | 3607 static void freeobj(upb_refcounted *o) { |
3401 trackfree(o); | 3608 trackfree(o); |
3402 o->vtbl->free((upb_refcounted*)o); | 3609 o->vtbl->free((upb_refcounted*)o); |
3403 } | 3610 } |
3404 | 3611 |
3405 | 3612 |
3406 /* Public interface ***********************************************************/ | 3613 /* Public interface ***********************************************************/ |
3407 | 3614 |
3408 bool upb_refcounted_init(upb_refcounted *r, | 3615 bool upb_refcounted_init(upb_refcounted *r, |
3409 const struct upb_refcounted_vtbl *vtbl, | 3616 const struct upb_refcounted_vtbl *vtbl, |
3410 const void *owner) { | 3617 const void *owner) { |
3411 #ifndef NDEBUG | 3618 #ifndef NDEBUG |
3412 /* Endianness check. This is unrelated to upb_refcounted, it's just a | 3619 /* Endianness check. This is unrelated to upb_refcounted, it's just a |
3413 * convenient place to put the check that we can be assured will run for | 3620 * convenient place to put the check that we can be assured will run for |
3414 * basically every program using upb. */ | 3621 * basically every program using upb. */ |
3415 const int x = 1; | 3622 const int x = 1; |
3416 #ifdef UPB_BIG_ENDIAN | 3623 #ifdef UPB_BIG_ENDIAN |
3417 assert(*(char*)&x != 1); | 3624 UPB_ASSERT(*(char*)&x != 1); |
3418 #else | 3625 #else |
3419 assert(*(char*)&x == 1); | 3626 UPB_ASSERT(*(char*)&x == 1); |
3420 #endif | 3627 #endif |
3421 #endif | 3628 #endif |
3422 | 3629 |
3423 r->next = r; | 3630 r->next = r; |
3424 r->vtbl = vtbl; | 3631 r->vtbl = vtbl; |
3425 r->individual_count = 0; | 3632 r->individual_count = 0; |
3426 r->is_frozen = false; | 3633 r->is_frozen = false; |
3427 r->group = malloc(sizeof(*r->group)); | 3634 r->group = upb_gmalloc(sizeof(*r->group)); |
3428 if (!r->group) return false; | 3635 if (!r->group) return false; |
3429 *r->group = 0; | 3636 *r->group = 0; |
3430 if (!trackinit(r)) { | 3637 trackinit(r); |
3431 free(r->group); | |
3432 return false; | |
3433 } | |
3434 upb_refcounted_ref(r, owner); | 3638 upb_refcounted_ref(r, owner); |
3435 return true; | 3639 return true; |
3436 } | 3640 } |
3437 | 3641 |
3438 bool upb_refcounted_isfrozen(const upb_refcounted *r) { | 3642 bool upb_refcounted_isfrozen(const upb_refcounted *r) { |
3439 return r->is_frozen; | 3643 return r->is_frozen; |
3440 } | 3644 } |
3441 | 3645 |
3442 void upb_refcounted_ref(const upb_refcounted *r, const void *owner) { | 3646 void upb_refcounted_ref(const upb_refcounted *r, const void *owner) { |
3443 track(r, owner, false); | 3647 track(r, owner, false); |
3444 if (!r->is_frozen) | 3648 if (!r->is_frozen) |
3445 ((upb_refcounted*)r)->individual_count++; | 3649 ((upb_refcounted*)r)->individual_count++; |
3446 refgroup(r->group); | 3650 refgroup(r->group); |
3447 } | 3651 } |
3448 | 3652 |
3449 void upb_refcounted_unref(const upb_refcounted *r, const void *owner) { | 3653 void upb_refcounted_unref(const upb_refcounted *r, const void *owner) { |
3450 untrack(r, owner, false); | 3654 untrack(r, owner, false); |
3451 if (!r->is_frozen) | 3655 if (!r->is_frozen) |
3452 ((upb_refcounted*)r)->individual_count--; | 3656 ((upb_refcounted*)r)->individual_count--; |
3453 unref(r); | 3657 unref(r); |
3454 } | 3658 } |
3455 | 3659 |
3456 void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from) { | 3660 void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from) { |
3457 assert(!from->is_frozen); /* Non-const pointer implies this. */ | 3661 UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */ |
3458 track(r, from, true); | 3662 track(r, from, true); |
3459 if (r->is_frozen) { | 3663 if (r->is_frozen) { |
3460 refgroup(r->group); | 3664 refgroup(r->group); |
3461 } else { | 3665 } else { |
3462 merge((upb_refcounted*)r, from); | 3666 merge((upb_refcounted*)r, from); |
3463 } | 3667 } |
3464 } | 3668 } |
3465 | 3669 |
3466 void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from) { | 3670 void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from) { |
3467 assert(!from->is_frozen); /* Non-const pointer implies this. */ | 3671 UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */ |
3468 untrack(r, from, true); | 3672 untrack(r, from, true); |
3469 if (r->is_frozen) { | 3673 if (r->is_frozen) { |
3470 unref(r); | 3674 unref(r); |
3471 } else { | 3675 } else { |
3472 assert(merged(r, from)); | 3676 UPB_ASSERT(merged(r, from)); |
3473 } | 3677 } |
3474 } | 3678 } |
3475 | 3679 |
3476 void upb_refcounted_donateref( | 3680 void upb_refcounted_donateref( |
3477 const upb_refcounted *r, const void *from, const void *to) { | 3681 const upb_refcounted *r, const void *from, const void *to) { |
3478 assert(from != to); | 3682 UPB_ASSERT(from != to); |
3479 if (to != NULL) | 3683 if (to != NULL) |
3480 upb_refcounted_ref(r, to); | 3684 upb_refcounted_ref(r, to); |
3481 if (from != NULL) | 3685 if (from != NULL) |
3482 upb_refcounted_unref(r, from); | 3686 upb_refcounted_unref(r, from); |
3483 } | 3687 } |
3484 | 3688 |
3485 void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) { | 3689 void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) { |
3486 checkref(r, owner, false); | 3690 checkref(r, owner, false); |
3487 } | 3691 } |
3488 | 3692 |
3489 bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s, | 3693 bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s, |
3490 int maxdepth) { | 3694 int maxdepth) { |
3491 int i; | 3695 int i; |
| 3696 bool ret; |
3492 for (i = 0; i < n; i++) { | 3697 for (i = 0; i < n; i++) { |
3493 assert(!roots[i]->is_frozen); | 3698 UPB_ASSERT(!roots[i]->is_frozen); |
3494 } | 3699 } |
3495 return freeze(roots, n, s, maxdepth); | 3700 ret = freeze(roots, n, s, maxdepth); |
| 3701 UPB_ASSERT(!s || ret == upb_ok(s)); |
| 3702 return ret; |
3496 } | 3703 } |
3497 | 3704 |
3498 | 3705 |
3499 #include <stdlib.h> | |
3500 | |
3501 /* Fallback implementation if the shim is not specialized by the JIT. */ | 3706 /* Fallback implementation if the shim is not specialized by the JIT. */ |
3502 #define SHIM_WRITER(type, ctype) \ | 3707 #define SHIM_WRITER(type, ctype) \ |
3503 bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \ | 3708 bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \ |
3504 uint8_t *m = c; \ | 3709 uint8_t *m = c; \ |
3505 const upb_shim_data *d = hd; \ | 3710 const upb_shim_data *d = hd; \ |
3506 if (d->hasbit > 0) \ | 3711 if (d->hasbit > 0) \ |
3507 *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ | 3712 *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ |
3508 *(ctype*)&m[d->offset] = val; \ | 3713 *(ctype*)&m[d->offset] = val; \ |
3509 return true; \ | 3714 return true; \ |
3510 } \ | 3715 } \ |
3511 | 3716 |
3512 SHIM_WRITER(double, double) | 3717 SHIM_WRITER(double, double) |
3513 SHIM_WRITER(float, float) | 3718 SHIM_WRITER(float, float) |
3514 SHIM_WRITER(int32, int32_t) | 3719 SHIM_WRITER(int32, int32_t) |
3515 SHIM_WRITER(int64, int64_t) | 3720 SHIM_WRITER(int64, int64_t) |
3516 SHIM_WRITER(uint32, uint32_t) | 3721 SHIM_WRITER(uint32, uint32_t) |
3517 SHIM_WRITER(uint64, uint64_t) | 3722 SHIM_WRITER(uint64, uint64_t) |
3518 SHIM_WRITER(bool, bool) | 3723 SHIM_WRITER(bool, bool) |
3519 #undef SHIM_WRITER | 3724 #undef SHIM_WRITER |
3520 | 3725 |
3521 bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, | 3726 bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, |
3522 int32_t hasbit) { | 3727 int32_t hasbit) { |
3523 upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; | 3728 upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; |
3524 bool ok; | 3729 bool ok; |
3525 | 3730 |
3526 upb_shim_data *d = malloc(sizeof(*d)); | 3731 upb_shim_data *d = upb_gmalloc(sizeof(*d)); |
3527 if (!d) return false; | 3732 if (!d) return false; |
3528 d->offset = offset; | 3733 d->offset = offset; |
3529 d->hasbit = hasbit; | 3734 d->hasbit = hasbit; |
3530 | 3735 |
3531 upb_handlerattr_sethandlerdata(&attr, d); | 3736 upb_handlerattr_sethandlerdata(&attr, d); |
3532 upb_handlerattr_setalwaysok(&attr, true); | 3737 upb_handlerattr_setalwaysok(&attr, true); |
3533 upb_handlers_addcleanup(h, d, free); | 3738 upb_handlers_addcleanup(h, d, upb_gfree); |
3534 | 3739 |
3535 #define TYPE(u, l) \ | 3740 #define TYPE(u, l) \ |
3536 case UPB_TYPE_##u: \ | 3741 case UPB_TYPE_##u: \ |
3537 ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break; | 3742 ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break; |
3538 | 3743 |
3539 ok = false; | 3744 ok = false; |
3540 | 3745 |
3541 switch (upb_fielddef_type(f)) { | 3746 switch (upb_fielddef_type(f)) { |
3542 TYPE(INT64, int64); | 3747 TYPE(INT64, int64); |
3543 TYPE(INT32, int32); | 3748 TYPE(INT32, int32); |
3544 TYPE(ENUM, int32); | 3749 TYPE(ENUM, int32); |
3545 TYPE(UINT64, uint64); | 3750 TYPE(UINT64, uint64); |
3546 TYPE(UINT32, uint32); | 3751 TYPE(UINT32, uint32); |
3547 TYPE(DOUBLE, double); | 3752 TYPE(DOUBLE, double); |
3548 TYPE(FLOAT, float); | 3753 TYPE(FLOAT, float); |
3549 TYPE(BOOL, bool); | 3754 TYPE(BOOL, bool); |
3550 default: assert(false); break; | 3755 default: UPB_ASSERT(false); break; |
3551 } | 3756 } |
3552 #undef TYPE | 3757 #undef TYPE |
3553 | 3758 |
3554 upb_handlerattr_uninit(&attr); | 3759 upb_handlerattr_uninit(&attr); |
3555 return ok; | 3760 return ok; |
3556 } | 3761 } |
3557 | 3762 |
3558 const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, | 3763 const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, |
3559 upb_fieldtype_t *type) { | 3764 upb_fieldtype_t *type) { |
3560 upb_func *f = upb_handlers_gethandler(h, s); | 3765 upb_func *f = upb_handlers_gethandler(h, s); |
(...skipping 13 matching lines...) Expand all Loading... |
3574 } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) { | 3779 } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) { |
3575 *type = UPB_TYPE_BOOL; | 3780 *type = UPB_TYPE_BOOL; |
3576 } else { | 3781 } else { |
3577 return NULL; | 3782 return NULL; |
3578 } | 3783 } |
3579 | 3784 |
3580 return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s); | 3785 return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s); |
3581 } | 3786 } |
3582 | 3787 |
3583 | 3788 |
3584 #include <stdlib.h> | |
3585 #include <string.h> | 3789 #include <string.h> |
3586 | 3790 |
3587 static void upb_symtab_free(upb_refcounted *r) { | 3791 static void upb_symtab_free(upb_refcounted *r) { |
3588 upb_symtab *s = (upb_symtab*)r; | 3792 upb_symtab *s = (upb_symtab*)r; |
3589 upb_strtable_iter i; | 3793 upb_strtable_iter i; |
3590 upb_strtable_begin(&i, &s->symtab); | 3794 upb_strtable_begin(&i, &s->symtab); |
3591 for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { | 3795 for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { |
3592 const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i)); | 3796 const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i)); |
3593 upb_def_unref(def, s); | 3797 upb_def_unref(def, s); |
3594 } | 3798 } |
3595 upb_strtable_uninit(&s->symtab); | 3799 upb_strtable_uninit(&s->symtab); |
3596 free(s); | 3800 upb_gfree(s); |
3597 } | 3801 } |
3598 | 3802 |
3599 | |
3600 upb_symtab *upb_symtab_new(const void *owner) { | 3803 upb_symtab *upb_symtab_new(const void *owner) { |
3601 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free}; | 3804 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free}; |
3602 upb_symtab *s = malloc(sizeof(*s)); | 3805 |
| 3806 upb_symtab *s = upb_gmalloc(sizeof(*s)); |
| 3807 if (!s) { |
| 3808 return NULL; |
| 3809 } |
| 3810 |
3603 upb_refcounted_init(upb_symtab_upcast_mutable(s), &vtbl, owner); | 3811 upb_refcounted_init(upb_symtab_upcast_mutable(s), &vtbl, owner); |
3604 upb_strtable_init(&s->symtab, UPB_CTYPE_PTR); | 3812 upb_strtable_init(&s->symtab, UPB_CTYPE_PTR); |
3605 return s; | 3813 return s; |
3606 } | 3814 } |
3607 | 3815 |
3608 void upb_symtab_freeze(upb_symtab *s) { | 3816 void upb_symtab_freeze(upb_symtab *s) { |
3609 upb_refcounted *r; | 3817 upb_refcounted *r; |
3610 bool ok; | 3818 bool ok; |
3611 | 3819 |
3612 assert(!upb_symtab_isfrozen(s)); | 3820 UPB_ASSERT(!upb_symtab_isfrozen(s)); |
3613 r = upb_symtab_upcast_mutable(s); | 3821 r = upb_symtab_upcast_mutable(s); |
3614 /* The symtab does not take ref2's (see refcounted.h) on the defs, because | 3822 /* The symtab does not take ref2's (see refcounted.h) on the defs, because |
3615 * defs cannot refer back to the table and therefore cannot create cycles. So | 3823 * defs cannot refer back to the table and therefore cannot create cycles. So |
3616 * 0 will suffice for maxdepth here. */ | 3824 * 0 will suffice for maxdepth here. */ |
3617 ok = upb_refcounted_freeze(&r, 1, NULL, 0); | 3825 ok = upb_refcounted_freeze(&r, 1, NULL, 0); |
3618 UPB_ASSERT_VAR(ok, ok); | 3826 UPB_ASSERT(ok); |
3619 } | 3827 } |
3620 | 3828 |
3621 const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) { | 3829 const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) { |
3622 upb_value v; | 3830 upb_value v; |
3623 upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ? | 3831 upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ? |
3624 upb_value_getptr(v) : NULL; | 3832 upb_value_getptr(v) : NULL; |
3625 return ret; | 3833 return ret; |
3626 } | 3834 } |
3627 | 3835 |
3628 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { | 3836 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { |
(...skipping 17 matching lines...) Expand all Loading... |
3646 if(strlen(sym) == 0) return NULL; | 3854 if(strlen(sym) == 0) return NULL; |
3647 if(sym[0] == '.') { | 3855 if(sym[0] == '.') { |
3648 /* Symbols starting with '.' are absolute, so we do a single lookup. | 3856 /* Symbols starting with '.' are absolute, so we do a single lookup. |
3649 * Slice to omit the leading '.' */ | 3857 * Slice to omit the leading '.' */ |
3650 upb_value v; | 3858 upb_value v; |
3651 return upb_strtable_lookup(t, sym + 1, &v) ? upb_value_getptr(v) : NULL; | 3859 return upb_strtable_lookup(t, sym + 1, &v) ? upb_value_getptr(v) : NULL; |
3652 } else { | 3860 } else { |
3653 /* Remove components from base until we find an entry or run out. | 3861 /* Remove components from base until we find an entry or run out. |
3654 * TODO: This branch is totally broken, but currently not used. */ | 3862 * TODO: This branch is totally broken, but currently not used. */ |
3655 (void)base; | 3863 (void)base; |
3656 assert(false); | 3864 UPB_ASSERT(false); |
3657 return NULL; | 3865 return NULL; |
3658 } | 3866 } |
3659 } | 3867 } |
3660 | 3868 |
3661 const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, | 3869 const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, |
3662 const char *sym) { | 3870 const char *sym) { |
3663 upb_def *ret = upb_resolvename(&s->symtab, base, sym); | 3871 upb_def *ret = upb_resolvename(&s->symtab, base, sym); |
3664 return ret; | 3872 return ret; |
3665 } | 3873 } |
3666 | 3874 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3708 if (upb_inttable_lookupptr(seen, memoize_key, &v)) | 3916 if (upb_inttable_lookupptr(seen, memoize_key, &v)) |
3709 return upb_value_getbool(v); | 3917 return upb_value_getbool(v); |
3710 | 3918 |
3711 /* Visit submessages for all messages in the SCC. */ | 3919 /* Visit submessages for all messages in the SCC. */ |
3712 need_dup = false; | 3920 need_dup = false; |
3713 base = def; | 3921 base = def; |
3714 do { | 3922 do { |
3715 upb_value v; | 3923 upb_value v; |
3716 const upb_msgdef *m; | 3924 const upb_msgdef *m; |
3717 | 3925 |
3718 assert(upb_def_isfrozen(def)); | 3926 UPB_ASSERT(upb_def_isfrozen(def)); |
3719 if (def->type == UPB_DEF_FIELD) continue; | 3927 if (def->type == UPB_DEF_FIELD) continue; |
3720 if (upb_strtable_lookup(addtab, upb_def_fullname(def), &v)) { | 3928 if (upb_strtable_lookup(addtab, upb_def_fullname(def), &v)) { |
3721 need_dup = true; | 3929 need_dup = true; |
3722 } | 3930 } |
3723 | 3931 |
3724 /* For messages, continue the recursion by visiting all subdefs, but only | 3932 /* For messages, continue the recursion by visiting all subdefs, but only |
3725 * ones in different SCCs. */ | 3933 * ones in different SCCs. */ |
3726 m = upb_dyncast_msgdef(def); | 3934 m = upb_dyncast_msgdef(def); |
3727 if (m) { | 3935 if (m) { |
3728 upb_msg_field_iter i; | 3936 upb_msg_field_iter i; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3766 upb_inttable_insertptr(seen, memoize_key, upb_value_bool(need_dup)); | 3974 upb_inttable_insertptr(seen, memoize_key, upb_value_bool(need_dup)); |
3767 return need_dup; | 3975 return need_dup; |
3768 | 3976 |
3769 oom: | 3977 oom: |
3770 upb_status_seterrmsg(s, "out of memory"); | 3978 upb_status_seterrmsg(s, "out of memory"); |
3771 return false; | 3979 return false; |
3772 } | 3980 } |
3773 | 3981 |
3774 /* TODO(haberman): we need a lot more testing of error conditions. | 3982 /* TODO(haberman): we need a lot more testing of error conditions. |
3775 * The came_from_user stuff in particular is not tested. */ | 3983 * 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, | 3984 static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, |
3777 upb_status *status) { | 3985 void *ref_donor, upb_refcounted *freeze_also, |
3778 int i; | 3986 upb_status *status) { |
| 3987 size_t i; |
| 3988 size_t add_n; |
| 3989 size_t freeze_n; |
3779 upb_strtable_iter iter; | 3990 upb_strtable_iter iter; |
| 3991 upb_refcounted **add_objs = NULL; |
3780 upb_def **add_defs = NULL; | 3992 upb_def **add_defs = NULL; |
| 3993 size_t add_objs_size; |
3781 upb_strtable addtab; | 3994 upb_strtable addtab; |
3782 upb_inttable seen; | 3995 upb_inttable seen; |
3783 | 3996 |
3784 assert(!upb_symtab_isfrozen(s)); | 3997 if (n == 0 && !freeze_also) { |
| 3998 return true; |
| 3999 } |
| 4000 |
| 4001 UPB_ASSERT(!upb_symtab_isfrozen(s)); |
3785 if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) { | 4002 if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) { |
3786 upb_status_seterrmsg(status, "out of memory"); | 4003 upb_status_seterrmsg(status, "out of memory"); |
3787 return false; | 4004 return false; |
3788 } | 4005 } |
3789 | 4006 |
3790 /* Add new defs to our "add" set. */ | 4007 /* Add new defs to our "add" set. */ |
3791 for (i = 0; i < n; i++) { | 4008 for (i = 0; i < n; i++) { |
3792 upb_def *def = defs[i]; | 4009 upb_def *def = defs[i]; |
3793 const char *fullname; | 4010 const char *fullname; |
3794 upb_fielddef *f; | 4011 upb_fielddef *f; |
3795 | 4012 |
3796 if (upb_def_isfrozen(def)) { | 4013 if (upb_def_isfrozen(def)) { |
3797 upb_status_seterrmsg(status, "added defs must be mutable"); | 4014 upb_status_seterrmsg(status, "added defs must be mutable"); |
3798 goto err; | 4015 goto err; |
3799 } | 4016 } |
3800 assert(!upb_def_isfrozen(def)); | 4017 UPB_ASSERT(!upb_def_isfrozen(def)); |
3801 fullname = upb_def_fullname(def); | 4018 fullname = upb_def_fullname(def); |
3802 if (!fullname) { | 4019 if (!fullname) { |
3803 upb_status_seterrmsg( | 4020 upb_status_seterrmsg( |
3804 status, "Anonymous defs cannot be added to a symtab"); | 4021 status, "Anonymous defs cannot be added to a symtab"); |
3805 goto err; | 4022 goto err; |
3806 } | 4023 } |
3807 | 4024 |
3808 f = upb_dyncast_fielddef_mutable(def); | 4025 f = upb_dyncast_fielddef_mutable(def); |
3809 | 4026 |
3810 if (f) { | 4027 if (f) { |
(...skipping 23 matching lines...) Expand all Loading... |
3834 for (i = 0; i < n; i++) { | 4051 for (i = 0; i < n; i++) { |
3835 upb_def *def = defs[i]; | 4052 upb_def *def = defs[i]; |
3836 upb_fielddef *f = upb_dyncast_fielddef_mutable(def); | 4053 upb_fielddef *f = upb_dyncast_fielddef_mutable(def); |
3837 const char *msgname; | 4054 const char *msgname; |
3838 upb_value v; | 4055 upb_value v; |
3839 upb_msgdef *m; | 4056 upb_msgdef *m; |
3840 | 4057 |
3841 if (!f) continue; | 4058 if (!f) continue; |
3842 msgname = upb_fielddef_containingtypename(f); | 4059 msgname = upb_fielddef_containingtypename(f); |
3843 /* We validated this earlier in this function. */ | 4060 /* We validated this earlier in this function. */ |
3844 assert(msgname); | 4061 UPB_ASSERT(msgname); |
3845 | 4062 |
3846 /* If the extendee name is absolutely qualified, move past the initial ".". | 4063 /* If the extendee name is absolutely qualified, move past the initial ".". |
3847 * TODO(haberman): it is not obvious what it would mean if this was not | 4064 * TODO(haberman): it is not obvious what it would mean if this was not |
3848 * absolutely qualified. */ | 4065 * absolutely qualified. */ |
3849 if (msgname[0] == '.') { | 4066 if (msgname[0] == '.') { |
3850 msgname++; | 4067 msgname++; |
3851 } | 4068 } |
3852 | 4069 |
3853 if (upb_strtable_lookup(&addtab, msgname, &v)) { | 4070 if (upb_strtable_lookup(&addtab, msgname, &v)) { |
3854 /* Extendee is in the set of defs the user asked us to add. */ | 4071 /* Extendee is in the set of defs the user asked us to add. */ |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3915 upb_status_seterrf( | 4132 upb_status_seterrf( |
3916 status, "couldn't resolve name '%s' in message '%s'", name, base); | 4133 status, "couldn't resolve name '%s' in message '%s'", name, base); |
3917 goto err; | 4134 goto err; |
3918 } else if (!upb_fielddef_setsubdef(f, subdef, status)) { | 4135 } else if (!upb_fielddef_setsubdef(f, subdef, status)) { |
3919 goto err; | 4136 goto err; |
3920 } | 4137 } |
3921 } | 4138 } |
3922 } | 4139 } |
3923 } | 4140 } |
3924 | 4141 |
3925 /* We need an array of the defs in addtab, for passing to upb_def_freeze. */ | 4142 /* We need an array of the defs in addtab, for passing to |
3926 add_defs = malloc(sizeof(void*) * upb_strtable_count(&addtab)); | 4143 * upb_refcounted_freeze(). */ |
| 4144 add_objs_size = upb_strtable_count(&addtab); |
| 4145 if (freeze_also) { |
| 4146 add_objs_size++; |
| 4147 } |
| 4148 |
| 4149 add_defs = upb_gmalloc(sizeof(void*) * add_objs_size); |
3927 if (add_defs == NULL) goto oom_err; | 4150 if (add_defs == NULL) goto oom_err; |
3928 upb_strtable_begin(&iter, &addtab); | 4151 upb_strtable_begin(&iter, &addtab); |
3929 for (n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { | 4152 for (add_n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { |
3930 add_defs[n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); | 4153 add_defs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); |
3931 } | 4154 } |
3932 | 4155 |
3933 if (!upb_def_freeze(add_defs, n, status)) goto err; | 4156 /* Validate defs. */ |
| 4157 if (!_upb_def_validate(add_defs, add_n, status)) { |
| 4158 goto err; |
| 4159 } |
| 4160 |
| 4161 /* Cheat a little and give the array a new type. |
| 4162 * This is probably undefined behavior, but this code will be deleted soon. */ |
| 4163 add_objs = (upb_refcounted**)add_defs; |
| 4164 |
| 4165 freeze_n = add_n; |
| 4166 if (freeze_also) { |
| 4167 add_objs[freeze_n++] = freeze_also; |
| 4168 } |
| 4169 |
| 4170 if (!upb_refcounted_freeze(add_objs, freeze_n, status, |
| 4171 UPB_MAX_MESSAGE_DEPTH * 2)) { |
| 4172 goto err; |
| 4173 } |
3934 | 4174 |
3935 /* This must be delayed until all errors have been detected, since error | 4175 /* This must be delayed until all errors have been detected, since error |
3936 * recovery code uses this table to cleanup defs. */ | 4176 * recovery code uses this table to cleanup defs. */ |
3937 upb_strtable_uninit(&addtab); | 4177 upb_strtable_uninit(&addtab); |
3938 | 4178 |
3939 /* TODO(haberman) we don't properly handle errors after this point (like | 4179 /* TODO(haberman) we don't properly handle errors after this point (like |
3940 * OOM in upb_strtable_insert() below). */ | 4180 * OOM in upb_strtable_insert() below). */ |
3941 for (i = 0; i < n; i++) { | 4181 for (i = 0; i < add_n; i++) { |
3942 upb_def *def = add_defs[i]; | 4182 upb_def *def = (upb_def*)add_objs[i]; |
3943 const char *name = upb_def_fullname(def); | 4183 const char *name = upb_def_fullname(def); |
3944 upb_value v; | 4184 upb_value v; |
3945 bool success; | 4185 bool success; |
3946 | 4186 |
3947 if (upb_strtable_remove(&s->symtab, name, &v)) { | 4187 if (upb_strtable_remove(&s->symtab, name, &v)) { |
3948 const upb_def *def = upb_value_getptr(v); | 4188 const upb_def *def = upb_value_getptr(v); |
3949 upb_def_unref(def, s); | 4189 upb_def_unref(def, s); |
3950 } | 4190 } |
3951 success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def)); | 4191 success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def)); |
3952 UPB_ASSERT_VAR(success, success == true); | 4192 UPB_ASSERT(success == true); |
3953 } | 4193 } |
3954 free(add_defs); | 4194 upb_gfree(add_defs); |
3955 return true; | 4195 return true; |
3956 | 4196 |
3957 oom_err: | 4197 oom_err: |
3958 upb_status_seterrmsg(status, "out of memory"); | 4198 upb_status_seterrmsg(status, "out of memory"); |
3959 err: { | 4199 err: { |
3960 /* For defs the user passed in, we need to donate the refs back. For defs | 4200 /* 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. */ | 4201 * we dup'd, we need to just unref them. */ |
3962 upb_strtable_begin(&iter, &addtab); | 4202 upb_strtable_begin(&iter, &addtab); |
3963 for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { | 4203 for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { |
3964 upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter)); | 4204 upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter)); |
3965 bool came_from_user = def->came_from_user; | 4205 bool came_from_user = def->came_from_user; |
3966 def->came_from_user = false; | 4206 def->came_from_user = false; |
3967 if (came_from_user) { | 4207 if (came_from_user) { |
3968 upb_def_donateref(def, s, ref_donor); | 4208 upb_def_donateref(def, s, ref_donor); |
3969 } else { | 4209 } else { |
3970 upb_def_unref(def, s); | 4210 upb_def_unref(def, s); |
3971 } | 4211 } |
3972 } | 4212 } |
3973 } | 4213 } |
3974 upb_strtable_uninit(&addtab); | 4214 upb_strtable_uninit(&addtab); |
3975 free(add_defs); | 4215 upb_gfree(add_defs); |
3976 assert(!upb_ok(status)); | 4216 UPB_ASSERT(!upb_ok(status)); |
3977 return false; | 4217 return false; |
3978 } | 4218 } |
3979 | 4219 |
| 4220 bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, |
| 4221 void *ref_donor, upb_status *status) { |
| 4222 return symtab_add(s, defs, n, ref_donor, NULL, status); |
| 4223 } |
| 4224 |
| 4225 bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) { |
| 4226 size_t n; |
| 4227 size_t i; |
| 4228 upb_def **defs; |
| 4229 bool ret; |
| 4230 |
| 4231 n = upb_filedef_defcount(file); |
| 4232 defs = upb_gmalloc(sizeof(*defs) * n); |
| 4233 |
| 4234 if (defs == NULL) { |
| 4235 upb_status_seterrmsg(status, "Out of memory"); |
| 4236 return false; |
| 4237 } |
| 4238 |
| 4239 for (i = 0; i < n; i++) { |
| 4240 defs[i] = upb_filedef_mutabledef(file, i); |
| 4241 } |
| 4242 |
| 4243 ret = symtab_add(s, defs, n, NULL, upb_filedef_upcast_mutable(file), status); |
| 4244 |
| 4245 upb_gfree(defs); |
| 4246 return ret; |
| 4247 } |
| 4248 |
3980 /* Iteration. */ | 4249 /* Iteration. */ |
3981 | 4250 |
3982 static void advance_to_matching(upb_symtab_iter *iter) { | 4251 static void advance_to_matching(upb_symtab_iter *iter) { |
3983 if (iter->type == UPB_DEF_ANY) | 4252 if (iter->type == UPB_DEF_ANY) |
3984 return; | 4253 return; |
3985 | 4254 |
3986 while (!upb_strtable_done(&iter->iter) && | 4255 while (!upb_strtable_done(&iter->iter) && |
3987 iter->type != upb_symtab_iter_def(iter)->type) { | 4256 iter->type != upb_symtab_iter_def(iter)->type) { |
3988 upb_strtable_next(&iter->iter); | 4257 upb_strtable_next(&iter->iter); |
3989 } | 4258 } |
(...skipping 18 matching lines...) Expand all Loading... |
4008 const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) { | 4277 const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) { |
4009 return upb_value_getptr(upb_strtable_iter_value(&iter->iter)); | 4278 return upb_value_getptr(upb_strtable_iter_value(&iter->iter)); |
4010 } | 4279 } |
4011 /* | 4280 /* |
4012 ** upb_table Implementation | 4281 ** upb_table Implementation |
4013 ** | 4282 ** |
4014 ** Implementation is heavily inspired by Lua's ltable.c. | 4283 ** Implementation is heavily inspired by Lua's ltable.c. |
4015 */ | 4284 */ |
4016 | 4285 |
4017 | 4286 |
4018 #include <stdlib.h> | |
4019 #include <string.h> | 4287 #include <string.h> |
4020 | 4288 |
4021 #define UPB_MAXARRSIZE 16 /* 64k. */ | 4289 #define UPB_MAXARRSIZE 16 /* 64k. */ |
4022 | 4290 |
4023 /* From Chromium. */ | 4291 /* From Chromium. */ |
4024 #define ARRAY_SIZE(x) \ | 4292 #define ARRAY_SIZE(x) \ |
4025 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) | 4293 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) |
4026 | 4294 |
| 4295 static void upb_check_alloc(upb_table *t, upb_alloc *a) { |
| 4296 UPB_UNUSED(t); |
| 4297 UPB_UNUSED(a); |
| 4298 UPB_ASSERT_DEBUGVAR(t->alloc == a); |
| 4299 } |
| 4300 |
4027 static const double MAX_LOAD = 0.85; | 4301 static const double MAX_LOAD = 0.85; |
4028 | 4302 |
4029 /* The minimum utilization of the array part of a mixed hash/array table. This | 4303 /* 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 | 4304 * 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. */ | 4305 * cache effects). The lower this is, the more memory we'll use. */ |
4032 static const double MIN_DENSITY = 0.1; | 4306 static const double MIN_DENSITY = 0.1; |
4033 | 4307 |
4034 bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } | 4308 bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } |
4035 | 4309 |
4036 int log2ceil(uint64_t v) { | 4310 int log2ceil(uint64_t v) { |
4037 int ret = 0; | 4311 int ret = 0; |
4038 bool pow2 = is_pow2(v); | 4312 bool pow2 = is_pow2(v); |
4039 while (v >>= 1) ret++; | 4313 while (v >>= 1) ret++; |
4040 ret = pow2 ? ret : ret + 1; /* Ceiling. */ | 4314 ret = pow2 ? ret : ret + 1; /* Ceiling. */ |
4041 return UPB_MIN(UPB_MAXARRSIZE, ret); | 4315 return UPB_MIN(UPB_MAXARRSIZE, ret); |
4042 } | 4316 } |
4043 | 4317 |
4044 char *upb_strdup(const char *s) { | 4318 char *upb_strdup(const char *s, upb_alloc *a) { |
4045 return upb_strdup2(s, strlen(s)); | 4319 return upb_strdup2(s, strlen(s), a); |
4046 } | 4320 } |
4047 | 4321 |
4048 char *upb_strdup2(const char *s, size_t len) { | 4322 char *upb_strdup2(const char *s, size_t len, upb_alloc *a) { |
4049 size_t n; | 4323 size_t n; |
4050 char *p; | 4324 char *p; |
4051 | 4325 |
4052 /* Prevent overflow errors. */ | 4326 /* Prevent overflow errors. */ |
4053 if (len == SIZE_MAX) return NULL; | 4327 if (len == SIZE_MAX) return NULL; |
4054 /* Always null-terminate, even if binary data; but don't rely on the input to | 4328 /* 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. */ | 4329 * have a null-terminating byte since it may be a raw binary buffer. */ |
4056 n = len + 1; | 4330 n = len + 1; |
4057 p = malloc(n); | 4331 p = upb_malloc(a, n); |
4058 if (p) { | 4332 if (p) { |
4059 memcpy(p, s, len); | 4333 memcpy(p, s, len); |
4060 p[len] = 0; | 4334 p[len] = 0; |
4061 } | 4335 } |
4062 return p; | 4336 return p; |
4063 } | 4337 } |
4064 | 4338 |
4065 /* A type to represent the lookup key of either a strtable or an inttable. */ | 4339 /* A type to represent the lookup key of either a strtable or an inttable. */ |
4066 typedef union { | 4340 typedef union { |
4067 uintptr_t num; | 4341 uintptr_t num; |
(...skipping 20 matching lines...) Expand all Loading... |
4088 typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); | 4362 typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); |
4089 | 4363 |
4090 /* Base table (shared code) ***************************************************/ | 4364 /* Base table (shared code) ***************************************************/ |
4091 | 4365 |
4092 /* For when we need to cast away const. */ | 4366 /* For when we need to cast away const. */ |
4093 static upb_tabent *mutable_entries(upb_table *t) { | 4367 static upb_tabent *mutable_entries(upb_table *t) { |
4094 return (upb_tabent*)t->entries; | 4368 return (upb_tabent*)t->entries; |
4095 } | 4369 } |
4096 | 4370 |
4097 static bool isfull(upb_table *t) { | 4371 static bool isfull(upb_table *t) { |
4098 return (double)(t->count + 1) / upb_table_size(t) > MAX_LOAD; | 4372 if (upb_table_size(t) == 0) { |
| 4373 return true; |
| 4374 } else { |
| 4375 return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD; |
| 4376 } |
4099 } | 4377 } |
4100 | 4378 |
4101 static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2) { | 4379 static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2, |
| 4380 upb_alloc *a) { |
4102 size_t bytes; | 4381 size_t bytes; |
4103 | 4382 |
4104 t->count = 0; | 4383 t->count = 0; |
4105 t->ctype = ctype; | 4384 t->ctype = ctype; |
4106 t->size_lg2 = size_lg2; | 4385 t->size_lg2 = size_lg2; |
4107 t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; | 4386 t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; |
| 4387 #ifndef NDEBUG |
| 4388 t->alloc = a; |
| 4389 #endif |
4108 bytes = upb_table_size(t) * sizeof(upb_tabent); | 4390 bytes = upb_table_size(t) * sizeof(upb_tabent); |
4109 if (bytes > 0) { | 4391 if (bytes > 0) { |
4110 t->entries = malloc(bytes); | 4392 t->entries = upb_malloc(a, bytes); |
4111 if (!t->entries) return false; | 4393 if (!t->entries) return false; |
4112 memset(mutable_entries(t), 0, bytes); | 4394 memset(mutable_entries(t), 0, bytes); |
4113 } else { | 4395 } else { |
4114 t->entries = NULL; | 4396 t->entries = NULL; |
4115 } | 4397 } |
4116 return true; | 4398 return true; |
4117 } | 4399 } |
4118 | 4400 |
4119 static void uninit(upb_table *t) { free(mutable_entries(t)); } | 4401 static void uninit(upb_table *t, upb_alloc *a) { |
| 4402 upb_check_alloc(t, a); |
| 4403 upb_free(a, mutable_entries(t)); |
| 4404 } |
4120 | 4405 |
4121 static upb_tabent *emptyent(upb_table *t) { | 4406 static upb_tabent *emptyent(upb_table *t) { |
4122 upb_tabent *e = mutable_entries(t) + upb_table_size(t); | 4407 upb_tabent *e = mutable_entries(t) + upb_table_size(t); |
4123 while (1) { if (upb_tabent_isempty(--e)) return e; assert(e > t->entries); } | 4408 while (1) { if (upb_tabent_isempty(--e)) return e; UPB_ASSERT(e > t->entries);
} |
4124 } | 4409 } |
4125 | 4410 |
4126 static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) { | 4411 static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) { |
4127 return (upb_tabent*)upb_getentry(t, hash); | 4412 return (upb_tabent*)upb_getentry(t, hash); |
4128 } | 4413 } |
4129 | 4414 |
4130 static const upb_tabent *findentry(const upb_table *t, lookupkey_t key, | 4415 static const upb_tabent *findentry(const upb_table *t, lookupkey_t key, |
4131 uint32_t hash, eqlfunc_t *eql) { | 4416 uint32_t hash, eqlfunc_t *eql) { |
4132 const upb_tabent *e; | 4417 const upb_tabent *e; |
4133 | 4418 |
(...skipping 24 matching lines...) Expand all Loading... |
4158 } | 4443 } |
4159 } | 4444 } |
4160 | 4445 |
4161 /* The given key must not already exist in the table. */ | 4446 /* The given key must not already exist in the table. */ |
4162 static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, | 4447 static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, |
4163 upb_value val, uint32_t hash, | 4448 upb_value val, uint32_t hash, |
4164 hashfunc_t *hashfunc, eqlfunc_t *eql) { | 4449 hashfunc_t *hashfunc, eqlfunc_t *eql) { |
4165 upb_tabent *mainpos_e; | 4450 upb_tabent *mainpos_e; |
4166 upb_tabent *our_e; | 4451 upb_tabent *our_e; |
4167 | 4452 |
4168 UPB_UNUSED(eql); | 4453 UPB_ASSERT(findentry(t, key, hash, eql) == NULL); |
4169 UPB_UNUSED(key); | 4454 UPB_ASSERT_DEBUGVAR(val.ctype == t->ctype); |
4170 assert(findentry(t, key, hash, eql) == NULL); | |
4171 assert(val.ctype == t->ctype); | |
4172 | 4455 |
4173 t->count++; | 4456 t->count++; |
4174 mainpos_e = getentry_mutable(t, hash); | 4457 mainpos_e = getentry_mutable(t, hash); |
4175 our_e = mainpos_e; | 4458 our_e = mainpos_e; |
4176 | 4459 |
4177 if (upb_tabent_isempty(mainpos_e)) { | 4460 if (upb_tabent_isempty(mainpos_e)) { |
4178 /* Our main position is empty; use it. */ | 4461 /* Our main position is empty; use it. */ |
4179 our_e->next = NULL; | 4462 our_e->next = NULL; |
4180 } else { | 4463 } else { |
4181 /* Collision. */ | 4464 /* Collision. */ |
4182 upb_tabent *new_e = emptyent(t); | 4465 upb_tabent *new_e = emptyent(t); |
4183 /* Head of collider's chain. */ | 4466 /* Head of collider's chain. */ |
4184 upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key)); | 4467 upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key)); |
4185 if (chain == mainpos_e) { | 4468 if (chain == mainpos_e) { |
4186 /* Existing ent is in its main posisiton (it has the same hash as us, and | 4469 /* Existing ent is in its main posisiton (it has the same hash as us, and |
4187 * is the head of our chain). Insert to new ent and append to this chain.
*/ | 4470 * is the head of our chain). Insert to new ent and append to this chain.
*/ |
4188 new_e->next = mainpos_e->next; | 4471 new_e->next = mainpos_e->next; |
4189 mainpos_e->next = new_e; | 4472 mainpos_e->next = new_e; |
4190 our_e = new_e; | 4473 our_e = new_e; |
4191 } else { | 4474 } else { |
4192 /* Existing ent is not in its main position (it is a node in some other | 4475 /* Existing ent is not in its main position (it is a node in some other |
4193 * chain). This implies that no existing ent in the table has our hash. | 4476 * chain). This implies that no existing ent in the table has our hash. |
4194 * Evict it (updating its chain) and use its ent for head of our chain. */ | 4477 * Evict it (updating its chain) and use its ent for head of our chain. */ |
4195 *new_e = *mainpos_e; /* copies next. */ | 4478 *new_e = *mainpos_e; /* copies next. */ |
4196 while (chain->next != mainpos_e) { | 4479 while (chain->next != mainpos_e) { |
4197 chain = (upb_tabent*)chain->next; | 4480 chain = (upb_tabent*)chain->next; |
4198 assert(chain); | 4481 UPB_ASSERT(chain); |
4199 } | 4482 } |
4200 chain->next = new_e; | 4483 chain->next = new_e; |
4201 our_e = mainpos_e; | 4484 our_e = mainpos_e; |
4202 our_e->next = NULL; | 4485 our_e->next = NULL; |
4203 } | 4486 } |
4204 } | 4487 } |
4205 our_e->key = tabkey; | 4488 our_e->key = tabkey; |
4206 our_e->val.val = val.val; | 4489 our_e->val.val = val.val; |
4207 assert(findentry(t, key, hash, eql) == our_e); | 4490 UPB_ASSERT(findentry(t, key, hash, eql) == our_e); |
4208 } | 4491 } |
4209 | 4492 |
4210 static bool rm(upb_table *t, lookupkey_t key, upb_value *val, | 4493 static bool rm(upb_table *t, lookupkey_t key, upb_value *val, |
4211 upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) { | 4494 upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) { |
4212 upb_tabent *chain = getentry_mutable(t, hash); | 4495 upb_tabent *chain = getentry_mutable(t, hash); |
4213 if (upb_tabent_isempty(chain)) return false; | 4496 if (upb_tabent_isempty(chain)) return false; |
4214 if (eql(chain->key, key)) { | 4497 if (eql(chain->key, key)) { |
4215 /* Element to remove is at the head of its chain. */ | 4498 /* Element to remove is at the head of its chain. */ |
4216 t->count--; | 4499 t->count--; |
4217 if (val) { | 4500 if (val) _upb_value_setval(val, chain->val.val, t->ctype); |
4218 _upb_value_setval(val, chain->val.val, t->ctype); | 4501 if (removed) *removed = chain->key; |
4219 } | |
4220 if (chain->next) { | 4502 if (chain->next) { |
4221 upb_tabent *move = (upb_tabent*)chain->next; | 4503 upb_tabent *move = (upb_tabent*)chain->next; |
4222 *chain = *move; | 4504 *chain = *move; |
4223 if (removed) *removed = move->key; | |
4224 move->key = 0; /* Make the slot empty. */ | 4505 move->key = 0; /* Make the slot empty. */ |
4225 } else { | 4506 } else { |
4226 if (removed) *removed = chain->key; | |
4227 chain->key = 0; /* Make the slot empty. */ | 4507 chain->key = 0; /* Make the slot empty. */ |
4228 } | 4508 } |
4229 return true; | 4509 return true; |
4230 } else { | 4510 } else { |
4231 /* Element to remove is either in a non-head position or not in the | 4511 /* Element to remove is either in a non-head position or not in the |
4232 * table. */ | 4512 * table. */ |
4233 while (chain->next && !eql(chain->next->key, key)) | 4513 while (chain->next && !eql(chain->next->key, key)) { |
4234 chain = (upb_tabent*)chain->next; | 4514 chain = (upb_tabent*)chain->next; |
| 4515 } |
4235 if (chain->next) { | 4516 if (chain->next) { |
4236 /* Found element to remove. */ | 4517 /* Found element to remove. */ |
4237 upb_tabent *rm; | 4518 upb_tabent *rm = (upb_tabent*)chain->next; |
4238 | 4519 t->count--; |
4239 if (val) { | 4520 if (val) _upb_value_setval(val, chain->next->val.val, t->ctype); |
4240 _upb_value_setval(val, chain->next->val.val, t->ctype); | |
4241 } | |
4242 rm = (upb_tabent*)chain->next; | |
4243 if (removed) *removed = rm->key; | 4521 if (removed) *removed = rm->key; |
4244 rm->key = 0; | 4522 rm->key = 0; /* Make the slot empty. */ |
4245 chain->next = rm->next; | 4523 chain->next = rm->next; |
4246 t->count--; | |
4247 return true; | 4524 return true; |
4248 } else { | 4525 } else { |
| 4526 /* Element to remove is not in the table. */ |
4249 return false; | 4527 return false; |
4250 } | 4528 } |
4251 } | 4529 } |
4252 } | 4530 } |
4253 | 4531 |
4254 static size_t next(const upb_table *t, size_t i) { | 4532 static size_t next(const upb_table *t, size_t i) { |
4255 do { | 4533 do { |
4256 if (++i >= upb_table_size(t)) | 4534 if (++i >= upb_table_size(t)) |
4257 return SIZE_MAX; | 4535 return SIZE_MAX; |
4258 } while(upb_tabent_isempty(&t->entries[i])); | 4536 } while(upb_tabent_isempty(&t->entries[i])); |
4259 | 4537 |
4260 return i; | 4538 return i; |
4261 } | 4539 } |
4262 | 4540 |
4263 static size_t begin(const upb_table *t) { | 4541 static size_t begin(const upb_table *t) { |
4264 return next(t, -1); | 4542 return next(t, -1); |
4265 } | 4543 } |
4266 | 4544 |
4267 | 4545 |
4268 /* upb_strtable ***************************************************************/ | 4546 /* upb_strtable ***************************************************************/ |
4269 | 4547 |
4270 /* A simple "subclass" of upb_table that only adds a hash function for strings.
*/ | 4548 /* A simple "subclass" of upb_table that only adds a hash function for strings.
*/ |
4271 | 4549 |
4272 static upb_tabkey strcopy(lookupkey_t k2) { | 4550 static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { |
4273 char *str = malloc(k2.str.len + sizeof(uint32_t) + 1); | 4551 char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1); |
4274 if (str == NULL) return 0; | 4552 if (str == NULL) return 0; |
4275 memcpy(str, &k2.str.len, sizeof(uint32_t)); | 4553 memcpy(str, &k2.str.len, sizeof(uint32_t)); |
4276 memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); | 4554 memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); |
4277 return (uintptr_t)str; | 4555 return (uintptr_t)str; |
4278 } | 4556 } |
4279 | 4557 |
4280 static uint32_t strhash(upb_tabkey key) { | 4558 static uint32_t strhash(upb_tabkey key) { |
4281 uint32_t len; | 4559 uint32_t len; |
4282 char *str = upb_tabstr(key, &len); | 4560 char *str = upb_tabstr(key, &len); |
4283 return MurmurHash2(str, len, 0); | 4561 return MurmurHash2(str, len, 0); |
4284 } | 4562 } |
4285 | 4563 |
4286 static bool streql(upb_tabkey k1, lookupkey_t k2) { | 4564 static bool streql(upb_tabkey k1, lookupkey_t k2) { |
4287 uint32_t len; | 4565 uint32_t len; |
4288 char *str = upb_tabstr(k1, &len); | 4566 char *str = upb_tabstr(k1, &len); |
4289 return len == k2.str.len && memcmp(str, k2.str.str, len) == 0; | 4567 return len == k2.str.len && memcmp(str, k2.str.str, len) == 0; |
4290 } | 4568 } |
4291 | 4569 |
4292 bool upb_strtable_init(upb_strtable *t, upb_ctype_t ctype) { | 4570 bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) { |
4293 return init(&t->t, ctype, 2); | 4571 return init(&t->t, ctype, 2, a); |
4294 } | 4572 } |
4295 | 4573 |
4296 void upb_strtable_uninit(upb_strtable *t) { | 4574 void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) { |
4297 size_t i; | 4575 size_t i; |
4298 for (i = 0; i < upb_table_size(&t->t); i++) | 4576 for (i = 0; i < upb_table_size(&t->t); i++) |
4299 free((void*)t->t.entries[i].key); | 4577 upb_free(a, (void*)t->t.entries[i].key); |
4300 uninit(&t->t); | 4578 uninit(&t->t, a); |
4301 } | 4579 } |
4302 | 4580 |
4303 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2) { | 4581 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) { |
4304 upb_strtable new_table; | 4582 upb_strtable new_table; |
4305 upb_strtable_iter i; | 4583 upb_strtable_iter i; |
4306 | 4584 |
4307 if (!init(&new_table.t, t->t.ctype, size_lg2)) | 4585 upb_check_alloc(&t->t, a); |
| 4586 |
| 4587 if (!init(&new_table.t, t->t.ctype, size_lg2, a)) |
4308 return false; | 4588 return false; |
4309 upb_strtable_begin(&i, t); | 4589 upb_strtable_begin(&i, t); |
4310 for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { | 4590 for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { |
4311 upb_strtable_insert2( | 4591 upb_strtable_insert3( |
4312 &new_table, | 4592 &new_table, |
4313 upb_strtable_iter_key(&i), | 4593 upb_strtable_iter_key(&i), |
4314 upb_strtable_iter_keylength(&i), | 4594 upb_strtable_iter_keylength(&i), |
4315 upb_strtable_iter_value(&i)); | 4595 upb_strtable_iter_value(&i), |
| 4596 a); |
4316 } | 4597 } |
4317 upb_strtable_uninit(t); | 4598 upb_strtable_uninit2(t, a); |
4318 *t = new_table; | 4599 *t = new_table; |
4319 return true; | 4600 return true; |
4320 } | 4601 } |
4321 | 4602 |
4322 bool upb_strtable_insert2(upb_strtable *t, const char *k, size_t len, | 4603 bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len, |
4323 upb_value v) { | 4604 upb_value v, upb_alloc *a) { |
4324 lookupkey_t key; | 4605 lookupkey_t key; |
4325 upb_tabkey tabkey; | 4606 upb_tabkey tabkey; |
4326 uint32_t hash; | 4607 uint32_t hash; |
4327 | 4608 |
| 4609 upb_check_alloc(&t->t, a); |
| 4610 |
4328 if (isfull(&t->t)) { | 4611 if (isfull(&t->t)) { |
4329 /* Need to resize. New table of double the size, add old elements to it. */ | 4612 /* 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)) { | 4613 if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { |
4331 return false; | 4614 return false; |
4332 } | 4615 } |
4333 } | 4616 } |
4334 | 4617 |
4335 key = strkey2(k, len); | 4618 key = strkey2(k, len); |
4336 tabkey = strcopy(key); | 4619 tabkey = strcopy(key, a); |
4337 if (tabkey == 0) return false; | 4620 if (tabkey == 0) return false; |
4338 | 4621 |
4339 hash = MurmurHash2(key.str.str, key.str.len, 0); | 4622 hash = MurmurHash2(key.str.str, key.str.len, 0); |
4340 insert(&t->t, key, tabkey, v, hash, &strhash, &streql); | 4623 insert(&t->t, key, tabkey, v, hash, &strhash, &streql); |
4341 return true; | 4624 return true; |
4342 } | 4625 } |
4343 | 4626 |
4344 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, | 4627 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, |
4345 upb_value *v) { | 4628 upb_value *v) { |
4346 uint32_t hash = MurmurHash2(key, len, 0); | 4629 uint32_t hash = MurmurHash2(key, len, 0); |
4347 return lookup(&t->t, strkey2(key, len), v, hash, &streql); | 4630 return lookup(&t->t, strkey2(key, len), v, hash, &streql); |
4348 } | 4631 } |
4349 | 4632 |
4350 bool upb_strtable_remove2(upb_strtable *t, const char *key, size_t len, | 4633 bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len, |
4351 upb_value *val) { | 4634 upb_value *val, upb_alloc *alloc) { |
4352 uint32_t hash = MurmurHash2(key, strlen(key), 0); | 4635 uint32_t hash = MurmurHash2(key, len, 0); |
4353 upb_tabkey tabkey; | 4636 upb_tabkey tabkey; |
4354 if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) { | 4637 if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) { |
4355 free((void*)tabkey); | 4638 upb_free(alloc, (void*)tabkey); |
4356 return true; | 4639 return true; |
4357 } else { | 4640 } else { |
4358 return false; | 4641 return false; |
4359 } | 4642 } |
4360 } | 4643 } |
4361 | 4644 |
4362 /* Iteration */ | 4645 /* Iteration */ |
4363 | 4646 |
4364 static const upb_tabent *str_tabent(const upb_strtable_iter *i) { | 4647 static const upb_tabent *str_tabent(const upb_strtable_iter *i) { |
4365 return &i->t->t.entries[i->index]; | 4648 return &i->t->t.entries[i->index]; |
4366 } | 4649 } |
4367 | 4650 |
4368 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) { | 4651 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) { |
4369 i->t = t; | 4652 i->t = t; |
4370 i->index = begin(&t->t); | 4653 i->index = begin(&t->t); |
4371 } | 4654 } |
4372 | 4655 |
4373 void upb_strtable_next(upb_strtable_iter *i) { | 4656 void upb_strtable_next(upb_strtable_iter *i) { |
4374 i->index = next(&i->t->t, i->index); | 4657 i->index = next(&i->t->t, i->index); |
4375 } | 4658 } |
4376 | 4659 |
4377 bool upb_strtable_done(const upb_strtable_iter *i) { | 4660 bool upb_strtable_done(const upb_strtable_iter *i) { |
4378 return i->index >= upb_table_size(&i->t->t) || | 4661 return i->index >= upb_table_size(&i->t->t) || |
4379 upb_tabent_isempty(str_tabent(i)); | 4662 upb_tabent_isempty(str_tabent(i)); |
4380 } | 4663 } |
4381 | 4664 |
4382 const char *upb_strtable_iter_key(upb_strtable_iter *i) { | 4665 const char *upb_strtable_iter_key(const upb_strtable_iter *i) { |
4383 assert(!upb_strtable_done(i)); | 4666 UPB_ASSERT(!upb_strtable_done(i)); |
4384 return upb_tabstr(str_tabent(i)->key, NULL); | 4667 return upb_tabstr(str_tabent(i)->key, NULL); |
4385 } | 4668 } |
4386 | 4669 |
4387 size_t upb_strtable_iter_keylength(upb_strtable_iter *i) { | 4670 size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) { |
4388 uint32_t len; | 4671 uint32_t len; |
4389 assert(!upb_strtable_done(i)); | 4672 UPB_ASSERT(!upb_strtable_done(i)); |
4390 upb_tabstr(str_tabent(i)->key, &len); | 4673 upb_tabstr(str_tabent(i)->key, &len); |
4391 return len; | 4674 return len; |
4392 } | 4675 } |
4393 | 4676 |
4394 upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { | 4677 upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { |
4395 assert(!upb_strtable_done(i)); | 4678 UPB_ASSERT(!upb_strtable_done(i)); |
4396 return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype); | 4679 return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype); |
4397 } | 4680 } |
4398 | 4681 |
4399 void upb_strtable_iter_setdone(upb_strtable_iter *i) { | 4682 void upb_strtable_iter_setdone(upb_strtable_iter *i) { |
4400 i->index = SIZE_MAX; | 4683 i->index = SIZE_MAX; |
4401 } | 4684 } |
4402 | 4685 |
4403 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, | 4686 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, |
4404 const upb_strtable_iter *i2) { | 4687 const upb_strtable_iter *i2) { |
4405 if (upb_strtable_done(i1) && upb_strtable_done(i2)) | 4688 if (upb_strtable_done(i1) && upb_strtable_done(i2)) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4444 | 4727 |
4445 static void check(upb_inttable *t) { | 4728 static void check(upb_inttable *t) { |
4446 UPB_UNUSED(t); | 4729 UPB_UNUSED(t); |
4447 #if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) | 4730 #if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) |
4448 { | 4731 { |
4449 /* This check is very expensive (makes inserts/deletes O(N)). */ | 4732 /* This check is very expensive (makes inserts/deletes O(N)). */ |
4450 size_t count = 0; | 4733 size_t count = 0; |
4451 upb_inttable_iter i; | 4734 upb_inttable_iter i; |
4452 upb_inttable_begin(&i, t); | 4735 upb_inttable_begin(&i, t); |
4453 for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { | 4736 for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { |
4454 assert(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL)); | 4737 UPB_ASSERT(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL)); |
4455 } | 4738 } |
4456 assert(count == upb_inttable_count(t)); | 4739 UPB_ASSERT(count == upb_inttable_count(t)); |
4457 } | 4740 } |
4458 #endif | 4741 #endif |
4459 } | 4742 } |
4460 | 4743 |
4461 bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, | 4744 bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, |
4462 size_t asize, int hsize_lg2) { | 4745 size_t asize, int hsize_lg2, upb_alloc *a) { |
4463 size_t array_bytes; | 4746 size_t array_bytes; |
4464 | 4747 |
4465 if (!init(&t->t, ctype, hsize_lg2)) return false; | 4748 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 | 4749 /* 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. */ | 4750 * won't be in the hash part, which simplifies things. */ |
4468 t->array_size = UPB_MAX(1, asize); | 4751 t->array_size = UPB_MAX(1, asize); |
4469 t->array_count = 0; | 4752 t->array_count = 0; |
4470 array_bytes = t->array_size * sizeof(upb_value); | 4753 array_bytes = t->array_size * sizeof(upb_value); |
4471 t->array = malloc(array_bytes); | 4754 t->array = upb_malloc(a, array_bytes); |
4472 if (!t->array) { | 4755 if (!t->array) { |
4473 uninit(&t->t); | 4756 uninit(&t->t, a); |
4474 return false; | 4757 return false; |
4475 } | 4758 } |
4476 memset(mutable_array(t), 0xff, array_bytes); | 4759 memset(mutable_array(t), 0xff, array_bytes); |
4477 check(t); | 4760 check(t); |
4478 return true; | 4761 return true; |
4479 } | 4762 } |
4480 | 4763 |
4481 bool upb_inttable_init(upb_inttable *t, upb_ctype_t ctype) { | 4764 bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) { |
4482 return upb_inttable_sizedinit(t, ctype, 0, 4); | 4765 return upb_inttable_sizedinit(t, ctype, 0, 4, a); |
4483 } | 4766 } |
4484 | 4767 |
4485 void upb_inttable_uninit(upb_inttable *t) { | 4768 void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) { |
4486 uninit(&t->t); | 4769 uninit(&t->t, a); |
4487 free(mutable_array(t)); | 4770 upb_free(a, mutable_array(t)); |
4488 } | 4771 } |
4489 | 4772 |
4490 bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val) { | 4773 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 | 4774 upb_alloc *a) { |
4492 * guarantee that this is not necessary, or fix the limitation. */ | |
4493 upb_tabval tabval; | 4775 upb_tabval tabval; |
4494 tabval.val = val.val; | 4776 tabval.val = val.val; |
4495 UPB_UNUSED(tabval); | 4777 UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this.
*/ |
4496 assert(upb_arrhas(tabval)); | 4778 |
| 4779 upb_check_alloc(&t->t, a); |
4497 | 4780 |
4498 if (key < t->array_size) { | 4781 if (key < t->array_size) { |
4499 assert(!upb_arrhas(t->array[key])); | 4782 UPB_ASSERT(!upb_arrhas(t->array[key])); |
4500 t->array_count++; | 4783 t->array_count++; |
4501 mutable_array(t)[key].val = val.val; | 4784 mutable_array(t)[key].val = val.val; |
4502 } else { | 4785 } else { |
4503 if (isfull(&t->t)) { | 4786 if (isfull(&t->t)) { |
4504 /* Need to resize the hash part, but we re-use the array part. */ | 4787 /* Need to resize the hash part, but we re-use the array part. */ |
4505 size_t i; | 4788 size_t i; |
4506 upb_table new_table; | 4789 upb_table new_table; |
4507 if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1)) | 4790 |
| 4791 if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) { |
4508 return false; | 4792 return false; |
| 4793 } |
| 4794 |
4509 for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { | 4795 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]; | 4796 const upb_tabent *e = &t->t.entries[i]; |
4511 uint32_t hash; | 4797 uint32_t hash; |
4512 upb_value v; | 4798 upb_value v; |
4513 | 4799 |
4514 _upb_value_setval(&v, e->val.val, t->t.ctype); | 4800 _upb_value_setval(&v, e->val.val, t->t.ctype); |
4515 hash = upb_inthash(e->key); | 4801 hash = upb_inthash(e->key); |
4516 insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); | 4802 insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); |
4517 } | 4803 } |
4518 | 4804 |
4519 assert(t->t.count == new_table.count); | 4805 UPB_ASSERT(t->t.count == new_table.count); |
4520 | 4806 |
4521 uninit(&t->t); | 4807 uninit(&t->t, a); |
4522 t->t = new_table; | 4808 t->t = new_table; |
4523 } | 4809 } |
4524 insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); | 4810 insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); |
4525 } | 4811 } |
4526 check(t); | 4812 check(t); |
4527 return true; | 4813 return true; |
4528 } | 4814 } |
4529 | 4815 |
4530 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) { | 4816 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); | 4817 const upb_tabval *table_v = inttable_val_const(t, key); |
(...skipping 17 matching lines...) Expand all Loading... |
4549 t->array_count--; | 4835 t->array_count--; |
4550 if (val) { | 4836 if (val) { |
4551 _upb_value_setval(val, t->array[key].val, t->t.ctype); | 4837 _upb_value_setval(val, t->array[key].val, t->t.ctype); |
4552 } | 4838 } |
4553 mutable_array(t)[key] = empty; | 4839 mutable_array(t)[key] = empty; |
4554 success = true; | 4840 success = true; |
4555 } else { | 4841 } else { |
4556 success = false; | 4842 success = false; |
4557 } | 4843 } |
4558 } else { | 4844 } else { |
4559 upb_tabkey removed; | 4845 success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql); |
4560 uint32_t hash = upb_inthash(key); | |
4561 success = rm(&t->t, intkey(key), val, &removed, hash, &inteql); | |
4562 } | 4846 } |
4563 check(t); | 4847 check(t); |
4564 return success; | 4848 return success; |
4565 } | 4849 } |
4566 | 4850 |
4567 bool upb_inttable_push(upb_inttable *t, upb_value val) { | 4851 bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) { |
4568 return upb_inttable_insert(t, upb_inttable_count(t), val); | 4852 upb_check_alloc(&t->t, a); |
| 4853 return upb_inttable_insert2(t, upb_inttable_count(t), val, a); |
4569 } | 4854 } |
4570 | 4855 |
4571 upb_value upb_inttable_pop(upb_inttable *t) { | 4856 upb_value upb_inttable_pop(upb_inttable *t) { |
4572 upb_value val; | 4857 upb_value val; |
4573 bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val); | 4858 bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val); |
4574 UPB_ASSERT_VAR(ok, ok); | 4859 UPB_ASSERT(ok); |
4575 return val; | 4860 return val; |
4576 } | 4861 } |
4577 | 4862 |
4578 bool upb_inttable_insertptr(upb_inttable *t, const void *key, upb_value val) { | 4863 bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val, |
4579 return upb_inttable_insert(t, (uintptr_t)key, val); | 4864 upb_alloc *a) { |
| 4865 upb_check_alloc(&t->t, a); |
| 4866 return upb_inttable_insert2(t, (uintptr_t)key, val, a); |
4580 } | 4867 } |
4581 | 4868 |
4582 bool upb_inttable_lookupptr(const upb_inttable *t, const void *key, | 4869 bool upb_inttable_lookupptr(const upb_inttable *t, const void *key, |
4583 upb_value *v) { | 4870 upb_value *v) { |
4584 return upb_inttable_lookup(t, (uintptr_t)key, v); | 4871 return upb_inttable_lookup(t, (uintptr_t)key, v); |
4585 } | 4872 } |
4586 | 4873 |
4587 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) { | 4874 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) { |
4588 return upb_inttable_remove(t, (uintptr_t)key, val); | 4875 return upb_inttable_remove(t, (uintptr_t)key, val); |
4589 } | 4876 } |
4590 | 4877 |
4591 void upb_inttable_compact(upb_inttable *t) { | 4878 void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) { |
4592 /* Create a power-of-two histogram of the table keys. */ | 4879 /* A power-of-two histogram of the table keys. */ |
4593 int counts[UPB_MAXARRSIZE + 1] = {0}; | 4880 size_t counts[UPB_MAXARRSIZE + 1] = {0}; |
4594 uintptr_t max_key = 0; | 4881 |
| 4882 /* The max key in each bucket. */ |
| 4883 uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; |
| 4884 |
4595 upb_inttable_iter i; | 4885 upb_inttable_iter i; |
4596 size_t arr_size; | 4886 size_t arr_count; |
4597 int arr_count; | 4887 int size_lg2; |
4598 upb_inttable new_t; | 4888 upb_inttable new_t; |
4599 | 4889 |
| 4890 upb_check_alloc(&t->t, a); |
| 4891 |
4600 upb_inttable_begin(&i, t); | 4892 upb_inttable_begin(&i, t); |
4601 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 4893 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
4602 uintptr_t key = upb_inttable_iter_key(&i); | 4894 uintptr_t key = upb_inttable_iter_key(&i); |
4603 if (key > max_key) { | 4895 int bucket = log2ceil(key); |
4604 max_key = key; | 4896 max[bucket] = UPB_MAX(max[bucket], key); |
4605 } | 4897 counts[bucket]++; |
4606 counts[log2ceil(key)]++; | |
4607 } | 4898 } |
4608 | 4899 |
4609 arr_size = 1; | 4900 /* Find the largest power of two that satisfies the MIN_DENSITY |
| 4901 * definition (while actually having some keys). */ |
4610 arr_count = upb_inttable_count(t); | 4902 arr_count = upb_inttable_count(t); |
4611 | 4903 |
4612 if (upb_inttable_count(t) >= max_key * MIN_DENSITY) { | 4904 for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { |
4613 /* We can put 100% of the entries in the array part. */ | 4905 if (counts[size_lg2] == 0) { |
4614 arr_size = max_key + 1; | 4906 /* We can halve again without losing any entries. */ |
4615 } else { | 4907 continue; |
4616 /* Find the largest power of two that satisfies the MIN_DENSITY | 4908 } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { |
4617 * definition. */ | 4909 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 } | 4910 } |
| 4911 |
| 4912 arr_count -= counts[size_lg2]; |
4626 } | 4913 } |
4627 | 4914 |
4628 /* Array part must always be at least 1 entry large to catch lookups of key | 4915 UPB_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 | 4916 |
4633 { | 4917 { |
4634 /* Insert all elements into new, perfectly-sized table. */ | 4918 /* Insert all elements into new, perfectly-sized table. */ |
4635 int hash_count = upb_inttable_count(t) - arr_count; | 4919 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; | 4920 size_t hash_count = upb_inttable_count(t) - arr_count; |
4637 int hashsize_lg2 = log2ceil(hash_size); | 4921 size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; |
| 4922 size_t hashsize_lg2 = log2ceil(hash_size); |
4638 | 4923 |
4639 assert(hash_count >= 0); | 4924 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); | 4925 upb_inttable_begin(&i, t); |
4642 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 4926 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
4643 uintptr_t k = upb_inttable_iter_key(&i); | 4927 uintptr_t k = upb_inttable_iter_key(&i); |
4644 upb_inttable_insert(&new_t, k, upb_inttable_iter_value(&i)); | 4928 upb_inttable_insert2(&new_t, k, upb_inttable_iter_value(&i), a); |
4645 } | 4929 } |
4646 assert(new_t.array_size == arr_size); | 4930 UPB_ASSERT(new_t.array_size == arr_size); |
4647 assert(new_t.t.size_lg2 == hashsize_lg2); | 4931 UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2); |
4648 } | 4932 } |
4649 upb_inttable_uninit(t); | 4933 upb_inttable_uninit2(t, a); |
4650 *t = new_t; | 4934 *t = new_t; |
4651 } | 4935 } |
4652 | 4936 |
4653 /* Iteration. */ | 4937 /* Iteration. */ |
4654 | 4938 |
4655 static const upb_tabent *int_tabent(const upb_inttable_iter *i) { | 4939 static const upb_tabent *int_tabent(const upb_inttable_iter *i) { |
4656 assert(!i->array_part); | 4940 UPB_ASSERT(!i->array_part); |
4657 return &i->t->t.entries[i->index]; | 4941 return &i->t->t.entries[i->index]; |
4658 } | 4942 } |
4659 | 4943 |
4660 static upb_tabval int_arrent(const upb_inttable_iter *i) { | 4944 static upb_tabval int_arrent(const upb_inttable_iter *i) { |
4661 assert(i->array_part); | 4945 UPB_ASSERT(i->array_part); |
4662 return i->t->array[i->index]; | 4946 return i->t->array[i->index]; |
4663 } | 4947 } |
4664 | 4948 |
4665 void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) { | 4949 void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) { |
4666 i->t = t; | 4950 i->t = t; |
4667 i->index = -1; | 4951 i->index = -1; |
4668 i->array_part = true; | 4952 i->array_part = true; |
4669 upb_inttable_next(i); | 4953 upb_inttable_next(i); |
4670 } | 4954 } |
4671 | 4955 |
(...skipping 16 matching lines...) Expand all Loading... |
4688 if (i->array_part) { | 4972 if (i->array_part) { |
4689 return i->index >= i->t->array_size || | 4973 return i->index >= i->t->array_size || |
4690 !upb_arrhas(int_arrent(i)); | 4974 !upb_arrhas(int_arrent(i)); |
4691 } else { | 4975 } else { |
4692 return i->index >= upb_table_size(&i->t->t) || | 4976 return i->index >= upb_table_size(&i->t->t) || |
4693 upb_tabent_isempty(int_tabent(i)); | 4977 upb_tabent_isempty(int_tabent(i)); |
4694 } | 4978 } |
4695 } | 4979 } |
4696 | 4980 |
4697 uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) { | 4981 uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) { |
4698 assert(!upb_inttable_done(i)); | 4982 UPB_ASSERT(!upb_inttable_done(i)); |
4699 return i->array_part ? i->index : int_tabent(i)->key; | 4983 return i->array_part ? i->index : int_tabent(i)->key; |
4700 } | 4984 } |
4701 | 4985 |
4702 upb_value upb_inttable_iter_value(const upb_inttable_iter *i) { | 4986 upb_value upb_inttable_iter_value(const upb_inttable_iter *i) { |
4703 assert(!upb_inttable_done(i)); | 4987 UPB_ASSERT(!upb_inttable_done(i)); |
4704 return _upb_value_val( | 4988 return _upb_value_val( |
4705 i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val, | 4989 i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val, |
4706 i->t->t.ctype); | 4990 i->t->t.ctype); |
4707 } | 4991 } |
4708 | 4992 |
4709 void upb_inttable_iter_setdone(upb_inttable_iter *i) { | 4993 void upb_inttable_iter_setdone(upb_inttable_iter *i) { |
4710 i->index = SIZE_MAX; | 4994 i->index = SIZE_MAX; |
4711 i->array_part = false; | 4995 i->array_part = false; |
4712 } | 4996 } |
4713 | 4997 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4911 return false; | 5195 return false; |
4912 } | 5196 } |
4913 | 5197 |
4914 /* Guarantee null-termination and provide ellipsis truncation. | 5198 /* Guarantee null-termination and provide ellipsis truncation. |
4915 * It may be tempting to "optimize" this by initializing these final | 5199 * It may be tempting to "optimize" this by initializing these final |
4916 * four bytes up-front and then being careful never to overwrite them, | 5200 * four bytes up-front and then being careful never to overwrite them, |
4917 * this is safer and simpler. */ | 5201 * this is safer and simpler. */ |
4918 static void nullz(upb_status *status) { | 5202 static void nullz(upb_status *status) { |
4919 const char *ellipsis = "..."; | 5203 const char *ellipsis = "..."; |
4920 size_t len = strlen(ellipsis); | 5204 size_t len = strlen(ellipsis); |
4921 assert(sizeof(status->msg) > len); | 5205 UPB_ASSERT(sizeof(status->msg) > len); |
4922 memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); | 5206 memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); |
4923 } | 5207 } |
4924 | 5208 |
| 5209 |
| 5210 /* upb_upberr *****************************************************************/ |
| 5211 |
| 5212 upb_errorspace upb_upberr = {"upb error"}; |
| 5213 |
| 5214 void upb_upberr_setoom(upb_status *status) { |
| 5215 status->error_space_ = &upb_upberr; |
| 5216 upb_status_seterrmsg(status, "Out of memory"); |
| 5217 } |
| 5218 |
| 5219 |
| 5220 /* upb_status *****************************************************************/ |
| 5221 |
4925 void upb_status_clear(upb_status *status) { | 5222 void upb_status_clear(upb_status *status) { |
4926 if (!status) return; | 5223 if (!status) return; |
4927 status->ok_ = true; | 5224 status->ok_ = true; |
4928 status->code_ = 0; | 5225 status->code_ = 0; |
4929 status->msg[0] = '\0'; | 5226 status->msg[0] = '\0'; |
4930 } | 5227 } |
4931 | 5228 |
4932 bool upb_ok(const upb_status *status) { return status->ok_; } | 5229 bool upb_ok(const upb_status *status) { return status->ok_; } |
4933 | 5230 |
4934 upb_errorspace *upb_status_errspace(const upb_status *status) { | 5231 upb_errorspace *upb_status_errspace(const upb_status *status) { |
(...skipping 18 matching lines...) Expand all Loading... |
4953 va_end(args); | 5250 va_end(args); |
4954 } | 5251 } |
4955 | 5252 |
4956 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { | 5253 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { |
4957 if (!status) return; | 5254 if (!status) return; |
4958 status->ok_ = false; | 5255 status->ok_ = false; |
4959 _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); | 5256 _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); |
4960 nullz(status); | 5257 nullz(status); |
4961 } | 5258 } |
4962 | 5259 |
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) { | 5260 void upb_status_copy(upb_status *to, const upb_status *from) { |
4973 if (!to) return; | 5261 if (!to) return; |
4974 *to = *from; | 5262 *to = *from; |
4975 } | 5263 } |
4976 /* This file was generated by upbc (the upb compiler). | 5264 |
| 5265 |
| 5266 /* upb_alloc ******************************************************************/ |
| 5267 |
| 5268 static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize, |
| 5269 size_t size) { |
| 5270 UPB_UNUSED(alloc); |
| 5271 UPB_UNUSED(oldsize); |
| 5272 if (size == 0) { |
| 5273 free(ptr); |
| 5274 return NULL; |
| 5275 } else { |
| 5276 return realloc(ptr, size); |
| 5277 } |
| 5278 } |
| 5279 |
| 5280 upb_alloc upb_alloc_global = {&upb_global_allocfunc}; |
| 5281 |
| 5282 |
| 5283 /* upb_arena ******************************************************************/ |
| 5284 |
| 5285 /* Be conservative and choose 16 in case anyone is using SSE. */ |
| 5286 static const size_t maxalign = 16; |
| 5287 |
| 5288 static size_t align_up(size_t size) { |
| 5289 return ((size + maxalign - 1) / maxalign) * maxalign; |
| 5290 } |
| 5291 |
| 5292 typedef struct mem_block { |
| 5293 struct mem_block *next; |
| 5294 size_t size; |
| 5295 size_t used; |
| 5296 bool owned; |
| 5297 /* Data follows. */ |
| 5298 } mem_block; |
| 5299 |
| 5300 typedef struct cleanup_ent { |
| 5301 struct cleanup_ent *next; |
| 5302 upb_cleanup_func *cleanup; |
| 5303 void *ud; |
| 5304 } cleanup_ent; |
| 5305 |
| 5306 static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size, |
| 5307 bool owned) { |
| 5308 mem_block *block = ptr; |
| 5309 |
| 5310 block->next = a->block_head; |
| 5311 block->size = size; |
| 5312 block->used = align_up(sizeof(mem_block)); |
| 5313 block->owned = owned; |
| 5314 |
| 5315 a->block_head = block; |
| 5316 |
| 5317 /* TODO(haberman): ASAN poison. */ |
| 5318 } |
| 5319 |
| 5320 |
| 5321 static mem_block *upb_arena_allocblock(upb_arena *a, size_t size) { |
| 5322 size_t block_size = UPB_MAX(size, a->next_block_size) + sizeof(mem_block); |
| 5323 mem_block *block = upb_malloc(a->block_alloc, block_size); |
| 5324 |
| 5325 if (!block) { |
| 5326 return NULL; |
| 5327 } |
| 5328 |
| 5329 upb_arena_addblock(a, block, block_size, true); |
| 5330 a->next_block_size = UPB_MIN(block_size * 2, a->max_block_size); |
| 5331 |
| 5332 return block; |
| 5333 } |
| 5334 |
| 5335 static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize, |
| 5336 size_t size) { |
| 5337 upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */ |
| 5338 mem_block *block = a->block_head; |
| 5339 void *ret; |
| 5340 |
| 5341 if (size == 0) { |
| 5342 return NULL; /* We are an arena, don't need individual frees. */ |
| 5343 } |
| 5344 |
| 5345 size = align_up(size); |
| 5346 |
| 5347 /* TODO(haberman): special-case if this is a realloc of the last alloc? */ |
| 5348 |
| 5349 if (!block || block->size - block->used < size) { |
| 5350 /* Slow path: have to allocate a new block. */ |
| 5351 block = upb_arena_allocblock(a, size); |
| 5352 |
| 5353 if (!block) { |
| 5354 return NULL; /* Out of memory. */ |
| 5355 } |
| 5356 } |
| 5357 |
| 5358 ret = (char*)block + block->used; |
| 5359 block->used += size; |
| 5360 |
| 5361 if (oldsize > 0) { |
| 5362 memcpy(ret, ptr, oldsize); /* Preserve existing data. */ |
| 5363 } |
| 5364 |
| 5365 /* TODO(haberman): ASAN unpoison. */ |
| 5366 |
| 5367 a->bytes_allocated += size; |
| 5368 return ret; |
| 5369 } |
| 5370 |
| 5371 /* Public Arena API ***********************************************************/ |
| 5372 |
| 5373 void upb_arena_init(upb_arena *a) { |
| 5374 a->alloc.func = &upb_arena_doalloc; |
| 5375 a->block_alloc = &upb_alloc_global; |
| 5376 a->bytes_allocated = 0; |
| 5377 a->next_block_size = 256; |
| 5378 a->max_block_size = 16384; |
| 5379 a->cleanup_head = NULL; |
| 5380 a->block_head = NULL; |
| 5381 } |
| 5382 |
| 5383 void upb_arena_init2(upb_arena *a, void *mem, size_t size, upb_alloc *alloc) { |
| 5384 upb_arena_init(a); |
| 5385 |
| 5386 if (size > sizeof(mem_block)) { |
| 5387 upb_arena_addblock(a, mem, size, false); |
| 5388 } |
| 5389 |
| 5390 if (alloc) { |
| 5391 a->block_alloc = alloc; |
| 5392 } |
| 5393 } |
| 5394 |
| 5395 void upb_arena_uninit(upb_arena *a) { |
| 5396 cleanup_ent *ent = a->cleanup_head; |
| 5397 mem_block *block = a->block_head; |
| 5398 |
| 5399 while (ent) { |
| 5400 ent->cleanup(ent->ud); |
| 5401 ent = ent->next; |
| 5402 } |
| 5403 |
| 5404 /* Must do this after running cleanup functions, because this will delete |
| 5405 * the memory we store our cleanup entries in! */ |
| 5406 while (block) { |
| 5407 mem_block *next = block->next; |
| 5408 |
| 5409 if (block->owned) { |
| 5410 upb_free(a->block_alloc, block); |
| 5411 } |
| 5412 |
| 5413 block = next; |
| 5414 } |
| 5415 } |
| 5416 |
| 5417 bool upb_arena_addcleanup(upb_arena *a, upb_cleanup_func *func, void *ud) { |
| 5418 cleanup_ent *ent = upb_malloc(&a->alloc, sizeof(cleanup_ent)); |
| 5419 if (!ent) { |
| 5420 return false; /* Out of memory. */ |
| 5421 } |
| 5422 |
| 5423 ent->cleanup = func; |
| 5424 ent->ud = ud; |
| 5425 ent->next = a->cleanup_head; |
| 5426 a->cleanup_head = ent; |
| 5427 |
| 5428 return true; |
| 5429 } |
| 5430 |
| 5431 size_t upb_arena_bytesallocated(const upb_arena *a) { |
| 5432 return a->bytes_allocated; |
| 5433 } |
| 5434 |
| 5435 |
| 5436 /* Standard error functions ***************************************************/ |
| 5437 |
| 5438 static bool default_err(void *ud, const upb_status *status) { |
| 5439 UPB_UNUSED(ud); |
| 5440 UPB_UNUSED(status); |
| 5441 return false; |
| 5442 } |
| 5443 |
| 5444 static bool write_err_to(void *ud, const upb_status *status) { |
| 5445 upb_status *copy_to = ud; |
| 5446 upb_status_copy(copy_to, status); |
| 5447 return false; |
| 5448 } |
| 5449 |
| 5450 |
| 5451 /* upb_env ********************************************************************/ |
| 5452 |
| 5453 void upb_env_initonly(upb_env *e) { |
| 5454 e->ok_ = true; |
| 5455 e->error_func_ = &default_err; |
| 5456 e->error_ud_ = NULL; |
| 5457 } |
| 5458 |
| 5459 void upb_env_init(upb_env *e) { |
| 5460 upb_arena_init(&e->arena_); |
| 5461 upb_env_initonly(e); |
| 5462 } |
| 5463 |
| 5464 void upb_env_init2(upb_env *e, void *mem, size_t n, upb_alloc *alloc) { |
| 5465 upb_arena_init2(&e->arena_, mem, n, alloc); |
| 5466 upb_env_initonly(e); |
| 5467 } |
| 5468 |
| 5469 void upb_env_uninit(upb_env *e) { |
| 5470 upb_arena_uninit(&e->arena_); |
| 5471 } |
| 5472 |
| 5473 void upb_env_seterrorfunc(upb_env *e, upb_error_func *func, void *ud) { |
| 5474 e->error_func_ = func; |
| 5475 e->error_ud_ = ud; |
| 5476 } |
| 5477 |
| 5478 void upb_env_reporterrorsto(upb_env *e, upb_status *s) { |
| 5479 e->error_func_ = &write_err_to; |
| 5480 e->error_ud_ = s; |
| 5481 } |
| 5482 |
| 5483 bool upb_env_reporterror(upb_env *e, const upb_status *status) { |
| 5484 e->ok_ = false; |
| 5485 return e->error_func_(e->error_ud_, status); |
| 5486 } |
| 5487 |
| 5488 void *upb_env_malloc(upb_env *e, size_t size) { |
| 5489 return upb_malloc(&e->arena_.alloc, size); |
| 5490 } |
| 5491 |
| 5492 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) { |
| 5493 return upb_realloc(&e->arena_.alloc, ptr, oldsize, size); |
| 5494 } |
| 5495 |
| 5496 void upb_env_free(upb_env *e, void *ptr) { |
| 5497 upb_free(&e->arena_.alloc, ptr); |
| 5498 } |
| 5499 |
| 5500 bool upb_env_addcleanup(upb_env *e, upb_cleanup_func *func, void *ud) { |
| 5501 return upb_arena_addcleanup(&e->arena_, func, ud); |
| 5502 } |
| 5503 |
| 5504 size_t upb_env_bytesallocated(const upb_env *e) { |
| 5505 return upb_arena_bytesallocated(&e->arena_); |
| 5506 } |
| 5507 /* This file was generated by upbc (the upb compiler) from the input |
| 5508 * file: |
| 5509 * |
| 5510 * upb/descriptor/descriptor.proto |
| 5511 * |
4977 * Do not edit -- your changes will be discarded when the file is | 5512 * Do not edit -- your changes will be discarded when the file is |
4978 * regenerated. */ | 5513 * regenerated. */ |
4979 | 5514 |
4980 | 5515 |
4981 static const upb_msgdef msgs[20]; | 5516 static const upb_msgdef msgs[22]; |
4982 static const upb_fielddef fields[81]; | 5517 static const upb_fielddef fields[105]; |
4983 static const upb_enumdef enums[4]; | 5518 static const upb_enumdef enums[5]; |
4984 static const upb_tabent strentries[236]; | 5519 static const upb_tabent strentries[236]; |
4985 static const upb_tabent intentries[14]; | 5520 static const upb_tabent intentries[18]; |
4986 static const upb_tabval arrays[232]; | 5521 static const upb_tabval arrays[184]; |
4987 | 5522 |
4988 #ifdef UPB_DEBUG_REFS | 5523 #ifdef UPB_DEBUG_REFS |
4989 static upb_inttable reftables[212]; | 5524 static upb_inttable reftables[264]; |
4990 #endif | 5525 #endif |
4991 | 5526 |
4992 static const upb_msgdef msgs[20] = { | 5527 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]), | 5528 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]), | 5529 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]), | 5530 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]), | 5531 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]), | 5532 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]), | 5533 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]), | 5534 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]), | 5535 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]), | 5536 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]), | 5537 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]), | 5538 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]), | 5539 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]), | 5540 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]), | 5541 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]), | 5542 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]), | 5543 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]), | 5544 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]), | 5545 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]), | 5546 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]), | 5547 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]), |
| 5548 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]), |
| 5549 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 }; | 5550 }; |
5014 | 5551 |
5015 static const upb_fielddef fields[81] = { | 5552 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]), | 5553 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]
), | 5554 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]), | 5555 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]), | 5556 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]), | 5557 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]), | 5558 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])
, | 5559 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]), | 5560 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]), | 5561 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]), | 5562 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]), | 5563 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]), | 5564 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])
, | 5565 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]), | 5566 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]), | 5567 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]), | 5568 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]), | 5569 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]), | 5570 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]), | 5571 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]), | 5572 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]), | 5573 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]), | 5574 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]), | 5575 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]), | 5576 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]), | 5577 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]), | 5578 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]), | 5579 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]), | 5580 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]), | 5581 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]), | 5582 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]), | 5583 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]), | 5584 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]), | 5585 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]), | 5586 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]), | 5587 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]), | 5588 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]), | 5589 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]), | 5590 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]), | 5591 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]), | 5592 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]), | 5593 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]), | 5594 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]), | 5595 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]), | 5596 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]), | 5597 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]), | 5598 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]), | 5599 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]), | 5600 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]), | 5601 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]), | 5602 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]), | 5603 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]), | 5604 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]), | 5605 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]), | 5606 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]), | 5607 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]), | 5608 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]), | 5609 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
]), | 5610 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]), | 5611 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]), | 5612 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]), | 5613 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]), | 5614 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]), | 5615 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]), | 5616 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]), | 5617 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]), | 5618 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]), | 5619 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]), | 5620 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]), | 5621 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]), | 5622 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]), | 5623 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]), | 5624 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]), | 5625 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]), | 5626 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]), | 5627 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]), | 5628 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]), | 5629 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]), | 5630 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]), | 5631 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]), | 5632 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]), | 5633 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]), |
| 5634 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]), |
| 5635 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]), |
| 5636 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]), |
| 5637 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]), |
| 5638 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]), |
| 5639 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]), |
| 5640 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]), |
| 5641 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]), |
| 5642 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]), |
| 5643 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]), |
| 5644 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]), |
| 5645 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]), |
| 5646 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]), |
| 5647 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]), |
| 5648 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]), |
| 5649 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]), |
| 5650 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]), |
| 5651 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]), |
| 5652 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]), |
| 5653 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]), |
| 5654 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]), |
| 5655 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]), |
| 5656 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]), |
| 5657 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 }; | 5658 }; |
5098 | 5659 |
5099 static const upb_enumdef enums[4] = { | 5660 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]), | 5661 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]), | 5662 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]), | 5663 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]), | 5664 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]), |
| 5665 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 }; | 5666 }; |
5105 | 5667 |
5106 static const upb_tabent strentries[236] = { | 5668 static const upb_tabent strentries[236] = { |
5107 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[14]), NULL}, | 5669 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[22]), NULL}, |
5108 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5670 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5109 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5671 {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}, | 5672 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[52]), NULL}, |
5111 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5673 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5112 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5674 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5113 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5675 {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}, | 5676 {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}, | 5677 {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}, | 5678 {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}, | 5679 {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}, | 5680 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5119 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5681 {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}, | 5682 {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}, | 5683 {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]}, | 5684 {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}, | 5685 {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}, | 5686 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(
&fields[18]), NULL}, |
5125 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5687 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5126 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5688 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5127 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5689 {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}, | 5690 {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}, | 5691 {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]}, | 5692 {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}, | 5693 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5132 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5694 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INI
T(&fields[102]), NULL}, |
| 5695 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[74]), NULL}, |
| 5696 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[49]), &strentries[26]}, |
| 5697 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[98]), NULL}, |
| 5698 {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}, | 5699 {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}, | 5700 {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}, | 5701 {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}, | 5702 {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}, | 5703 {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]}, | 5704 {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}, | 5705 {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}, | 5706 {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}, | 5707 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5142 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5708 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5143 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5709 {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}, | 5710 {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}, | 5711 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5146 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[41]), NULL}, | 5712 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[55]), NULL}, |
5147 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5713 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5148 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5714 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5149 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5715 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5150 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5716 {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]}, | 5717 {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}, | 5718 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5153 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5719 {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}, | 5720 {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}, | 5721 {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]}, | 5722 {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}, | 5723 {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}, | 5724 {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]}, | 5725 {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}, | 5726 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5161 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT
(&fields[79]), NULL}, | 5727 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT
(&fields[103]), NULL}, |
5162 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5728 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5163 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5729 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5164 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5730 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5165 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5731 {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}, | 5732 {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}, | 5733 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT
(&fields[41]), NULL}, |
5168 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5734 {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}, | 5735 {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}, | 5736 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5171 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5737 {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}, | 5738 {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}, | 5739 {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}, | 5740 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5175 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[13]), NULL}, | 5741 {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}, | 5742 {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}, | 5743 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5178 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[34]), NULL}, | 5744 {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}, | 5745 {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}, | 5746 {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}, | 5747 {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}, | 5748 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5183 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5749 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5184 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5750 {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}, | 5751 {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}, | 5752 {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}, | 5753 {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]}, | 5754 {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}, | 5755 {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]}, | 5756 {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}, | 5757 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5192 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT
(&fields[17]), NULL}, | 5758 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT
(&fields[26]), NULL}, |
5193 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5759 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5194 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5760 {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}, | 5761 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5196 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5762 {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}, | 5763 {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}, | 5764 {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}, | 5765 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5200 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5766 {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]}, | 5767 {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}, | 5768 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5203 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5769 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5204 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5770 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5205 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5771 {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}, | 5772 {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}, | 5773 {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}, | 5774 {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}, | 5775 {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}, | 5776 {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]}, | 5777 {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}, | 5778 {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}, | 5779 {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}, | 5780 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5215 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5781 {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}, | 5782 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5217 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5783 {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}, | 5784 {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}, | 5785 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5220 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5786 {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}, | 5787 {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}, | 5788 {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}, | 5789 {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}, | 5790 {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}, | 5791 {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}, | 5792 {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}, | 5793 {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]}, | 5794 {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}, | 5795 {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]}, | 5796 {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}, | 5797 {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}, | 5798 {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}, | 5799 {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}, | 5800 {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}, | 5801 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5236 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5802 {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}, | 5803 {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}, | 5804 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[56]), NULL}, |
5239 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5805 {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}, | 5806 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5241 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5807 {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]}, | 5808 {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}, | 5809 {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}, | 5810 {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]}, | 5811 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5246 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT
(&fields[59]), NULL}, | 5812 {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}, | 5813 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5248 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5814 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5249 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5815 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5250 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[36]), NULL}, | 5816 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[50]), NULL}, |
5251 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5817 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5252 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5818 {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}, | 5819 {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}, | 5820 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[57]), &strentries[149]}, |
| 5821 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[101]), NULL}, |
| 5822 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[14]), NULL}, |
| 5823 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5824 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5825 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5826 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5827 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_
INIT(&fields[44]), NULL}, |
| 5828 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5829 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5830 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5831 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5832 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT
(&fields[87]), &strentries[167]}, |
| 5833 {UPB_TABKEY_STR("\031", "\000", "\000", "\000", "leading_detached_comments"),
UPB_TABVALUE_PTR_INIT(&fields[43]), &strentries[165]}, |
| 5834 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABV
ALUE_PTR_INIT(&fields[92]), NULL}, |
| 5835 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVA
LUE_PTR_INIT(&fields[42]), &strentries[164]}, |
| 5836 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT
(&fields[78]), NULL}, |
| 5837 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "double_value"), UPB_TABVALUE_
PTR_INIT(&fields[16]), NULL}, |
| 5838 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5839 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5840 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[51]), NULL}, |
| 5841 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5842 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5843 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5844 {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}, | 5845 {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}, | 5846 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5257 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5847 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5258 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5848 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5259 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5849 {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}, | 5850 {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}, | 5851 {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]}, | 5852 {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}, | 5853 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5264 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5854 {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}, | 5855 {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}, | 5856 {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]}, | 5857 {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}, | 5858 {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}, | 5859 {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}, | 5860 {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}, | 5861 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_
INT_INIT(6), NULL}, |
5272 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5862 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5273 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5863 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5274 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5864 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5275 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5865 {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}, | 5866 {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]}, | 5867 {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}, | 5868 {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}, | 5869 {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}, | 5870 {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}, | 5871 {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}, | 5872 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_
INT_INIT(7), NULL}, |
5283 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5873 {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]}, | 5874 {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}, | 5875 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5286 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5876 {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]}, | 5877 {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}, | 5878 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5289 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5879 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5290 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5880 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5291 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5881 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5292 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT
_INIT(14), NULL}, | 5882 {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}, | 5883 {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}, | 5884 {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]}, | 5885 {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}, | 5886 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5297 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE
_INT_INIT(16), NULL}, | 5887 {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}, | 5888 {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}, | 5889 {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}, | 5890 {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}, | 5891 {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}, | 5892 {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}, | 5893 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5304 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT
(1), NULL}, | 5894 {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]}, | 5895 {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}, | 5896 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_
INT_INIT(2), NULL}, |
| 5897 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5898 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NORMAL"), UPB_TABVALUE_INT
_INIT(0), NULL}, |
| 5899 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "JS_NUMBER"), UPB_TABVALUE_INT
_INIT(2), NULL}, |
| 5900 {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}, | 5901 {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]}, | 5902 {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}, | 5903 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5310 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_
INT_INIT(3), NULL}, | 5904 {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 }; | 5905 }; |
5344 | 5906 |
5345 static const upb_tabent intentries[14] = { | 5907 static const upb_tabent intentries[18] = { |
5346 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5908 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5347 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[73]), NULL}, | 5909 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL}, |
5348 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5910 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5349 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL}, | 5911 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL}, |
5350 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5912 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5351 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL}, | 5913 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL}, |
5352 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5914 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5353 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL}, | 5915 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL}, |
5354 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5916 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5355 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL}, | 5917 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL}, |
5356 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5918 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5357 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL}, | 5919 {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL}, |
5358 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5920 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5359 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[72]), NULL}, | 5921 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL}, |
| 5922 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5923 {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[14]), NULL}, |
| 5924 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
| 5925 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[101]), NULL}, |
5360 }; | 5926 }; |
5361 | 5927 |
5362 static const upb_tabval arrays[232] = { | 5928 static const upb_tabval arrays[184] = { |
5363 UPB_TABVALUE_EMPTY_INIT, | 5929 UPB_TABVALUE_EMPTY_INIT, |
5364 UPB_TABVALUE_PTR_INIT(&fields[38]), | 5930 UPB_TABVALUE_PTR_INIT(&fields[52]), |
5365 UPB_TABVALUE_PTR_INIT(&fields[16]), | 5931 UPB_TABVALUE_PTR_INIT(&fields[25]), |
5366 UPB_TABVALUE_PTR_INIT(&fields[44]), | 5932 UPB_TABVALUE_PTR_INIT(&fields[60]), |
5367 UPB_TABVALUE_PTR_INIT(&fields[9]), | 5933 UPB_TABVALUE_PTR_INIT(&fields[19]), |
5368 UPB_TABVALUE_PTR_INIT(&fields[15]), | 5934 UPB_TABVALUE_PTR_INIT(&fields[24]), |
5369 UPB_TABVALUE_PTR_INIT(&fields[14]), | 5935 UPB_TABVALUE_PTR_INIT(&fields[22]), |
| 5936 UPB_TABVALUE_PTR_INIT(&fields[68]), |
| 5937 UPB_TABVALUE_PTR_INIT(&fields[65]), |
| 5938 UPB_TABVALUE_PTR_INIT(&fields[83]), |
| 5939 UPB_TABVALUE_PTR_INIT(&fields[82]), |
| 5940 UPB_TABVALUE_EMPTY_INIT, |
| 5941 UPB_TABVALUE_PTR_INIT(&fields[89]), |
| 5942 UPB_TABVALUE_PTR_INIT(&fields[18]), |
| 5943 UPB_TABVALUE_EMPTY_INIT, |
| 5944 UPB_TABVALUE_PTR_INIT(&fields[88]), |
| 5945 UPB_TABVALUE_PTR_INIT(&fields[17]), |
| 5946 UPB_TABVALUE_EMPTY_INIT, |
5370 UPB_TABVALUE_PTR_INIT(&fields[49]), | 5947 UPB_TABVALUE_PTR_INIT(&fields[49]), |
5371 UPB_TABVALUE_EMPTY_INIT, | 5948 UPB_TABVALUE_PTR_INIT(&fields[102]), |
5372 UPB_TABVALUE_PTR_INIT(&fields[66]), | 5949 UPB_TABVALUE_PTR_INIT(&fields[74]), |
5373 UPB_TABVALUE_PTR_INIT(&fields[8]), | |
5374 UPB_TABVALUE_EMPTY_INIT, | |
5375 UPB_TABVALUE_PTR_INIT(&fields[40]), | |
5376 UPB_TABVALUE_PTR_INIT(&fields[78]), | |
5377 UPB_TABVALUE_PTR_INIT(&fields[50]), | |
5378 UPB_TABVALUE_EMPTY_INIT, | 5950 UPB_TABVALUE_EMPTY_INIT, |
5379 UPB_TABVALUE_EMPTY_INIT, | 5951 UPB_TABVALUE_EMPTY_INIT, |
5380 UPB_TABVALUE_PTR_INIT(&fields[1]), | 5952 UPB_TABVALUE_PTR_INIT(&fields[1]), |
| 5953 UPB_TABVALUE_PTR_INIT(&fields[13]), |
| 5954 UPB_TABVALUE_EMPTY_INIT, |
| 5955 UPB_TABVALUE_PTR_INIT(&fields[53]), |
| 5956 UPB_TABVALUE_PTR_INIT(&fields[62]), |
| 5957 UPB_TABVALUE_PTR_INIT(&fields[73]), |
| 5958 UPB_TABVALUE_EMPTY_INIT, |
| 5959 UPB_TABVALUE_PTR_INIT(&fields[15]), |
| 5960 UPB_TABVALUE_EMPTY_INIT, |
| 5961 UPB_TABVALUE_PTR_INIT(&fields[55]), |
| 5962 UPB_TABVALUE_PTR_INIT(&fields[21]), |
| 5963 UPB_TABVALUE_PTR_INIT(&fields[63]), |
| 5964 UPB_TABVALUE_PTR_INIT(&fields[40]), |
| 5965 UPB_TABVALUE_PTR_INIT(&fields[93]), |
| 5966 UPB_TABVALUE_PTR_INIT(&fields[94]), |
| 5967 UPB_TABVALUE_PTR_INIT(&fields[7]), |
| 5968 UPB_TABVALUE_PTR_INIT(&fields[71]), |
| 5969 UPB_TABVALUE_PTR_INIT(&fields[66]), |
| 5970 UPB_TABVALUE_PTR_INIT(&fields[38]), |
| 5971 UPB_TABVALUE_EMPTY_INIT, |
| 5972 UPB_TABVALUE_PTR_INIT(&fields[6]), |
| 5973 UPB_TABVALUE_PTR_INIT(&fields[77]), |
| 5974 UPB_TABVALUE_PTR_INIT(&fields[10]), |
| 5975 UPB_TABVALUE_EMPTY_INIT, |
| 5976 UPB_TABVALUE_PTR_INIT(&fields[41]), |
| 5977 UPB_TABVALUE_PTR_INIT(&fields[39]), |
5381 UPB_TABVALUE_EMPTY_INIT, | 5978 UPB_TABVALUE_EMPTY_INIT, |
5382 UPB_TABVALUE_EMPTY_INIT, | 5979 UPB_TABVALUE_EMPTY_INIT, |
5383 UPB_TABVALUE_EMPTY_INIT, | 5980 UPB_TABVALUE_EMPTY_INIT, |
| 5981 UPB_TABVALUE_PTR_INIT(&fields[103]), |
5384 UPB_TABVALUE_EMPTY_INIT, | 5982 UPB_TABVALUE_EMPTY_INIT, |
| 5983 UPB_TABVALUE_PTR_INIT(&fields[54]), |
| 5984 UPB_TABVALUE_PTR_INIT(&fields[76]), |
| 5985 UPB_TABVALUE_PTR_INIT(&fields[8]), |
| 5986 UPB_TABVALUE_PTR_INIT(&fields[47]), |
| 5987 UPB_TABVALUE_PTR_INIT(&fields[20]), |
| 5988 UPB_TABVALUE_PTR_INIT(&fields[85]), |
| 5989 UPB_TABVALUE_PTR_INIT(&fields[23]), |
| 5990 UPB_TABVALUE_PTR_INIT(&fields[69]), |
| 5991 UPB_TABVALUE_PTR_INIT(&fields[86]), |
| 5992 UPB_TABVALUE_PTR_INIT(&fields[80]), |
| 5993 UPB_TABVALUE_PTR_INIT(&fields[104]), |
| 5994 UPB_TABVALUE_PTR_INIT(&fields[91]), |
5385 UPB_TABVALUE_EMPTY_INIT, | 5995 UPB_TABVALUE_EMPTY_INIT, |
| 5996 UPB_TABVALUE_PTR_INIT(&fields[26]), |
5386 UPB_TABVALUE_EMPTY_INIT, | 5997 UPB_TABVALUE_EMPTY_INIT, |
5387 UPB_TABVALUE_PTR_INIT(&fields[37]), | 5998 UPB_TABVALUE_PTR_INIT(&fields[35]), |
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]), | |
5401 UPB_TABVALUE_PTR_INIT(&fields[4]), | |
5402 UPB_TABVALUE_PTR_INIT(&fields[51]), | |
5403 UPB_TABVALUE_EMPTY_INIT, | |
5404 UPB_TABVALUE_PTR_INIT(&fields[3]), | |
5405 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, | 5999 UPB_TABVALUE_EMPTY_INIT, |
5431 UPB_TABVALUE_EMPTY_INIT, | 6000 UPB_TABVALUE_EMPTY_INIT, |
5432 UPB_TABVALUE_EMPTY_INIT, | 6001 UPB_TABVALUE_EMPTY_INIT, |
5433 UPB_TABVALUE_EMPTY_INIT, | 6002 UPB_TABVALUE_EMPTY_INIT, |
5434 UPB_TABVALUE_EMPTY_INIT, | 6003 UPB_TABVALUE_EMPTY_INIT, |
5435 UPB_TABVALUE_EMPTY_INIT, | 6004 UPB_TABVALUE_EMPTY_INIT, |
5436 UPB_TABVALUE_PTR_INIT(&fields[34]), | 6005 UPB_TABVALUE_PTR_INIT(&fields[34]), |
5437 UPB_TABVALUE_PTR_INIT(&fields[57]), | 6006 UPB_TABVALUE_PTR_INIT(&fields[67]), |
5438 UPB_TABVALUE_PTR_INIT(&fields[5]), | 6007 UPB_TABVALUE_PTR_INIT(&fields[33]), |
5439 UPB_TABVALUE_PTR_INIT(&fields[32]), | 6008 UPB_TABVALUE_PTR_INIT(&fields[27]), |
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, | 6009 UPB_TABVALUE_EMPTY_INIT, |
5452 UPB_TABVALUE_EMPTY_INIT, | 6010 UPB_TABVALUE_EMPTY_INIT, |
5453 UPB_TABVALUE_EMPTY_INIT, | 6011 UPB_TABVALUE_EMPTY_INIT, |
5454 UPB_TABVALUE_EMPTY_INIT, | 6012 UPB_TABVALUE_EMPTY_INIT, |
| 6013 UPB_TABVALUE_PTR_INIT(&fields[3]), |
| 6014 UPB_TABVALUE_PTR_INIT(&fields[32]), |
| 6015 UPB_TABVALUE_PTR_INIT(&fields[81]), |
| 6016 UPB_TABVALUE_EMPTY_INIT, |
| 6017 UPB_TABVALUE_PTR_INIT(&fields[31]), |
5455 UPB_TABVALUE_EMPTY_INIT, | 6018 UPB_TABVALUE_EMPTY_INIT, |
5456 UPB_TABVALUE_EMPTY_INIT, | 6019 UPB_TABVALUE_EMPTY_INIT, |
5457 UPB_TABVALUE_PTR_INIT(&fields[25]), | 6020 UPB_TABVALUE_PTR_INIT(&fields[12]), |
5458 UPB_TABVALUE_PTR_INIT(&fields[48]), | 6021 UPB_TABVALUE_EMPTY_INIT, |
5459 UPB_TABVALUE_PTR_INIT(&fields[24]), | 6022 UPB_TABVALUE_EMPTY_INIT, |
5460 UPB_TABVALUE_PTR_INIT(&fields[18]), | 6023 UPB_TABVALUE_EMPTY_INIT, |
| 6024 UPB_TABVALUE_PTR_INIT(&fields[36]), |
| 6025 UPB_TABVALUE_EMPTY_INIT, |
| 6026 UPB_TABVALUE_EMPTY_INIT, |
| 6027 UPB_TABVALUE_EMPTY_INIT, |
| 6028 UPB_TABVALUE_PTR_INIT(&fields[2]), |
5461 UPB_TABVALUE_EMPTY_INIT, | 6029 UPB_TABVALUE_EMPTY_INIT, |
5462 UPB_TABVALUE_EMPTY_INIT, | 6030 UPB_TABVALUE_EMPTY_INIT, |
5463 UPB_TABVALUE_EMPTY_INIT, | 6031 UPB_TABVALUE_EMPTY_INIT, |
5464 UPB_TABVALUE_EMPTY_INIT, | 6032 UPB_TABVALUE_EMPTY_INIT, |
5465 UPB_TABVALUE_PTR_INIT(&fields[2]), | 6033 UPB_TABVALUE_PTR_INIT(&fields[64]), |
5466 UPB_TABVALUE_PTR_INIT(&fields[23]), | 6034 UPB_TABVALUE_PTR_INIT(&fields[5]), |
5467 UPB_TABVALUE_PTR_INIT(&fields[62]), | 6035 UPB_TABVALUE_PTR_INIT(&fields[37]), |
5468 UPB_TABVALUE_EMPTY_INIT, | 6036 UPB_TABVALUE_EMPTY_INIT, |
5469 UPB_TABVALUE_PTR_INIT(&fields[22]), | 6037 UPB_TABVALUE_PTR_INIT(&fields[46]), |
| 6038 UPB_TABVALUE_PTR_INIT(&fields[61]), |
| 6039 UPB_TABVALUE_PTR_INIT(&fields[9]), |
5470 UPB_TABVALUE_EMPTY_INIT, | 6040 UPB_TABVALUE_EMPTY_INIT, |
5471 UPB_TABVALUE_EMPTY_INIT, | 6041 UPB_TABVALUE_EMPTY_INIT, |
5472 UPB_TABVALUE_EMPTY_INIT, | 6042 UPB_TABVALUE_EMPTY_INIT, |
| 6043 UPB_TABVALUE_PTR_INIT(&fields[45]), |
| 6044 UPB_TABVALUE_EMPTY_INIT, |
| 6045 UPB_TABVALUE_PTR_INIT(&fields[56]), |
| 6046 UPB_TABVALUE_PTR_INIT(&fields[29]), |
| 6047 UPB_TABVALUE_PTR_INIT(&fields[75]), |
| 6048 UPB_TABVALUE_PTR_INIT(&fields[70]), |
| 6049 UPB_TABVALUE_PTR_INIT(&fields[4]), |
| 6050 UPB_TABVALUE_PTR_INIT(&fields[84]), |
5473 UPB_TABVALUE_EMPTY_INIT, | 6051 UPB_TABVALUE_EMPTY_INIT, |
5474 UPB_TABVALUE_EMPTY_INIT, | 6052 UPB_TABVALUE_EMPTY_INIT, |
| 6053 UPB_TABVALUE_PTR_INIT(&fields[50]), |
| 6054 UPB_TABVALUE_EMPTY_INIT, |
| 6055 UPB_TABVALUE_PTR_INIT(&fields[57]), |
| 6056 UPB_TABVALUE_PTR_INIT(&fields[48]), |
| 6057 UPB_TABVALUE_PTR_INIT(&fields[72]), |
5475 UPB_TABVALUE_EMPTY_INIT, | 6058 UPB_TABVALUE_EMPTY_INIT, |
5476 UPB_TABVALUE_EMPTY_INIT, | 6059 UPB_TABVALUE_EMPTY_INIT, |
| 6060 UPB_TABVALUE_PTR_INIT(&fields[44]), |
| 6061 UPB_TABVALUE_EMPTY_INIT, |
| 6062 UPB_TABVALUE_PTR_INIT(&fields[78]), |
| 6063 UPB_TABVALUE_PTR_INIT(&fields[87]), |
| 6064 UPB_TABVALUE_PTR_INIT(&fields[42]), |
| 6065 UPB_TABVALUE_PTR_INIT(&fields[92]), |
| 6066 UPB_TABVALUE_EMPTY_INIT, |
| 6067 UPB_TABVALUE_PTR_INIT(&fields[43]), |
5477 UPB_TABVALUE_EMPTY_INIT, | 6068 UPB_TABVALUE_EMPTY_INIT, |
5478 UPB_TABVALUE_EMPTY_INIT, | 6069 UPB_TABVALUE_EMPTY_INIT, |
5479 UPB_TABVALUE_EMPTY_INIT, | 6070 UPB_TABVALUE_PTR_INIT(&fields[51]), |
5480 UPB_TABVALUE_EMPTY_INIT, | 6071 UPB_TABVALUE_PTR_INIT(&fields[28]), |
5481 UPB_TABVALUE_EMPTY_INIT, | 6072 UPB_TABVALUE_PTR_INIT(&fields[79]), |
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]), | |
5548 UPB_TABVALUE_EMPTY_INIT, | |
5549 UPB_TABVALUE_PTR_INIT(&fields[59]), | 6073 UPB_TABVALUE_PTR_INIT(&fields[59]), |
5550 UPB_TABVALUE_PTR_INIT(&fields[65]), | 6074 UPB_TABVALUE_PTR_INIT(&fields[16]), |
5551 UPB_TABVALUE_PTR_INIT(&fields[29]), | 6075 UPB_TABVALUE_PTR_INIT(&fields[90]), |
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]), | 6076 UPB_TABVALUE_PTR_INIT(&fields[0]), |
5562 UPB_TABVALUE_EMPTY_INIT, | 6077 UPB_TABVALUE_EMPTY_INIT, |
5563 UPB_TABVALUE_PTR_INIT(&fields[42]), | 6078 UPB_TABVALUE_PTR_INIT(&fields[58]), |
5564 UPB_TABVALUE_PTR_INIT(&fields[21]), | 6079 UPB_TABVALUE_PTR_INIT(&fields[30]), |
5565 UPB_TABVALUE_EMPTY_INIT, | 6080 UPB_TABVALUE_EMPTY_INIT, |
5566 UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"), | 6081 UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"), |
5567 UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"), | 6082 UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"), |
5568 UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"), | 6083 UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"), |
5569 UPB_TABVALUE_EMPTY_INIT, | 6084 UPB_TABVALUE_EMPTY_INIT, |
5570 UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"), | 6085 UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"), |
5571 UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"), | 6086 UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"), |
5572 UPB_TABVALUE_PTR_INIT("TYPE_INT64"), | 6087 UPB_TABVALUE_PTR_INIT("TYPE_INT64"), |
5573 UPB_TABVALUE_PTR_INIT("TYPE_UINT64"), | 6088 UPB_TABVALUE_PTR_INIT("TYPE_UINT64"), |
5574 UPB_TABVALUE_PTR_INIT("TYPE_INT32"), | 6089 UPB_TABVALUE_PTR_INIT("TYPE_INT32"), |
5575 UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"), | 6090 UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"), |
5576 UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"), | 6091 UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"), |
5577 UPB_TABVALUE_PTR_INIT("TYPE_BOOL"), | 6092 UPB_TABVALUE_PTR_INIT("TYPE_BOOL"), |
5578 UPB_TABVALUE_PTR_INIT("TYPE_STRING"), | 6093 UPB_TABVALUE_PTR_INIT("TYPE_STRING"), |
5579 UPB_TABVALUE_PTR_INIT("TYPE_GROUP"), | 6094 UPB_TABVALUE_PTR_INIT("TYPE_GROUP"), |
5580 UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"), | 6095 UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"), |
5581 UPB_TABVALUE_PTR_INIT("TYPE_BYTES"), | 6096 UPB_TABVALUE_PTR_INIT("TYPE_BYTES"), |
5582 UPB_TABVALUE_PTR_INIT("TYPE_UINT32"), | 6097 UPB_TABVALUE_PTR_INIT("TYPE_UINT32"), |
5583 UPB_TABVALUE_PTR_INIT("TYPE_ENUM"), | 6098 UPB_TABVALUE_PTR_INIT("TYPE_ENUM"), |
5584 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"), | 6099 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"), |
5585 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"), | 6100 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"), |
5586 UPB_TABVALUE_PTR_INIT("TYPE_SINT32"), | 6101 UPB_TABVALUE_PTR_INIT("TYPE_SINT32"), |
5587 UPB_TABVALUE_PTR_INIT("TYPE_SINT64"), | 6102 UPB_TABVALUE_PTR_INIT("TYPE_SINT64"), |
5588 UPB_TABVALUE_PTR_INIT("STRING"), | 6103 UPB_TABVALUE_PTR_INIT("STRING"), |
5589 UPB_TABVALUE_PTR_INIT("CORD"), | 6104 UPB_TABVALUE_PTR_INIT("CORD"), |
5590 UPB_TABVALUE_PTR_INIT("STRING_PIECE"), | 6105 UPB_TABVALUE_PTR_INIT("STRING_PIECE"), |
| 6106 UPB_TABVALUE_PTR_INIT("JS_NORMAL"), |
| 6107 UPB_TABVALUE_PTR_INIT("JS_STRING"), |
| 6108 UPB_TABVALUE_PTR_INIT("JS_NUMBER"), |
5591 UPB_TABVALUE_EMPTY_INIT, | 6109 UPB_TABVALUE_EMPTY_INIT, |
5592 UPB_TABVALUE_PTR_INIT("SPEED"), | 6110 UPB_TABVALUE_PTR_INIT("SPEED"), |
5593 UPB_TABVALUE_PTR_INIT("CODE_SIZE"), | 6111 UPB_TABVALUE_PTR_INIT("CODE_SIZE"), |
5594 UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"), | 6112 UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"), |
5595 }; | 6113 }; |
5596 | 6114 |
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 | 6115 #ifdef UPB_DEBUG_REFS |
5605 static upb_inttable reftables[212] = { | 6116 static upb_inttable reftables[264] = { |
5606 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6117 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5607 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6118 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5608 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), |
| 6141 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6142 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6143 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6144 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6145 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6146 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6147 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6148 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6149 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6150 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6151 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6152 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6153 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6154 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6155 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6156 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6157 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6158 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6159 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6160 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6161 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6162 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6163 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6164 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6165 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6166 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6167 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6168 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6169 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6170 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
| 6171 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5609 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6172 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5610 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6173 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5611 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6174 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5612 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6175 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5613 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6176 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5614 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6177 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5615 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6178 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5616 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6179 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5617 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6180 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5618 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6181 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5811 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6374 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5812 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6375 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5813 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6376 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5814 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6377 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5815 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6378 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5816 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6379 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5817 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 6380 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
5818 }; | 6381 }; |
5819 #endif | 6382 #endif |
5820 | 6383 |
| 6384 static const upb_msgdef *refm(const upb_msgdef *m, const void *owner) { |
| 6385 upb_msgdef_ref(m, owner); |
| 6386 return m; |
| 6387 } |
| 6388 |
| 6389 static const upb_enumdef *refe(const upb_enumdef *e, const void *owner) { |
| 6390 upb_enumdef_ref(e, owner); |
| 6391 return e; |
| 6392 } |
| 6393 |
| 6394 /* Public API. */ |
| 6395 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_get(const void *owner)
{ return refm(&msgs[0], owner); } |
| 6396 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ExtensionRange_get(con
st void *owner) { return refm(&msgs[1], owner); } |
| 6397 const upb_msgdef *upbdefs_google_protobuf_DescriptorProto_ReservedRange_get(cons
t void *owner) { return refm(&msgs[2], owner); } |
| 6398 const upb_msgdef *upbdefs_google_protobuf_EnumDescriptorProto_get(const void *ow
ner) { return refm(&msgs[3], owner); } |
| 6399 const upb_msgdef *upbdefs_google_protobuf_EnumOptions_get(const void *owner) { r
eturn refm(&msgs[4], owner); } |
| 6400 const upb_msgdef *upbdefs_google_protobuf_EnumValueDescriptorProto_get(const voi
d *owner) { return refm(&msgs[5], owner); } |
| 6401 const upb_msgdef *upbdefs_google_protobuf_EnumValueOptions_get(const void *owner
) { return refm(&msgs[6], owner); } |
| 6402 const upb_msgdef *upbdefs_google_protobuf_FieldDescriptorProto_get(const void *o
wner) { return refm(&msgs[7], owner); } |
| 6403 const upb_msgdef *upbdefs_google_protobuf_FieldOptions_get(const void *owner) {
return refm(&msgs[8], owner); } |
| 6404 const upb_msgdef *upbdefs_google_protobuf_FileDescriptorProto_get(const void *ow
ner) { return refm(&msgs[9], owner); } |
| 6405 const upb_msgdef *upbdefs_google_protobuf_FileDescriptorSet_get(const void *owne
r) { return refm(&msgs[10], owner); } |
| 6406 const upb_msgdef *upbdefs_google_protobuf_FileOptions_get(const void *owner) { r
eturn refm(&msgs[11], owner); } |
| 6407 const upb_msgdef *upbdefs_google_protobuf_MessageOptions_get(const void *owner)
{ return refm(&msgs[12], owner); } |
| 6408 const upb_msgdef *upbdefs_google_protobuf_MethodDescriptorProto_get(const void *
owner) { return refm(&msgs[13], owner); } |
| 6409 const upb_msgdef *upbdefs_google_protobuf_MethodOptions_get(const void *owner) {
return refm(&msgs[14], owner); } |
| 6410 const upb_msgdef *upbdefs_google_protobuf_OneofDescriptorProto_get(const void *o
wner) { return refm(&msgs[15], owner); } |
| 6411 const upb_msgdef *upbdefs_google_protobuf_ServiceDescriptorProto_get(const void
*owner) { return refm(&msgs[16], owner); } |
| 6412 const upb_msgdef *upbdefs_google_protobuf_ServiceOptions_get(const void *owner)
{ return refm(&msgs[17], owner); } |
| 6413 const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_get(const void *owner)
{ return refm(&msgs[18], owner); } |
| 6414 const upb_msgdef *upbdefs_google_protobuf_SourceCodeInfo_Location_get(const void
*owner) { return refm(&msgs[19], owner); } |
| 6415 const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_get(const void *ow
ner) { return refm(&msgs[20], owner); } |
| 6416 const upb_msgdef *upbdefs_google_protobuf_UninterpretedOption_NamePart_get(const
void *owner) { return refm(&msgs[21], owner); } |
| 6417 |
| 6418 const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Label_get(const
void *owner) { return refe(&enums[0], owner); } |
| 6419 const upb_enumdef *upbdefs_google_protobuf_FieldDescriptorProto_Type_get(const v
oid *owner) { return refe(&enums[1], owner); } |
| 6420 const upb_enumdef *upbdefs_google_protobuf_FieldOptions_CType_get(const void *ow
ner) { return refe(&enums[2], owner); } |
| 6421 const upb_enumdef *upbdefs_google_protobuf_FieldOptions_JSType_get(const void *o
wner) { return refe(&enums[3], owner); } |
| 6422 const upb_enumdef *upbdefs_google_protobuf_FileOptions_OptimizeMode_get(const vo
id *owner) { return refe(&enums[4], owner); } |
5821 /* | 6423 /* |
5822 ** XXX: The routines in this file that consume a string do not currently | 6424 ** 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 | 6425 ** 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 | 6426 ** its buffering/sharing functionality evolve there should be an easy and |
5825 ** idiomatic way of correctly handling this case. For now, we accept this | 6427 ** idiomatic way of correctly handling this case. For now, we accept this |
5826 ** limitation since we currently only parse descriptors from single strings. | 6428 ** limitation since we currently only parse descriptors from single strings. |
5827 */ | 6429 */ |
5828 | 6430 |
5829 | 6431 |
5830 #include <errno.h> | 6432 #include <errno.h> |
5831 #include <stdlib.h> | 6433 #include <stdlib.h> |
5832 #include <string.h> | 6434 #include <string.h> |
5833 | 6435 |
5834 /* upb_deflist is an internal-only dynamic array for storing a growing list of | 6436 /* Compares a NULL-terminated string with a non-NULL-terminated string. */ |
5835 * upb_defs. */ | 6437 static bool upb_streq(const char *str, const char *buf, size_t n) { |
5836 typedef struct { | 6438 return strlen(str) == n && memcmp(str, buf, n) == 0; |
5837 upb_def **defs; | 6439 } |
5838 size_t len; | |
5839 size_t size; | |
5840 bool owned; | |
5841 } upb_deflist; | |
5842 | 6440 |
5843 /* We keep a stack of all the messages scopes we are currently in, as well as | 6441 /* 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 | 6442 * the top-level file scope. This is necessary to correctly qualify the |
5845 * definitions that are contained inside. "name" tracks the name of the | 6443 * definitions that are contained inside. "name" tracks the name of the |
5846 * message or package (a bare name -- not qualified by any enclosing scopes). */ | 6444 * message or package (a bare name -- not qualified by any enclosing scopes). */ |
5847 typedef struct { | 6445 typedef struct { |
5848 char *name; | 6446 char *name; |
5849 /* Index of the first def that is under this scope. For msgdefs, the | 6447 /* Index of the first def that is under this scope. For msgdefs, the |
5850 * msgdef itself is at start-1. */ | 6448 * msgdef itself is at start-1. */ |
5851 int start; | 6449 int start; |
| 6450 uint32_t oneof_start; |
| 6451 uint32_t oneof_index; |
5852 } upb_descreader_frame; | 6452 } upb_descreader_frame; |
5853 | 6453 |
5854 /* The maximum number of nested declarations that are allowed, ie. | 6454 /* The maximum number of nested declarations that are allowed, ie. |
5855 * message Foo { | 6455 * message Foo { |
5856 * message Bar { | 6456 * message Bar { |
5857 * message Baz { | 6457 * message Baz { |
5858 * } | 6458 * } |
5859 * } | 6459 * } |
5860 * } | 6460 * } |
5861 * | 6461 * |
5862 * This is a resource limit that affects how big our runtime stack can grow. | 6462 * 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. */ | 6463 * TODO: make this a runtime-settable property of the Reader instance. */ |
5864 #define UPB_MAX_MESSAGE_NESTING 64 | 6464 #define UPB_MAX_MESSAGE_NESTING 64 |
5865 | 6465 |
5866 struct upb_descreader { | 6466 struct upb_descreader { |
5867 upb_sink sink; | 6467 upb_sink sink; |
5868 upb_deflist defs; | 6468 upb_inttable files; |
| 6469 upb_filedef *file; /* The last file in files. */ |
5869 upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; | 6470 upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; |
5870 int stack_len; | 6471 int stack_len; |
| 6472 upb_inttable oneofs; |
5871 | 6473 |
5872 uint32_t number; | 6474 uint32_t number; |
5873 char *name; | 6475 char *name; |
5874 bool saw_number; | 6476 bool saw_number; |
5875 bool saw_name; | 6477 bool saw_name; |
5876 | 6478 |
5877 char *default_string; | 6479 char *default_string; |
5878 | 6480 |
5879 upb_fielddef *f; | 6481 upb_fielddef *f; |
5880 }; | 6482 }; |
5881 | 6483 |
5882 static char *upb_strndup(const char *buf, size_t n) { | 6484 static char *upb_strndup(const char *buf, size_t n) { |
5883 char *ret = malloc(n + 1); | 6485 char *ret = upb_gmalloc(n + 1); |
5884 if (!ret) return NULL; | 6486 if (!ret) return NULL; |
5885 memcpy(ret, buf, n); | 6487 memcpy(ret, buf, n); |
5886 ret[n] = '\0'; | 6488 ret[n] = '\0'; |
5887 return ret; | 6489 return ret; |
5888 } | 6490 } |
5889 | 6491 |
5890 /* Returns a newly allocated string that joins input strings together, for | 6492 /* Returns a newly allocated string that joins input strings together, for |
5891 * example: | 6493 * example: |
5892 * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz" | 6494 * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz" |
5893 * join("", "Baz") -> "Baz" | 6495 * join("", "Baz") -> "Baz" |
5894 * Caller owns a ref on the returned string. */ | 6496 * Caller owns a ref on the returned string. */ |
5895 static char *upb_join(const char *base, const char *name) { | 6497 static char *upb_join(const char *base, const char *name) { |
5896 if (!base || strlen(base) == 0) { | 6498 if (!base || strlen(base) == 0) { |
5897 return upb_strdup(name); | 6499 return upb_gstrdup(name); |
5898 } else { | 6500 } else { |
5899 char *ret = malloc(strlen(base) + strlen(name) + 2); | 6501 char *ret = upb_gmalloc(strlen(base) + strlen(name) + 2); |
| 6502 if (!ret) { |
| 6503 return NULL; |
| 6504 } |
5900 ret[0] = '\0'; | 6505 ret[0] = '\0'; |
5901 strcat(ret, base); | 6506 strcat(ret, base); |
5902 strcat(ret, "."); | 6507 strcat(ret, "."); |
5903 strcat(ret, name); | 6508 strcat(ret, name); |
5904 return ret; | 6509 return ret; |
5905 } | 6510 } |
5906 } | 6511 } |
5907 | 6512 |
5908 | 6513 /* Qualify the defname for all defs starting with offset "start" with "str". */ |
5909 /* upb_deflist ****************************************************************/ | 6514 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; | 6515 size_t i; |
5920 if (l->owned) | 6516 for (i = start; i < upb_filedef_defcount(f); i++) { |
5921 for(i = 0; i < l->len; i++) | 6517 upb_def *def = upb_filedef_mutabledef(f, i); |
5922 upb_def_unref(l->defs[i], l); | 6518 char *name = upb_join(str, upb_def_fullname(def)); |
5923 free(l->defs); | 6519 if (!name) { |
5924 } | 6520 /* Need better logic here; at this point we've qualified some names but |
5925 | 6521 * not others. */ |
5926 bool upb_deflist_push(upb_deflist *l, upb_def *d) { | 6522 return false; |
5927 if(++l->len >= l->size) { | 6523 } |
5928 size_t new_size = UPB_MAX(l->size, 4); | 6524 upb_def_setfullname(def, name, NULL); |
5929 new_size *= 2; | 6525 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 } | 6526 } |
5934 l->defs[l->len - 1] = d; | |
5935 return true; | 6527 return true; |
5936 } | 6528 } |
5937 | 6529 |
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 | 6530 |
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 ************************************************************/ | 6531 /* upb_descreader ************************************************************/ |
5963 | 6532 |
5964 static upb_msgdef *upb_descreader_top(upb_descreader *r) { | 6533 static upb_msgdef *upb_descreader_top(upb_descreader *r) { |
5965 int index; | 6534 int index; |
5966 assert(r->stack_len > 1); | 6535 UPB_ASSERT(r->stack_len > 1); |
5967 index = r->stack[r->stack_len-1].start - 1; | 6536 index = r->stack[r->stack_len-1].start - 1; |
5968 assert(index >= 0); | 6537 UPB_ASSERT(index >= 0); |
5969 return upb_downcast_msgdef_mutable(r->defs.defs[index]); | 6538 return upb_downcast_msgdef_mutable(upb_filedef_mutabledef(r->file, index)); |
5970 } | 6539 } |
5971 | 6540 |
5972 static upb_def *upb_descreader_last(upb_descreader *r) { | 6541 static upb_def *upb_descreader_last(upb_descreader *r) { |
5973 return upb_deflist_last(&r->defs); | 6542 return upb_filedef_mutabledef(r->file, upb_filedef_defcount(r->file) - 1); |
5974 } | 6543 } |
5975 | 6544 |
5976 /* Start/end handlers for FileDescriptorProto and DescriptorProto (the two | 6545 /* Start/end handlers for FileDescriptorProto and DescriptorProto (the two |
5977 * entities that have names and can contain sub-definitions. */ | 6546 * entities that have names and can contain sub-definitions. */ |
5978 void upb_descreader_startcontainer(upb_descreader *r) { | 6547 void upb_descreader_startcontainer(upb_descreader *r) { |
5979 upb_descreader_frame *f = &r->stack[r->stack_len++]; | 6548 upb_descreader_frame *f = &r->stack[r->stack_len++]; |
5980 f->start = r->defs.len; | 6549 f->start = upb_filedef_defcount(r->file); |
| 6550 f->oneof_start = upb_inttable_count(&r->oneofs); |
| 6551 f->oneof_index = 0; |
5981 f->name = NULL; | 6552 f->name = NULL; |
5982 } | 6553 } |
5983 | 6554 |
5984 void upb_descreader_endcontainer(upb_descreader *r) { | 6555 bool upb_descreader_endcontainer(upb_descreader *r) { |
5985 upb_descreader_frame *f = &r->stack[--r->stack_len]; | 6556 upb_descreader_frame *f = &r->stack[r->stack_len - 1]; |
5986 upb_deflist_qualify(&r->defs, f->name, f->start); | 6557 |
5987 free(f->name); | 6558 while (upb_inttable_count(&r->oneofs) > f->oneof_start) { |
| 6559 upb_oneofdef *o = upb_value_getptr(upb_inttable_pop(&r->oneofs)); |
| 6560 bool ok = upb_msgdef_addoneof(upb_descreader_top(r), o, &r->oneofs, NULL); |
| 6561 UPB_ASSERT(ok); |
| 6562 } |
| 6563 |
| 6564 if (!upb_descreader_qualify(r->file, f->name, f->start)) { |
| 6565 return false; |
| 6566 } |
| 6567 upb_gfree(f->name); |
5988 f->name = NULL; | 6568 f->name = NULL; |
| 6569 |
| 6570 r->stack_len--; |
| 6571 return true; |
5989 } | 6572 } |
5990 | 6573 |
5991 void upb_descreader_setscopename(upb_descreader *r, char *str) { | 6574 void upb_descreader_setscopename(upb_descreader *r, char *str) { |
5992 upb_descreader_frame *f = &r->stack[r->stack_len-1]; | 6575 upb_descreader_frame *f = &r->stack[r->stack_len-1]; |
5993 free(f->name); | 6576 upb_gfree(f->name); |
5994 f->name = str; | 6577 f->name = str; |
5995 } | 6578 } |
5996 | 6579 |
5997 /* Handlers for google.protobuf.FileDescriptorProto. */ | 6580 static upb_oneofdef *upb_descreader_getoneof(upb_descreader *r, |
5998 static bool file_startmsg(void *r, const void *hd) { | 6581 uint32_t index) { |
| 6582 bool found; |
| 6583 upb_value val; |
| 6584 upb_descreader_frame *f = &r->stack[r->stack_len-1]; |
| 6585 |
| 6586 /* DescriptorProto messages can be nested, so we will see the nested messages |
| 6587 * between when we see the FieldDescriptorProto and the OneofDescriptorProto. |
| 6588 * We need to preserve the oneofs in between these two things. */ |
| 6589 index += f->oneof_start; |
| 6590 |
| 6591 while (upb_inttable_count(&r->oneofs) <= index) { |
| 6592 upb_inttable_push(&r->oneofs, upb_value_ptr(upb_oneofdef_new(&r->oneofs))); |
| 6593 } |
| 6594 |
| 6595 found = upb_inttable_lookup(&r->oneofs, index, &val); |
| 6596 UPB_ASSERT(found); |
| 6597 return upb_value_getptr(val); |
| 6598 } |
| 6599 |
| 6600 /** Handlers for google.protobuf.FileDescriptorSet. ***************************/ |
| 6601 |
| 6602 static void *fileset_startfile(void *closure, const void *hd) { |
| 6603 upb_descreader *r = closure; |
| 6604 UPB_UNUSED(hd); |
| 6605 r->file = upb_filedef_new(&r->files); |
| 6606 upb_inttable_push(&r->files, upb_value_ptr(r->file)); |
| 6607 return r; |
| 6608 } |
| 6609 |
| 6610 /** Handlers for google.protobuf.FileDescriptorProto. *************************/ |
| 6611 |
| 6612 static bool file_start(void *closure, const void *hd) { |
| 6613 upb_descreader *r = closure; |
5999 UPB_UNUSED(hd); | 6614 UPB_UNUSED(hd); |
6000 upb_descreader_startcontainer(r); | 6615 upb_descreader_startcontainer(r); |
6001 return true; | 6616 return true; |
6002 } | 6617 } |
6003 | 6618 |
6004 static bool file_endmsg(void *closure, const void *hd, upb_status *status) { | 6619 static bool file_end(void *closure, const void *hd, upb_status *status) { |
6005 upb_descreader *r = closure; | 6620 upb_descreader *r = closure; |
6006 UPB_UNUSED(hd); | 6621 UPB_UNUSED(hd); |
6007 UPB_UNUSED(status); | 6622 UPB_UNUSED(status); |
6008 upb_descreader_endcontainer(r); | 6623 return upb_descreader_endcontainer(r); |
6009 return true; | 6624 } |
| 6625 |
| 6626 static size_t file_onname(void *closure, const void *hd, const char *buf, |
| 6627 size_t n, const upb_bufhandle *handle) { |
| 6628 upb_descreader *r = closure; |
| 6629 char *name; |
| 6630 bool ok; |
| 6631 UPB_UNUSED(hd); |
| 6632 UPB_UNUSED(handle); |
| 6633 |
| 6634 name = upb_strndup(buf, n); |
| 6635 /* XXX: see comment at the top of the file. */ |
| 6636 ok = upb_filedef_setname(r->file, name, NULL); |
| 6637 upb_gfree(name); |
| 6638 UPB_ASSERT(ok); |
| 6639 return n; |
6010 } | 6640 } |
6011 | 6641 |
6012 static size_t file_onpackage(void *closure, const void *hd, const char *buf, | 6642 static size_t file_onpackage(void *closure, const void *hd, const char *buf, |
6013 size_t n, const upb_bufhandle *handle) { | 6643 size_t n, const upb_bufhandle *handle) { |
6014 upb_descreader *r = closure; | 6644 upb_descreader *r = closure; |
| 6645 char *package; |
| 6646 bool ok; |
| 6647 UPB_UNUSED(hd); |
| 6648 UPB_UNUSED(handle); |
| 6649 |
| 6650 package = upb_strndup(buf, n); |
| 6651 /* XXX: see comment at the top of the file. */ |
| 6652 upb_descreader_setscopename(r, package); |
| 6653 ok = upb_filedef_setpackage(r->file, package, NULL); |
| 6654 UPB_ASSERT(ok); |
| 6655 return n; |
| 6656 } |
| 6657 |
| 6658 static size_t file_onsyntax(void *closure, const void *hd, const char *buf, |
| 6659 size_t n, const upb_bufhandle *handle) { |
| 6660 upb_descreader *r = closure; |
| 6661 bool ok; |
6015 UPB_UNUSED(hd); | 6662 UPB_UNUSED(hd); |
6016 UPB_UNUSED(handle); | 6663 UPB_UNUSED(handle); |
6017 /* XXX: see comment at the top of the file. */ | 6664 /* XXX: see comment at the top of the file. */ |
6018 upb_descreader_setscopename(r, upb_strndup(buf, n)); | 6665 if (upb_streq("proto2", buf, n)) { |
| 6666 ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO2, NULL); |
| 6667 } else if (upb_streq("proto3", buf, n)) { |
| 6668 ok = upb_filedef_setsyntax(r->file, UPB_SYNTAX_PROTO3, NULL); |
| 6669 } else { |
| 6670 ok = false; |
| 6671 } |
| 6672 |
| 6673 UPB_ASSERT(ok); |
6019 return n; | 6674 return n; |
6020 } | 6675 } |
6021 | 6676 |
6022 /* Handlers for google.protobuf.EnumValueDescriptorProto. */ | 6677 static void *file_startmsg(void *closure, const void *hd) { |
| 6678 upb_descreader *r = closure; |
| 6679 upb_msgdef *m = upb_msgdef_new(&m); |
| 6680 bool ok = upb_filedef_addmsg(r->file, m, &m, NULL); |
| 6681 UPB_UNUSED(hd); |
| 6682 UPB_ASSERT(ok); |
| 6683 return r; |
| 6684 } |
| 6685 |
| 6686 static void *file_startenum(void *closure, const void *hd) { |
| 6687 upb_descreader *r = closure; |
| 6688 upb_enumdef *e = upb_enumdef_new(&e); |
| 6689 bool ok = upb_filedef_addenum(r->file, e, &e, NULL); |
| 6690 UPB_UNUSED(hd); |
| 6691 UPB_ASSERT(ok); |
| 6692 return r; |
| 6693 } |
| 6694 |
| 6695 static void *file_startext(void *closure, const void *hd) { |
| 6696 upb_descreader *r = closure; |
| 6697 bool ok; |
| 6698 r->f = upb_fielddef_new(r); |
| 6699 ok = upb_filedef_addext(r->file, r->f, r, NULL); |
| 6700 UPB_UNUSED(hd); |
| 6701 UPB_ASSERT(ok); |
| 6702 return r; |
| 6703 } |
| 6704 |
| 6705 /** Handlers for google.protobuf.EnumValueDescriptorProto. *********************
/ |
| 6706 |
6023 static bool enumval_startmsg(void *closure, const void *hd) { | 6707 static bool enumval_startmsg(void *closure, const void *hd) { |
6024 upb_descreader *r = closure; | 6708 upb_descreader *r = closure; |
6025 UPB_UNUSED(hd); | 6709 UPB_UNUSED(hd); |
6026 r->saw_number = false; | 6710 r->saw_number = false; |
6027 r->saw_name = false; | 6711 r->saw_name = false; |
6028 return true; | 6712 return true; |
6029 } | 6713 } |
6030 | 6714 |
6031 static size_t enumval_onname(void *closure, const void *hd, const char *buf, | 6715 static size_t enumval_onname(void *closure, const void *hd, const char *buf, |
6032 size_t n, const upb_bufhandle *handle) { | 6716 size_t n, const upb_bufhandle *handle) { |
6033 upb_descreader *r = closure; | 6717 upb_descreader *r = closure; |
6034 UPB_UNUSED(hd); | 6718 UPB_UNUSED(hd); |
6035 UPB_UNUSED(handle); | 6719 UPB_UNUSED(handle); |
6036 /* XXX: see comment at the top of the file. */ | 6720 /* XXX: see comment at the top of the file. */ |
6037 free(r->name); | 6721 upb_gfree(r->name); |
6038 r->name = upb_strndup(buf, n); | 6722 r->name = upb_strndup(buf, n); |
6039 r->saw_name = true; | 6723 r->saw_name = true; |
6040 return n; | 6724 return n; |
6041 } | 6725 } |
6042 | 6726 |
6043 static bool enumval_onnumber(void *closure, const void *hd, int32_t val) { | 6727 static bool enumval_onnumber(void *closure, const void *hd, int32_t val) { |
6044 upb_descreader *r = closure; | 6728 upb_descreader *r = closure; |
6045 UPB_UNUSED(hd); | 6729 UPB_UNUSED(hd); |
6046 r->number = val; | 6730 r->number = val; |
6047 r->saw_number = true; | 6731 r->saw_number = true; |
6048 return true; | 6732 return true; |
6049 } | 6733 } |
6050 | 6734 |
6051 static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) { | 6735 static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) { |
6052 upb_descreader *r = closure; | 6736 upb_descreader *r = closure; |
6053 upb_enumdef *e; | 6737 upb_enumdef *e; |
6054 UPB_UNUSED(hd); | 6738 UPB_UNUSED(hd); |
6055 | 6739 |
6056 if(!r->saw_number || !r->saw_name) { | 6740 if(!r->saw_number || !r->saw_name) { |
6057 upb_status_seterrmsg(status, "Enum value missing name or number."); | 6741 upb_status_seterrmsg(status, "Enum value missing name or number."); |
6058 return false; | 6742 return false; |
6059 } | 6743 } |
6060 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); | 6744 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); |
6061 upb_enumdef_addval(e, r->name, r->number, status); | 6745 upb_enumdef_addval(e, r->name, r->number, status); |
6062 free(r->name); | 6746 upb_gfree(r->name); |
6063 r->name = NULL; | 6747 r->name = NULL; |
6064 return true; | 6748 return true; |
6065 } | 6749 } |
6066 | 6750 |
6067 | 6751 /** 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 | 6752 |
6077 static bool enum_endmsg(void *closure, const void *hd, upb_status *status) { | 6753 static bool enum_endmsg(void *closure, const void *hd, upb_status *status) { |
6078 upb_descreader *r = closure; | 6754 upb_descreader *r = closure; |
6079 upb_enumdef *e; | 6755 upb_enumdef *e; |
6080 UPB_UNUSED(hd); | 6756 UPB_UNUSED(hd); |
6081 | 6757 |
6082 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); | 6758 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); |
6083 if (upb_def_fullname(upb_descreader_last(r)) == NULL) { | 6759 if (upb_def_fullname(upb_descreader_last(r)) == NULL) { |
6084 upb_status_seterrmsg(status, "Enum had no name."); | 6760 upb_status_seterrmsg(status, "Enum had no name."); |
6085 return false; | 6761 return false; |
6086 } | 6762 } |
6087 if (upb_enumdef_numvals(e) == 0) { | 6763 if (upb_enumdef_numvals(e) == 0) { |
6088 upb_status_seterrmsg(status, "Enum had no values."); | 6764 upb_status_seterrmsg(status, "Enum had no values."); |
6089 return false; | 6765 return false; |
6090 } | 6766 } |
6091 return true; | 6767 return true; |
6092 } | 6768 } |
6093 | 6769 |
6094 static size_t enum_onname(void *closure, const void *hd, const char *buf, | 6770 static size_t enum_onname(void *closure, const void *hd, const char *buf, |
6095 size_t n, const upb_bufhandle *handle) { | 6771 size_t n, const upb_bufhandle *handle) { |
6096 upb_descreader *r = closure; | 6772 upb_descreader *r = closure; |
6097 char *fullname = upb_strndup(buf, n); | 6773 char *fullname = upb_strndup(buf, n); |
6098 UPB_UNUSED(hd); | 6774 UPB_UNUSED(hd); |
6099 UPB_UNUSED(handle); | 6775 UPB_UNUSED(handle); |
6100 /* XXX: see comment at the top of the file. */ | 6776 /* XXX: see comment at the top of the file. */ |
6101 upb_def_setfullname(upb_descreader_last(r), fullname, NULL); | 6777 upb_def_setfullname(upb_descreader_last(r), fullname, NULL); |
6102 free(fullname); | 6778 upb_gfree(fullname); |
6103 return n; | 6779 return n; |
6104 } | 6780 } |
6105 | 6781 |
6106 /* Handlers for google.protobuf.FieldDescriptorProto */ | 6782 /** Handlers for google.protobuf.FieldDescriptorProto *************************/ |
| 6783 |
6107 static bool field_startmsg(void *closure, const void *hd) { | 6784 static bool field_startmsg(void *closure, const void *hd) { |
6108 upb_descreader *r = closure; | 6785 upb_descreader *r = closure; |
6109 UPB_UNUSED(hd); | 6786 UPB_UNUSED(hd); |
6110 r->f = upb_fielddef_new(&r->defs); | 6787 UPB_ASSERT(r->f); |
6111 free(r->default_string); | 6788 upb_gfree(r->default_string); |
6112 r->default_string = NULL; | 6789 r->default_string = NULL; |
6113 | 6790 |
6114 /* fielddefs default to packed, but descriptors default to non-packed. */ | 6791 /* fielddefs default to packed, but descriptors default to non-packed. */ |
6115 upb_fielddef_setpacked(r->f, false); | 6792 upb_fielddef_setpacked(r->f, false); |
6116 return true; | 6793 return true; |
6117 } | 6794 } |
6118 | 6795 |
6119 /* Converts the default value in string "str" into "d". Passes a ref on str. | 6796 /* Converts the default value in string "str" into "d". Passes a ref on str. |
6120 * Returns true on success. */ | 6797 * Returns true on success. */ |
6121 static bool parse_default(char *str, upb_fielddef *f) { | 6798 static bool parse_default(char *str, upb_fielddef *f) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6186 } | 6863 } |
6187 return success; | 6864 return success; |
6188 } | 6865 } |
6189 | 6866 |
6190 static bool field_endmsg(void *closure, const void *hd, upb_status *status) { | 6867 static bool field_endmsg(void *closure, const void *hd, upb_status *status) { |
6191 upb_descreader *r = closure; | 6868 upb_descreader *r = closure; |
6192 upb_fielddef *f = r->f; | 6869 upb_fielddef *f = r->f; |
6193 UPB_UNUSED(hd); | 6870 UPB_UNUSED(hd); |
6194 | 6871 |
6195 /* TODO: verify that all required fields were present. */ | 6872 /* TODO: verify that all required fields were present. */ |
6196 assert(upb_fielddef_number(f) != 0); | 6873 UPB_ASSERT(upb_fielddef_number(f) != 0); |
6197 assert(upb_fielddef_name(f) != NULL); | 6874 UPB_ASSERT(upb_fielddef_name(f) != NULL); |
6198 assert((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f)); | 6875 UPB_ASSERT((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f)); |
6199 | 6876 |
6200 if (r->default_string) { | 6877 if (r->default_string) { |
6201 if (upb_fielddef_issubmsg(f)) { | 6878 if (upb_fielddef_issubmsg(f)) { |
6202 upb_status_seterrmsg(status, "Submessages cannot have defaults."); | 6879 upb_status_seterrmsg(status, "Submessages cannot have defaults."); |
6203 return false; | 6880 return false; |
6204 } | 6881 } |
6205 if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 6882 if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
6206 upb_fielddef_setdefaultcstr(f, r->default_string, NULL); | 6883 upb_fielddef_setdefaultcstr(f, r->default_string, NULL); |
6207 } else { | 6884 } else { |
6208 if (r->default_string && !parse_default(r->default_string, f)) { | 6885 if (r->default_string && !parse_default(r->default_string, f)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6243 static bool field_onlabel(void *closure, const void *hd, int32_t val) { | 6920 static bool field_onlabel(void *closure, const void *hd, int32_t val) { |
6244 upb_descreader *r = closure; | 6921 upb_descreader *r = closure; |
6245 UPB_UNUSED(hd); | 6922 UPB_UNUSED(hd); |
6246 | 6923 |
6247 upb_fielddef_setlabel(r->f, val); | 6924 upb_fielddef_setlabel(r->f, val); |
6248 return true; | 6925 return true; |
6249 } | 6926 } |
6250 | 6927 |
6251 static bool field_onnumber(void *closure, const void *hd, int32_t val) { | 6928 static bool field_onnumber(void *closure, const void *hd, int32_t val) { |
6252 upb_descreader *r = closure; | 6929 upb_descreader *r = closure; |
6253 bool ok = upb_fielddef_setnumber(r->f, val, NULL); | 6930 bool ok; |
6254 UPB_UNUSED(hd); | 6931 UPB_UNUSED(hd); |
6255 | 6932 |
6256 UPB_ASSERT_VAR(ok, ok); | 6933 ok = upb_fielddef_setnumber(r->f, val, NULL); |
| 6934 UPB_ASSERT(ok); |
6257 return true; | 6935 return true; |
6258 } | 6936 } |
6259 | 6937 |
6260 static size_t field_onname(void *closure, const void *hd, const char *buf, | 6938 static size_t field_onname(void *closure, const void *hd, const char *buf, |
6261 size_t n, const upb_bufhandle *handle) { | 6939 size_t n, const upb_bufhandle *handle) { |
6262 upb_descreader *r = closure; | 6940 upb_descreader *r = closure; |
6263 char *name = upb_strndup(buf, n); | 6941 char *name = upb_strndup(buf, n); |
6264 UPB_UNUSED(hd); | 6942 UPB_UNUSED(hd); |
6265 UPB_UNUSED(handle); | 6943 UPB_UNUSED(handle); |
6266 | 6944 |
6267 /* XXX: see comment at the top of the file. */ | 6945 /* XXX: see comment at the top of the file. */ |
6268 upb_fielddef_setname(r->f, name, NULL); | 6946 upb_fielddef_setname(r->f, name, NULL); |
6269 free(name); | 6947 upb_gfree(name); |
6270 return n; | 6948 return n; |
6271 } | 6949 } |
6272 | 6950 |
6273 static size_t field_ontypename(void *closure, const void *hd, const char *buf, | 6951 static size_t field_ontypename(void *closure, const void *hd, const char *buf, |
6274 size_t n, const upb_bufhandle *handle) { | 6952 size_t n, const upb_bufhandle *handle) { |
6275 upb_descreader *r = closure; | 6953 upb_descreader *r = closure; |
6276 char *name = upb_strndup(buf, n); | 6954 char *name = upb_strndup(buf, n); |
6277 UPB_UNUSED(hd); | 6955 UPB_UNUSED(hd); |
6278 UPB_UNUSED(handle); | 6956 UPB_UNUSED(handle); |
6279 | 6957 |
6280 /* XXX: see comment at the top of the file. */ | 6958 /* XXX: see comment at the top of the file. */ |
6281 upb_fielddef_setsubdefname(r->f, name, NULL); | 6959 upb_fielddef_setsubdefname(r->f, name, NULL); |
6282 free(name); | 6960 upb_gfree(name); |
6283 return n; | 6961 return n; |
6284 } | 6962 } |
6285 | 6963 |
6286 static size_t field_onextendee(void *closure, const void *hd, const char *buf, | 6964 static size_t field_onextendee(void *closure, const void *hd, const char *buf, |
6287 size_t n, const upb_bufhandle *handle) { | 6965 size_t n, const upb_bufhandle *handle) { |
6288 upb_descreader *r = closure; | 6966 upb_descreader *r = closure; |
6289 char *name = upb_strndup(buf, n); | 6967 char *name = upb_strndup(buf, n); |
6290 UPB_UNUSED(hd); | 6968 UPB_UNUSED(hd); |
6291 UPB_UNUSED(handle); | 6969 UPB_UNUSED(handle); |
6292 | 6970 |
6293 /* XXX: see comment at the top of the file. */ | 6971 /* XXX: see comment at the top of the file. */ |
6294 upb_fielddef_setcontainingtypename(r->f, name, NULL); | 6972 upb_fielddef_setcontainingtypename(r->f, name, NULL); |
6295 free(name); | 6973 upb_gfree(name); |
6296 return n; | 6974 return n; |
6297 } | 6975 } |
6298 | 6976 |
6299 static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, | 6977 static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, |
6300 size_t n, const upb_bufhandle *handle) { | 6978 size_t n, const upb_bufhandle *handle) { |
6301 upb_descreader *r = closure; | 6979 upb_descreader *r = closure; |
6302 UPB_UNUSED(hd); | 6980 UPB_UNUSED(hd); |
6303 UPB_UNUSED(handle); | 6981 UPB_UNUSED(handle); |
6304 | 6982 |
6305 /* Have to convert from string to the correct type, but we might not know the | 6983 /* 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. | 6984 * 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. */ | 6985 * XXX: see comment at the top of the file. */ |
6308 free(r->default_string); | 6986 upb_gfree(r->default_string); |
6309 r->default_string = upb_strndup(buf, n); | 6987 r->default_string = upb_strndup(buf, n); |
6310 return n; | 6988 return n; |
6311 } | 6989 } |
6312 | 6990 |
6313 /* Handlers for google.protobuf.DescriptorProto (representing a message). */ | 6991 static bool field_ononeofindex(void *closure, const void *hd, int32_t index) { |
6314 static bool msg_startmsg(void *closure, const void *hd) { | 6992 upb_descreader *r = closure; |
| 6993 upb_oneofdef *o = upb_descreader_getoneof(r, index); |
| 6994 bool ok = upb_oneofdef_addfield(o, r->f, &r->f, NULL); |
| 6995 UPB_UNUSED(hd); |
| 6996 |
| 6997 UPB_ASSERT(ok); |
| 6998 return true; |
| 6999 } |
| 7000 |
| 7001 /** Handlers for google.protobuf.OneofDescriptorProto. ************************/ |
| 7002 |
| 7003 static size_t oneof_name(void *closure, const void *hd, const char *buf, |
| 7004 size_t n, const upb_bufhandle *handle) { |
| 7005 upb_descreader *r = closure; |
| 7006 upb_descreader_frame *f = &r->stack[r->stack_len-1]; |
| 7007 upb_oneofdef *o = upb_descreader_getoneof(r, f->oneof_index++); |
| 7008 char *name_null_terminated = upb_strndup(buf, n); |
| 7009 bool ok = upb_oneofdef_setname(o, name_null_terminated, NULL); |
| 7010 UPB_UNUSED(hd); |
| 7011 UPB_UNUSED(handle); |
| 7012 |
| 7013 UPB_ASSERT(ok); |
| 7014 free(name_null_terminated); |
| 7015 return n; |
| 7016 } |
| 7017 |
| 7018 /** Handlers for google.protobuf.DescriptorProto ******************************/ |
| 7019 |
| 7020 static bool msg_start(void *closure, const void *hd) { |
6315 upb_descreader *r = closure; | 7021 upb_descreader *r = closure; |
6316 UPB_UNUSED(hd); | 7022 UPB_UNUSED(hd); |
6317 | 7023 |
6318 upb_deflist_push(&r->defs, | |
6319 upb_msgdef_upcast_mutable(upb_msgdef_new(&r->defs))); | |
6320 upb_descreader_startcontainer(r); | 7024 upb_descreader_startcontainer(r); |
6321 return true; | 7025 return true; |
6322 } | 7026 } |
6323 | 7027 |
6324 static bool msg_endmsg(void *closure, const void *hd, upb_status *status) { | 7028 static bool msg_end(void *closure, const void *hd, upb_status *status) { |
6325 upb_descreader *r = closure; | 7029 upb_descreader *r = closure; |
6326 upb_msgdef *m = upb_descreader_top(r); | 7030 upb_msgdef *m = upb_descreader_top(r); |
6327 UPB_UNUSED(hd); | 7031 UPB_UNUSED(hd); |
6328 | 7032 |
6329 if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) { | 7033 if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) { |
6330 upb_status_seterrmsg(status, "Encountered message with no name."); | 7034 upb_status_seterrmsg(status, "Encountered message with no name."); |
6331 return false; | 7035 return false; |
6332 } | 7036 } |
6333 upb_descreader_endcontainer(r); | 7037 return upb_descreader_endcontainer(r); |
6334 return true; | |
6335 } | 7038 } |
6336 | 7039 |
6337 static size_t msg_onname(void *closure, const void *hd, const char *buf, | 7040 static size_t msg_name(void *closure, const void *hd, const char *buf, |
6338 size_t n, const upb_bufhandle *handle) { | 7041 size_t n, const upb_bufhandle *handle) { |
6339 upb_descreader *r = closure; | 7042 upb_descreader *r = closure; |
6340 upb_msgdef *m = upb_descreader_top(r); | 7043 upb_msgdef *m = upb_descreader_top(r); |
6341 /* XXX: see comment at the top of the file. */ | 7044 /* XXX: see comment at the top of the file. */ |
6342 char *name = upb_strndup(buf, n); | 7045 char *name = upb_strndup(buf, n); |
6343 UPB_UNUSED(hd); | 7046 UPB_UNUSED(hd); |
6344 UPB_UNUSED(handle); | 7047 UPB_UNUSED(handle); |
6345 | 7048 |
6346 upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); | 7049 upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); |
6347 upb_descreader_setscopename(r, name); /* Passes ownership of name. */ | 7050 upb_descreader_setscopename(r, name); /* Passes ownership of name. */ |
6348 return n; | 7051 return n; |
6349 } | 7052 } |
6350 | 7053 |
6351 static bool msg_onendfield(void *closure, const void *hd) { | 7054 static void *msg_startmsg(void *closure, const void *hd) { |
| 7055 upb_descreader *r = closure; |
| 7056 upb_msgdef *m = upb_msgdef_new(&m); |
| 7057 bool ok = upb_filedef_addmsg(r->file, m, &m, NULL); |
| 7058 UPB_UNUSED(hd); |
| 7059 UPB_ASSERT(ok); |
| 7060 return r; |
| 7061 } |
| 7062 |
| 7063 static void *msg_startext(void *closure, const void *hd) { |
| 7064 upb_descreader *r = closure; |
| 7065 upb_fielddef *f = upb_fielddef_new(&f); |
| 7066 bool ok = upb_filedef_addext(r->file, f, &f, NULL); |
| 7067 UPB_UNUSED(hd); |
| 7068 UPB_ASSERT(ok); |
| 7069 return r; |
| 7070 } |
| 7071 |
| 7072 static void *msg_startfield(void *closure, const void *hd) { |
| 7073 upb_descreader *r = closure; |
| 7074 r->f = upb_fielddef_new(&r->f); |
| 7075 /* We can't add the new field to the message until its name/number are |
| 7076 * filled in. */ |
| 7077 UPB_UNUSED(hd); |
| 7078 return r; |
| 7079 } |
| 7080 |
| 7081 static bool msg_endfield(void *closure, const void *hd) { |
| 7082 upb_descreader *r = closure; |
| 7083 upb_msgdef *m = upb_descreader_top(r); |
| 7084 bool ok; |
| 7085 UPB_UNUSED(hd); |
| 7086 |
| 7087 /* Oneof fields are added to the msgdef through their oneof, so don't need to |
| 7088 * be added here. */ |
| 7089 if (upb_fielddef_containingoneof(r->f) == NULL) { |
| 7090 ok = upb_msgdef_addfield(m, r->f, &r->f, NULL); |
| 7091 UPB_ASSERT(ok); |
| 7092 } |
| 7093 r->f = NULL; |
| 7094 return true; |
| 7095 } |
| 7096 |
| 7097 static bool msg_onmapentry(void *closure, const void *hd, bool mapentry) { |
6352 upb_descreader *r = closure; | 7098 upb_descreader *r = closure; |
6353 upb_msgdef *m = upb_descreader_top(r); | 7099 upb_msgdef *m = upb_descreader_top(r); |
6354 UPB_UNUSED(hd); | 7100 UPB_UNUSED(hd); |
6355 | 7101 |
6356 upb_msgdef_addfield(m, r->f, &r->defs, NULL); | 7102 upb_msgdef_setmapentry(m, mapentry); |
6357 r->f = NULL; | 7103 r->f = NULL; |
6358 return true; | 7104 return true; |
6359 } | 7105 } |
6360 | 7106 |
6361 static bool pushextension(void *closure, const void *hd) { | |
6362 upb_descreader *r = closure; | |
6363 UPB_UNUSED(hd); | |
6364 | 7107 |
6365 assert(upb_fielddef_containingtypename(r->f)); | 7108 |
6366 upb_fielddef_setisextension(r->f, true); | 7109 /** Code to register handlers *************************************************/ |
6367 upb_deflist_push(&r->defs, upb_fielddef_upcast_mutable(r->f)); | 7110 |
6368 r->f = NULL; | 7111 #define F(msg, field) upbdefs_google_protobuf_ ## msg ## _f_ ## field(m) |
6369 return true; | 7112 |
| 7113 static void reghandlers(const void *closure, upb_handlers *h) { |
| 7114 const upb_msgdef *m = upb_handlers_msgdef(h); |
| 7115 UPB_UNUSED(closure); |
| 7116 |
| 7117 if (upbdefs_google_protobuf_FileDescriptorSet_is(m)) { |
| 7118 upb_handlers_setstartsubmsg(h, F(FileDescriptorSet, file), |
| 7119 &fileset_startfile, NULL); |
| 7120 } else if (upbdefs_google_protobuf_DescriptorProto_is(m)) { |
| 7121 upb_handlers_setstartmsg(h, &msg_start, NULL); |
| 7122 upb_handlers_setendmsg(h, &msg_end, NULL); |
| 7123 upb_handlers_setstring(h, F(DescriptorProto, name), &msg_name, NULL); |
| 7124 upb_handlers_setstartsubmsg(h, F(DescriptorProto, extension), &msg_startext, |
| 7125 NULL); |
| 7126 upb_handlers_setstartsubmsg(h, F(DescriptorProto, nested_type), |
| 7127 &msg_startmsg, NULL); |
| 7128 upb_handlers_setstartsubmsg(h, F(DescriptorProto, field), |
| 7129 &msg_startfield, NULL); |
| 7130 upb_handlers_setendsubmsg(h, F(DescriptorProto, field), |
| 7131 &msg_endfield, NULL); |
| 7132 upb_handlers_setstartsubmsg(h, F(DescriptorProto, enum_type), |
| 7133 &file_startenum, NULL); |
| 7134 } else if (upbdefs_google_protobuf_FileDescriptorProto_is(m)) { |
| 7135 upb_handlers_setstartmsg(h, &file_start, NULL); |
| 7136 upb_handlers_setendmsg(h, &file_end, NULL); |
| 7137 upb_handlers_setstring(h, F(FileDescriptorProto, name), &file_onname, |
| 7138 NULL); |
| 7139 upb_handlers_setstring(h, F(FileDescriptorProto, package), &file_onpackage, |
| 7140 NULL); |
| 7141 upb_handlers_setstring(h, F(FileDescriptorProto, syntax), &file_onsyntax, |
| 7142 NULL); |
| 7143 upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, message_type), |
| 7144 &file_startmsg, NULL); |
| 7145 upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, enum_type), |
| 7146 &file_startenum, NULL); |
| 7147 upb_handlers_setstartsubmsg(h, F(FileDescriptorProto, extension), |
| 7148 &file_startext, NULL); |
| 7149 } else if (upbdefs_google_protobuf_EnumValueDescriptorProto_is(m)) { |
| 7150 upb_handlers_setstartmsg(h, &enumval_startmsg, NULL); |
| 7151 upb_handlers_setendmsg(h, &enumval_endmsg, NULL); |
| 7152 upb_handlers_setstring(h, F(EnumValueDescriptorProto, name), &enumval_onname
, NULL); |
| 7153 upb_handlers_setint32(h, F(EnumValueDescriptorProto, number), &enumval_onnum
ber, |
| 7154 NULL); |
| 7155 } else if (upbdefs_google_protobuf_EnumDescriptorProto_is(m)) { |
| 7156 upb_handlers_setendmsg(h, &enum_endmsg, NULL); |
| 7157 upb_handlers_setstring(h, F(EnumDescriptorProto, name), &enum_onname, NULL); |
| 7158 } else if (upbdefs_google_protobuf_FieldDescriptorProto_is(m)) { |
| 7159 upb_handlers_setstartmsg(h, &field_startmsg, NULL); |
| 7160 upb_handlers_setendmsg(h, &field_endmsg, NULL); |
| 7161 upb_handlers_setint32(h, F(FieldDescriptorProto, type), &field_ontype, |
| 7162 NULL); |
| 7163 upb_handlers_setint32(h, F(FieldDescriptorProto, label), &field_onlabel, |
| 7164 NULL); |
| 7165 upb_handlers_setint32(h, F(FieldDescriptorProto, number), &field_onnumber, |
| 7166 NULL); |
| 7167 upb_handlers_setstring(h, F(FieldDescriptorProto, name), &field_onname, |
| 7168 NULL); |
| 7169 upb_handlers_setstring(h, F(FieldDescriptorProto, type_name), |
| 7170 &field_ontypename, NULL); |
| 7171 upb_handlers_setstring(h, F(FieldDescriptorProto, extendee), |
| 7172 &field_onextendee, NULL); |
| 7173 upb_handlers_setstring(h, F(FieldDescriptorProto, default_value), |
| 7174 &field_ondefaultval, NULL); |
| 7175 upb_handlers_setint32(h, F(FieldDescriptorProto, oneof_index), |
| 7176 &field_ononeofindex, NULL); |
| 7177 } else if (upbdefs_google_protobuf_OneofDescriptorProto_is(m)) { |
| 7178 upb_handlers_setstring(h, F(OneofDescriptorProto, name), &oneof_name, NULL); |
| 7179 } else if (upbdefs_google_protobuf_FieldOptions_is(m)) { |
| 7180 upb_handlers_setbool(h, F(FieldOptions, lazy), &field_onlazy, NULL); |
| 7181 upb_handlers_setbool(h, F(FieldOptions, packed), &field_onpacked, NULL); |
| 7182 } else if (upbdefs_google_protobuf_MessageOptions_is(m)) { |
| 7183 upb_handlers_setbool(h, F(MessageOptions, map_entry), &msg_onmapentry, NULL)
; |
| 7184 } |
| 7185 |
| 7186 UPB_ASSERT(upb_ok(upb_handlers_status(h))); |
6370 } | 7187 } |
6371 | 7188 |
6372 #define D(name) upbdefs_google_protobuf_ ## name(s) | 7189 #undef F |
6373 | 7190 |
6374 static void reghandlers(const void *closure, upb_handlers *h) { | 7191 void descreader_cleanup(void *_r) { |
6375 const upb_symtab *s = closure; | 7192 upb_descreader *r = _r; |
6376 const upb_msgdef *m = upb_handlers_msgdef(h); | 7193 size_t i; |
6377 | 7194 |
6378 if (m == D(DescriptorProto)) { | 7195 for (i = 0; i < upb_descreader_filecount(r); i++) { |
6379 upb_handlers_setstartmsg(h, &msg_startmsg, NULL); | 7196 upb_filedef_unref(upb_descreader_file(r, i), &r->files); |
6380 upb_handlers_setendmsg(h, &msg_endmsg, NULL); | 7197 } |
6381 upb_handlers_setstring(h, D(DescriptorProto_name), &msg_onname, NULL); | 7198 |
6382 upb_handlers_setendsubmsg(h, D(DescriptorProto_field), &msg_onendfield, | 7199 upb_gfree(r->name); |
6383 NULL); | 7200 upb_inttable_uninit(&r->files); |
6384 upb_handlers_setendsubmsg(h, D(DescriptorProto_extension), &pushextension, | 7201 upb_inttable_uninit(&r->oneofs); |
6385 NULL); | 7202 upb_gfree(r->default_string); |
6386 } else if (m == D(FileDescriptorProto)) { | 7203 while (r->stack_len > 0) { |
6387 upb_handlers_setstartmsg(h, &file_startmsg, NULL); | 7204 upb_descreader_frame *f = &r->stack[--r->stack_len]; |
6388 upb_handlers_setendmsg(h, &file_endmsg, NULL); | 7205 upb_gfree(f->name); |
6389 upb_handlers_setstring(h, D(FileDescriptorProto_package), &file_onpackage, | |
6390 NULL); | |
6391 upb_handlers_setendsubmsg(h, D(FileDescriptorProto_extension), &pushextensio
n, | |
6392 NULL); | |
6393 } else if (m == D(EnumValueDescriptorProto)) { | |
6394 upb_handlers_setstartmsg(h, &enumval_startmsg, NULL); | |
6395 upb_handlers_setendmsg(h, &enumval_endmsg, NULL); | |
6396 upb_handlers_setstring(h, D(EnumValueDescriptorProto_name), &enumval_onname,
NULL); | |
6397 upb_handlers_setint32(h, D(EnumValueDescriptorProto_number), &enumval_onnumb
er, | |
6398 NULL); | |
6399 } else if (m == D(EnumDescriptorProto)) { | |
6400 upb_handlers_setstartmsg(h, &enum_startmsg, NULL); | |
6401 upb_handlers_setendmsg(h, &enum_endmsg, NULL); | |
6402 upb_handlers_setstring(h, D(EnumDescriptorProto_name), &enum_onname, NULL); | |
6403 } else if (m == D(FieldDescriptorProto)) { | |
6404 upb_handlers_setstartmsg(h, &field_startmsg, NULL); | |
6405 upb_handlers_setendmsg(h, &field_endmsg, NULL); | |
6406 upb_handlers_setint32(h, D(FieldDescriptorProto_type), &field_ontype, | |
6407 NULL); | |
6408 upb_handlers_setint32(h, D(FieldDescriptorProto_label), &field_onlabel, | |
6409 NULL); | |
6410 upb_handlers_setint32(h, D(FieldDescriptorProto_number), &field_onnumber, | |
6411 NULL); | |
6412 upb_handlers_setstring(h, D(FieldDescriptorProto_name), &field_onname, | |
6413 NULL); | |
6414 upb_handlers_setstring(h, D(FieldDescriptorProto_type_name), | |
6415 &field_ontypename, NULL); | |
6416 upb_handlers_setstring(h, D(FieldDescriptorProto_extendee), | |
6417 &field_onextendee, NULL); | |
6418 upb_handlers_setstring(h, D(FieldDescriptorProto_default_value), | |
6419 &field_ondefaultval, NULL); | |
6420 } else if (m == D(FieldOptions)) { | |
6421 upb_handlers_setbool(h, D(FieldOptions_lazy), &field_onlazy, NULL); | |
6422 upb_handlers_setbool(h, D(FieldOptions_packed), &field_onpacked, NULL); | |
6423 } | 7206 } |
6424 } | 7207 } |
6425 | 7208 |
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 | 7209 |
6440 /* Public API ****************************************************************/ | 7210 /* Public API ****************************************************************/ |
6441 | 7211 |
6442 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) { | 7212 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) { |
6443 upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader)); | 7213 upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader)); |
6444 if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) { | 7214 if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) { |
6445 return NULL; | 7215 return NULL; |
6446 } | 7216 } |
6447 | 7217 |
6448 upb_deflist_init(&r->defs); | 7218 upb_inttable_init(&r->files, UPB_CTYPE_PTR); |
| 7219 upb_inttable_init(&r->oneofs, UPB_CTYPE_PTR); |
6449 upb_sink_reset(upb_descreader_input(r), h, r); | 7220 upb_sink_reset(upb_descreader_input(r), h, r); |
6450 r->stack_len = 0; | 7221 r->stack_len = 0; |
6451 r->name = NULL; | 7222 r->name = NULL; |
6452 r->default_string = NULL; | 7223 r->default_string = NULL; |
6453 | 7224 |
6454 return r; | 7225 return r; |
6455 } | 7226 } |
6456 | 7227 |
6457 upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n) { | 7228 size_t upb_descreader_filecount(const upb_descreader *r) { |
6458 *n = r->defs.len; | 7229 return upb_inttable_count(&r->files); |
6459 upb_deflist_donaterefs(&r->defs, owner); | 7230 } |
6460 return r->defs.defs; | 7231 |
| 7232 upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i) { |
| 7233 upb_value v; |
| 7234 if (upb_inttable_lookup(&r->files, i, &v)) { |
| 7235 return upb_value_getptr(v); |
| 7236 } else { |
| 7237 return NULL; |
| 7238 } |
6461 } | 7239 } |
6462 | 7240 |
6463 upb_sink *upb_descreader_input(upb_descreader *r) { | 7241 upb_sink *upb_descreader_input(upb_descreader *r) { |
6464 return &r->sink; | 7242 return &r->sink; |
6465 } | 7243 } |
6466 | 7244 |
6467 const upb_handlers *upb_descreader_newhandlers(const void *owner) { | 7245 const upb_handlers *upb_descreader_newhandlers(const void *owner) { |
6468 const upb_symtab *s = upbdefs_google_protobuf_descriptor(&s); | 7246 const upb_msgdef *m = upbdefs_google_protobuf_FileDescriptorSet_get(&m); |
6469 const upb_handlers *h = upb_handlers_newfrozen( | 7247 const upb_handlers *h = upb_handlers_newfrozen(m, owner, reghandlers, NULL); |
6470 upbdefs_google_protobuf_FileDescriptorSet(s), owner, reghandlers, s); | 7248 upb_msgdef_unref(m, &m); |
6471 upb_symtab_unref(s, &s); | |
6472 return h; | 7249 return h; |
6473 } | 7250 } |
6474 /* | 7251 /* |
6475 ** protobuf decoder bytecode compiler | 7252 ** protobuf decoder bytecode compiler |
6476 ** | 7253 ** |
6477 ** Code to compile a upb::Handlers into bytecode for decoding a protobuf | 7254 ** Code to compile a upb::Handlers into bytecode for decoding a protobuf |
6478 ** according to that specific schema and destination handlers. | 7255 ** according to that specific schema and destination handlers. |
6479 ** | 7256 ** |
6480 ** Compiling to bytecode is always the first step. If we are using the | 7257 ** 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 | 7258 ** interpreted decoder we leave it as bytecode and interpret that. If we are |
(...skipping 13 matching lines...) Expand all Loading... |
6495 #define EMPTYLABEL -1 | 7272 #define EMPTYLABEL -1 |
6496 | 7273 |
6497 /* mgroup *********************************************************************/ | 7274 /* mgroup *********************************************************************/ |
6498 | 7275 |
6499 static void freegroup(upb_refcounted *r) { | 7276 static void freegroup(upb_refcounted *r) { |
6500 mgroup *g = (mgroup*)r; | 7277 mgroup *g = (mgroup*)r; |
6501 upb_inttable_uninit(&g->methods); | 7278 upb_inttable_uninit(&g->methods); |
6502 #ifdef UPB_USE_JIT_X64 | 7279 #ifdef UPB_USE_JIT_X64 |
6503 upb_pbdecoder_freejit(g); | 7280 upb_pbdecoder_freejit(g); |
6504 #endif | 7281 #endif |
6505 free(g->bytecode); | 7282 upb_gfree(g->bytecode); |
6506 free(g); | 7283 upb_gfree(g); |
6507 } | 7284 } |
6508 | 7285 |
6509 static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit, | 7286 static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit, |
6510 void *closure) { | 7287 void *closure) { |
6511 const mgroup *g = (const mgroup*)r; | 7288 const mgroup *g = (const mgroup*)r; |
6512 upb_inttable_iter i; | 7289 upb_inttable_iter i; |
6513 upb_inttable_begin(&i, &g->methods); | 7290 upb_inttable_begin(&i, &g->methods); |
6514 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 7291 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
6515 upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i)); | 7292 upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i)); |
6516 visit(r, upb_pbdecodermethod_upcast(method), closure); | 7293 visit(r, upb_pbdecodermethod_upcast(method), closure); |
6517 } | 7294 } |
6518 } | 7295 } |
6519 | 7296 |
6520 mgroup *newgroup(const void *owner) { | 7297 mgroup *newgroup(const void *owner) { |
6521 mgroup *g = malloc(sizeof(*g)); | 7298 mgroup *g = upb_gmalloc(sizeof(*g)); |
6522 static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup}; | 7299 static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup}; |
6523 upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner); | 7300 upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner); |
6524 upb_inttable_init(&g->methods, UPB_CTYPE_PTR); | 7301 upb_inttable_init(&g->methods, UPB_CTYPE_PTR); |
6525 g->bytecode = NULL; | 7302 g->bytecode = NULL; |
6526 g->bytecode_end = NULL; | 7303 g->bytecode_end = NULL; |
6527 return g; | 7304 return g; |
6528 } | 7305 } |
6529 | 7306 |
6530 | 7307 |
6531 /* upb_pbdecodermethod ********************************************************/ | 7308 /* upb_pbdecodermethod ********************************************************/ |
6532 | 7309 |
6533 static void freemethod(upb_refcounted *r) { | 7310 static void freemethod(upb_refcounted *r) { |
6534 upb_pbdecodermethod *method = (upb_pbdecodermethod*)r; | 7311 upb_pbdecodermethod *method = (upb_pbdecodermethod*)r; |
6535 | 7312 |
6536 if (method->dest_handlers_) { | 7313 if (method->dest_handlers_) { |
6537 upb_handlers_unref(method->dest_handlers_, method); | 7314 upb_handlers_unref(method->dest_handlers_, method); |
6538 } | 7315 } |
6539 | 7316 |
6540 upb_inttable_uninit(&method->dispatch); | 7317 upb_inttable_uninit(&method->dispatch); |
6541 free(method); | 7318 upb_gfree(method); |
6542 } | 7319 } |
6543 | 7320 |
6544 static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit, | 7321 static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit, |
6545 void *closure) { | 7322 void *closure) { |
6546 const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r; | 7323 const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r; |
6547 visit(r, m->group, closure); | 7324 visit(r, m->group, closure); |
6548 } | 7325 } |
6549 | 7326 |
6550 static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers, | 7327 static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers, |
6551 mgroup *group) { | 7328 mgroup *group) { |
6552 static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod}; | 7329 static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod}; |
6553 upb_pbdecodermethod *ret = malloc(sizeof(*ret)); | 7330 upb_pbdecodermethod *ret = upb_gmalloc(sizeof(*ret)); |
6554 upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret); | 7331 upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret); |
6555 upb_byteshandler_init(&ret->input_handler_); | 7332 upb_byteshandler_init(&ret->input_handler_); |
6556 | 7333 |
6557 /* The method references the group and vice-versa, in a circular reference. */ | 7334 /* The method references the group and vice-versa, in a circular reference. */ |
6558 upb_ref2(ret, group); | 7335 upb_ref2(ret, group); |
6559 upb_ref2(group, ret); | 7336 upb_ref2(group, ret); |
6560 upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret)); | 7337 upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret)); |
6561 upb_pbdecodermethod_unref(ret, &ret); | 7338 upb_pbdecodermethod_unref(ret, &ret); |
6562 | 7339 |
6563 ret->group = mgroup_upcast_mutable(group); | 7340 ret->group = mgroup_upcast_mutable(group); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6606 | 7383 |
6607 uint32_t *pc; | 7384 uint32_t *pc; |
6608 int fwd_labels[MAXLABEL]; | 7385 int fwd_labels[MAXLABEL]; |
6609 int back_labels[MAXLABEL]; | 7386 int back_labels[MAXLABEL]; |
6610 | 7387 |
6611 /* For fields marked "lazy", parse them lazily or eagerly? */ | 7388 /* For fields marked "lazy", parse them lazily or eagerly? */ |
6612 bool lazy; | 7389 bool lazy; |
6613 } compiler; | 7390 } compiler; |
6614 | 7391 |
6615 static compiler *newcompiler(mgroup *group, bool lazy) { | 7392 static compiler *newcompiler(mgroup *group, bool lazy) { |
6616 compiler *ret = malloc(sizeof(*ret)); | 7393 compiler *ret = upb_gmalloc(sizeof(*ret)); |
6617 int i; | 7394 int i; |
6618 | 7395 |
6619 ret->group = group; | 7396 ret->group = group; |
6620 ret->lazy = lazy; | 7397 ret->lazy = lazy; |
6621 for (i = 0; i < MAXLABEL; i++) { | 7398 for (i = 0; i < MAXLABEL; i++) { |
6622 ret->fwd_labels[i] = EMPTYLABEL; | 7399 ret->fwd_labels[i] = EMPTYLABEL; |
6623 ret->back_labels[i] = EMPTYLABEL; | 7400 ret->back_labels[i] = EMPTYLABEL; |
6624 } | 7401 } |
6625 return ret; | 7402 return ret; |
6626 } | 7403 } |
6627 | 7404 |
6628 static void freecompiler(compiler *c) { | 7405 static void freecompiler(compiler *c) { |
6629 free(c); | 7406 upb_gfree(c); |
6630 } | 7407 } |
6631 | 7408 |
6632 const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); | 7409 const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); |
6633 | 7410 |
6634 /* How many words an instruction is. */ | 7411 /* How many words an instruction is. */ |
6635 static int instruction_len(uint32_t instr) { | 7412 static int instruction_len(uint32_t instr) { |
6636 switch (getop(instr)) { | 7413 switch (getop(instr)) { |
6637 case OP_SETDISPATCH: return 1 + ptr_words; | 7414 case OP_SETDISPATCH: return 1 + ptr_words; |
6638 case OP_TAGN: return 3; | 7415 case OP_TAGN: return 3; |
6639 case OP_SETBIGGROUPNUM: return 2; | 7416 case OP_SETBIGGROUPNUM: return 2; |
6640 default: return 1; | 7417 default: return 1; |
6641 } | 7418 } |
6642 } | 7419 } |
6643 | 7420 |
6644 bool op_has_longofs(int32_t instruction) { | 7421 bool op_has_longofs(int32_t instruction) { |
6645 switch (getop(instruction)) { | 7422 switch (getop(instruction)) { |
6646 case OP_CALL: | 7423 case OP_CALL: |
6647 case OP_BRANCH: | 7424 case OP_BRANCH: |
6648 case OP_CHECKDELIM: | 7425 case OP_CHECKDELIM: |
6649 return true; | 7426 return true; |
6650 /* The "tag" instructions only have 8 bytes available for the jump target, | 7427 /* The "tag" instructions only have 8 bytes available for the jump target, |
6651 * but that is ok because these opcodes only require short jumps. */ | 7428 * but that is ok because these opcodes only require short jumps. */ |
6652 case OP_TAG1: | 7429 case OP_TAG1: |
6653 case OP_TAG2: | 7430 case OP_TAG2: |
6654 case OP_TAGN: | 7431 case OP_TAGN: |
6655 return false; | 7432 return false; |
6656 default: | 7433 default: |
6657 assert(false); | 7434 UPB_ASSERT(false); |
6658 return false; | 7435 return false; |
6659 } | 7436 } |
6660 } | 7437 } |
6661 | 7438 |
6662 static int32_t getofs(uint32_t instruction) { | 7439 static int32_t getofs(uint32_t instruction) { |
6663 if (op_has_longofs(instruction)) { | 7440 if (op_has_longofs(instruction)) { |
6664 return (int32_t)instruction >> 8; | 7441 return (int32_t)instruction >> 8; |
6665 } else { | 7442 } else { |
6666 return (int8_t)(instruction >> 8); | 7443 return (int8_t)(instruction >> 8); |
6667 } | 7444 } |
6668 } | 7445 } |
6669 | 7446 |
6670 static void setofs(uint32_t *instruction, int32_t ofs) { | 7447 static void setofs(uint32_t *instruction, int32_t ofs) { |
6671 if (op_has_longofs(*instruction)) { | 7448 if (op_has_longofs(*instruction)) { |
6672 *instruction = getop(*instruction) | ofs << 8; | 7449 *instruction = getop(*instruction) | ofs << 8; |
6673 } else { | 7450 } else { |
6674 *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8); | 7451 *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8); |
6675 } | 7452 } |
6676 assert(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ | 7453 UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow.
*/ |
6677 } | 7454 } |
6678 | 7455 |
6679 static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } | 7456 static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } |
6680 | 7457 |
6681 /* Defines a local label at the current PC location. All previous forward | 7458 /* Defines a local label at the current PC location. All previous forward |
6682 * references are updated to point to this location. The location is noted | 7459 * references are updated to point to this location. The location is noted |
6683 * for any future backward references. */ | 7460 * for any future backward references. */ |
6684 static void label(compiler *c, unsigned int label) { | 7461 static void label(compiler *c, unsigned int label) { |
6685 int val; | 7462 int val; |
6686 uint32_t *codep; | 7463 uint32_t *codep; |
6687 | 7464 |
6688 assert(label < MAXLABEL); | 7465 UPB_ASSERT(label < MAXLABEL); |
6689 val = c->fwd_labels[label]; | 7466 val = c->fwd_labels[label]; |
6690 codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; | 7467 codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; |
6691 while (codep) { | 7468 while (codep) { |
6692 int ofs = getofs(*codep); | 7469 int ofs = getofs(*codep); |
6693 setofs(codep, c->pc - codep - instruction_len(*codep)); | 7470 setofs(codep, c->pc - codep - instruction_len(*codep)); |
6694 codep = ofs ? codep + ofs : NULL; | 7471 codep = ofs ? codep + ofs : NULL; |
6695 } | 7472 } |
6696 c->fwd_labels[label] = EMPTYLABEL; | 7473 c->fwd_labels[label] = EMPTYLABEL; |
6697 c->back_labels[label] = pcofs(c); | 7474 c->back_labels[label] = pcofs(c); |
6698 } | 7475 } |
6699 | 7476 |
6700 /* Creates a reference to a numbered label; either a forward reference | 7477 /* Creates a reference to a numbered label; either a forward reference |
6701 * (positive arg) or backward reference (negative arg). For forward references | 7478 * (positive arg) or backward reference (negative arg). For forward references |
6702 * the value returned now is actually a "next" pointer into a linked list of all | 7479 * the value returned now is actually a "next" pointer into a linked list of all |
6703 * instructions that use this label and will be patched later when the label is | 7480 * instructions that use this label and will be patched later when the label is |
6704 * defined with label(). | 7481 * defined with label(). |
6705 * | 7482 * |
6706 * The returned value is the offset that should be written into the instruction. | 7483 * The returned value is the offset that should be written into the instruction. |
6707 */ | 7484 */ |
6708 static int32_t labelref(compiler *c, int label) { | 7485 static int32_t labelref(compiler *c, int label) { |
6709 assert(label < MAXLABEL); | 7486 UPB_ASSERT(label < MAXLABEL); |
6710 if (label == LABEL_DISPATCH) { | 7487 if (label == LABEL_DISPATCH) { |
6711 /* No resolving required. */ | 7488 /* No resolving required. */ |
6712 return 0; | 7489 return 0; |
6713 } else if (label < 0) { | 7490 } else if (label < 0) { |
6714 /* Backward local label. Relative to the next instruction. */ | 7491 /* Backward local label. Relative to the next instruction. */ |
6715 uint32_t from = (c->pc + 1) - c->group->bytecode; | 7492 uint32_t from = (c->pc + 1) - c->group->bytecode; |
6716 return c->back_labels[-label] - from; | 7493 return c->back_labels[-label] - from; |
6717 } else { | 7494 } else { |
6718 /* Forward local label: prepend to (possibly-empty) linked list. */ | 7495 /* Forward local label: prepend to (possibly-empty) linked list. */ |
6719 int *lptr = &c->fwd_labels[label]; | 7496 int *lptr = &c->fwd_labels[label]; |
6720 int32_t ret = (*lptr == EMPTYLABEL) ? 0 : *lptr - pcofs(c); | 7497 int32_t ret = (*lptr == EMPTYLABEL) ? 0 : *lptr - pcofs(c); |
6721 *lptr = pcofs(c); | 7498 *lptr = pcofs(c); |
6722 return ret; | 7499 return ret; |
6723 } | 7500 } |
6724 } | 7501 } |
6725 | 7502 |
6726 static void put32(compiler *c, uint32_t v) { | 7503 static void put32(compiler *c, uint32_t v) { |
6727 mgroup *g = c->group; | 7504 mgroup *g = c->group; |
6728 if (c->pc == g->bytecode_end) { | 7505 if (c->pc == g->bytecode_end) { |
6729 int ofs = pcofs(c); | 7506 int ofs = pcofs(c); |
6730 size_t oldsize = g->bytecode_end - g->bytecode; | 7507 size_t oldsize = g->bytecode_end - g->bytecode; |
6731 size_t newsize = UPB_MAX(oldsize * 2, 64); | 7508 size_t newsize = UPB_MAX(oldsize * 2, 64); |
6732 /* TODO(haberman): handle OOM. */ | 7509 /* TODO(haberman): handle OOM. */ |
6733 g->bytecode = realloc(g->bytecode, newsize * sizeof(uint32_t)); | 7510 g->bytecode = upb_grealloc(g->bytecode, oldsize * sizeof(uint32_t), |
| 7511 newsize * sizeof(uint32_t)); |
6734 g->bytecode_end = g->bytecode + newsize; | 7512 g->bytecode_end = g->bytecode + newsize; |
6735 c->pc = g->bytecode + ofs; | 7513 c->pc = g->bytecode + ofs; |
6736 } | 7514 } |
6737 *c->pc++ = v; | 7515 *c->pc++ = v; |
6738 } | 7516 } |
6739 | 7517 |
6740 static void putop(compiler *c, opcode op, ...) { | 7518 static void putop(compiler *c, opcode op, ...) { |
6741 va_list ap; | 7519 va_list ap; |
6742 va_start(ap, op); | 7520 va_start(ap, op); |
6743 | 7521 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6798 int label = va_arg(ap, int); | 7576 int label = va_arg(ap, int); |
6799 setofs(&instruction, labelref(c, label)); | 7577 setofs(&instruction, labelref(c, label)); |
6800 put32(c, instruction); | 7578 put32(c, instruction); |
6801 break; | 7579 break; |
6802 } | 7580 } |
6803 case OP_TAG1: | 7581 case OP_TAG1: |
6804 case OP_TAG2: { | 7582 case OP_TAG2: { |
6805 int label = va_arg(ap, int); | 7583 int label = va_arg(ap, int); |
6806 uint64_t tag = va_arg(ap, uint64_t); | 7584 uint64_t tag = va_arg(ap, uint64_t); |
6807 uint32_t instruction = op | (tag << 16); | 7585 uint32_t instruction = op | (tag << 16); |
6808 assert(tag <= 0xffff); | 7586 UPB_ASSERT(tag <= 0xffff); |
6809 setofs(&instruction, labelref(c, label)); | 7587 setofs(&instruction, labelref(c, label)); |
6810 put32(c, instruction); | 7588 put32(c, instruction); |
6811 break; | 7589 break; |
6812 } | 7590 } |
6813 case OP_TAGN: { | 7591 case OP_TAGN: { |
6814 int label = va_arg(ap, int); | 7592 int label = va_arg(ap, int); |
6815 uint64_t tag = va_arg(ap, uint64_t); | 7593 uint64_t tag = va_arg(ap, uint64_t); |
6816 uint32_t instruction = op | (upb_value_size(tag) << 16); | 7594 uint32_t instruction = op | (upb_value_size(tag) << 16); |
6817 setofs(&instruction, labelref(c, label)); | 7595 setofs(&instruction, labelref(c, label)); |
6818 put32(c, instruction); | 7596 put32(c, instruction); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6935 fputs("\n", f); | 7713 fputs("\n", f); |
6936 } | 7714 } |
6937 } | 7715 } |
6938 | 7716 |
6939 #endif | 7717 #endif |
6940 | 7718 |
6941 static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) { | 7719 static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) { |
6942 uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type; | 7720 uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type; |
6943 uint64_t encoded_tag = upb_vencode32(tag); | 7721 uint64_t encoded_tag = upb_vencode32(tag); |
6944 /* No tag should be greater than 5 bytes. */ | 7722 /* No tag should be greater than 5 bytes. */ |
6945 assert(encoded_tag <= 0xffffffffff); | 7723 UPB_ASSERT(encoded_tag <= 0xffffffffff); |
6946 return encoded_tag; | 7724 return encoded_tag; |
6947 } | 7725 } |
6948 | 7726 |
6949 static void putchecktag(compiler *c, const upb_fielddef *f, | 7727 static void putchecktag(compiler *c, const upb_fielddef *f, |
6950 int wire_type, int dest) { | 7728 int wire_type, int dest) { |
6951 uint64_t tag = get_encoded_tag(f, wire_type); | 7729 uint64_t tag = get_encoded_tag(f, wire_type); |
6952 switch (upb_value_size(tag)) { | 7730 switch (upb_value_size(tag)) { |
6953 case 1: | 7731 case 1: |
6954 putop(c, OP_TAG1, dest, tag); | 7732 putop(c, OP_TAG1, dest, tag); |
6955 break; | 7733 break; |
6956 case 2: | 7734 case 2: |
6957 putop(c, OP_TAG2, dest, tag); | 7735 putop(c, OP_TAG2, dest, tag); |
6958 break; | 7736 break; |
6959 default: | 7737 default: |
6960 putop(c, OP_TAGN, dest, tag); | 7738 putop(c, OP_TAGN, dest, tag); |
6961 break; | 7739 break; |
6962 } | 7740 } |
6963 } | 7741 } |
6964 | 7742 |
6965 static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) { | 7743 static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) { |
6966 upb_selector_t selector; | 7744 upb_selector_t selector; |
6967 bool ok = upb_handlers_getselector(f, type, &selector); | 7745 bool ok = upb_handlers_getselector(f, type, &selector); |
6968 UPB_ASSERT_VAR(ok, ok); | 7746 UPB_ASSERT(ok); |
6969 return selector; | 7747 return selector; |
6970 } | 7748 } |
6971 | 7749 |
6972 /* Takes an existing, primary dispatch table entry and repacks it with a | 7750 /* Takes an existing, primary dispatch table entry and repacks it with a |
6973 * different alternate wire type. Called when we are inserting a secondary | 7751 * different alternate wire type. Called when we are inserting a secondary |
6974 * dispatch table entry for an alternate wire type. */ | 7752 * dispatch table entry for an alternate wire type. */ |
6975 static uint64_t repack(uint64_t dispatch, int new_wt2) { | 7753 static uint64_t repack(uint64_t dispatch, int new_wt2) { |
6976 uint64_t ofs; | 7754 uint64_t ofs; |
6977 uint8_t wt1; | 7755 uint8_t wt1; |
6978 uint8_t old_wt2; | 7756 uint8_t old_wt2; |
6979 upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2); | 7757 upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2); |
6980 assert(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */ | 7758 UPB_ASSERT(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */ |
6981 return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2); | 7759 return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2); |
6982 } | 7760 } |
6983 | 7761 |
6984 /* Marks the current bytecode position as the dispatch target for this message, | 7762 /* Marks the current bytecode position as the dispatch target for this message, |
6985 * field, and wire type. */ | 7763 * field, and wire type. */ |
6986 static void dispatchtarget(compiler *c, upb_pbdecodermethod *method, | 7764 static void dispatchtarget(compiler *c, upb_pbdecodermethod *method, |
6987 const upb_fielddef *f, int wire_type) { | 7765 const upb_fielddef *f, int wire_type) { |
6988 /* Offset is relative to msg base. */ | 7766 /* Offset is relative to msg base. */ |
6989 uint64_t ofs = pcofs(c) - method->code_base.ofs; | 7767 uint64_t ofs = pcofs(c) - method->code_base.ofs; |
6990 uint32_t fn = upb_fielddef_number(f); | 7768 uint32_t fn = upb_fielddef_number(f); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7060 | 7838 |
7061 /* Generates bytecode to parse a single non-lazy message field. */ | 7839 /* Generates bytecode to parse a single non-lazy message field. */ |
7062 static void generate_msgfield(compiler *c, const upb_fielddef *f, | 7840 static void generate_msgfield(compiler *c, const upb_fielddef *f, |
7063 upb_pbdecodermethod *method) { | 7841 upb_pbdecodermethod *method) { |
7064 const upb_handlers *h = upb_pbdecodermethod_desthandlers(method); | 7842 const upb_handlers *h = upb_pbdecodermethod_desthandlers(method); |
7065 const upb_pbdecodermethod *sub_m = find_submethod(c, method, f); | 7843 const upb_pbdecodermethod *sub_m = find_submethod(c, method, f); |
7066 int wire_type; | 7844 int wire_type; |
7067 | 7845 |
7068 if (!sub_m) { | 7846 if (!sub_m) { |
7069 /* Don't emit any code for this field at all; it will be parsed as an | 7847 /* Don't emit any code for this field at all; it will be parsed as an |
7070 * unknown field. */ | 7848 * unknown field. |
| 7849 * |
| 7850 * TODO(haberman): we should change this to parse it as a string field |
| 7851 * instead. It will probably be faster, but more importantly, once we |
| 7852 * start vending unknown fields, a field shouldn't be treated as unknown |
| 7853 * just because it doesn't have subhandlers registered. */ |
7071 return; | 7854 return; |
7072 } | 7855 } |
7073 | 7856 |
7074 label(c, LABEL_FIELD); | 7857 label(c, LABEL_FIELD); |
7075 | 7858 |
7076 wire_type = | 7859 wire_type = |
7077 (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) | 7860 (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) |
7078 ? UPB_WIRE_TYPE_DELIMITED | 7861 ? UPB_WIRE_TYPE_DELIMITED |
7079 : UPB_WIRE_TYPE_START_GROUP; | 7862 : UPB_WIRE_TYPE_START_GROUP; |
7080 | 7863 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7167 /* From a decoding perspective, ENUM is the same as INT32. */ | 7950 /* From a decoding perspective, ENUM is the same as INT32. */ |
7168 if (descriptor_type == UPB_DESCRIPTOR_TYPE_ENUM) | 7951 if (descriptor_type == UPB_DESCRIPTOR_TYPE_ENUM) |
7169 descriptor_type = UPB_DESCRIPTOR_TYPE_INT32; | 7952 descriptor_type = UPB_DESCRIPTOR_TYPE_INT32; |
7170 | 7953 |
7171 parse_type = (opcode)descriptor_type; | 7954 parse_type = (opcode)descriptor_type; |
7172 | 7955 |
7173 /* TODO(haberman): generate packed or non-packed first depending on "packed" | 7956 /* TODO(haberman): generate packed or non-packed first depending on "packed" |
7174 * setting in the fielddef. This will favor (in speed) whichever was | 7957 * setting in the fielddef. This will favor (in speed) whichever was |
7175 * specified. */ | 7958 * specified. */ |
7176 | 7959 |
7177 assert((int)parse_type >= 0 && parse_type <= OP_MAX); | 7960 UPB_ASSERT((int)parse_type >= 0 && parse_type <= OP_MAX); |
7178 sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); | 7961 sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); |
7179 wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)]; | 7962 wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)]; |
7180 if (upb_fielddef_isseq(f)) { | 7963 if (upb_fielddef_isseq(f)) { |
7181 putop(c, OP_CHECKDELIM, LABEL_ENDMSG); | 7964 putop(c, OP_CHECKDELIM, LABEL_ENDMSG); |
7182 putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH); | 7965 putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH); |
7183 dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED); | 7966 dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED); |
7184 putop(c, OP_PUSHLENDELIM); | 7967 putop(c, OP_PUSHLENDELIM); |
7185 putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Packed */ | 7968 putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Packed */ |
7186 label(c, LABEL_LOOPSTART); | 7969 label(c, LABEL_LOOPSTART); |
7187 putop(c, parse_type, sel); | 7970 putop(c, parse_type, sel); |
(...skipping 21 matching lines...) Expand all Loading... |
7209 | 7992 |
7210 /* Adds bytecode for parsing the given message to the given decoderplan, | 7993 /* Adds bytecode for parsing the given message to the given decoderplan, |
7211 * while adding all dispatch targets to this message's dispatch table. */ | 7994 * while adding all dispatch targets to this message's dispatch table. */ |
7212 static void compile_method(compiler *c, upb_pbdecodermethod *method) { | 7995 static void compile_method(compiler *c, upb_pbdecodermethod *method) { |
7213 const upb_handlers *h; | 7996 const upb_handlers *h; |
7214 const upb_msgdef *md; | 7997 const upb_msgdef *md; |
7215 uint32_t* start_pc; | 7998 uint32_t* start_pc; |
7216 upb_msg_field_iter i; | 7999 upb_msg_field_iter i; |
7217 upb_value val; | 8000 upb_value val; |
7218 | 8001 |
7219 assert(method); | 8002 UPB_ASSERT(method); |
7220 | 8003 |
7221 /* Clear all entries in the dispatch table. */ | 8004 /* Clear all entries in the dispatch table. */ |
7222 upb_inttable_uninit(&method->dispatch); | 8005 upb_inttable_uninit(&method->dispatch); |
7223 upb_inttable_init(&method->dispatch, UPB_CTYPE_UINT64); | 8006 upb_inttable_init(&method->dispatch, UPB_CTYPE_UINT64); |
7224 | 8007 |
7225 h = upb_pbdecodermethod_desthandlers(method); | 8008 h = upb_pbdecodermethod_desthandlers(method); |
7226 md = upb_handlers_msgdef(h); | 8009 md = upb_handlers_msgdef(h); |
7227 | 8010 |
7228 method->code_base.ofs = pcofs(c); | 8011 method->code_base.ofs = pcofs(c); |
7229 putop(c, OP_SETDISPATCH, &method->dispatch); | 8012 putop(c, OP_SETDISPATCH, &method->dispatch); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7357 | 8140 |
7358 | 8141 |
7359 /* TODO(haberman): allow this to be constructed for an arbitrary set of dest | 8142 /* TODO(haberman): allow this to be constructed for an arbitrary set of dest |
7360 * handlers and other mgroups (but verify we have a transitive closure). */ | 8143 * handlers and other mgroups (but verify we have a transitive closure). */ |
7361 const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, | 8144 const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, |
7362 const void *owner) { | 8145 const void *owner) { |
7363 mgroup *g; | 8146 mgroup *g; |
7364 compiler *c; | 8147 compiler *c; |
7365 | 8148 |
7366 UPB_UNUSED(allowjit); | 8149 UPB_UNUSED(allowjit); |
7367 assert(upb_handlers_isfrozen(dest)); | 8150 UPB_ASSERT(upb_handlers_isfrozen(dest)); |
7368 | 8151 |
7369 g = newgroup(owner); | 8152 g = newgroup(owner); |
7370 c = newcompiler(g, lazy); | 8153 c = newcompiler(g, lazy); |
7371 find_methods(c, dest); | 8154 find_methods(c, dest); |
7372 | 8155 |
7373 /* We compile in two passes: | 8156 /* We compile in two passes: |
7374 * 1. all messages are assigned relative offsets from the beginning of the | 8157 * 1. all messages are assigned relative offsets from the beginning of the |
7375 * bytecode (saved in method->code_base). | 8158 * bytecode (saved in method->code_base). |
7376 * 2. forwards OP_CALL instructions can be correctly linked since message | 8159 * 2. forwards OP_CALL instructions can be correctly linked since message |
7377 * offsets have been previously assigned. | 8160 * offsets have been previously assigned. |
7378 * | 8161 * |
7379 * Could avoid the second pass by linking OP_CALL instructions somehow. */ | 8162 * Could avoid the second pass by linking OP_CALL instructions somehow. */ |
7380 compile_methods(c); | 8163 compile_methods(c); |
7381 compile_methods(c); | 8164 compile_methods(c); |
7382 g->bytecode_end = c->pc; | 8165 g->bytecode_end = c->pc; |
7383 freecompiler(c); | 8166 freecompiler(c); |
7384 | 8167 |
7385 #ifdef UPB_DUMP_BYTECODE | 8168 #ifdef UPB_DUMP_BYTECODE |
7386 { | 8169 { |
7387 FILE *f = fopen("/tmp/upb-bytecode", "wb"); | 8170 FILE *f = fopen("/tmp/upb-bytecode", "w"); |
7388 assert(f); | 8171 UPB_ASSERT(f); |
7389 dumpbc(g->bytecode, g->bytecode_end, stderr); | 8172 dumpbc(g->bytecode, g->bytecode_end, stderr); |
7390 dumpbc(g->bytecode, g->bytecode_end, f); | 8173 dumpbc(g->bytecode, g->bytecode_end, f); |
7391 fclose(f); | 8174 fclose(f); |
| 8175 |
| 8176 f = fopen("/tmp/upb-bytecode.bin", "wb"); |
| 8177 UPB_ASSERT(f); |
| 8178 fwrite(g->bytecode, 1, g->bytecode_end - g->bytecode, f); |
| 8179 fclose(f); |
7392 } | 8180 } |
7393 #endif | 8181 #endif |
7394 | 8182 |
7395 sethandlers(g, allowjit); | 8183 sethandlers(g, allowjit); |
7396 return g; | 8184 return g; |
7397 } | 8185 } |
7398 | 8186 |
7399 | 8187 |
7400 /* upb_pbcodecache ************************************************************/ | 8188 /* upb_pbcodecache ************************************************************/ |
7401 | 8189 |
(...skipping 27 matching lines...) Expand all Loading... |
7429 upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) { | 8217 upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) { |
7430 upb_value v; | 8218 upb_value v; |
7431 bool ok; | 8219 bool ok; |
7432 | 8220 |
7433 /* Right now we build a new DecoderMethod every time. | 8221 /* Right now we build a new DecoderMethod every time. |
7434 * TODO(haberman): properly cache methods by their true key. */ | 8222 * TODO(haberman): properly cache methods by their true key. */ |
7435 const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c); | 8223 const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c); |
7436 upb_inttable_push(&c->groups, upb_value_constptr(g)); | 8224 upb_inttable_push(&c->groups, upb_value_constptr(g)); |
7437 | 8225 |
7438 ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v); | 8226 ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v); |
7439 UPB_ASSERT_VAR(ok, ok); | 8227 UPB_ASSERT(ok); |
7440 return upb_value_getptr(v); | 8228 return upb_value_getptr(v); |
7441 } | 8229 } |
7442 | 8230 |
7443 | 8231 |
7444 /* upb_pbdecodermethodopts ****************************************************/ | 8232 /* upb_pbdecodermethodopts ****************************************************/ |
7445 | 8233 |
7446 void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts, | 8234 void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts, |
7447 const upb_handlers *h) { | 8235 const upb_handlers *h) { |
7448 opts->handlers = h; | 8236 opts->handlers = h; |
7449 opts->lazy = false; | 8237 opts->lazy = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7481 const char *kPbDecoderSubmessageTooLong = | 8269 const char *kPbDecoderSubmessageTooLong = |
7482 "Submessage end extends past enclosing submessage."; | 8270 "Submessage end extends past enclosing submessage."; |
7483 | 8271 |
7484 /* Error messages shared within this file. */ | 8272 /* Error messages shared within this file. */ |
7485 static const char *kUnterminatedVarint = "Unterminated varint."; | 8273 static const char *kUnterminatedVarint = "Unterminated varint."; |
7486 | 8274 |
7487 /* upb_pbdecoder **************************************************************/ | 8275 /* upb_pbdecoder **************************************************************/ |
7488 | 8276 |
7489 static opcode halt = OP_HALT; | 8277 static opcode halt = OP_HALT; |
7490 | 8278 |
| 8279 /* A dummy character we can point to when the user passes us a NULL buffer. |
| 8280 * We need this because in C (NULL + 0) and (NULL - NULL) are undefined |
| 8281 * behavior, which would invalidate functions like curbufleft(). */ |
| 8282 static const char dummy_char; |
| 8283 |
7491 /* Whether an op consumes any of the input buffer. */ | 8284 /* Whether an op consumes any of the input buffer. */ |
7492 static bool consumes_input(opcode op) { | 8285 static bool consumes_input(opcode op) { |
7493 switch (op) { | 8286 switch (op) { |
7494 case OP_SETDISPATCH: | 8287 case OP_SETDISPATCH: |
7495 case OP_STARTMSG: | 8288 case OP_STARTMSG: |
7496 case OP_ENDMSG: | 8289 case OP_ENDMSG: |
7497 case OP_STARTSEQ: | 8290 case OP_STARTSEQ: |
7498 case OP_ENDSEQ: | 8291 case OP_ENDSEQ: |
7499 case OP_STARTSUBMSG: | 8292 case OP_STARTSUBMSG: |
7500 case OP_ENDSUBMSG: | 8293 case OP_ENDSUBMSG: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7557 | 8350 |
7558 | 8351 |
7559 /* Buffering ******************************************************************/ | 8352 /* Buffering ******************************************************************/ |
7560 | 8353 |
7561 /* We operate on one buffer at a time, which is either the user's buffer passed | 8354 /* We operate on one buffer at a time, which is either the user's buffer passed |
7562 * to our "decode" callback or some residual bytes from the previous buffer. */ | 8355 * to our "decode" callback or some residual bytes from the previous buffer. */ |
7563 | 8356 |
7564 /* How many bytes can be safely read from d->ptr without reading past end-of-buf | 8357 /* How many bytes can be safely read from d->ptr without reading past end-of-buf |
7565 * or past the current delimited end. */ | 8358 * or past the current delimited end. */ |
7566 static size_t curbufleft(const upb_pbdecoder *d) { | 8359 static size_t curbufleft(const upb_pbdecoder *d) { |
7567 assert(d->data_end >= d->ptr); | 8360 UPB_ASSERT(d->data_end >= d->ptr); |
7568 return d->data_end - d->ptr; | 8361 return d->data_end - d->ptr; |
7569 } | 8362 } |
7570 | 8363 |
7571 /* How many bytes are available before end-of-buffer. */ | 8364 /* How many bytes are available before end-of-buffer. */ |
7572 static size_t bufleft(const upb_pbdecoder *d) { | 8365 static size_t bufleft(const upb_pbdecoder *d) { |
7573 return d->end - d->ptr; | 8366 return d->end - d->ptr; |
7574 } | 8367 } |
7575 | 8368 |
7576 /* Overall stream offset of d->ptr. */ | 8369 /* Overall stream offset of d->ptr. */ |
7577 uint64_t offset(const upb_pbdecoder *d) { | 8370 uint64_t offset(const upb_pbdecoder *d) { |
7578 return d->bufstart_ofs + (d->ptr - d->buf); | 8371 return d->bufstart_ofs + (d->ptr - d->buf); |
7579 } | 8372 } |
7580 | 8373 |
7581 /* How many bytes are available before the end of this delimited region. */ | 8374 /* How many bytes are available before the end of this delimited region. */ |
7582 size_t delim_remaining(const upb_pbdecoder *d) { | 8375 size_t delim_remaining(const upb_pbdecoder *d) { |
7583 return d->top->end_ofs - offset(d); | 8376 return d->top->end_ofs - offset(d); |
7584 } | 8377 } |
7585 | 8378 |
7586 /* Advances d->ptr. */ | 8379 /* Advances d->ptr. */ |
7587 static void advance(upb_pbdecoder *d, size_t len) { | 8380 static void advance(upb_pbdecoder *d, size_t len) { |
7588 assert(curbufleft(d) >= len); | 8381 UPB_ASSERT(curbufleft(d) >= len); |
7589 d->ptr += len; | 8382 d->ptr += len; |
7590 } | 8383 } |
7591 | 8384 |
7592 static bool in_buf(const char *p, const char *buf, const char *end) { | 8385 static bool in_buf(const char *p, const char *buf, const char *end) { |
7593 return p >= buf && p <= end; | 8386 return p >= buf && p <= end; |
7594 } | 8387 } |
7595 | 8388 |
7596 static bool in_residual_buf(const upb_pbdecoder *d, const char *p) { | 8389 static bool in_residual_buf(const upb_pbdecoder *d, const char *p) { |
7597 return in_buf(p, d->residual, d->residual_end); | 8390 return in_buf(p, d->residual, d->residual_end); |
7598 } | 8391 } |
(...skipping 12 matching lines...) Expand all Loading... |
7611 } | 8404 } |
7612 | 8405 |
7613 static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) { | 8406 static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) { |
7614 d->ptr = buf; | 8407 d->ptr = buf; |
7615 d->buf = buf; | 8408 d->buf = buf; |
7616 d->end = end; | 8409 d->end = end; |
7617 set_delim_end(d); | 8410 set_delim_end(d); |
7618 } | 8411 } |
7619 | 8412 |
7620 static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) { | 8413 static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) { |
7621 assert(curbufleft(d) == 0); | 8414 UPB_ASSERT(curbufleft(d) == 0); |
7622 d->bufstart_ofs += (d->end - d->buf); | 8415 d->bufstart_ofs += (d->end - d->buf); |
7623 switchtobuf(d, buf, buf + len); | 8416 switchtobuf(d, buf, buf + len); |
7624 } | 8417 } |
7625 | 8418 |
7626 static void checkpoint(upb_pbdecoder *d) { | 8419 static void checkpoint(upb_pbdecoder *d) { |
7627 /* The assertion here is in the interests of efficiency, not correctness. | 8420 /* The assertion here is in the interests of efficiency, not correctness. |
7628 * We are trying to ensure that we don't checkpoint() more often than | 8421 * We are trying to ensure that we don't checkpoint() more often than |
7629 * necessary. */ | 8422 * necessary. */ |
7630 assert(d->checkpoint != d->ptr); | 8423 UPB_ASSERT(d->checkpoint != d->ptr); |
7631 d->checkpoint = d->ptr; | 8424 d->checkpoint = d->ptr; |
7632 } | 8425 } |
7633 | 8426 |
7634 /* Skips "bytes" bytes in the stream, which may be more than available. If we | 8427 /* Skips "bytes" bytes in the stream, which may be more than available. If we |
7635 * skip more bytes than are available, we return a long read count to the caller | 8428 * skip more bytes than are available, we return a long read count to the caller |
7636 * indicating how many bytes can be skipped over before passing actual data | 8429 * 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 | 8430 * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they |
7638 * won't actually be read. | 8431 * won't actually be read. |
7639 */ | 8432 */ |
7640 static int32_t skip(upb_pbdecoder *d, size_t bytes) { | 8433 static int32_t skip(upb_pbdecoder *d, size_t bytes) { |
7641 assert(!in_residual_buf(d, d->ptr) || d->size_param == 0); | 8434 UPB_ASSERT(!in_residual_buf(d, d->ptr) || d->size_param == 0); |
7642 assert(d->skip == 0); | 8435 UPB_ASSERT(d->skip == 0); |
7643 if (bytes > delim_remaining(d)) { | 8436 if (bytes > delim_remaining(d)) { |
7644 seterr(d, "Skipped value extended beyond enclosing submessage."); | 8437 seterr(d, "Skipped value extended beyond enclosing submessage."); |
7645 return upb_pbdecoder_suspend(d); | 8438 return upb_pbdecoder_suspend(d); |
7646 } else if (bufleft(d) > bytes) { | 8439 } else if (bufleft(d) >= bytes) { |
7647 /* Skipped data is all in current buffer, and more is still available. */ | 8440 /* Skipped data is all in current buffer, and more is still available. */ |
7648 advance(d, bytes); | 8441 advance(d, bytes); |
7649 d->skip = 0; | 8442 d->skip = 0; |
7650 return DECODE_OK; | 8443 return DECODE_OK; |
7651 } else { | 8444 } else { |
7652 /* Skipped data extends beyond currently available buffers. */ | 8445 /* Skipped data extends beyond currently available buffers. */ |
7653 d->pc = d->last; | 8446 d->pc = d->last; |
7654 d->skip = bytes - curbufleft(d); | 8447 d->skip = bytes - curbufleft(d); |
7655 d->bufstart_ofs += (d->end - d->buf); | 8448 d->bufstart_ofs += (d->end - d->buf); |
7656 d->residual_end = d->residual; | 8449 d->residual_end = d->residual; |
7657 switchtobuf(d, d->residual, d->residual_end); | 8450 switchtobuf(d, d->residual, d->residual_end); |
7658 return d->size_param + d->skip; | 8451 return d->size_param + d->skip; |
7659 } | 8452 } |
7660 } | 8453 } |
7661 | 8454 |
7662 | 8455 |
7663 /* Resumes the decoder from an initial state or from a previous suspend. */ | 8456 /* 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, | 8457 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, |
7665 size_t size, const upb_bufhandle *handle) { | 8458 size_t size, const upb_bufhandle *handle) { |
7666 UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */ | 8459 UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */ |
7667 | 8460 |
7668 d->buf_param = buf; | 8461 /* d->skip and d->residual_end could probably elegantly be represented |
| 8462 * as a single variable, to more easily represent this invariant. */ |
| 8463 UPB_ASSERT(!(d->skip && d->residual_end > d->residual)); |
| 8464 |
| 8465 /* We need to remember the original size_param, so that the value we return |
| 8466 * is relative to it, even if we do some skipping first. */ |
7669 d->size_param = size; | 8467 d->size_param = size; |
7670 d->handle = handle; | 8468 d->handle = handle; |
7671 | 8469 |
7672 if (d->residual_end > d->residual) { | 8470 /* Have to handle this case specially (ie. not with skip()) because the user |
7673 /* We have residual bytes from the last buffer. */ | 8471 * is allowed to pass a NULL buffer here, which won't allow us to safely |
7674 assert(d->ptr == d->residual); | 8472 * calculate a d->end or use our normal functions like curbufleft(). */ |
7675 } else { | 8473 if (d->skip && d->skip >= size) { |
7676 switchtobuf(d, buf, buf + size); | 8474 d->skip -= size; |
| 8475 d->bufstart_ofs += size; |
| 8476 buf = &dummy_char; |
| 8477 size = 0; |
| 8478 |
| 8479 /* We can't just return now, because we might need to execute some ops |
| 8480 * like CHECKDELIM, which could call some callbacks and pop the stack. */ |
7677 } | 8481 } |
7678 | 8482 |
7679 d->checkpoint = d->ptr; | 8483 /* We need to pretend that this was the actual buffer param, since some of the |
7680 | 8484 * calculations assume that d->ptr/d->buf is relative to this. */ |
7681 if (d->skip) { | 8485 d->buf_param = buf; |
7682 size_t skip_bytes = d->skip; | |
7683 d->skip = 0; | |
7684 CHECK_RETURN(skip(d, skip_bytes)); | |
7685 d->checkpoint = d->ptr; | |
7686 } | |
7687 | 8486 |
7688 if (!buf) { | 8487 if (!buf) { |
7689 /* NULL buf is ok if its entire span is covered by the "skip" above, but | 8488 /* 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. */ | 8489 * by this point we know that "skip" doesn't cover the buffer. */ |
7691 seterr(d, "Passed NULL buffer over non-skippable region."); | 8490 seterr(d, "Passed NULL buffer over non-skippable region."); |
7692 return upb_pbdecoder_suspend(d); | 8491 return upb_pbdecoder_suspend(d); |
7693 } | 8492 } |
7694 | 8493 |
| 8494 if (d->residual_end > d->residual) { |
| 8495 /* We have residual bytes from the last buffer. */ |
| 8496 UPB_ASSERT(d->ptr == d->residual); |
| 8497 } else { |
| 8498 switchtobuf(d, buf, buf + size); |
| 8499 } |
| 8500 |
| 8501 d->checkpoint = d->ptr; |
| 8502 |
| 8503 /* Handle skips that don't cover the whole buffer (as above). */ |
| 8504 if (d->skip) { |
| 8505 size_t skip_bytes = d->skip; |
| 8506 d->skip = 0; |
| 8507 CHECK_RETURN(skip(d, skip_bytes)); |
| 8508 checkpoint(d); |
| 8509 } |
| 8510 |
| 8511 /* If we're inside an unknown group, continue to parse unknown values. */ |
7695 if (d->top->groupnum < 0) { | 8512 if (d->top->groupnum < 0) { |
7696 CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0)); | 8513 CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0)); |
7697 d->checkpoint = d->ptr; | 8514 checkpoint(d); |
7698 } | 8515 } |
7699 | 8516 |
7700 return DECODE_OK; | 8517 return DECODE_OK; |
7701 } | 8518 } |
7702 | 8519 |
7703 /* Suspends the decoder at the last checkpoint, without saving any residual | 8520 /* Suspends the decoder at the last checkpoint, without saving any residual |
7704 * bytes. If there are any unconsumed bytes, returns a short byte count. */ | 8521 * bytes. If there are any unconsumed bytes, returns a short byte count. */ |
7705 size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { | 8522 size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { |
7706 d->pc = d->last; | 8523 d->pc = d->last; |
7707 if (d->checkpoint == d->residual) { | 8524 if (d->checkpoint == d->residual) { |
7708 /* Checkpoint was in residual buf; no user bytes were consumed. */ | 8525 /* Checkpoint was in residual buf; no user bytes were consumed. */ |
7709 d->ptr = d->residual; | 8526 d->ptr = d->residual; |
7710 return 0; | 8527 return 0; |
7711 } else { | 8528 } else { |
7712 size_t consumed; | 8529 size_t ret = d->size_param - (d->end - d->checkpoint); |
7713 assert(!in_residual_buf(d, d->checkpoint)); | 8530 UPB_ASSERT(!in_residual_buf(d, d->checkpoint)); |
7714 assert(d->buf == d->buf_param); | 8531 UPB_ASSERT(d->buf == d->buf_param || d->buf == &dummy_char); |
7715 | 8532 |
7716 consumed = d->checkpoint - d->buf; | 8533 d->bufstart_ofs += (d->checkpoint - d->buf); |
7717 d->bufstart_ofs += consumed; | |
7718 d->residual_end = d->residual; | 8534 d->residual_end = d->residual; |
7719 switchtobuf(d, d->residual, d->residual_end); | 8535 switchtobuf(d, d->residual, d->residual_end); |
7720 return consumed; | 8536 return ret; |
7721 } | 8537 } |
7722 } | 8538 } |
7723 | 8539 |
7724 /* Suspends the decoder at the last checkpoint, and saves any unconsumed | 8540 /* 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 | 8541 * 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 | 8542 * bytes to form a complete value, which might not be contiguous in the |
7727 * user's buffers. Always consumes all user bytes. */ | 8543 * user's buffers. Always consumes all user bytes. */ |
7728 static size_t suspend_save(upb_pbdecoder *d) { | 8544 static size_t suspend_save(upb_pbdecoder *d) { |
7729 /* We hit end-of-buffer before we could parse a full value. | 8545 /* We hit end-of-buffer before we could parse a full value. |
7730 * Save any unconsumed bytes (if any) to the residual buffer. */ | 8546 * Save any unconsumed bytes (if any) to the residual buffer. */ |
7731 d->pc = d->last; | 8547 d->pc = d->last; |
7732 | 8548 |
7733 if (d->checkpoint == d->residual) { | 8549 if (d->checkpoint == d->residual) { |
7734 /* Checkpoint was in residual buf; append user byte(s) to residual buf. */ | 8550 /* Checkpoint was in residual buf; append user byte(s) to residual buf. */ |
7735 assert((d->residual_end - d->residual) + d->size_param <= | 8551 UPB_ASSERT((d->residual_end - d->residual) + d->size_param <= |
7736 sizeof(d->residual)); | 8552 sizeof(d->residual)); |
7737 if (!in_residual_buf(d, d->ptr)) { | 8553 if (!in_residual_buf(d, d->ptr)) { |
7738 d->bufstart_ofs -= (d->residual_end - d->residual); | 8554 d->bufstart_ofs -= (d->residual_end - d->residual); |
7739 } | 8555 } |
7740 memcpy(d->residual_end, d->buf_param, d->size_param); | 8556 memcpy(d->residual_end, d->buf_param, d->size_param); |
7741 d->residual_end += d->size_param; | 8557 d->residual_end += d->size_param; |
7742 } else { | 8558 } else { |
7743 /* Checkpoint was in user buf; old residual bytes not needed. */ | 8559 /* Checkpoint was in user buf; old residual bytes not needed. */ |
7744 size_t save; | 8560 size_t save; |
7745 assert(!in_residual_buf(d, d->checkpoint)); | 8561 UPB_ASSERT(!in_residual_buf(d, d->checkpoint)); |
7746 | 8562 |
7747 d->ptr = d->checkpoint; | 8563 d->ptr = d->checkpoint; |
7748 save = curbufleft(d); | 8564 save = curbufleft(d); |
7749 assert(save <= sizeof(d->residual)); | 8565 UPB_ASSERT(save <= sizeof(d->residual)); |
7750 memcpy(d->residual, d->ptr, save); | 8566 memcpy(d->residual, d->ptr, save); |
7751 d->residual_end = d->residual + save; | 8567 d->residual_end = d->residual + save; |
7752 d->bufstart_ofs = offset(d); | 8568 d->bufstart_ofs = offset(d); |
7753 } | 8569 } |
7754 | 8570 |
7755 switchtobuf(d, d->residual, d->residual_end); | 8571 switchtobuf(d, d->residual, d->residual_end); |
7756 return d->size_param; | 8572 return d->size_param; |
7757 } | 8573 } |
7758 | 8574 |
7759 /* Copies the next "bytes" bytes into "buf" and advances the stream. | 8575 /* Copies the next "bytes" bytes into "buf" and advances the stream. |
7760 * Requires that this many bytes are available in the current buffer. */ | 8576 * Requires that this many bytes are available in the current buffer. */ |
7761 UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf, | 8577 UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf, |
7762 size_t bytes) { | 8578 size_t bytes) { |
7763 assert(bytes <= curbufleft(d)); | 8579 UPB_ASSERT(bytes <= curbufleft(d)); |
7764 memcpy(buf, d->ptr, bytes); | 8580 memcpy(buf, d->ptr, bytes); |
7765 advance(d, bytes); | 8581 advance(d, bytes); |
7766 } | 8582 } |
7767 | 8583 |
7768 /* Slow path for getting the next "bytes" bytes, regardless of whether they are | 8584 /* Slow path for getting the next "bytes" bytes, regardless of whether they are |
7769 * available in the current buffer or not. Returns a status code as described | 8585 * available in the current buffer or not. Returns a status code as described |
7770 * in decoder.int.h. */ | 8586 * in decoder.int.h. */ |
7771 UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, | 8587 UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, |
7772 size_t bytes) { | 8588 size_t bytes) { |
7773 const size_t avail = curbufleft(d); | 8589 const size_t avail = curbufleft(d); |
7774 consumebytes(d, buf, avail); | 8590 consumebytes(d, buf, avail); |
7775 bytes -= avail; | 8591 bytes -= avail; |
7776 assert(bytes > 0); | 8592 UPB_ASSERT(bytes > 0); |
7777 if (in_residual_buf(d, d->ptr)) { | 8593 if (in_residual_buf(d, d->ptr)) { |
7778 advancetobuf(d, d->buf_param, d->size_param); | 8594 advancetobuf(d, d->buf_param, d->size_param); |
7779 } | 8595 } |
7780 if (curbufleft(d) >= bytes) { | 8596 if (curbufleft(d) >= bytes) { |
7781 consumebytes(d, (char *)buf + avail, bytes); | 8597 consumebytes(d, (char *)buf + avail, bytes); |
7782 return DECODE_OK; | 8598 return DECODE_OK; |
7783 } else if (d->data_end == d->delim_end) { | 8599 } else if (d->data_end == d->delim_end) { |
7784 seterr(d, "Submessage ended in the middle of a value or group"); | 8600 seterr(d, "Submessage ended in the middle of a value or group"); |
7785 return upb_pbdecoder_suspend(d); | 8601 return upb_pbdecoder_suspend(d); |
7786 } else { | 8602 } else { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7828 /* Decoding of wire types *****************************************************/ | 8644 /* Decoding of wire types *****************************************************/ |
7829 | 8645 |
7830 /* Slow path for decoding a varint from the current buffer position. | 8646 /* Slow path for decoding a varint from the current buffer position. |
7831 * Returns a status code as described in decoder.int.h. */ | 8647 * Returns a status code as described in decoder.int.h. */ |
7832 UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, | 8648 UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, |
7833 uint64_t *u64) { | 8649 uint64_t *u64) { |
7834 uint8_t byte = 0x80; | 8650 uint8_t byte = 0x80; |
7835 int bitpos; | 8651 int bitpos; |
7836 *u64 = 0; | 8652 *u64 = 0; |
7837 for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { | 8653 for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { |
7838 int32_t ret = getbytes(d, &byte, 1); | 8654 CHECK_RETURN(getbytes(d, &byte, 1)); |
7839 if (ret >= 0) return ret; | |
7840 *u64 |= (uint64_t)(byte & 0x7F) << bitpos; | 8655 *u64 |= (uint64_t)(byte & 0x7F) << bitpos; |
7841 } | 8656 } |
7842 if(bitpos == 70 && (byte & 0x80)) { | 8657 if(bitpos == 70 && (byte & 0x80)) { |
7843 seterr(d, kUnterminatedVarint); | 8658 seterr(d, kUnterminatedVarint); |
7844 return upb_pbdecoder_suspend(d); | 8659 return upb_pbdecoder_suspend(d); |
7845 } | 8660 } |
7846 return DECODE_OK; | 8661 return DECODE_OK; |
7847 } | 8662 } |
7848 | 8663 |
7849 /* Decodes a varint from the current buffer position. | 8664 /* Decodes a varint from the current buffer position. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7950 static void decoder_pop(upb_pbdecoder *d) { d->top--; } | 8765 static void decoder_pop(upb_pbdecoder *d) { d->top--; } |
7951 | 8766 |
7952 UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, | 8767 UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, |
7953 uint64_t expected) { | 8768 uint64_t expected) { |
7954 uint64_t data = 0; | 8769 uint64_t data = 0; |
7955 size_t bytes = upb_value_size(expected); | 8770 size_t bytes = upb_value_size(expected); |
7956 size_t read = peekbytes(d, &data, bytes); | 8771 size_t read = peekbytes(d, &data, bytes); |
7957 if (read == bytes && data == expected) { | 8772 if (read == bytes && data == expected) { |
7958 /* Advance past matched bytes. */ | 8773 /* Advance past matched bytes. */ |
7959 int32_t ok = getbytes(d, &data, read); | 8774 int32_t ok = getbytes(d, &data, read); |
7960 UPB_ASSERT_VAR(ok, ok < 0); | 8775 UPB_ASSERT(ok < 0); |
7961 return DECODE_OK; | 8776 return DECODE_OK; |
7962 } else if (read < bytes && memcmp(&data, &expected, read) == 0) { | 8777 } else if (read < bytes && memcmp(&data, &expected, read) == 0) { |
7963 return suspend_save(d); | 8778 return suspend_save(d); |
7964 } else { | 8779 } else { |
7965 return DECODE_MISMATCH; | 8780 return DECODE_MISMATCH; |
7966 } | 8781 } |
7967 } | 8782 } |
7968 | 8783 |
7969 int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, | 8784 int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, |
7970 uint8_t wire_type) { | 8785 uint8_t wire_type) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8025 } | 8840 } |
8026 | 8841 |
8027 /* Unknown group -- continue looping over unknown fields. */ | 8842 /* Unknown group -- continue looping over unknown fields. */ |
8028 checkpoint(d); | 8843 checkpoint(d); |
8029 } | 8844 } |
8030 } | 8845 } |
8031 | 8846 |
8032 static void goto_endmsg(upb_pbdecoder *d) { | 8847 static void goto_endmsg(upb_pbdecoder *d) { |
8033 upb_value v; | 8848 upb_value v; |
8034 bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v); | 8849 bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v); |
8035 UPB_ASSERT_VAR(found, found); | 8850 UPB_ASSERT(found); |
8036 d->pc = d->top->base + upb_value_getuint64(v); | 8851 d->pc = d->top->base + upb_value_getuint64(v); |
8037 } | 8852 } |
8038 | 8853 |
8039 /* Parses a tag and jumps to the corresponding bytecode instruction for this | 8854 /* Parses a tag and jumps to the corresponding bytecode instruction for this |
8040 * field. | 8855 * field. |
8041 * | 8856 * |
8042 * If the tag is unknown (or the wire type doesn't match), parses the field as | 8857 * If the tag is unknown (or the wire type doesn't match), parses the field as |
8043 * unknown. If the tag is a valid ENDGROUP tag, jumps to the bytecode | 8858 * unknown. If the tag is a valid ENDGROUP tag, jumps to the bytecode |
8044 * instruction for the end of message. */ | 8859 * instruction for the end of message. */ |
8045 static int32_t dispatch(upb_pbdecoder *d) { | 8860 static int32_t dispatch(upb_pbdecoder *d) { |
(...skipping 13 matching lines...) Expand all Loading... |
8059 * check the wire type against two possibilities. */ | 8874 * check the wire type against two possibilities. */ |
8060 if (fieldnum != DISPATCH_ENDMSG && | 8875 if (fieldnum != DISPATCH_ENDMSG && |
8061 upb_inttable_lookup32(dispatch, fieldnum, &val)) { | 8876 upb_inttable_lookup32(dispatch, fieldnum, &val)) { |
8062 uint64_t v = upb_value_getuint64(val); | 8877 uint64_t v = upb_value_getuint64(val); |
8063 if (wire_type == (v & 0xff)) { | 8878 if (wire_type == (v & 0xff)) { |
8064 d->pc = d->top->base + (v >> 16); | 8879 d->pc = d->top->base + (v >> 16); |
8065 return DECODE_OK; | 8880 return DECODE_OK; |
8066 } else if (wire_type == ((v >> 8) & 0xff)) { | 8881 } else if (wire_type == ((v >> 8) & 0xff)) { |
8067 bool found = | 8882 bool found = |
8068 upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val); | 8883 upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val); |
8069 UPB_ASSERT_VAR(found, found); | 8884 UPB_ASSERT(found); |
8070 d->pc = d->top->base + upb_value_getuint64(val); | 8885 d->pc = d->top->base + upb_value_getuint64(val); |
8071 return DECODE_OK; | 8886 return DECODE_OK; |
8072 } | 8887 } |
8073 } | 8888 } |
8074 | 8889 |
8075 /* We have some unknown fields (or ENDGROUP) to parse. The DISPATCH or TAG | 8890 /* We have some unknown fields (or ENDGROUP) to parse. The DISPATCH or TAG |
8076 * bytecode that triggered this is preceded by a CHECKDELIM bytecode which | 8891 * bytecode that triggered this is preceded by a CHECKDELIM bytecode which |
8077 * we need to back up to, so that when we're done skipping unknown data we | 8892 * we need to back up to, so that when we're done skipping unknown data we |
8078 * can re-check the delimited end. */ | 8893 * can re-check the delimited end. */ |
8079 d->last--; /* Necessary if we get suspended */ | 8894 d->last--; /* Necessary if we get suspended */ |
8080 d->pc = d->last; | 8895 d->pc = d->last; |
8081 assert(getop(*d->last) == OP_CHECKDELIM); | 8896 UPB_ASSERT(getop(*d->last) == OP_CHECKDELIM); |
8082 | 8897 |
8083 /* Unknown field or ENDGROUP. */ | 8898 /* Unknown field or ENDGROUP. */ |
8084 retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type); | 8899 retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type); |
8085 | 8900 |
8086 CHECK_RETURN(retval); | 8901 CHECK_RETURN(retval); |
8087 | 8902 |
8088 if (retval == DECODE_ENDGROUP) { | 8903 if (retval == DECODE_ENDGROUP) { |
8089 goto_endmsg(d); | 8904 goto_endmsg(d); |
8090 return DECODE_OK; | 8905 return DECODE_OK; |
8091 } | 8906 } |
8092 | 8907 |
8093 return DECODE_OK; | 8908 return DECODE_OK; |
8094 } | 8909 } |
8095 | 8910 |
8096 /* Callers know that the stack is more than one deep because the opcodes that | 8911 /* Callers know that the stack is more than one deep because the opcodes that |
8097 * call this only occur after PUSH operations. */ | 8912 * call this only occur after PUSH operations. */ |
8098 upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) { | 8913 upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) { |
8099 assert(d->top != d->stack); | 8914 UPB_ASSERT(d->top != d->stack); |
8100 return d->top - 1; | 8915 return d->top - 1; |
8101 } | 8916 } |
8102 | 8917 |
8103 | 8918 |
8104 /* The main decoding loop *****************************************************/ | 8919 /* The main decoding loop *****************************************************/ |
8105 | 8920 |
8106 /* The main decoder VM function. Uses traditional bytecode dispatch loop with a | 8921 /* The main decoder VM function. Uses traditional bytecode dispatch loop with a |
8107 * switch() statement. */ | 8922 * switch() statement. */ |
8108 size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, | 8923 size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, |
8109 const upb_bufhandle* handle) { | 8924 const upb_bufhandle* handle) { |
(...skipping 11 matching lines...) Expand all Loading... |
8121 int32_t instruction; | 8936 int32_t instruction; |
8122 opcode op; | 8937 opcode op; |
8123 uint32_t arg; | 8938 uint32_t arg; |
8124 int32_t longofs; | 8939 int32_t longofs; |
8125 | 8940 |
8126 d->last = d->pc; | 8941 d->last = d->pc; |
8127 instruction = *d->pc++; | 8942 instruction = *d->pc++; |
8128 op = getop(instruction); | 8943 op = getop(instruction); |
8129 arg = instruction >> 8; | 8944 arg = instruction >> 8; |
8130 longofs = arg; | 8945 longofs = arg; |
8131 assert(d->ptr != d->residual_end); | 8946 UPB_ASSERT(d->ptr != d->residual_end); |
8132 UPB_UNUSED(group); | 8947 UPB_UNUSED(group); |
8133 #ifdef UPB_DUMP_BYTECODE | 8948 #ifdef UPB_DUMP_BYTECODE |
8134 fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d " | 8949 fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d " |
8135 "%x %s (%d)\n", | 8950 "%x %s (%d)\n", |
8136 (int)offset(d), | 8951 (int)offset(d), |
8137 (int)(d->ptr - d->buf), | 8952 (int)(d->ptr - d->buf), |
8138 (int)(d->data_end - d->ptr), | 8953 (int)(d->data_end - d->ptr), |
8139 (int)(d->end - d->ptr), | 8954 (int)(d->end - d->ptr), |
8140 (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)), | 8955 (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)), |
8141 (int)(d->pc - 1 - group->bytecode), | 8956 (int)(d->pc - 1 - group->bytecode), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8196 VMCASE(OP_STRING, | 9011 VMCASE(OP_STRING, |
8197 uint32_t len = curbufleft(d); | 9012 uint32_t len = curbufleft(d); |
8198 size_t n = upb_sink_putstring(&d->top->sink, arg, d->ptr, len, handle); | 9013 size_t n = upb_sink_putstring(&d->top->sink, arg, d->ptr, len, handle); |
8199 if (n > len) { | 9014 if (n > len) { |
8200 if (n > delim_remaining(d)) { | 9015 if (n > delim_remaining(d)) { |
8201 seterr(d, "Tried to skip past end of string."); | 9016 seterr(d, "Tried to skip past end of string."); |
8202 return upb_pbdecoder_suspend(d); | 9017 return upb_pbdecoder_suspend(d); |
8203 } else { | 9018 } else { |
8204 int32_t ret = skip(d, n); | 9019 int32_t ret = skip(d, n); |
8205 /* This shouldn't return DECODE_OK, because n > len. */ | 9020 /* This shouldn't return DECODE_OK, because n > len. */ |
8206 assert(ret >= 0); | 9021 UPB_ASSERT(ret >= 0); |
8207 return ret; | 9022 return ret; |
8208 } | 9023 } |
8209 } | 9024 } |
8210 advance(d, n); | 9025 advance(d, n); |
8211 if (n < len || d->delim_end == NULL) { | 9026 if (n < len || d->delim_end == NULL) { |
8212 /* We aren't finished with this string yet. */ | 9027 /* We aren't finished with this string yet. */ |
8213 d->pc--; /* Repeat OP_STRING. */ | 9028 d->pc--; /* Repeat OP_STRING. */ |
8214 if (n > 0) checkpoint(d); | 9029 if (n > 0) checkpoint(d); |
8215 return upb_pbdecoder_suspend(d); | 9030 return upb_pbdecoder_suspend(d); |
8216 } | 9031 } |
8217 ) | 9032 ) |
8218 VMCASE(OP_ENDSTR, | 9033 VMCASE(OP_ENDSTR, |
8219 CHECK_SUSPEND(upb_sink_endstr(&d->top->sink, arg)); | 9034 CHECK_SUSPEND(upb_sink_endstr(&d->top->sink, arg)); |
8220 ) | 9035 ) |
8221 VMCASE(OP_PUSHTAGDELIM, | 9036 VMCASE(OP_PUSHTAGDELIM, |
8222 CHECK_SUSPEND(pushtagdelim(d, arg)); | 9037 CHECK_SUSPEND(pushtagdelim(d, arg)); |
8223 ) | 9038 ) |
8224 VMCASE(OP_SETBIGGROUPNUM, | 9039 VMCASE(OP_SETBIGGROUPNUM, |
8225 d->top->groupnum = *d->pc++; | 9040 d->top->groupnum = *d->pc++; |
8226 ) | 9041 ) |
8227 VMCASE(OP_POP, | 9042 VMCASE(OP_POP, |
8228 assert(d->top > d->stack); | 9043 UPB_ASSERT(d->top > d->stack); |
8229 decoder_pop(d); | 9044 decoder_pop(d); |
8230 ) | 9045 ) |
8231 VMCASE(OP_PUSHLENDELIM, | 9046 VMCASE(OP_PUSHLENDELIM, |
8232 uint32_t len; | 9047 uint32_t len; |
8233 CHECK_RETURN(decode_v32(d, &len)); | 9048 CHECK_RETURN(decode_v32(d, &len)); |
8234 CHECK_SUSPEND(decoder_push(d, offset(d) + len)); | 9049 CHECK_SUSPEND(decoder_push(d, offset(d) + len)); |
8235 set_delim_end(d); | 9050 set_delim_end(d); |
8236 ) | 9051 ) |
8237 VMCASE(OP_SETDELIM, | 9052 VMCASE(OP_SETDELIM, |
8238 set_delim_end(d); | 9053 set_delim_end(d); |
8239 ) | 9054 ) |
8240 VMCASE(OP_CHECKDELIM, | 9055 VMCASE(OP_CHECKDELIM, |
8241 /* We are guaranteed of this assert because we never allow ourselves to | 9056 /* We are guaranteed of this assert because we never allow ourselves to |
8242 * consume bytes beyond data_end, which covers delim_end when non-NULL. | 9057 * consume bytes beyond data_end, which covers delim_end when non-NULL. |
8243 */ | 9058 */ |
8244 assert(!(d->delim_end && d->ptr > d->delim_end)); | 9059 UPB_ASSERT(!(d->delim_end && d->ptr > d->delim_end)); |
8245 if (d->ptr == d->delim_end) | 9060 if (d->ptr == d->delim_end) |
8246 d->pc += longofs; | 9061 d->pc += longofs; |
8247 ) | 9062 ) |
8248 VMCASE(OP_CALL, | 9063 VMCASE(OP_CALL, |
8249 d->callstack[d->call_len++] = d->pc; | 9064 d->callstack[d->call_len++] = d->pc; |
8250 d->pc += longofs; | 9065 d->pc += longofs; |
8251 ) | 9066 ) |
8252 VMCASE(OP_RET, | 9067 VMCASE(OP_RET, |
8253 assert(d->call_len > 0); | 9068 UPB_ASSERT(d->call_len > 0); |
8254 d->pc = d->callstack[--d->call_len]; | 9069 d->pc = d->callstack[--d->call_len]; |
8255 ) | 9070 ) |
8256 VMCASE(OP_BRANCH, | 9071 VMCASE(OP_BRANCH, |
8257 d->pc += longofs; | 9072 d->pc += longofs; |
8258 ) | 9073 ) |
8259 VMCASE(OP_TAG1, | 9074 VMCASE(OP_TAG1, |
8260 uint8_t expected; | 9075 uint8_t expected; |
8261 CHECK_SUSPEND(curbufleft(d) > 0); | 9076 CHECK_SUSPEND(curbufleft(d) > 0); |
8262 expected = (arg >> 8) & 0xff; | 9077 expected = (arg >> 8) & 0xff; |
8263 if (*d->ptr == expected) { | 9078 if (*d->ptr == expected) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8370 group->jit_code(closure, method->code_base.ptr, &dummy, 0, NULL); | 9185 group->jit_code(closure, method->code_base.ptr, &dummy, 0, NULL); |
8371 } else | 9186 } else |
8372 #endif | 9187 #endif |
8373 { | 9188 { |
8374 const uint32_t *p = d->pc; | 9189 const uint32_t *p = d->pc; |
8375 d->stack->end_ofs = end; | 9190 d->stack->end_ofs = end; |
8376 /* Check the previous bytecode, but guard against beginning. */ | 9191 /* Check the previous bytecode, but guard against beginning. */ |
8377 if (p != method->code_base.ptr) p--; | 9192 if (p != method->code_base.ptr) p--; |
8378 if (getop(*p) == OP_CHECKDELIM) { | 9193 if (getop(*p) == OP_CHECKDELIM) { |
8379 /* Rewind from OP_TAG* to OP_CHECKDELIM. */ | 9194 /* Rewind from OP_TAG* to OP_CHECKDELIM. */ |
8380 assert(getop(*d->pc) == OP_TAG1 || | 9195 UPB_ASSERT(getop(*d->pc) == OP_TAG1 || |
8381 getop(*d->pc) == OP_TAG2 || | 9196 getop(*d->pc) == OP_TAG2 || |
8382 getop(*d->pc) == OP_TAGN || | 9197 getop(*d->pc) == OP_TAGN || |
8383 getop(*d->pc) == OP_DISPATCH); | 9198 getop(*d->pc) == OP_DISPATCH); |
8384 d->pc = p; | 9199 d->pc = p; |
8385 } | 9200 } |
8386 upb_pbdecoder_decode(closure, handler_data, &dummy, 0, NULL); | 9201 upb_pbdecoder_decode(closure, handler_data, &dummy, 0, NULL); |
8387 } | 9202 } |
8388 | 9203 |
8389 if (d->call_len != 0) { | 9204 if (d->call_len != 0) { |
8390 seterr(d, "Unexpected EOF inside submessage or group"); | 9205 seterr(d, "Unexpected EOF inside submessage or group"); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8429 d->method_ = m; | 9244 d->method_ = m; |
8430 d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting)); | 9245 d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting)); |
8431 d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting)); | 9246 d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting)); |
8432 if (!d->stack || !d->callstack) { | 9247 if (!d->stack || !d->callstack) { |
8433 return NULL; | 9248 return NULL; |
8434 } | 9249 } |
8435 | 9250 |
8436 d->env = e; | 9251 d->env = e; |
8437 d->limit = d->stack + default_max_nesting - 1; | 9252 d->limit = d->stack + default_max_nesting - 1; |
8438 d->stack_size = default_max_nesting; | 9253 d->stack_size = default_max_nesting; |
| 9254 d->status = NULL; |
8439 | 9255 |
8440 upb_pbdecoder_reset(d); | 9256 upb_pbdecoder_reset(d); |
8441 upb_bytessink_reset(&d->input_, &m->input_handler_, d); | 9257 upb_bytessink_reset(&d->input_, &m->input_handler_, d); |
8442 | 9258 |
8443 assert(sink); | 9259 UPB_ASSERT(sink); |
8444 if (d->method_->dest_handlers_) { | 9260 if (d->method_->dest_handlers_) { |
8445 if (sink->handlers != d->method_->dest_handlers_) | 9261 if (sink->handlers != d->method_->dest_handlers_) |
8446 return NULL; | 9262 return NULL; |
8447 } | 9263 } |
8448 upb_sink_reset(&d->top->sink, sink->handlers, sink->closure); | 9264 upb_sink_reset(&d->top->sink, sink->handlers, sink->closure); |
8449 | 9265 |
8450 /* If this fails, increase the value in decoder.h. */ | 9266 /* If this fails, increase the value in decoder.h. */ |
8451 assert(upb_env_bytesallocated(e) - size_before <= UPB_PB_DECODER_SIZE); | 9267 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= |
| 9268 UPB_PB_DECODER_SIZE); |
8452 return d; | 9269 return d; |
8453 } | 9270 } |
8454 | 9271 |
8455 uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d) { | 9272 uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d) { |
8456 return offset(d); | 9273 return offset(d); |
8457 } | 9274 } |
8458 | 9275 |
8459 const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d) { | 9276 const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d) { |
8460 return d->method_; | 9277 return d->method_; |
8461 } | 9278 } |
8462 | 9279 |
8463 upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d) { | 9280 upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d) { |
8464 return &d->input_; | 9281 return &d->input_; |
8465 } | 9282 } |
8466 | 9283 |
8467 size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) { | 9284 size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) { |
8468 return d->stack_size; | 9285 return d->stack_size; |
8469 } | 9286 } |
8470 | 9287 |
8471 bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) { | 9288 bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) { |
8472 assert(d->top >= d->stack); | 9289 UPB_ASSERT(d->top >= d->stack); |
8473 | 9290 |
8474 if (max < (size_t)(d->top - d->stack)) { | 9291 if (max < (size_t)(d->top - d->stack)) { |
8475 /* Can't set a limit smaller than what we are currently at. */ | 9292 /* Can't set a limit smaller than what we are currently at. */ |
8476 return false; | 9293 return false; |
8477 } | 9294 } |
8478 | 9295 |
8479 if (max > d->stack_size) { | 9296 if (max > d->stack_size) { |
8480 /* Need to reallocate stack and callstack to accommodate. */ | 9297 /* Need to reallocate stack and callstack to accommodate. */ |
8481 size_t old_size = stacksize(d, d->stack_size); | 9298 size_t old_size = stacksize(d, d->stack_size); |
8482 size_t new_size = stacksize(d, max); | 9299 size_t new_size = stacksize(d, max); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8550 ** be able to do it without affecting users. | 9367 ** be able to do it without affecting users. |
8551 ** | 9368 ** |
8552 ** The strategy is to buffer the segments of data that do *not* depend on | 9369 ** 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 | 9370 ** 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, | 9371 ** 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. | 9372 ** alternating the writing of lengths with memcpy() of the rest of the data. |
8556 ** At the top level though, no buffering is required. | 9373 ** At the top level though, no buffering is required. |
8557 */ | 9374 */ |
8558 | 9375 |
8559 | 9376 |
8560 #include <stdlib.h> | |
8561 | 9377 |
8562 /* The output buffer is divided into segments; a segment is a string of data | 9378 /* 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 | 9379 * 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 | 9380 * the middle. The seams between segments are where varints will be inserted |
8565 * once they are known. | 9381 * once they are known. |
8566 * | 9382 * |
8567 * We also use the concept of a "run", which is a range of encoded bytes that | 9383 * 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. | 9384 * occur at a single submessage level. Every segment contains one or more runs. |
8569 * | 9385 * |
8570 * A segment can span messages. Consider: | 9386 * A segment can span messages. Consider: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8622 int depth; | 9438 int depth; |
8623 }; | 9439 }; |
8624 | 9440 |
8625 /* low-level buffering ********************************************************/ | 9441 /* low-level buffering ********************************************************/ |
8626 | 9442 |
8627 /* Low-level functions for interacting with the output buffer. */ | 9443 /* Low-level functions for interacting with the output buffer. */ |
8628 | 9444 |
8629 /* TODO(haberman): handle pushback */ | 9445 /* TODO(haberman): handle pushback */ |
8630 static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) { | 9446 static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) { |
8631 size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL); | 9447 size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL); |
8632 UPB_ASSERT_VAR(n, n == len); | 9448 UPB_ASSERT(n == len); |
8633 } | 9449 } |
8634 | 9450 |
8635 static upb_pb_encoder_segment *top(upb_pb_encoder *e) { | 9451 static upb_pb_encoder_segment *top(upb_pb_encoder *e) { |
8636 return &e->segbuf[*e->top]; | 9452 return &e->segbuf[*e->top]; |
8637 } | 9453 } |
8638 | 9454 |
8639 /* Call to ensure that at least "bytes" bytes are available for writing at | 9455 /* Call to ensure that at least "bytes" bytes are available for writing at |
8640 * e->ptr. Returns false if the bytes could not be allocated. */ | 9456 * e->ptr. Returns false if the bytes could not be allocated. */ |
8641 static bool reserve(upb_pb_encoder *e, size_t bytes) { | 9457 static bool reserve(upb_pb_encoder *e, size_t bytes) { |
8642 if ((size_t)(e->limit - e->ptr) < bytes) { | 9458 if ((size_t)(e->limit - e->ptr) < bytes) { |
(...skipping 19 matching lines...) Expand all Loading... |
8662 e->limit = new_buf + new_size; | 9478 e->limit = new_buf + new_size; |
8663 e->buf = new_buf; | 9479 e->buf = new_buf; |
8664 } | 9480 } |
8665 | 9481 |
8666 return true; | 9482 return true; |
8667 } | 9483 } |
8668 | 9484 |
8669 /* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have | 9485 /* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have |
8670 * previously called reserve() with at least this many bytes. */ | 9486 * previously called reserve() with at least this many bytes. */ |
8671 static void encoder_advance(upb_pb_encoder *e, size_t bytes) { | 9487 static void encoder_advance(upb_pb_encoder *e, size_t bytes) { |
8672 assert((size_t)(e->limit - e->ptr) >= bytes); | 9488 UPB_ASSERT((size_t)(e->limit - e->ptr) >= bytes); |
8673 e->ptr += bytes; | 9489 e->ptr += bytes; |
8674 } | 9490 } |
8675 | 9491 |
8676 /* Call when all of the bytes for a handler have been written. Flushes the | 9492 /* Call when all of the bytes for a handler have been written. Flushes the |
8677 * bytes if possible and necessary, returning false if this failed. */ | 9493 * bytes if possible and necessary, returning false if this failed. */ |
8678 static bool commit(upb_pb_encoder *e) { | 9494 static bool commit(upb_pb_encoder *e) { |
8679 if (!e->top) { | 9495 if (!e->top) { |
8680 /* We aren't inside a delimited region. Flush our accumulated bytes to | 9496 /* We aren't inside a delimited region. Flush our accumulated bytes to |
8681 * the output. | 9497 * the output. |
8682 * | 9498 * |
(...skipping 14 matching lines...) Expand all Loading... |
8697 | 9513 |
8698 memcpy(e->ptr, data, len); | 9514 memcpy(e->ptr, data, len); |
8699 encoder_advance(e, len); | 9515 encoder_advance(e, len); |
8700 return true; | 9516 return true; |
8701 } | 9517 } |
8702 | 9518 |
8703 /* Finish the current run by adding the run totals to the segment and message | 9519 /* Finish the current run by adding the run totals to the segment and message |
8704 * length. */ | 9520 * length. */ |
8705 static void accumulate(upb_pb_encoder *e) { | 9521 static void accumulate(upb_pb_encoder *e) { |
8706 size_t run_len; | 9522 size_t run_len; |
8707 assert(e->ptr >= e->runbegin); | 9523 UPB_ASSERT(e->ptr >= e->runbegin); |
8708 run_len = e->ptr - e->runbegin; | 9524 run_len = e->ptr - e->runbegin; |
8709 e->segptr->seglen += run_len; | 9525 e->segptr->seglen += run_len; |
8710 top(e)->msglen += run_len; | 9526 top(e)->msglen += run_len; |
8711 e->runbegin = e->ptr; | 9527 e->runbegin = e->ptr; |
8712 } | 9528 } |
8713 | 9529 |
8714 /* Call to indicate the start of delimited region for which the full length is | 9530 /* Call to indicate the start of delimited region for which the full length is |
8715 * not yet known. All data will be buffered until the length is known. | 9531 * not yet known. All data will be buffered until the length is known. |
8716 * Delimited regions may be nested; their lengths will all be tracked properly.
*/ | 9532 * Delimited regions may be nested; their lengths will all be tracked properly.
*/ |
8717 static bool start_delim(upb_pb_encoder *e) { | 9533 static bool start_delim(upb_pb_encoder *e) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8795 typedef struct { | 9611 typedef struct { |
8796 uint8_t bytes; | 9612 uint8_t bytes; |
8797 char tag[7]; | 9613 char tag[7]; |
8798 } tag_t; | 9614 } tag_t; |
8799 | 9615 |
8800 /* Allocates a new tag for this field, and sets it in these handlerattr. */ | 9616 /* 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, | 9617 static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt, |
8802 upb_handlerattr *attr) { | 9618 upb_handlerattr *attr) { |
8803 uint32_t n = upb_fielddef_number(f); | 9619 uint32_t n = upb_fielddef_number(f); |
8804 | 9620 |
8805 tag_t *tag = malloc(sizeof(tag_t)); | 9621 tag_t *tag = upb_gmalloc(sizeof(tag_t)); |
8806 tag->bytes = upb_vencode64((n << 3) | wt, tag->tag); | 9622 tag->bytes = upb_vencode64((n << 3) | wt, tag->tag); |
8807 | 9623 |
8808 upb_handlerattr_init(attr); | 9624 upb_handlerattr_init(attr); |
8809 upb_handlerattr_sethandlerdata(attr, tag); | 9625 upb_handlerattr_sethandlerdata(attr, tag); |
8810 upb_handlers_addcleanup(h, tag, free); | 9626 upb_handlers_addcleanup(h, tag, upb_gfree); |
8811 } | 9627 } |
8812 | 9628 |
8813 static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) { | 9629 static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) { |
8814 return encode_bytes(e, tag->tag, tag->bytes); | 9630 return encode_bytes(e, tag->tag, tag->bytes); |
8815 } | 9631 } |
8816 | 9632 |
8817 | 9633 |
8818 /* encoding of wire types *****************************************************/ | 9634 /* encoding of wire types *****************************************************/ |
8819 | 9635 |
8820 static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) { | 9636 static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9052 | 9868 |
9053 upb_pb_encoder_reset(e); | 9869 upb_pb_encoder_reset(e); |
9054 upb_sink_reset(&e->input_, h, e); | 9870 upb_sink_reset(&e->input_, h, e); |
9055 | 9871 |
9056 e->env = env; | 9872 e->env = env; |
9057 e->output_ = output; | 9873 e->output_ = output; |
9058 e->subc = output->closure; | 9874 e->subc = output->closure; |
9059 e->ptr = e->buf; | 9875 e->ptr = e->buf; |
9060 | 9876 |
9061 /* If this fails, increase the value in encoder.h. */ | 9877 /* If this fails, increase the value in encoder.h. */ |
9062 assert(upb_env_bytesallocated(env) - size_before <= UPB_PB_ENCODER_SIZE); | 9878 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= |
| 9879 UPB_PB_ENCODER_SIZE); |
9063 return e; | 9880 return e; |
9064 } | 9881 } |
9065 | 9882 |
9066 upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } | 9883 upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } |
9067 | 9884 |
9068 | 9885 |
9069 #include <stdio.h> | |
9070 #include <stdlib.h> | |
9071 #include <string.h> | |
9072 | 9886 |
9073 upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n, | 9887 upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner, |
9074 void *owner, upb_status *status) { | 9888 upb_status *status) { |
9075 /* Create handlers. */ | 9889 /* Create handlers. */ |
9076 const upb_pbdecodermethod *decoder_m; | 9890 const upb_pbdecodermethod *decoder_m; |
9077 const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h); | 9891 const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h); |
9078 upb_env env; | 9892 upb_env env; |
9079 upb_pbdecodermethodopts opts; | 9893 upb_pbdecodermethodopts opts; |
9080 upb_pbdecoder *decoder; | 9894 upb_pbdecoder *decoder; |
9081 upb_descreader *reader; | 9895 upb_descreader *reader; |
9082 bool ok; | 9896 bool ok; |
9083 upb_def **ret = NULL; | 9897 size_t i; |
9084 upb_def **defs; | 9898 upb_filedef **ret = NULL; |
9085 | 9899 |
9086 upb_pbdecodermethodopts_init(&opts, reader_h); | 9900 upb_pbdecodermethodopts_init(&opts, reader_h); |
9087 decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m); | 9901 decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m); |
9088 | 9902 |
9089 upb_env_init(&env); | 9903 upb_env_init(&env); |
9090 upb_env_reporterrorsto(&env, status); | 9904 upb_env_reporterrorsto(&env, status); |
9091 | 9905 |
9092 reader = upb_descreader_create(&env, reader_h); | 9906 reader = upb_descreader_create(&env, reader_h); |
9093 decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader)); | 9907 decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader)); |
9094 | 9908 |
9095 /* Push input data. */ | 9909 /* Push input data. */ |
9096 ok = upb_bufsrc_putbuf(str, len, upb_pbdecoder_input(decoder)); | 9910 ok = upb_bufsrc_putbuf(buf, n, upb_pbdecoder_input(decoder)); |
9097 | 9911 |
9098 if (!ok) goto cleanup; | 9912 if (!ok) { |
9099 defs = upb_descreader_getdefs(reader, owner, n); | 9913 goto cleanup; |
9100 ret = malloc(sizeof(upb_def*) * (*n)); | 9914 } |
9101 memcpy(ret, defs, sizeof(upb_def*) * (*n)); | 9915 |
| 9916 ret = upb_gmalloc(sizeof (*ret) * (upb_descreader_filecount(reader) + 1)); |
| 9917 |
| 9918 if (!ret) { |
| 9919 goto cleanup; |
| 9920 } |
| 9921 |
| 9922 for (i = 0; i < upb_descreader_filecount(reader); i++) { |
| 9923 ret[i] = upb_descreader_file(reader, i); |
| 9924 upb_filedef_ref(ret[i], owner); |
| 9925 } |
| 9926 |
| 9927 ret[i] = NULL; |
9102 | 9928 |
9103 cleanup: | 9929 cleanup: |
9104 upb_env_uninit(&env); | 9930 upb_env_uninit(&env); |
9105 upb_handlers_unref(reader_h, &reader_h); | 9931 upb_handlers_unref(reader_h, &reader_h); |
9106 upb_pbdecodermethod_unref(decoder_m, &decoder_m); | 9932 upb_pbdecodermethod_unref(decoder_m, &decoder_m); |
9107 return ret; | 9933 return ret; |
9108 } | 9934 } |
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 /* | 9935 /* |
9155 * upb::pb::TextPrinter | 9936 * upb::pb::TextPrinter |
9156 * | 9937 * |
9157 * OPT: This is not optimized at all. It uses printf() which parses the format | 9938 * 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. | 9939 * string every time, and it allocates memory for every put. |
9159 */ | 9940 */ |
9160 | 9941 |
9161 | 9942 |
9162 #include <ctype.h> | 9943 #include <ctype.h> |
9163 #include <float.h> | 9944 #include <float.h> |
9164 #include <inttypes.h> | 9945 #include <inttypes.h> |
9165 #include <stdarg.h> | 9946 #include <stdarg.h> |
9166 #include <stdio.h> | 9947 #include <stdio.h> |
9167 #include <stdlib.h> | |
9168 #include <string.h> | 9948 #include <string.h> |
9169 | 9949 |
9170 | 9950 |
9171 struct upb_textprinter { | 9951 struct upb_textprinter { |
9172 upb_sink input_; | 9952 upb_sink input_; |
9173 upb_bytessink *output_; | 9953 upb_bytessink *output_; |
9174 int indent_depth_; | 9954 int indent_depth_; |
9175 bool single_line_; | 9955 bool single_line_; |
9176 void *subc; | 9956 void *subc; |
9177 }; | 9957 }; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9253 bool ok; | 10033 bool ok; |
9254 | 10034 |
9255 va_start(args, fmt); | 10035 va_start(args, fmt); |
9256 | 10036 |
9257 /* Run once to get the length of the string. */ | 10037 /* Run once to get the length of the string. */ |
9258 _upb_va_copy(args_copy, args); | 10038 _upb_va_copy(args_copy, args); |
9259 len = _upb_vsnprintf(NULL, 0, fmt, args_copy); | 10039 len = _upb_vsnprintf(NULL, 0, fmt, args_copy); |
9260 va_end(args_copy); | 10040 va_end(args_copy); |
9261 | 10041 |
9262 /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */ | 10042 /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */ |
9263 str = malloc(len + 1); | 10043 str = upb_gmalloc(len + 1); |
9264 if (!str) return false; | 10044 if (!str) return false; |
9265 written = vsprintf(str, fmt, args); | 10045 written = vsprintf(str, fmt, args); |
9266 va_end(args); | 10046 va_end(args); |
9267 UPB_ASSERT_VAR(written, written == len); | 10047 UPB_ASSERT(written == len); |
9268 | 10048 |
9269 ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL); | 10049 ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL); |
9270 free(str); | 10050 upb_gfree(str); |
9271 return ok; | 10051 return ok; |
9272 } | 10052 } |
9273 | 10053 |
9274 | 10054 |
9275 /* handlers *******************************************************************/ | 10055 /* handlers *******************************************************************/ |
9276 | 10056 |
9277 static bool textprinter_startmsg(void *c, const void *hd) { | 10057 static bool textprinter_startmsg(void *c, const void *hd) { |
9278 upb_textprinter *p = c; | 10058 upb_textprinter *p = c; |
9279 UPB_UNUSED(hd); | 10059 UPB_UNUSED(hd); |
9280 if (p->indent_depth_ == 0) { | 10060 if (p->indent_depth_ == 0) { |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9629 ** out: | 10409 ** out: |
9630 ** | 10410 ** |
9631 ** - handling of unicode escape sequences (including high surrogate pairs). | 10411 ** - handling of unicode escape sequences (including high surrogate pairs). |
9632 ** - properly check and report errors for unknown fields, stack overflow, | 10412 ** - properly check and report errors for unknown fields, stack overflow, |
9633 ** improper array nesting (or lack of nesting). | 10413 ** improper array nesting (or lack of nesting). |
9634 ** - handling of base64 sequences with padding characters. | 10414 ** - handling of base64 sequences with padding characters. |
9635 ** - handling of push-back (non-success returns from sink functions). | 10415 ** - handling of push-back (non-success returns from sink functions). |
9636 ** - handling of keys/escape-sequences/etc that span input buffers. | 10416 ** - handling of keys/escape-sequences/etc that span input buffers. |
9637 */ | 10417 */ |
9638 | 10418 |
9639 #include <stdio.h> | 10419 #include <assert.h> |
| 10420 #include <errno.h> |
9640 #include <stdint.h> | 10421 #include <stdint.h> |
9641 #include <assert.h> | 10422 #include <stdlib.h> |
9642 #include <string.h> | 10423 #include <string.h> |
9643 #include <stdlib.h> | |
9644 #include <errno.h> | |
9645 | 10424 |
9646 | 10425 |
9647 #define UPB_JSON_MAX_DEPTH 64 | 10426 #define UPB_JSON_MAX_DEPTH 64 |
9648 | 10427 |
9649 typedef struct { | 10428 typedef struct { |
9650 upb_sink sink; | 10429 upb_sink sink; |
9651 | 10430 |
9652 /* The current message in which we're parsing, and the field whose value we're | 10431 /* The current message in which we're parsing, and the field whose value we're |
9653 * expecting next. */ | 10432 * expecting next. */ |
9654 const upb_msgdef *m; | 10433 const upb_msgdef *m; |
9655 const upb_fielddef *f; | 10434 const upb_fielddef *f; |
9656 | 10435 |
| 10436 /* The table mapping json name to fielddef for this message. */ |
| 10437 upb_strtable *name_table; |
| 10438 |
9657 /* We are in a repeated-field context, ready to emit mapentries as | 10439 /* 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 | 10440 * submessages. This flag alters the start-of-object (open-brace) behavior to |
9659 * begin a sequence of mapentry messages rather than a single submessage. */ | 10441 * begin a sequence of mapentry messages rather than a single submessage. */ |
9660 bool is_map; | 10442 bool is_map; |
9661 | 10443 |
9662 /* We are in a map-entry message context. This flag is set when parsing the | 10444 /* 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 | 10445 * 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 | 10446 * (subobjects, strings, numbers, and bools) that the map-entry submessage |
9665 * should end as soon as the value is parsed. */ | 10447 * should end as soon as the value is parsed. */ |
9666 bool is_mapentry; | 10448 bool is_mapentry; |
9667 | 10449 |
9668 /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent | 10450 /* 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| | 10451 * 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 | 10452 * 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. */ | 10453 * message itself), not the parent's field that leads to this map. */ |
9672 const upb_fielddef *mapfield; | 10454 const upb_fielddef *mapfield; |
9673 } upb_jsonparser_frame; | 10455 } upb_jsonparser_frame; |
9674 | 10456 |
9675 struct upb_json_parser { | 10457 struct upb_json_parser { |
9676 upb_env *env; | 10458 upb_env *env; |
9677 upb_byteshandler input_handler_; | 10459 const upb_json_parsermethod *method; |
9678 upb_bytessink input_; | 10460 upb_bytessink input_; |
9679 | 10461 |
9680 /* Stack to track the JSON scopes we are in. */ | 10462 /* Stack to track the JSON scopes we are in. */ |
9681 upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH]; | 10463 upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH]; |
9682 upb_jsonparser_frame *top; | 10464 upb_jsonparser_frame *top; |
9683 upb_jsonparser_frame *limit; | 10465 upb_jsonparser_frame *limit; |
9684 | 10466 |
9685 upb_status status; | 10467 upb_status status; |
9686 | 10468 |
9687 /* Ragel's internal parsing stack for the parsing state machine. */ | 10469 /* Ragel's internal parsing stack for the parsing state machine. */ |
(...skipping 14 matching lines...) Expand all Loading... |
9702 int multipart_state; | 10484 int multipart_state; |
9703 upb_selector_t string_selector; | 10485 upb_selector_t string_selector; |
9704 | 10486 |
9705 /* Input capture. See details in parser.rl. */ | 10487 /* Input capture. See details in parser.rl. */ |
9706 const char *capture; | 10488 const char *capture; |
9707 | 10489 |
9708 /* Intermediate result of parsing a unicode escape sequence. */ | 10490 /* Intermediate result of parsing a unicode escape sequence. */ |
9709 uint32_t digit; | 10491 uint32_t digit; |
9710 }; | 10492 }; |
9711 | 10493 |
| 10494 struct upb_json_parsermethod { |
| 10495 upb_refcounted base; |
| 10496 |
| 10497 upb_byteshandler input_handler_; |
| 10498 |
| 10499 /* Mainly for the purposes of refcounting, so all the fielddefs we point |
| 10500 * to stay alive. */ |
| 10501 const upb_msgdef *msg; |
| 10502 |
| 10503 /* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */ |
| 10504 upb_inttable name_tables; |
| 10505 }; |
| 10506 |
9712 #define PARSER_CHECK_RETURN(x) if (!(x)) return false | 10507 #define PARSER_CHECK_RETURN(x) if (!(x)) return false |
9713 | 10508 |
9714 /* Used to signal that a capture has been suspended. */ | 10509 /* Used to signal that a capture has been suspended. */ |
9715 static char suspend_capture; | 10510 static char suspend_capture; |
9716 | 10511 |
9717 static upb_selector_t getsel_for_handlertype(upb_json_parser *p, | 10512 static upb_selector_t getsel_for_handlertype(upb_json_parser *p, |
9718 upb_handlertype_t type) { | 10513 upb_handlertype_t type) { |
9719 upb_selector_t sel; | 10514 upb_selector_t sel; |
9720 bool ok = upb_handlers_getselector(p->top->f, type, &sel); | 10515 bool ok = upb_handlers_getselector(p->top->f, type, &sel); |
9721 UPB_ASSERT_VAR(ok, ok); | 10516 UPB_ASSERT(ok); |
9722 return sel; | 10517 return sel; |
9723 } | 10518 } |
9724 | 10519 |
9725 static upb_selector_t parser_getsel(upb_json_parser *p) { | 10520 static upb_selector_t parser_getsel(upb_json_parser *p) { |
9726 return getsel_for_handlertype( | 10521 return getsel_for_handlertype( |
9727 p, upb_handlers_getprimitivehandlertype(p->top->f)); | 10522 p, upb_handlers_getprimitivehandlertype(p->top->f)); |
9728 } | 10523 } |
9729 | 10524 |
9730 static bool check_stack(upb_json_parser *p) { | 10525 static bool check_stack(upb_json_parser *p) { |
9731 if ((p->top + 1) == p->limit) { | 10526 if ((p->top + 1) == p->limit) { |
9732 upb_status_seterrmsg(&p->status, "Nesting too deep"); | 10527 upb_status_seterrmsg(&p->status, "Nesting too deep"); |
9733 upb_env_reporterror(p->env, &p->status); | 10528 upb_env_reporterror(p->env, &p->status); |
9734 return false; | 10529 return false; |
9735 } | 10530 } |
9736 | 10531 |
9737 return true; | 10532 return true; |
9738 } | 10533 } |
9739 | 10534 |
| 10535 static void set_name_table(upb_json_parser *p, upb_jsonparser_frame *frame) { |
| 10536 upb_value v; |
| 10537 bool ok = upb_inttable_lookupptr(&p->method->name_tables, frame->m, &v); |
| 10538 UPB_ASSERT(ok); |
| 10539 frame->name_table = upb_value_getptr(v); |
| 10540 } |
| 10541 |
9740 /* There are GCC/Clang built-ins for overflow checking which we could start | 10542 /* There are GCC/Clang built-ins for overflow checking which we could start |
9741 * using if there was any performance benefit to it. */ | 10543 * using if there was any performance benefit to it. */ |
9742 | 10544 |
9743 static bool checked_add(size_t a, size_t b, size_t *c) { | 10545 static bool checked_add(size_t a, size_t b, size_t *c) { |
9744 if (SIZE_MAX - a < b) return false; | 10546 if (SIZE_MAX - a < b) return false; |
9745 *c = a + b; | 10547 *c = a + b; |
9746 return true; | 10548 return true; |
9747 } | 10549 } |
9748 | 10550 |
9749 static size_t saturating_multiply(size_t a, size_t b) { | 10551 static size_t saturating_multiply(size_t a, size_t b) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9849 char output; | 10651 char output; |
9850 | 10652 |
9851 /* Last group contains only two input bytes, one output byte. */ | 10653 /* Last group contains only two input bytes, one output byte. */ |
9852 if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') { | 10654 if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') { |
9853 goto badpadding; | 10655 goto badpadding; |
9854 } | 10656 } |
9855 | 10657 |
9856 val = b64lookup(ptr[0]) << 18 | | 10658 val = b64lookup(ptr[0]) << 18 | |
9857 b64lookup(ptr[1]) << 12; | 10659 b64lookup(ptr[1]) << 12; |
9858 | 10660 |
9859 assert(!(val & 0x80000000)); | 10661 UPB_ASSERT(!(val & 0x80000000)); |
9860 output = val >> 16; | 10662 output = val >> 16; |
9861 upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL); | 10663 upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL); |
9862 return true; | 10664 return true; |
9863 } else { | 10665 } else { |
9864 uint32_t val; | 10666 uint32_t val; |
9865 char output[2]; | 10667 char output[2]; |
9866 | 10668 |
9867 /* Last group contains only three input bytes, two output bytes. */ | 10669 /* Last group contains only three input bytes, two output bytes. */ |
9868 if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') { | 10670 if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') { |
9869 goto badpadding; | 10671 goto badpadding; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9903 * contiguous string and avoid any actual copy. So we optimistically begin | 10705 * contiguous string and avoid any actual copy. So we optimistically begin |
9904 * this way. But there are a few cases where we must instead copy into a | 10706 * this way. But there are a few cases where we must instead copy into a |
9905 * separate buffer: | 10707 * separate buffer: |
9906 * | 10708 * |
9907 * 1. The string was not contiguous in the input (it spanned buffers). | 10709 * 1. The string was not contiguous in the input (it spanned buffers). |
9908 * | 10710 * |
9909 * 2. The string included escape sequences that need to be interpreted to get | 10711 * 2. The string included escape sequences that need to be interpreted to get |
9910 * the true value in a contiguous buffer. */ | 10712 * the true value in a contiguous buffer. */ |
9911 | 10713 |
9912 static void assert_accumulate_empty(upb_json_parser *p) { | 10714 static void assert_accumulate_empty(upb_json_parser *p) { |
9913 UPB_UNUSED(p); | 10715 UPB_ASSERT(p->accumulated == NULL); |
9914 assert(p->accumulated == NULL); | 10716 UPB_ASSERT(p->accumulated_len == 0); |
9915 assert(p->accumulated_len == 0); | |
9916 } | 10717 } |
9917 | 10718 |
9918 static void accumulate_clear(upb_json_parser *p) { | 10719 static void accumulate_clear(upb_json_parser *p) { |
9919 p->accumulated = NULL; | 10720 p->accumulated = NULL; |
9920 p->accumulated_len = 0; | 10721 p->accumulated_len = 0; |
9921 } | 10722 } |
9922 | 10723 |
9923 /* Used internally by accumulate_append(). */ | 10724 /* Used internally by accumulate_append(). */ |
9924 static bool accumulate_realloc(upb_json_parser *p, size_t need) { | 10725 static bool accumulate_realloc(upb_json_parser *p, size_t need) { |
9925 void *mem; | 10726 void *mem; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9971 | 10772 |
9972 memcpy(p->accumulate_buf + p->accumulated_len, buf, len); | 10773 memcpy(p->accumulate_buf + p->accumulated_len, buf, len); |
9973 p->accumulated_len += len; | 10774 p->accumulated_len += len; |
9974 return true; | 10775 return true; |
9975 } | 10776 } |
9976 | 10777 |
9977 /* Returns a pointer to the data accumulated since the last accumulate_clear() | 10778 /* Returns a pointer to the data accumulated since the last accumulate_clear() |
9978 * call, and writes the length to *len. This with point either to the input | 10779 * call, and writes the length to *len. This with point either to the input |
9979 * buffer or a temporary accumulate buffer. */ | 10780 * buffer or a temporary accumulate buffer. */ |
9980 static const char *accumulate_getptr(upb_json_parser *p, size_t *len) { | 10781 static const char *accumulate_getptr(upb_json_parser *p, size_t *len) { |
9981 assert(p->accumulated); | 10782 UPB_ASSERT(p->accumulated); |
9982 *len = p->accumulated_len; | 10783 *len = p->accumulated_len; |
9983 return p->accumulated; | 10784 return p->accumulated; |
9984 } | 10785 } |
9985 | 10786 |
9986 | 10787 |
9987 /* Mult-part text data ********************************************************/ | 10788 /* Mult-part text data ********************************************************/ |
9988 | 10789 |
9989 /* When we have text data in the input, it can often come in multiple segments. | 10790 /* When we have text data in the input, it can often come in multiple segments. |
9990 * For example, there may be some raw string data followed by an escape | 10791 * For example, there may be some raw string data followed by an escape |
9991 * sequence. The two segments are processed with different logic. Also buffer | 10792 * sequence. The two segments are processed with different logic. Also buffer |
(...skipping 17 matching lines...) Expand all Loading... |
10009 | 10810 |
10010 /* We are processing multipart data by pushing each part directly to the | 10811 /* We are processing multipart data by pushing each part directly to the |
10011 * current string handlers. */ | 10812 * current string handlers. */ |
10012 MULTIPART_PUSHEAGERLY = 2 | 10813 MULTIPART_PUSHEAGERLY = 2 |
10013 }; | 10814 }; |
10014 | 10815 |
10015 /* Start a multi-part text value where we accumulate the data for processing at | 10816 /* Start a multi-part text value where we accumulate the data for processing at |
10016 * the end. */ | 10817 * the end. */ |
10017 static void multipart_startaccum(upb_json_parser *p) { | 10818 static void multipart_startaccum(upb_json_parser *p) { |
10018 assert_accumulate_empty(p); | 10819 assert_accumulate_empty(p); |
10019 assert(p->multipart_state == MULTIPART_INACTIVE); | 10820 UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE); |
10020 p->multipart_state = MULTIPART_ACCUMULATE; | 10821 p->multipart_state = MULTIPART_ACCUMULATE; |
10021 } | 10822 } |
10022 | 10823 |
10023 /* Start a multi-part text value where we immediately push text data to a string | 10824 /* Start a multi-part text value where we immediately push text data to a string |
10024 * value with the given selector. */ | 10825 * value with the given selector. */ |
10025 static void multipart_start(upb_json_parser *p, upb_selector_t sel) { | 10826 static void multipart_start(upb_json_parser *p, upb_selector_t sel) { |
10026 assert_accumulate_empty(p); | 10827 assert_accumulate_empty(p); |
10027 assert(p->multipart_state == MULTIPART_INACTIVE); | 10828 UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE); |
10028 p->multipart_state = MULTIPART_PUSHEAGERLY; | 10829 p->multipart_state = MULTIPART_PUSHEAGERLY; |
10029 p->string_selector = sel; | 10830 p->string_selector = sel; |
10030 } | 10831 } |
10031 | 10832 |
10032 static bool multipart_text(upb_json_parser *p, const char *buf, size_t len, | 10833 static bool multipart_text(upb_json_parser *p, const char *buf, size_t len, |
10033 bool can_alias) { | 10834 bool can_alias) { |
10034 switch (p->multipart_state) { | 10835 switch (p->multipart_state) { |
10035 case MULTIPART_INACTIVE: | 10836 case MULTIPART_INACTIVE: |
10036 upb_status_seterrmsg( | 10837 upb_status_seterrmsg( |
10037 &p->status, "Internal error: unexpected state MULTIPART_INACTIVE"); | 10838 &p->status, "Internal error: unexpected state MULTIPART_INACTIVE"); |
(...skipping 12 matching lines...) Expand all Loading... |
10050 break; | 10851 break; |
10051 } | 10852 } |
10052 } | 10853 } |
10053 | 10854 |
10054 return true; | 10855 return true; |
10055 } | 10856 } |
10056 | 10857 |
10057 /* Note: this invalidates the accumulate buffer! Call only after reading its | 10858 /* Note: this invalidates the accumulate buffer! Call only after reading its |
10058 * contents. */ | 10859 * contents. */ |
10059 static void multipart_end(upb_json_parser *p) { | 10860 static void multipart_end(upb_json_parser *p) { |
10060 assert(p->multipart_state != MULTIPART_INACTIVE); | 10861 UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE); |
10061 p->multipart_state = MULTIPART_INACTIVE; | 10862 p->multipart_state = MULTIPART_INACTIVE; |
10062 accumulate_clear(p); | 10863 accumulate_clear(p); |
10063 } | 10864 } |
10064 | 10865 |
10065 | 10866 |
10066 /* Input capture **************************************************************/ | 10867 /* Input capture **************************************************************/ |
10067 | 10868 |
10068 /* Functionality for capturing a region of the input as text. Gracefully | 10869 /* Functionality for capturing a region of the input as text. Gracefully |
10069 * handles the case where a buffer seam occurs in the middle of the captured | 10870 * handles the case where a buffer seam occurs in the middle of the captured |
10070 * region. */ | 10871 * region. */ |
10071 | 10872 |
10072 static void capture_begin(upb_json_parser *p, const char *ptr) { | 10873 static void capture_begin(upb_json_parser *p, const char *ptr) { |
10073 assert(p->multipart_state != MULTIPART_INACTIVE); | 10874 UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE); |
10074 assert(p->capture == NULL); | 10875 UPB_ASSERT(p->capture == NULL); |
10075 p->capture = ptr; | 10876 p->capture = ptr; |
10076 } | 10877 } |
10077 | 10878 |
10078 static bool capture_end(upb_json_parser *p, const char *ptr) { | 10879 static bool capture_end(upb_json_parser *p, const char *ptr) { |
10079 assert(p->capture); | 10880 UPB_ASSERT(p->capture); |
10080 if (multipart_text(p, p->capture, ptr - p->capture, true)) { | 10881 if (multipart_text(p, p->capture, ptr - p->capture, true)) { |
10081 p->capture = NULL; | 10882 p->capture = NULL; |
10082 return true; | 10883 return true; |
10083 } else { | 10884 } else { |
10084 return false; | 10885 return false; |
10085 } | 10886 } |
10086 } | 10887 } |
10087 | 10888 |
10088 /* This is called at the end of each input buffer (ie. when we have hit a | 10889 /* This is called at the end of each input buffer (ie. when we have hit a |
10089 * buffer seam). If we are in the middle of capturing the input, this | 10890 * buffer seam). If we are in the middle of capturing the input, this |
(...skipping 12 matching lines...) Expand all Loading... |
10102 p->capture = &suspend_capture; | 10903 p->capture = &suspend_capture; |
10103 } else { | 10904 } else { |
10104 /* Need to back up the pointer to the beginning of the capture, since | 10905 /* Need to back up the pointer to the beginning of the capture, since |
10105 * we were not able to actually preserve it. */ | 10906 * we were not able to actually preserve it. */ |
10106 *ptr = p->capture; | 10907 *ptr = p->capture; |
10107 } | 10908 } |
10108 } | 10909 } |
10109 | 10910 |
10110 static void capture_resume(upb_json_parser *p, const char *ptr) { | 10911 static void capture_resume(upb_json_parser *p, const char *ptr) { |
10111 if (p->capture) { | 10912 if (p->capture) { |
10112 assert(p->capture == &suspend_capture); | 10913 UPB_ASSERT(p->capture == &suspend_capture); |
10113 p->capture = ptr; | 10914 p->capture = ptr; |
10114 } | 10915 } |
10115 } | 10916 } |
10116 | 10917 |
10117 | 10918 |
10118 /* Callbacks from the parser **************************************************/ | 10919 /* Callbacks from the parser **************************************************/ |
10119 | 10920 |
10120 /* These are the functions called directly from the parser itself. | 10921 /* These are the functions called directly from the parser itself. |
10121 * We define these in the same order as their declarations in the parser. */ | 10922 * We define these in the same order as their declarations in the parser. */ |
10122 | 10923 |
10123 static char escape_char(char in) { | 10924 static char escape_char(char in) { |
10124 switch (in) { | 10925 switch (in) { |
10125 case 'r': return '\r'; | 10926 case 'r': return '\r'; |
10126 case 't': return '\t'; | 10927 case 't': return '\t'; |
10127 case 'n': return '\n'; | 10928 case 'n': return '\n'; |
10128 case 'f': return '\f'; | 10929 case 'f': return '\f'; |
10129 case 'b': return '\b'; | 10930 case 'b': return '\b'; |
10130 case '/': return '/'; | 10931 case '/': return '/'; |
10131 case '"': return '"'; | 10932 case '"': return '"'; |
10132 case '\\': return '\\'; | 10933 case '\\': return '\\'; |
10133 default: | 10934 default: |
10134 assert(0); | 10935 UPB_ASSERT(0); |
10135 return 'x'; | 10936 return 'x'; |
10136 } | 10937 } |
10137 } | 10938 } |
10138 | 10939 |
10139 static bool escape(upb_json_parser *p, const char *ptr) { | 10940 static bool escape(upb_json_parser *p, const char *ptr) { |
10140 char ch = escape_char(*ptr); | 10941 char ch = escape_char(*ptr); |
10141 return multipart_text(p, &ch, 1, false); | 10942 return multipart_text(p, &ch, 1, false); |
10142 } | 10943 } |
10143 | 10944 |
10144 static void start_hex(upb_json_parser *p) { | 10945 static void start_hex(upb_json_parser *p) { |
10145 p->digit = 0; | 10946 p->digit = 0; |
10146 } | 10947 } |
10147 | 10948 |
10148 static void hexdigit(upb_json_parser *p, const char *ptr) { | 10949 static void hexdigit(upb_json_parser *p, const char *ptr) { |
10149 char ch = *ptr; | 10950 char ch = *ptr; |
10150 | 10951 |
10151 p->digit <<= 4; | 10952 p->digit <<= 4; |
10152 | 10953 |
10153 if (ch >= '0' && ch <= '9') { | 10954 if (ch >= '0' && ch <= '9') { |
10154 p->digit += (ch - '0'); | 10955 p->digit += (ch - '0'); |
10155 } else if (ch >= 'a' && ch <= 'f') { | 10956 } else if (ch >= 'a' && ch <= 'f') { |
10156 p->digit += ((ch - 'a') + 10); | 10957 p->digit += ((ch - 'a') + 10); |
10157 } else { | 10958 } else { |
10158 assert(ch >= 'A' && ch <= 'F'); | 10959 UPB_ASSERT(ch >= 'A' && ch <= 'F'); |
10159 p->digit += ((ch - 'A') + 10); | 10960 p->digit += ((ch - 'A') + 10); |
10160 } | 10961 } |
10161 } | 10962 } |
10162 | 10963 |
10163 static bool end_hex(upb_json_parser *p) { | 10964 static bool end_hex(upb_json_parser *p) { |
10164 uint32_t codepoint = p->digit; | 10965 uint32_t codepoint = p->digit; |
10165 | 10966 |
10166 /* emit the codepoint as UTF-8. */ | 10967 /* emit the codepoint as UTF-8. */ |
10167 char utf8[3]; /* support \u0000 -- \uFFFF -- need only three bytes. */ | 10968 char utf8[3]; /* support \u0000 -- \uFFFF -- need only three bytes. */ |
10168 int length = 0; | 10969 int length = 0; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10279 } | 11080 } |
10280 case UPB_TYPE_FLOAT: { | 11081 case UPB_TYPE_FLOAT: { |
10281 float val = strtod(p->accumulated, &end); | 11082 float val = strtod(p->accumulated, &end); |
10282 if (errno == ERANGE || end != myend) | 11083 if (errno == ERANGE || end != myend) |
10283 goto err; | 11084 goto err; |
10284 else | 11085 else |
10285 upb_sink_putfloat(&p->top->sink, parser_getsel(p), val); | 11086 upb_sink_putfloat(&p->top->sink, parser_getsel(p), val); |
10286 break; | 11087 break; |
10287 } | 11088 } |
10288 default: | 11089 default: |
10289 assert(false); | 11090 UPB_ASSERT(false); |
10290 } | 11091 } |
10291 | 11092 |
10292 multipart_end(p); | 11093 multipart_end(p); |
10293 | 11094 |
10294 return true; | 11095 return true; |
10295 | 11096 |
10296 err: | 11097 err: |
10297 upb_status_seterrf(&p->status, "error parsing number: %s", buf); | 11098 upb_status_seterrf(&p->status, "error parsing number: %s", buf); |
10298 upb_env_reporterror(p->env, &p->status); | 11099 upb_env_reporterror(p->env, &p->status); |
10299 multipart_end(p); | 11100 multipart_end(p); |
10300 return false; | 11101 return false; |
10301 } | 11102 } |
10302 | 11103 |
10303 static bool parser_putbool(upb_json_parser *p, bool val) { | 11104 static bool parser_putbool(upb_json_parser *p, bool val) { |
10304 bool ok; | 11105 bool ok; |
10305 | 11106 |
10306 if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) { | 11107 if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) { |
10307 upb_status_seterrf(&p->status, | 11108 upb_status_seterrf(&p->status, |
10308 "Boolean value specified for non-bool field: %s", | 11109 "Boolean value specified for non-bool field: %s", |
10309 upb_fielddef_name(p->top->f)); | 11110 upb_fielddef_name(p->top->f)); |
10310 upb_env_reporterror(p->env, &p->status); | 11111 upb_env_reporterror(p->env, &p->status); |
10311 return false; | 11112 return false; |
10312 } | 11113 } |
10313 | 11114 |
10314 ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val); | 11115 ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val); |
10315 UPB_ASSERT_VAR(ok, ok); | 11116 UPB_ASSERT(ok); |
10316 | 11117 |
10317 return true; | 11118 return true; |
10318 } | 11119 } |
10319 | 11120 |
10320 static bool start_stringval(upb_json_parser *p) { | 11121 static bool start_stringval(upb_json_parser *p) { |
10321 assert(p->top->f); | 11122 UPB_ASSERT(p->top->f); |
10322 | 11123 |
10323 if (upb_fielddef_isstring(p->top->f)) { | 11124 if (upb_fielddef_isstring(p->top->f)) { |
10324 upb_jsonparser_frame *inner; | 11125 upb_jsonparser_frame *inner; |
10325 upb_selector_t sel; | 11126 upb_selector_t sel; |
10326 | 11127 |
10327 if (!check_stack(p)) return false; | 11128 if (!check_stack(p)) return false; |
10328 | 11129 |
10329 /* Start a new parser frame: parser frames correspond one-to-one with | 11130 /* Start a new parser frame: parser frames correspond one-to-one with |
10330 * handler frames, and string events occur in a sub-frame. */ | 11131 * handler frames, and string events occur in a sub-frame. */ |
10331 inner = p->top + 1; | 11132 inner = p->top + 1; |
10332 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); | 11133 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); |
10333 upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); | 11134 upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); |
10334 inner->m = p->top->m; | 11135 inner->m = p->top->m; |
10335 inner->f = p->top->f; | 11136 inner->f = p->top->f; |
| 11137 inner->name_table = NULL; |
10336 inner->is_map = false; | 11138 inner->is_map = false; |
10337 inner->is_mapentry = false; | 11139 inner->is_mapentry = false; |
10338 p->top = inner; | 11140 p->top = inner; |
10339 | 11141 |
10340 if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { | 11142 if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { |
10341 /* For STRING fields we push data directly to the handlers as it is | 11143 /* 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 | 11144 * parsed. We don't do this yet for BYTES fields, because our base64 |
10343 * decoder is not streaming. | 11145 * decoder is not streaming. |
10344 * | 11146 * |
10345 * TODO(haberman): make base64 decoding streaming also. */ | 11147 * TODO(haberman): make base64 decoding streaming also. */ |
(...skipping 26 matching lines...) Expand all Loading... |
10372 switch (upb_fielddef_type(p->top->f)) { | 11174 switch (upb_fielddef_type(p->top->f)) { |
10373 case UPB_TYPE_BYTES: | 11175 case UPB_TYPE_BYTES: |
10374 if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), | 11176 if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), |
10375 p->accumulated, p->accumulated_len)) { | 11177 p->accumulated, p->accumulated_len)) { |
10376 return false; | 11178 return false; |
10377 } | 11179 } |
10378 /* Fall through. */ | 11180 /* Fall through. */ |
10379 | 11181 |
10380 case UPB_TYPE_STRING: { | 11182 case UPB_TYPE_STRING: { |
10381 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); | 11183 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); |
| 11184 p->top--; |
10382 upb_sink_endstr(&p->top->sink, sel); | 11185 upb_sink_endstr(&p->top->sink, sel); |
10383 p->top--; | |
10384 break; | 11186 break; |
10385 } | 11187 } |
10386 | 11188 |
10387 case UPB_TYPE_ENUM: { | 11189 case UPB_TYPE_ENUM: { |
10388 /* Resolve enum symbolic name to integer value. */ | 11190 /* Resolve enum symbolic name to integer value. */ |
10389 const upb_enumdef *enumdef = | 11191 const upb_enumdef *enumdef = |
10390 (const upb_enumdef*)upb_fielddef_subdef(p->top->f); | 11192 (const upb_enumdef*)upb_fielddef_subdef(p->top->f); |
10391 | 11193 |
10392 size_t len; | 11194 size_t len; |
10393 const char *buf = accumulate_getptr(p, &len); | 11195 const char *buf = accumulate_getptr(p, &len); |
10394 | 11196 |
10395 int32_t int_val = 0; | 11197 int32_t int_val = 0; |
10396 ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); | 11198 ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); |
10397 | 11199 |
10398 if (ok) { | 11200 if (ok) { |
10399 upb_selector_t sel = parser_getsel(p); | 11201 upb_selector_t sel = parser_getsel(p); |
10400 upb_sink_putint32(&p->top->sink, sel, int_val); | 11202 upb_sink_putint32(&p->top->sink, sel, int_val); |
10401 } else { | 11203 } else { |
10402 upb_status_seterrf(&p->status, "Enum value unknown: '%.*s'", len, buf); | 11204 upb_status_seterrf(&p->status, "Enum value unknown: '%.*s'", len, buf); |
10403 upb_env_reporterror(p->env, &p->status); | 11205 upb_env_reporterror(p->env, &p->status); |
10404 } | 11206 } |
10405 | 11207 |
10406 break; | 11208 break; |
10407 } | 11209 } |
10408 | 11210 |
10409 default: | 11211 default: |
10410 assert(false); | 11212 UPB_ASSERT(false); |
10411 upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); | 11213 upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); |
10412 upb_env_reporterror(p->env, &p->status); | 11214 upb_env_reporterror(p->env, &p->status); |
10413 ok = false; | 11215 ok = false; |
10414 break; | 11216 break; |
10415 } | 11217 } |
10416 | 11218 |
10417 multipart_end(p); | 11219 multipart_end(p); |
10418 | 11220 |
10419 return ok; | 11221 return ok; |
10420 } | 11222 } |
10421 | 11223 |
10422 static void start_member(upb_json_parser *p) { | 11224 static void start_member(upb_json_parser *p) { |
10423 assert(!p->top->f); | 11225 UPB_ASSERT(!p->top->f); |
10424 multipart_startaccum(p); | 11226 multipart_startaccum(p); |
10425 } | 11227 } |
10426 | 11228 |
10427 /* Helper: invoked during parse_mapentry() to emit the mapentry message's key | 11229 /* Helper: invoked during parse_mapentry() to emit the mapentry message's key |
10428 * field based on the current contents of the accumulate buffer. */ | 11230 * field based on the current contents of the accumulate buffer. */ |
10429 static bool parse_mapentry_key(upb_json_parser *p) { | 11231 static bool parse_mapentry_key(upb_json_parser *p) { |
10430 | 11232 |
10431 size_t len; | 11233 size_t len; |
10432 const char *buf = accumulate_getptr(p, &len); | 11234 const char *buf = accumulate_getptr(p, &len); |
10433 | 11235 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10471 multipart_end(p); | 11273 multipart_end(p); |
10472 break; | 11274 break; |
10473 case UPB_TYPE_STRING: | 11275 case UPB_TYPE_STRING: |
10474 case UPB_TYPE_BYTES: { | 11276 case UPB_TYPE_BYTES: { |
10475 upb_sink subsink; | 11277 upb_sink subsink; |
10476 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); | 11278 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); |
10477 upb_sink_startstr(&p->top->sink, sel, len, &subsink); | 11279 upb_sink_startstr(&p->top->sink, sel, len, &subsink); |
10478 sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); | 11280 sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); |
10479 upb_sink_putstring(&subsink, sel, buf, len, NULL); | 11281 upb_sink_putstring(&subsink, sel, buf, len, NULL); |
10480 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); | 11282 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); |
10481 upb_sink_endstr(&subsink, sel); | 11283 upb_sink_endstr(&p->top->sink, sel); |
10482 multipart_end(p); | 11284 multipart_end(p); |
10483 break; | 11285 break; |
10484 } | 11286 } |
10485 default: | 11287 default: |
10486 upb_status_seterrmsg(&p->status, "Invalid field type for map key"); | 11288 upb_status_seterrmsg(&p->status, "Invalid field type for map key"); |
10487 upb_env_reporterror(p->env, &p->status); | 11289 upb_env_reporterror(p->env, &p->status); |
10488 return false; | 11290 return false; |
10489 } | 11291 } |
10490 | 11292 |
10491 return true; | 11293 return true; |
(...skipping 20 matching lines...) Expand all Loading... |
10512 if (!check_stack(p)) return false; | 11314 if (!check_stack(p)) return false; |
10513 | 11315 |
10514 mapfield = p->top->mapfield; | 11316 mapfield = p->top->mapfield; |
10515 mapentrymsg = upb_fielddef_msgsubdef(mapfield); | 11317 mapentrymsg = upb_fielddef_msgsubdef(mapfield); |
10516 | 11318 |
10517 inner = p->top + 1; | 11319 inner = p->top + 1; |
10518 p->top->f = mapfield; | 11320 p->top->f = mapfield; |
10519 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); | 11321 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); |
10520 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); | 11322 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); |
10521 inner->m = mapentrymsg; | 11323 inner->m = mapentrymsg; |
| 11324 inner->name_table = NULL; |
10522 inner->mapfield = mapfield; | 11325 inner->mapfield = mapfield; |
10523 inner->is_map = false; | 11326 inner->is_map = false; |
10524 | 11327 |
10525 /* Don't set this to true *yet* -- we reuse parsing handlers below to push | 11328 /* 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 | 11329 * 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 | 11330 * if they see is_mapentry (when invoked by the parser state machine, they |
10528 * would have just seen the map-entry value, not key). */ | 11331 * would have just seen the map-entry value, not key). */ |
10529 inner->is_mapentry = false; | 11332 inner->is_mapentry = false; |
10530 p->top = inner; | 11333 p->top = inner; |
10531 | 11334 |
10532 /* send STARTMSG in submsg frame. */ | 11335 /* send STARTMSG in submsg frame. */ |
10533 upb_sink_startmsg(&p->top->sink); | 11336 upb_sink_startmsg(&p->top->sink); |
10534 | 11337 |
10535 parse_mapentry_key(p); | 11338 parse_mapentry_key(p); |
10536 | 11339 |
10537 /* Set up the value field to receive the map-entry value. */ | 11340 /* Set up the value field to receive the map-entry value. */ |
10538 p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_VALUE); | 11341 p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_VALUE); |
10539 p->top->is_mapentry = true; /* set up to pop frame after value is parsed. */ | 11342 p->top->is_mapentry = true; /* set up to pop frame after value is parsed. */ |
10540 p->top->mapfield = mapfield; | 11343 p->top->mapfield = mapfield; |
10541 if (p->top->f == NULL) { | 11344 if (p->top->f == NULL) { |
10542 upb_status_seterrmsg(&p->status, "mapentry message has no value"); | 11345 upb_status_seterrmsg(&p->status, "mapentry message has no value"); |
10543 upb_env_reporterror(p->env, &p->status); | 11346 upb_env_reporterror(p->env, &p->status); |
10544 return false; | 11347 return false; |
10545 } | 11348 } |
10546 | 11349 |
10547 return true; | 11350 return true; |
10548 } | 11351 } |
10549 | 11352 |
10550 static bool end_membername(upb_json_parser *p) { | 11353 static bool end_membername(upb_json_parser *p) { |
10551 assert(!p->top->f); | 11354 UPB_ASSERT(!p->top->f); |
10552 | 11355 |
10553 if (p->top->is_map) { | 11356 if (p->top->is_map) { |
10554 return handle_mapentry(p); | 11357 return handle_mapentry(p); |
10555 } else { | 11358 } else { |
10556 size_t len; | 11359 size_t len; |
10557 const char *buf = accumulate_getptr(p, &len); | 11360 const char *buf = accumulate_getptr(p, &len); |
10558 const upb_fielddef *f = upb_msgdef_ntof(p->top->m, buf, len); | 11361 upb_value v; |
10559 | 11362 |
10560 if (!f) { | 11363 if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) { |
| 11364 p->top->f = upb_value_getconstptr(v); |
| 11365 multipart_end(p); |
| 11366 |
| 11367 return true; |
| 11368 } else { |
10561 /* TODO(haberman): Ignore unknown fields if requested/configured to do | 11369 /* TODO(haberman): Ignore unknown fields if requested/configured to do |
10562 * so. */ | 11370 * so. */ |
10563 upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); | 11371 upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); |
10564 upb_env_reporterror(p->env, &p->status); | 11372 upb_env_reporterror(p->env, &p->status); |
10565 return false; | 11373 return false; |
10566 } | 11374 } |
10567 | |
10568 p->top->f = f; | |
10569 multipart_end(p); | |
10570 | |
10571 return true; | |
10572 } | 11375 } |
10573 } | 11376 } |
10574 | 11377 |
10575 static void end_member(upb_json_parser *p) { | 11378 static void end_member(upb_json_parser *p) { |
10576 /* If we just parsed a map-entry value, end that frame too. */ | 11379 /* If we just parsed a map-entry value, end that frame too. */ |
10577 if (p->top->is_mapentry) { | 11380 if (p->top->is_mapentry) { |
10578 upb_status s = UPB_STATUS_INIT; | 11381 upb_status s = UPB_STATUS_INIT; |
10579 upb_selector_t sel; | 11382 upb_selector_t sel; |
10580 bool ok; | 11383 bool ok; |
10581 const upb_fielddef *mapfield; | 11384 const upb_fielddef *mapfield; |
10582 | 11385 |
10583 assert(p->top > p->stack); | 11386 UPB_ASSERT(p->top > p->stack); |
10584 /* send ENDMSG on submsg. */ | 11387 /* send ENDMSG on submsg. */ |
10585 upb_sink_endmsg(&p->top->sink, &s); | 11388 upb_sink_endmsg(&p->top->sink, &s); |
10586 mapfield = p->top->mapfield; | 11389 mapfield = p->top->mapfield; |
10587 | 11390 |
10588 /* send ENDSUBMSG in repeated-field-of-mapentries frame. */ | 11391 /* send ENDSUBMSG in repeated-field-of-mapentries frame. */ |
10589 p->top--; | 11392 p->top--; |
10590 ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); | 11393 ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); |
10591 UPB_ASSERT_VAR(ok, ok); | 11394 UPB_ASSERT(ok); |
10592 upb_sink_endsubmsg(&p->top->sink, sel); | 11395 upb_sink_endsubmsg(&p->top->sink, sel); |
10593 } | 11396 } |
10594 | 11397 |
10595 p->top->f = NULL; | 11398 p->top->f = NULL; |
10596 } | 11399 } |
10597 | 11400 |
10598 static bool start_subobject(upb_json_parser *p) { | 11401 static bool start_subobject(upb_json_parser *p) { |
10599 assert(p->top->f); | 11402 UPB_ASSERT(p->top->f); |
10600 | 11403 |
10601 if (upb_fielddef_ismap(p->top->f)) { | 11404 if (upb_fielddef_ismap(p->top->f)) { |
10602 upb_jsonparser_frame *inner; | 11405 upb_jsonparser_frame *inner; |
10603 upb_selector_t sel; | 11406 upb_selector_t sel; |
10604 | 11407 |
10605 /* Beginning of a map. Start a new parser frame in a repeated-field | 11408 /* Beginning of a map. Start a new parser frame in a repeated-field |
10606 * context. */ | 11409 * context. */ |
10607 if (!check_stack(p)) return false; | 11410 if (!check_stack(p)) return false; |
10608 | 11411 |
10609 inner = p->top + 1; | 11412 inner = p->top + 1; |
10610 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); | 11413 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); |
10611 upb_sink_startseq(&p->top->sink, sel, &inner->sink); | 11414 upb_sink_startseq(&p->top->sink, sel, &inner->sink); |
10612 inner->m = upb_fielddef_msgsubdef(p->top->f); | 11415 inner->m = upb_fielddef_msgsubdef(p->top->f); |
| 11416 inner->name_table = NULL; |
10613 inner->mapfield = p->top->f; | 11417 inner->mapfield = p->top->f; |
10614 inner->f = NULL; | 11418 inner->f = NULL; |
10615 inner->is_map = true; | 11419 inner->is_map = true; |
10616 inner->is_mapentry = false; | 11420 inner->is_mapentry = false; |
10617 p->top = inner; | 11421 p->top = inner; |
10618 | 11422 |
10619 return true; | 11423 return true; |
10620 } else if (upb_fielddef_issubmsg(p->top->f)) { | 11424 } else if (upb_fielddef_issubmsg(p->top->f)) { |
10621 upb_jsonparser_frame *inner; | 11425 upb_jsonparser_frame *inner; |
10622 upb_selector_t sel; | 11426 upb_selector_t sel; |
10623 | 11427 |
10624 /* Beginning of a subobject. Start a new parser frame in the submsg | 11428 /* Beginning of a subobject. Start a new parser frame in the submsg |
10625 * context. */ | 11429 * context. */ |
10626 if (!check_stack(p)) return false; | 11430 if (!check_stack(p)) return false; |
10627 | 11431 |
10628 inner = p->top + 1; | 11432 inner = p->top + 1; |
10629 | 11433 |
10630 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); | 11434 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); |
10631 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); | 11435 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); |
10632 inner->m = upb_fielddef_msgsubdef(p->top->f); | 11436 inner->m = upb_fielddef_msgsubdef(p->top->f); |
| 11437 set_name_table(p, inner); |
10633 inner->f = NULL; | 11438 inner->f = NULL; |
10634 inner->is_map = false; | 11439 inner->is_map = false; |
10635 inner->is_mapentry = false; | 11440 inner->is_mapentry = false; |
10636 p->top = inner; | 11441 p->top = inner; |
10637 | 11442 |
10638 return true; | 11443 return true; |
10639 } else { | 11444 } else { |
10640 upb_status_seterrf(&p->status, | 11445 upb_status_seterrf(&p->status, |
10641 "Object specified for non-message/group field: %s", | 11446 "Object specified for non-message/group field: %s", |
10642 upb_fielddef_name(p->top->f)); | 11447 upb_fielddef_name(p->top->f)); |
(...skipping 13 matching lines...) Expand all Loading... |
10656 p->top--; | 11461 p->top--; |
10657 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); | 11462 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); |
10658 upb_sink_endsubmsg(&p->top->sink, sel); | 11463 upb_sink_endsubmsg(&p->top->sink, sel); |
10659 } | 11464 } |
10660 } | 11465 } |
10661 | 11466 |
10662 static bool start_array(upb_json_parser *p) { | 11467 static bool start_array(upb_json_parser *p) { |
10663 upb_jsonparser_frame *inner; | 11468 upb_jsonparser_frame *inner; |
10664 upb_selector_t sel; | 11469 upb_selector_t sel; |
10665 | 11470 |
10666 assert(p->top->f); | 11471 UPB_ASSERT(p->top->f); |
10667 | 11472 |
10668 if (!upb_fielddef_isseq(p->top->f)) { | 11473 if (!upb_fielddef_isseq(p->top->f)) { |
10669 upb_status_seterrf(&p->status, | 11474 upb_status_seterrf(&p->status, |
10670 "Array specified for non-repeated field: %s", | 11475 "Array specified for non-repeated field: %s", |
10671 upb_fielddef_name(p->top->f)); | 11476 upb_fielddef_name(p->top->f)); |
10672 upb_env_reporterror(p->env, &p->status); | 11477 upb_env_reporterror(p->env, &p->status); |
10673 return false; | 11478 return false; |
10674 } | 11479 } |
10675 | 11480 |
10676 if (!check_stack(p)) return false; | 11481 if (!check_stack(p)) return false; |
10677 | 11482 |
10678 inner = p->top + 1; | 11483 inner = p->top + 1; |
10679 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); | 11484 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); |
10680 upb_sink_startseq(&p->top->sink, sel, &inner->sink); | 11485 upb_sink_startseq(&p->top->sink, sel, &inner->sink); |
10681 inner->m = p->top->m; | 11486 inner->m = p->top->m; |
| 11487 inner->name_table = NULL; |
10682 inner->f = p->top->f; | 11488 inner->f = p->top->f; |
10683 inner->is_map = false; | 11489 inner->is_map = false; |
10684 inner->is_mapentry = false; | 11490 inner->is_mapentry = false; |
10685 p->top = inner; | 11491 p->top = inner; |
10686 | 11492 |
10687 return true; | 11493 return true; |
10688 } | 11494 } |
10689 | 11495 |
10690 static void end_array(upb_json_parser *p) { | 11496 static void end_array(upb_json_parser *p) { |
10691 upb_selector_t sel; | 11497 upb_selector_t sel; |
10692 | 11498 |
10693 assert(p->top > p->stack); | 11499 UPB_ASSERT(p->top > p->stack); |
10694 | 11500 |
10695 p->top--; | 11501 p->top--; |
10696 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); | 11502 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); |
10697 upb_sink_endseq(&p->top->sink, sel); | 11503 upb_sink_endseq(&p->top->sink, sel); |
10698 } | 11504 } |
10699 | 11505 |
10700 static void start_object(upb_json_parser *p) { | 11506 static void start_object(upb_json_parser *p) { |
10701 if (!p->top->is_map) { | 11507 if (!p->top->is_map) { |
10702 upb_sink_startmsg(&p->top->sink); | 11508 upb_sink_startmsg(&p->top->sink); |
10703 } | 11509 } |
(...skipping 25 matching lines...) Expand all Loading... |
10729 * ">" -- transition into a machine | 11535 * ">" -- transition into a machine |
10730 * "%" -- transition out of a machine | 11536 * "%" -- transition out of a machine |
10731 * "@" -- transition into a final state of a machine. | 11537 * "@" -- transition into a final state of a machine. |
10732 * | 11538 * |
10733 * "@" transitions are tricky because a machine can transition into a final | 11539 * "@" 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 | 11540 * 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 | 11541 * a string which is delimited by a final '"' can only transition into its |
10736 * final state once, when the closing '"' is seen. */ | 11542 * final state once, when the closing '"' is seen. */ |
10737 | 11543 |
10738 | 11544 |
10739 #line 1218 "upb/json/parser.rl" | 11545 #line 1244 "upb/json/parser.rl" |
10740 | 11546 |
10741 | 11547 |
10742 | 11548 |
10743 #line 1130 "upb/json/parser.c" | 11549 #line 1156 "upb/json/parser.c" |
10744 static const char _json_actions[] = { | 11550 static const char _json_actions[] = { |
10745 0, 1, 0, 1, 2, 1, 3, 1, | 11551 0, 1, 0, 1, 2, 1, 3, 1, |
10746 5, 1, 6, 1, 7, 1, 8, 1, | 11552 5, 1, 6, 1, 7, 1, 8, 1, |
10747 10, 1, 12, 1, 13, 1, 14, 1, | 11553 10, 1, 12, 1, 13, 1, 14, 1, |
10748 15, 1, 16, 1, 17, 1, 21, 1, | 11554 15, 1, 16, 1, 17, 1, 21, 1, |
10749 25, 1, 27, 2, 3, 8, 2, 4, | 11555 25, 1, 27, 2, 3, 8, 2, 4, |
10750 5, 2, 6, 2, 2, 6, 8, 2, | 11556 5, 2, 6, 2, 2, 6, 8, 2, |
10751 11, 9, 2, 13, 15, 2, 14, 15, | 11557 11, 9, 2, 13, 15, 2, 14, 15, |
10752 2, 18, 1, 2, 19, 27, 2, 20, | 11558 2, 18, 1, 2, 19, 27, 2, 20, |
10753 9, 2, 22, 27, 2, 23, 27, 2, | 11559 9, 2, 22, 27, 2, 23, 27, 2, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10882 }; | 11688 }; |
10883 | 11689 |
10884 static const int json_start = 1; | 11690 static const int json_start = 1; |
10885 | 11691 |
10886 static const int json_en_number_machine = 10; | 11692 static const int json_en_number_machine = 10; |
10887 static const int json_en_string_machine = 19; | 11693 static const int json_en_string_machine = 19; |
10888 static const int json_en_value_machine = 27; | 11694 static const int json_en_value_machine = 27; |
10889 static const int json_en_main = 1; | 11695 static const int json_en_main = 1; |
10890 | 11696 |
10891 | 11697 |
10892 #line 1221 "upb/json/parser.rl" | 11698 #line 1247 "upb/json/parser.rl" |
10893 | 11699 |
10894 size_t parse(void *closure, const void *hd, const char *buf, size_t size, | 11700 size_t parse(void *closure, const void *hd, const char *buf, size_t size, |
10895 const upb_bufhandle *handle) { | 11701 const upb_bufhandle *handle) { |
10896 upb_json_parser *parser = closure; | 11702 upb_json_parser *parser = closure; |
10897 | 11703 |
10898 /* Variables used by Ragel's generated code. */ | 11704 /* Variables used by Ragel's generated code. */ |
10899 int cs = parser->current_state; | 11705 int cs = parser->current_state; |
10900 int *stack = parser->parser_stack; | 11706 int *stack = parser->parser_stack; |
10901 int top = parser->parser_top; | 11707 int top = parser->parser_top; |
10902 | 11708 |
10903 const char *p = buf; | 11709 const char *p = buf; |
10904 const char *pe = buf + size; | 11710 const char *pe = buf + size; |
10905 | 11711 |
10906 parser->handle = handle; | 11712 parser->handle = handle; |
10907 | 11713 |
10908 UPB_UNUSED(hd); | 11714 UPB_UNUSED(hd); |
10909 UPB_UNUSED(handle); | 11715 UPB_UNUSED(handle); |
10910 | 11716 |
10911 capture_resume(parser, buf); | 11717 capture_resume(parser, buf); |
10912 | 11718 |
10913 | 11719 |
10914 #line 1301 "upb/json/parser.c" | 11720 #line 1327 "upb/json/parser.c" |
10915 { | 11721 { |
10916 int _klen; | 11722 int _klen; |
10917 unsigned int _trans; | 11723 unsigned int _trans; |
10918 const char *_acts; | 11724 const char *_acts; |
10919 unsigned int _nacts; | 11725 unsigned int _nacts; |
10920 const char *_keys; | 11726 const char *_keys; |
10921 | 11727 |
10922 if ( p == pe ) | 11728 if ( p == pe ) |
10923 goto _test_eof; | 11729 goto _test_eof; |
10924 if ( cs == 0 ) | 11730 if ( cs == 0 ) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10979 if ( _json_trans_actions[_trans] == 0 ) | 11785 if ( _json_trans_actions[_trans] == 0 ) |
10980 goto _again; | 11786 goto _again; |
10981 | 11787 |
10982 _acts = _json_actions + _json_trans_actions[_trans]; | 11788 _acts = _json_actions + _json_trans_actions[_trans]; |
10983 _nacts = (unsigned int) *_acts++; | 11789 _nacts = (unsigned int) *_acts++; |
10984 while ( _nacts-- > 0 ) | 11790 while ( _nacts-- > 0 ) |
10985 { | 11791 { |
10986 switch ( *_acts++ ) | 11792 switch ( *_acts++ ) |
10987 { | 11793 { |
10988 case 0: | 11794 case 0: |
10989 #line 1133 "upb/json/parser.rl" | 11795 #line 1159 "upb/json/parser.rl" |
10990 { p--; {cs = stack[--top]; goto _again;} } | 11796 { p--; {cs = stack[--top]; goto _again;} } |
10991 break; | 11797 break; |
10992 case 1: | 11798 case 1: |
10993 #line 1134 "upb/json/parser.rl" | 11799 #line 1160 "upb/json/parser.rl" |
10994 { p--; {stack[top++] = cs; cs = 10; goto _again;} } | 11800 { p--; {stack[top++] = cs; cs = 10; goto _again;} } |
10995 break; | 11801 break; |
10996 case 2: | 11802 case 2: |
10997 #line 1138 "upb/json/parser.rl" | 11803 #line 1164 "upb/json/parser.rl" |
10998 { start_text(parser, p); } | 11804 { start_text(parser, p); } |
10999 break; | 11805 break; |
11000 case 3: | 11806 case 3: |
11001 #line 1139 "upb/json/parser.rl" | 11807 #line 1165 "upb/json/parser.rl" |
11002 { CHECK_RETURN_TOP(end_text(parser, p)); } | 11808 { CHECK_RETURN_TOP(end_text(parser, p)); } |
11003 break; | 11809 break; |
11004 case 4: | 11810 case 4: |
11005 #line 1145 "upb/json/parser.rl" | 11811 #line 1171 "upb/json/parser.rl" |
11006 { start_hex(parser); } | 11812 { start_hex(parser); } |
11007 break; | 11813 break; |
11008 case 5: | 11814 case 5: |
11009 #line 1146 "upb/json/parser.rl" | 11815 #line 1172 "upb/json/parser.rl" |
11010 { hexdigit(parser, p); } | 11816 { hexdigit(parser, p); } |
11011 break; | 11817 break; |
11012 case 6: | 11818 case 6: |
11013 #line 1147 "upb/json/parser.rl" | 11819 #line 1173 "upb/json/parser.rl" |
11014 { CHECK_RETURN_TOP(end_hex(parser)); } | 11820 { CHECK_RETURN_TOP(end_hex(parser)); } |
11015 break; | 11821 break; |
11016 case 7: | 11822 case 7: |
11017 #line 1153 "upb/json/parser.rl" | 11823 #line 1179 "upb/json/parser.rl" |
11018 { CHECK_RETURN_TOP(escape(parser, p)); } | 11824 { CHECK_RETURN_TOP(escape(parser, p)); } |
11019 break; | 11825 break; |
11020 case 8: | 11826 case 8: |
11021 #line 1159 "upb/json/parser.rl" | 11827 #line 1185 "upb/json/parser.rl" |
11022 { p--; {cs = stack[--top]; goto _again;} } | 11828 { p--; {cs = stack[--top]; goto _again;} } |
11023 break; | 11829 break; |
11024 case 9: | 11830 case 9: |
11025 #line 1162 "upb/json/parser.rl" | 11831 #line 1188 "upb/json/parser.rl" |
11026 { {stack[top++] = cs; cs = 19; goto _again;} } | 11832 { {stack[top++] = cs; cs = 19; goto _again;} } |
11027 break; | 11833 break; |
11028 case 10: | 11834 case 10: |
11029 #line 1164 "upb/json/parser.rl" | 11835 #line 1190 "upb/json/parser.rl" |
11030 { p--; {stack[top++] = cs; cs = 27; goto _again;} } | 11836 { p--; {stack[top++] = cs; cs = 27; goto _again;} } |
11031 break; | 11837 break; |
11032 case 11: | 11838 case 11: |
11033 #line 1169 "upb/json/parser.rl" | 11839 #line 1195 "upb/json/parser.rl" |
11034 { start_member(parser); } | 11840 { start_member(parser); } |
11035 break; | 11841 break; |
11036 case 12: | 11842 case 12: |
11037 #line 1170 "upb/json/parser.rl" | 11843 #line 1196 "upb/json/parser.rl" |
11038 { CHECK_RETURN_TOP(end_membername(parser)); } | 11844 { CHECK_RETURN_TOP(end_membername(parser)); } |
11039 break; | 11845 break; |
11040 case 13: | 11846 case 13: |
11041 #line 1173 "upb/json/parser.rl" | 11847 #line 1199 "upb/json/parser.rl" |
11042 { end_member(parser); } | 11848 { end_member(parser); } |
11043 break; | 11849 break; |
11044 case 14: | 11850 case 14: |
11045 #line 1179 "upb/json/parser.rl" | 11851 #line 1205 "upb/json/parser.rl" |
11046 { start_object(parser); } | 11852 { start_object(parser); } |
11047 break; | 11853 break; |
11048 case 15: | 11854 case 15: |
11049 #line 1182 "upb/json/parser.rl" | 11855 #line 1208 "upb/json/parser.rl" |
11050 { end_object(parser); } | 11856 { end_object(parser); } |
11051 break; | 11857 break; |
11052 case 16: | 11858 case 16: |
11053 #line 1188 "upb/json/parser.rl" | 11859 #line 1214 "upb/json/parser.rl" |
11054 { CHECK_RETURN_TOP(start_array(parser)); } | 11860 { CHECK_RETURN_TOP(start_array(parser)); } |
11055 break; | 11861 break; |
11056 case 17: | 11862 case 17: |
11057 #line 1192 "upb/json/parser.rl" | 11863 #line 1218 "upb/json/parser.rl" |
11058 { end_array(parser); } | 11864 { end_array(parser); } |
11059 break; | 11865 break; |
11060 case 18: | 11866 case 18: |
11061 #line 1197 "upb/json/parser.rl" | 11867 #line 1223 "upb/json/parser.rl" |
11062 { start_number(parser, p); } | 11868 { start_number(parser, p); } |
11063 break; | 11869 break; |
11064 case 19: | 11870 case 19: |
11065 #line 1198 "upb/json/parser.rl" | 11871 #line 1224 "upb/json/parser.rl" |
11066 { CHECK_RETURN_TOP(end_number(parser, p)); } | 11872 { CHECK_RETURN_TOP(end_number(parser, p)); } |
11067 break; | 11873 break; |
11068 case 20: | 11874 case 20: |
11069 #line 1200 "upb/json/parser.rl" | 11875 #line 1226 "upb/json/parser.rl" |
11070 { CHECK_RETURN_TOP(start_stringval(parser)); } | 11876 { CHECK_RETURN_TOP(start_stringval(parser)); } |
11071 break; | 11877 break; |
11072 case 21: | 11878 case 21: |
11073 #line 1201 "upb/json/parser.rl" | 11879 #line 1227 "upb/json/parser.rl" |
11074 { CHECK_RETURN_TOP(end_stringval(parser)); } | 11880 { CHECK_RETURN_TOP(end_stringval(parser)); } |
11075 break; | 11881 break; |
11076 case 22: | 11882 case 22: |
11077 #line 1203 "upb/json/parser.rl" | 11883 #line 1229 "upb/json/parser.rl" |
11078 { CHECK_RETURN_TOP(parser_putbool(parser, true)); } | 11884 { CHECK_RETURN_TOP(parser_putbool(parser, true)); } |
11079 break; | 11885 break; |
11080 case 23: | 11886 case 23: |
11081 #line 1205 "upb/json/parser.rl" | 11887 #line 1231 "upb/json/parser.rl" |
11082 { CHECK_RETURN_TOP(parser_putbool(parser, false)); } | 11888 { CHECK_RETURN_TOP(parser_putbool(parser, false)); } |
11083 break; | 11889 break; |
11084 case 24: | 11890 case 24: |
11085 #line 1207 "upb/json/parser.rl" | 11891 #line 1233 "upb/json/parser.rl" |
11086 { /* null value */ } | 11892 { /* null value */ } |
11087 break; | 11893 break; |
11088 case 25: | 11894 case 25: |
11089 #line 1209 "upb/json/parser.rl" | 11895 #line 1235 "upb/json/parser.rl" |
11090 { CHECK_RETURN_TOP(start_subobject(parser)); } | 11896 { CHECK_RETURN_TOP(start_subobject(parser)); } |
11091 break; | 11897 break; |
11092 case 26: | 11898 case 26: |
11093 #line 1210 "upb/json/parser.rl" | 11899 #line 1236 "upb/json/parser.rl" |
11094 { end_subobject(parser); } | 11900 { end_subobject(parser); } |
11095 break; | 11901 break; |
11096 case 27: | 11902 case 27: |
11097 #line 1215 "upb/json/parser.rl" | 11903 #line 1241 "upb/json/parser.rl" |
11098 { p--; {cs = stack[--top]; goto _again;} } | 11904 { p--; {cs = stack[--top]; goto _again;} } |
11099 break; | 11905 break; |
11100 #line 1487 "upb/json/parser.c" | 11906 #line 1513 "upb/json/parser.c" |
11101 } | 11907 } |
11102 } | 11908 } |
11103 | 11909 |
11104 _again: | 11910 _again: |
11105 if ( cs == 0 ) | 11911 if ( cs == 0 ) |
11106 goto _out; | 11912 goto _out; |
11107 if ( ++p != pe ) | 11913 if ( ++p != pe ) |
11108 goto _resume; | 11914 goto _resume; |
11109 _test_eof: {} | 11915 _test_eof: {} |
11110 _out: {} | 11916 _out: {} |
11111 } | 11917 } |
11112 | 11918 |
11113 #line 1242 "upb/json/parser.rl" | 11919 #line 1268 "upb/json/parser.rl" |
11114 | 11920 |
11115 if (p != pe) { | 11921 if (p != pe) { |
11116 upb_status_seterrf(&parser->status, "Parse error at %s\n", p); | 11922 upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); |
11117 upb_env_reporterror(parser->env, &parser->status); | 11923 upb_env_reporterror(parser->env, &parser->status); |
11118 } else { | 11924 } else { |
11119 capture_suspend(parser, &p); | 11925 capture_suspend(parser, &p); |
11120 } | 11926 } |
11121 | 11927 |
11122 error: | 11928 error: |
11123 /* Save parsing state back to parser. */ | 11929 /* Save parsing state back to parser. */ |
11124 parser->current_state = cs; | 11930 parser->current_state = cs; |
11125 parser->parser_top = top; | 11931 parser->parser_top = top; |
11126 | 11932 |
(...skipping 17 matching lines...) Expand all Loading... |
11144 int cs; | 11950 int cs; |
11145 int top; | 11951 int top; |
11146 | 11952 |
11147 p->top = p->stack; | 11953 p->top = p->stack; |
11148 p->top->f = NULL; | 11954 p->top->f = NULL; |
11149 p->top->is_map = false; | 11955 p->top->is_map = false; |
11150 p->top->is_mapentry = false; | 11956 p->top->is_mapentry = false; |
11151 | 11957 |
11152 /* Emit Ragel initialization of the parser. */ | 11958 /* Emit Ragel initialization of the parser. */ |
11153 | 11959 |
11154 #line 1541 "upb/json/parser.c" | 11960 #line 1567 "upb/json/parser.c" |
11155 { | 11961 { |
11156 cs = json_start; | 11962 cs = json_start; |
11157 top = 0; | 11963 top = 0; |
11158 } | 11964 } |
11159 | 11965 |
11160 #line 1282 "upb/json/parser.rl" | 11966 #line 1308 "upb/json/parser.rl" |
11161 p->current_state = cs; | 11967 p->current_state = cs; |
11162 p->parser_top = top; | 11968 p->parser_top = top; |
11163 accumulate_clear(p); | 11969 accumulate_clear(p); |
11164 p->multipart_state = MULTIPART_INACTIVE; | 11970 p->multipart_state = MULTIPART_INACTIVE; |
11165 p->capture = NULL; | 11971 p->capture = NULL; |
11166 p->accumulated = NULL; | 11972 p->accumulated = NULL; |
11167 upb_status_clear(&p->status); | 11973 upb_status_clear(&p->status); |
11168 } | 11974 } |
11169 | 11975 |
| 11976 static void visit_json_parsermethod(const upb_refcounted *r, |
| 11977 upb_refcounted_visit *visit, |
| 11978 void *closure) { |
| 11979 const upb_json_parsermethod *method = (upb_json_parsermethod*)r; |
| 11980 visit(r, upb_msgdef_upcast2(method->msg), closure); |
| 11981 } |
| 11982 |
| 11983 static void free_json_parsermethod(upb_refcounted *r) { |
| 11984 upb_json_parsermethod *method = (upb_json_parsermethod*)r; |
| 11985 |
| 11986 upb_inttable_iter i; |
| 11987 upb_inttable_begin(&i, &method->name_tables); |
| 11988 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
| 11989 upb_value val = upb_inttable_iter_value(&i); |
| 11990 upb_strtable *t = upb_value_getptr(val); |
| 11991 upb_strtable_uninit(t); |
| 11992 upb_gfree(t); |
| 11993 } |
| 11994 |
| 11995 upb_inttable_uninit(&method->name_tables); |
| 11996 |
| 11997 upb_gfree(r); |
| 11998 } |
| 11999 |
| 12000 static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { |
| 12001 upb_msg_field_iter i; |
| 12002 upb_strtable *t; |
| 12003 |
| 12004 /* It would be nice to stack-allocate this, but protobufs do not limit the |
| 12005 * length of fields to any reasonable limit. */ |
| 12006 char *buf = NULL; |
| 12007 size_t len = 0; |
| 12008 |
| 12009 if (upb_inttable_lookupptr(&m->name_tables, md, NULL)) { |
| 12010 return; |
| 12011 } |
| 12012 |
| 12013 /* TODO(haberman): handle malloc failure. */ |
| 12014 t = upb_gmalloc(sizeof(*t)); |
| 12015 upb_strtable_init(t, UPB_CTYPE_CONSTPTR); |
| 12016 upb_inttable_insertptr(&m->name_tables, md, upb_value_ptr(t)); |
| 12017 |
| 12018 for(upb_msg_field_begin(&i, md); |
| 12019 !upb_msg_field_done(&i); |
| 12020 upb_msg_field_next(&i)) { |
| 12021 const upb_fielddef *f = upb_msg_iter_field(&i); |
| 12022 |
| 12023 /* Add an entry for the JSON name. */ |
| 12024 size_t field_len = upb_fielddef_getjsonname(f, buf, len); |
| 12025 if (field_len > len) { |
| 12026 size_t len2; |
| 12027 buf = upb_grealloc(buf, 0, field_len); |
| 12028 len = field_len; |
| 12029 len2 = upb_fielddef_getjsonname(f, buf, len); |
| 12030 UPB_ASSERT(len == len2); |
| 12031 } |
| 12032 upb_strtable_insert(t, buf, upb_value_constptr(f)); |
| 12033 |
| 12034 if (strcmp(buf, upb_fielddef_name(f)) != 0) { |
| 12035 /* Since the JSON name is different from the regular field name, add an |
| 12036 * entry for the raw name (compliant proto3 JSON parsers must accept |
| 12037 * both). */ |
| 12038 upb_strtable_insert(t, upb_fielddef_name(f), upb_value_constptr(f)); |
| 12039 } |
| 12040 |
| 12041 if (upb_fielddef_issubmsg(f)) { |
| 12042 add_jsonname_table(m, upb_fielddef_msgsubdef(f)); |
| 12043 } |
| 12044 } |
| 12045 |
| 12046 upb_gfree(buf); |
| 12047 } |
11170 | 12048 |
11171 /* Public API *****************************************************************/ | 12049 /* Public API *****************************************************************/ |
11172 | 12050 |
11173 upb_json_parser *upb_json_parser_create(upb_env *env, upb_sink *output) { | 12051 upb_json_parser *upb_json_parser_create(upb_env *env, |
| 12052 const upb_json_parsermethod *method, |
| 12053 upb_sink *output) { |
11174 #ifndef NDEBUG | 12054 #ifndef NDEBUG |
11175 const size_t size_before = upb_env_bytesallocated(env); | 12055 const size_t size_before = upb_env_bytesallocated(env); |
11176 #endif | 12056 #endif |
11177 upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser)); | 12057 upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser)); |
11178 if (!p) return false; | 12058 if (!p) return false; |
11179 | 12059 |
11180 p->env = env; | 12060 p->env = env; |
| 12061 p->method = method; |
11181 p->limit = p->stack + UPB_JSON_MAX_DEPTH; | 12062 p->limit = p->stack + UPB_JSON_MAX_DEPTH; |
11182 p->accumulate_buf = NULL; | 12063 p->accumulate_buf = NULL; |
11183 p->accumulate_buf_size = 0; | 12064 p->accumulate_buf_size = 0; |
11184 upb_byteshandler_init(&p->input_handler_); | 12065 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 | 12066 |
11189 json_parser_reset(p); | 12067 json_parser_reset(p); |
11190 upb_sink_reset(&p->top->sink, output->handlers, output->closure); | 12068 upb_sink_reset(&p->top->sink, output->handlers, output->closure); |
11191 p->top->m = upb_handlers_msgdef(output->handlers); | 12069 p->top->m = upb_handlers_msgdef(output->handlers); |
| 12070 set_name_table(p, p->top); |
11192 | 12071 |
11193 /* If this fails, uncomment and increase the value in parser.h. */ | 12072 /* If this fails, uncomment and increase the value in parser.h. */ |
11194 /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ | 12073 /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ |
11195 assert(upb_env_bytesallocated(env) - size_before <= UPB_JSON_PARSER_SIZE); | 12074 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= |
| 12075 UPB_JSON_PARSER_SIZE); |
11196 return p; | 12076 return p; |
11197 } | 12077 } |
11198 | 12078 |
11199 upb_bytessink *upb_json_parser_input(upb_json_parser *p) { | 12079 upb_bytessink *upb_json_parser_input(upb_json_parser *p) { |
11200 return &p->input_; | 12080 return &p->input_; |
11201 } | 12081 } |
| 12082 |
| 12083 upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md, |
| 12084 const void* owner) { |
| 12085 static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod, |
| 12086 free_json_parsermethod}; |
| 12087 upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret)); |
| 12088 upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner); |
| 12089 |
| 12090 ret->msg = md; |
| 12091 upb_ref2(md, ret); |
| 12092 |
| 12093 upb_byteshandler_init(&ret->input_handler_); |
| 12094 upb_byteshandler_setstring(&ret->input_handler_, parse, ret); |
| 12095 upb_byteshandler_setendstr(&ret->input_handler_, end, ret); |
| 12096 |
| 12097 upb_inttable_init(&ret->name_tables, UPB_CTYPE_PTR); |
| 12098 |
| 12099 add_jsonname_table(ret, md); |
| 12100 |
| 12101 return ret; |
| 12102 } |
| 12103 |
| 12104 const upb_byteshandler *upb_json_parsermethod_inputhandler( |
| 12105 const upb_json_parsermethod *m) { |
| 12106 return &m->input_handler_; |
| 12107 } |
11202 /* | 12108 /* |
11203 ** This currently uses snprintf() to format primitives, and could be optimized | 12109 ** This currently uses snprintf() to format primitives, and could be optimized |
11204 ** further. | 12110 ** further. |
11205 */ | 12111 */ |
11206 | 12112 |
11207 | 12113 |
11208 #include <stdlib.h> | |
11209 #include <stdio.h> | |
11210 #include <string.h> | 12114 #include <string.h> |
11211 #include <stdint.h> | 12115 #include <stdint.h> |
11212 | 12116 |
11213 struct upb_json_printer { | 12117 struct upb_json_printer { |
11214 upb_sink input_; | 12118 upb_sink input_; |
11215 /* BytesSink closure. */ | 12119 /* BytesSink closure. */ |
11216 void *subc_; | 12120 void *subc_; |
11217 upb_bytessink *output_; | 12121 upb_bytessink *output_; |
11218 | 12122 |
11219 /* We track the depth so that we know when to emit startstr/endstr on the | 12123 /* We track the depth so that we know when to emit startstr/endstr on the |
11220 * output. */ | 12124 * output. */ |
11221 int depth_; | 12125 int depth_; |
11222 | 12126 |
11223 /* Have we emitted the first element? This state is necessary to emit commas | 12127 /* 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 | 12128 * without leaving a trailing comma in arrays/maps. We keep this state per |
11225 * frame depth. | 12129 * frame depth. |
11226 * | 12130 * |
11227 * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages. | 12131 * 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 | 12132 * 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 | 12133 * repeated fields and messages (maps), and the worst case is a |
11230 * message->repeated field->submessage->repeated field->... nesting. */ | 12134 * message->repeated field->submessage->repeated field->... nesting. */ |
11231 bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; | 12135 bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; |
11232 }; | 12136 }; |
11233 | 12137 |
11234 /* StringPiece; a pointer plus a length. */ | 12138 /* StringPiece; a pointer plus a length. */ |
11235 typedef struct { | 12139 typedef struct { |
11236 const char *ptr; | 12140 char *ptr; |
11237 size_t len; | 12141 size_t len; |
11238 } strpc; | 12142 } strpc; |
11239 | 12143 |
11240 strpc *newstrpc(upb_handlers *h, const upb_fielddef *f) { | 12144 void freestrpc(void *ptr) { |
11241 strpc *ret = malloc(sizeof(*ret)); | 12145 strpc *pc = ptr; |
11242 ret->ptr = upb_fielddef_name(f); | 12146 upb_gfree(pc->ptr); |
11243 ret->len = strlen(ret->ptr); | 12147 upb_gfree(pc); |
11244 upb_handlers_addcleanup(h, ret, free); | 12148 } |
| 12149 |
| 12150 /* Convert fielddef name to JSON name and return as a string piece. */ |
| 12151 strpc *newstrpc(upb_handlers *h, const upb_fielddef *f, |
| 12152 bool preserve_fieldnames) { |
| 12153 /* TODO(haberman): handle malloc failure. */ |
| 12154 strpc *ret = upb_gmalloc(sizeof(*ret)); |
| 12155 if (preserve_fieldnames) { |
| 12156 ret->ptr = upb_gstrdup(upb_fielddef_name(f)); |
| 12157 ret->len = strlen(ret->ptr); |
| 12158 } else { |
| 12159 size_t len; |
| 12160 ret->len = upb_fielddef_getjsonname(f, NULL, 0); |
| 12161 ret->ptr = upb_gmalloc(ret->len); |
| 12162 len = upb_fielddef_getjsonname(f, ret->ptr, ret->len); |
| 12163 UPB_ASSERT(len == ret->len); |
| 12164 ret->len--; /* NULL */ |
| 12165 } |
| 12166 |
| 12167 upb_handlers_addcleanup(h, ret, freestrpc); |
11245 return ret; | 12168 return ret; |
11246 } | 12169 } |
11247 | 12170 |
11248 /* ------------ JSON string printing: values, maps, arrays ------------------ */ | 12171 /* ------------ JSON string printing: values, maps, arrays ------------------ */ |
11249 | 12172 |
11250 static void print_data( | 12173 static void print_data( |
11251 upb_json_printer *p, const char *buf, unsigned int len) { | 12174 upb_json_printer *p, const char *buf, unsigned int len) { |
11252 /* TODO: Will need to change if we support pushback from the sink. */ | 12175 /* 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); | 12176 size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); |
11254 UPB_ASSERT_VAR(n, n == len); | 12177 UPB_ASSERT(n == len); |
11255 } | 12178 } |
11256 | 12179 |
11257 static void print_comma(upb_json_printer *p) { | 12180 static void print_comma(upb_json_printer *p) { |
11258 if (!p->first_elem_[p->depth_]) { | 12181 if (!p->first_elem_[p->depth_]) { |
11259 print_data(p, ",", 1); | 12182 print_data(p, ",", 1); |
11260 } | 12183 } |
11261 p->first_elem_[p->depth_] = false; | 12184 p->first_elem_[p->depth_] = false; |
11262 } | 12185 } |
11263 | 12186 |
11264 /* Helpers that print properly formatted elements to the JSON output stream. */ | 12187 /* Helpers that print properly formatted elements to the JSON output stream. */ |
11265 | 12188 |
11266 /* Used for escaping control chars in strings. */ | 12189 /* Used for escaping control chars in strings. */ |
11267 static const char kControlCharLimit = 0x20; | 12190 static const char kControlCharLimit = 0x20; |
11268 | 12191 |
11269 UPB_INLINE bool is_json_escaped(char c) { | 12192 UPB_INLINE bool is_json_escaped(char c) { |
11270 /* See RFC 4627. */ | 12193 /* See RFC 4627. */ |
11271 unsigned char uc = (unsigned char)c; | 12194 unsigned char uc = (unsigned char)c; |
11272 return uc < kControlCharLimit || uc == '"' || uc == '\\'; | 12195 return uc < kControlCharLimit || uc == '"' || uc == '\\'; |
11273 } | 12196 } |
11274 | 12197 |
11275 UPB_INLINE char* json_nice_escape(char c) { | 12198 UPB_INLINE const char* json_nice_escape(char c) { |
11276 switch (c) { | 12199 switch (c) { |
11277 case '"': return "\\\""; | 12200 case '"': return "\\\""; |
11278 case '\\': return "\\\\"; | 12201 case '\\': return "\\\\"; |
11279 case '\b': return "\\b"; | 12202 case '\b': return "\\b"; |
11280 case '\f': return "\\f"; | 12203 case '\f': return "\\f"; |
11281 case '\n': return "\\n"; | 12204 case '\n': return "\\n"; |
11282 case '\r': return "\\r"; | 12205 case '\r': return "\\r"; |
11283 case '\t': return "\\t"; | 12206 case '\t': return "\\t"; |
11284 default: return NULL; | 12207 default: return NULL; |
11285 } | 12208 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11594 const unsigned char *from = (const unsigned char*)str; | 12517 const unsigned char *from = (const unsigned char*)str; |
11595 char *to = data; | 12518 char *to = data; |
11596 size_t remaining = len; | 12519 size_t remaining = len; |
11597 size_t bytes; | 12520 size_t bytes; |
11598 | 12521 |
11599 UPB_UNUSED(handler_data); | 12522 UPB_UNUSED(handler_data); |
11600 UPB_UNUSED(handle); | 12523 UPB_UNUSED(handle); |
11601 | 12524 |
11602 while (remaining > 2) { | 12525 while (remaining > 2) { |
11603 /* TODO(haberman): handle encoded lengths > sizeof(data) */ | 12526 /* TODO(haberman): handle encoded lengths > sizeof(data) */ |
11604 UPB_ASSERT_VAR(limit, (limit - to) >= 4); | 12527 UPB_ASSERT((limit - to) >= 4); |
11605 | 12528 |
11606 to[0] = base64[from[0] >> 2]; | 12529 to[0] = base64[from[0] >> 2]; |
11607 to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)]; | 12530 to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)]; |
11608 to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)]; | 12531 to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)]; |
11609 to[3] = base64[from[2] & 0x3f]; | 12532 to[3] = base64[from[2] & 0x3f]; |
11610 | 12533 |
11611 remaining -= 3; | 12534 remaining -= 3; |
11612 to += 4; | 12535 to += 4; |
11613 from += 3; | 12536 from += 3; |
11614 } | 12537 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11738 const char *str, size_t len, | 12661 const char *str, size_t len, |
11739 const upb_bufhandle *handle) { | 12662 const upb_bufhandle *handle) { |
11740 upb_json_printer *p = closure; | 12663 upb_json_printer *p = closure; |
11741 CHK(putbytes(closure, handler_data, str, len, handle)); | 12664 CHK(putbytes(closure, handler_data, str, len, handle)); |
11742 print_data(p, ":", 1); | 12665 print_data(p, ":", 1); |
11743 return len; | 12666 return len; |
11744 } | 12667 } |
11745 | 12668 |
11746 static void set_enum_hd(upb_handlers *h, | 12669 static void set_enum_hd(upb_handlers *h, |
11747 const upb_fielddef *f, | 12670 const upb_fielddef *f, |
| 12671 bool preserve_fieldnames, |
11748 upb_handlerattr *attr) { | 12672 upb_handlerattr *attr) { |
11749 EnumHandlerData *hd = malloc(sizeof(EnumHandlerData)); | 12673 EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData)); |
11750 hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f); | 12674 hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f); |
11751 hd->keyname = newstrpc(h, f); | 12675 hd->keyname = newstrpc(h, f, preserve_fieldnames); |
11752 upb_handlers_addcleanup(h, hd, free); | 12676 upb_handlers_addcleanup(h, hd, upb_gfree); |
11753 upb_handlerattr_sethandlerdata(attr, hd); | 12677 upb_handlerattr_sethandlerdata(attr, hd); |
11754 } | 12678 } |
11755 | 12679 |
11756 /* Set up handlers for a mapentry submessage (i.e., an individual key/value pair | 12680 /* Set up handlers for a mapentry submessage (i.e., an individual key/value pair |
11757 * in a map). | 12681 * in a map). |
11758 * | 12682 * |
11759 * TODO: Handle missing key, missing value, out-of-order key/value, or repeated | 12683 * 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 | 12684 * 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 | 12685 * 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 | 12686 * 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 | 12687 * 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 | 12688 * 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 | 12689 * 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 | 12690 * field, and then one value field), so this is not a pressing concern at the |
11767 * moment. */ | 12691 * moment. */ |
11768 void printer_sethandlers_mapentry(const void *closure, upb_handlers *h) { | 12692 void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames, |
| 12693 upb_handlers *h) { |
11769 const upb_msgdef *md = upb_handlers_msgdef(h); | 12694 const upb_msgdef *md = upb_handlers_msgdef(h); |
11770 | 12695 |
11771 /* A mapentry message is printed simply as '"key": value'. Rather than | 12696 /* 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 | 12697 * special-case key and value for every type below, we just handle both |
11773 * fields explicitly here. */ | 12698 * fields explicitly here. */ |
11774 const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY); | 12699 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); | 12700 const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE); |
11776 | 12701 |
11777 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; | 12702 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; |
11778 | 12703 |
(...skipping 17 matching lines...) Expand all Loading... |
11796 break; | 12721 break; |
11797 case UPB_TYPE_STRING: | 12722 case UPB_TYPE_STRING: |
11798 upb_handlers_setstartstr(h, key_field, mapkeyval_startstr, &empty_attr); | 12723 upb_handlers_setstartstr(h, key_field, mapkeyval_startstr, &empty_attr); |
11799 upb_handlers_setstring(h, key_field, mapkey_str, &empty_attr); | 12724 upb_handlers_setstring(h, key_field, mapkey_str, &empty_attr); |
11800 upb_handlers_setendstr(h, key_field, mapkey_endstr, &empty_attr); | 12725 upb_handlers_setendstr(h, key_field, mapkey_endstr, &empty_attr); |
11801 break; | 12726 break; |
11802 case UPB_TYPE_BYTES: | 12727 case UPB_TYPE_BYTES: |
11803 upb_handlers_setstring(h, key_field, mapkey_bytes, &empty_attr); | 12728 upb_handlers_setstring(h, key_field, mapkey_bytes, &empty_attr); |
11804 break; | 12729 break; |
11805 default: | 12730 default: |
11806 assert(false); | 12731 UPB_ASSERT(false); |
11807 break; | 12732 break; |
11808 } | 12733 } |
11809 | 12734 |
11810 switch (upb_fielddef_type(value_field)) { | 12735 switch (upb_fielddef_type(value_field)) { |
11811 case UPB_TYPE_INT32: | 12736 case UPB_TYPE_INT32: |
11812 upb_handlers_setint32(h, value_field, putint32_t, &empty_attr); | 12737 upb_handlers_setint32(h, value_field, putint32_t, &empty_attr); |
11813 break; | 12738 break; |
11814 case UPB_TYPE_INT64: | 12739 case UPB_TYPE_INT64: |
11815 upb_handlers_setint64(h, value_field, putint64_t, &empty_attr); | 12740 upb_handlers_setint64(h, value_field, putint64_t, &empty_attr); |
11816 break; | 12741 break; |
(...skipping 15 matching lines...) Expand all Loading... |
11832 case UPB_TYPE_STRING: | 12757 case UPB_TYPE_STRING: |
11833 upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr); | 12758 upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr); |
11834 upb_handlers_setstring(h, value_field, putstr, &empty_attr); | 12759 upb_handlers_setstring(h, value_field, putstr, &empty_attr); |
11835 upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr); | 12760 upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr); |
11836 break; | 12761 break; |
11837 case UPB_TYPE_BYTES: | 12762 case UPB_TYPE_BYTES: |
11838 upb_handlers_setstring(h, value_field, putbytes, &empty_attr); | 12763 upb_handlers_setstring(h, value_field, putbytes, &empty_attr); |
11839 break; | 12764 break; |
11840 case UPB_TYPE_ENUM: { | 12765 case UPB_TYPE_ENUM: { |
11841 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; | 12766 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; |
11842 set_enum_hd(h, value_field, &enum_attr); | 12767 set_enum_hd(h, value_field, preserve_fieldnames, &enum_attr); |
11843 upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr); | 12768 upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr); |
11844 upb_handlerattr_uninit(&enum_attr); | 12769 upb_handlerattr_uninit(&enum_attr); |
11845 break; | 12770 break; |
11846 } | 12771 } |
11847 case UPB_TYPE_MESSAGE: | 12772 case UPB_TYPE_MESSAGE: |
11848 /* No handler necessary -- the submsg handlers will print the message | 12773 /* No handler necessary -- the submsg handlers will print the message |
11849 * as appropriate. */ | 12774 * as appropriate. */ |
11850 break; | 12775 break; |
11851 } | 12776 } |
11852 | 12777 |
11853 upb_handlerattr_uninit(&empty_attr); | 12778 upb_handlerattr_uninit(&empty_attr); |
11854 } | 12779 } |
11855 | 12780 |
11856 void printer_sethandlers(const void *closure, upb_handlers *h) { | 12781 void printer_sethandlers(const void *closure, upb_handlers *h) { |
11857 const upb_msgdef *md = upb_handlers_msgdef(h); | 12782 const upb_msgdef *md = upb_handlers_msgdef(h); |
11858 bool is_mapentry = upb_msgdef_mapentry(md); | 12783 bool is_mapentry = upb_msgdef_mapentry(md); |
11859 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; | 12784 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; |
11860 upb_msg_field_iter i; | 12785 upb_msg_field_iter i; |
11861 | 12786 const bool *preserve_fieldnames_ptr = closure; |
11862 UPB_UNUSED(closure); | 12787 const bool preserve_fieldnames = *preserve_fieldnames_ptr; |
11863 | 12788 |
11864 if (is_mapentry) { | 12789 if (is_mapentry) { |
11865 /* mapentry messages are sufficiently different that we handle them | 12790 /* mapentry messages are sufficiently different that we handle them |
11866 * separately. */ | 12791 * separately. */ |
11867 printer_sethandlers_mapentry(closure, h); | 12792 printer_sethandlers_mapentry(closure, preserve_fieldnames, h); |
11868 return; | 12793 return; |
11869 } | 12794 } |
11870 | 12795 |
11871 upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); | 12796 upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); |
11872 upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); | 12797 upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); |
11873 | 12798 |
11874 #define TYPE(type, name, ctype) \ | 12799 #define TYPE(type, name, ctype) \ |
11875 case type: \ | 12800 case type: \ |
11876 if (upb_fielddef_isseq(f)) { \ | 12801 if (upb_fielddef_isseq(f)) { \ |
11877 upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \ | 12802 upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \ |
11878 } else { \ | 12803 } else { \ |
11879 upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \ | 12804 upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \ |
11880 } \ | 12805 } \ |
11881 break; | 12806 break; |
11882 | 12807 |
11883 upb_msg_field_begin(&i, md); | 12808 upb_msg_field_begin(&i, md); |
11884 for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { | 12809 for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { |
11885 const upb_fielddef *f = upb_msg_iter_field(&i); | 12810 const upb_fielddef *f = upb_msg_iter_field(&i); |
11886 | 12811 |
11887 upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER; | 12812 upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER; |
11888 upb_handlerattr_sethandlerdata(&name_attr, newstrpc(h, f)); | 12813 upb_handlerattr_sethandlerdata(&name_attr, |
| 12814 newstrpc(h, f, preserve_fieldnames)); |
11889 | 12815 |
11890 if (upb_fielddef_ismap(f)) { | 12816 if (upb_fielddef_ismap(f)) { |
11891 upb_handlers_setstartseq(h, f, startmap, &name_attr); | 12817 upb_handlers_setstartseq(h, f, startmap, &name_attr); |
11892 upb_handlers_setendseq(h, f, endmap, &name_attr); | 12818 upb_handlers_setendseq(h, f, endmap, &name_attr); |
11893 } else if (upb_fielddef_isseq(f)) { | 12819 } else if (upb_fielddef_isseq(f)) { |
11894 upb_handlers_setstartseq(h, f, startseq, &name_attr); | 12820 upb_handlers_setstartseq(h, f, startseq, &name_attr); |
11895 upb_handlers_setendseq(h, f, endseq, &empty_attr); | 12821 upb_handlers_setendseq(h, f, endseq, &empty_attr); |
11896 } | 12822 } |
11897 | 12823 |
11898 switch (upb_fielddef_type(f)) { | 12824 switch (upb_fielddef_type(f)) { |
11899 TYPE(UPB_TYPE_FLOAT, float, float); | 12825 TYPE(UPB_TYPE_FLOAT, float, float); |
11900 TYPE(UPB_TYPE_DOUBLE, double, double); | 12826 TYPE(UPB_TYPE_DOUBLE, double, double); |
11901 TYPE(UPB_TYPE_BOOL, bool, bool); | 12827 TYPE(UPB_TYPE_BOOL, bool, bool); |
11902 TYPE(UPB_TYPE_INT32, int32, int32_t); | 12828 TYPE(UPB_TYPE_INT32, int32, int32_t); |
11903 TYPE(UPB_TYPE_UINT32, uint32, uint32_t); | 12829 TYPE(UPB_TYPE_UINT32, uint32, uint32_t); |
11904 TYPE(UPB_TYPE_INT64, int64, int64_t); | 12830 TYPE(UPB_TYPE_INT64, int64, int64_t); |
11905 TYPE(UPB_TYPE_UINT64, uint64, uint64_t); | 12831 TYPE(UPB_TYPE_UINT64, uint64, uint64_t); |
11906 case UPB_TYPE_ENUM: { | 12832 case UPB_TYPE_ENUM: { |
11907 /* For now, we always emit symbolic names for enums. We may want an | 12833 /* 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 | 12834 * option later to control this behavior, but we will wait for a real |
11909 * need first. */ | 12835 * need first. */ |
11910 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; | 12836 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; |
11911 set_enum_hd(h, f, &enum_attr); | 12837 set_enum_hd(h, f, preserve_fieldnames, &enum_attr); |
11912 | 12838 |
11913 if (upb_fielddef_isseq(f)) { | 12839 if (upb_fielddef_isseq(f)) { |
11914 upb_handlers_setint32(h, f, repeated_enum, &enum_attr); | 12840 upb_handlers_setint32(h, f, repeated_enum, &enum_attr); |
11915 } else { | 12841 } else { |
11916 upb_handlers_setint32(h, f, scalar_enum, &enum_attr); | 12842 upb_handlers_setint32(h, f, scalar_enum, &enum_attr); |
11917 } | 12843 } |
11918 | 12844 |
11919 upb_handlerattr_uninit(&enum_attr); | 12845 upb_handlerattr_uninit(&enum_attr); |
11920 break; | 12846 break; |
11921 } | 12847 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11969 #endif | 12895 #endif |
11970 | 12896 |
11971 upb_json_printer *p = upb_env_malloc(e, sizeof(upb_json_printer)); | 12897 upb_json_printer *p = upb_env_malloc(e, sizeof(upb_json_printer)); |
11972 if (!p) return NULL; | 12898 if (!p) return NULL; |
11973 | 12899 |
11974 p->output_ = output; | 12900 p->output_ = output; |
11975 json_printer_reset(p); | 12901 json_printer_reset(p); |
11976 upb_sink_reset(&p->input_, h, p); | 12902 upb_sink_reset(&p->input_, h, p); |
11977 | 12903 |
11978 /* If this fails, increase the value in printer.h. */ | 12904 /* If this fails, increase the value in printer.h. */ |
11979 assert(upb_env_bytesallocated(e) - size_before <= UPB_JSON_PRINTER_SIZE); | 12905 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= |
| 12906 UPB_JSON_PRINTER_SIZE); |
11980 return p; | 12907 return p; |
11981 } | 12908 } |
11982 | 12909 |
11983 upb_sink *upb_json_printer_input(upb_json_printer *p) { | 12910 upb_sink *upb_json_printer_input(upb_json_printer *p) { |
11984 return &p->input_; | 12911 return &p->input_; |
11985 } | 12912 } |
11986 | 12913 |
11987 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, | 12914 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, |
| 12915 bool preserve_fieldnames, |
11988 const void *owner) { | 12916 const void *owner) { |
11989 return upb_handlers_newfrozen(md, owner, printer_sethandlers, NULL); | 12917 return upb_handlers_newfrozen( |
| 12918 md, owner, printer_sethandlers, &preserve_fieldnames); |
11990 } | 12919 } |
OLD | NEW |