OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Amalgamated source file |
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 | |
31 #include "upb.h" | 2 #include "upb.h" |
32 | 3 |
33 | 4 |
34 #include <ctype.h> | |
35 #include <stdlib.h> | 5 #include <stdlib.h> |
36 #include <string.h> | 6 #include <string.h> |
37 | 7 |
38 typedef struct { | 8 typedef struct { |
39 size_t len; | 9 size_t len; |
40 char str[1]; /* Null-terminated string data follows. */ | 10 char str[1]; /* Null-terminated string data follows. */ |
41 } str_t; | 11 } str_t; |
42 | 12 |
43 static str_t *newstr(const char *data, size_t len) { | 13 static str_t *newstr(const char *data, size_t len) { |
44 str_t *ret = upb_gmalloc(sizeof(*ret) + len); | 14 str_t *ret = malloc(sizeof(*ret) + len); |
45 if (!ret) return NULL; | 15 if (!ret) return NULL; |
46 ret->len = len; | 16 ret->len = len; |
47 memcpy(ret->str, data, len); | 17 memcpy(ret->str, data, len); |
48 ret->str[len] = '\0'; | 18 ret->str[len] = '\0'; |
49 return ret; | 19 return ret; |
50 } | 20 } |
51 | 21 |
52 static void freestr(str_t *s) { upb_gfree(s); } | 22 static void freestr(str_t *s) { free(s); } |
53 | 23 |
54 /* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ | 24 /* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ |
55 static bool upb_isbetween(char c, char low, char high) { | 25 static bool upb_isbetween(char c, char low, char high) { |
56 return c >= low && c <= high; | 26 return c >= low && c <= high; |
57 } | 27 } |
58 | 28 |
59 static bool upb_isletter(char c) { | 29 static bool upb_isletter(char c) { |
60 return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_'; | 30 return upb_isbetween(c, 'A', 'Z') || upb_isbetween(c, 'a', 'z') || c == '_'; |
61 } | 31 } |
62 | 32 |
(...skipping 24 matching lines...) Expand all Loading... |
87 if (!upb_isalphanum(c)) { | 57 if (!upb_isalphanum(c)) { |
88 upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)", | 58 upb_status_seterrf(s, "invalid name: non-alphanumeric character (%s)", |
89 str); | 59 str); |
90 return false; | 60 return false; |
91 } | 61 } |
92 } | 62 } |
93 } | 63 } |
94 return !start; | 64 return !start; |
95 } | 65 } |
96 | 66 |
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 | |
113 | 67 |
114 /* upb_def ********************************************************************/ | 68 /* upb_def ********************************************************************/ |
115 | 69 |
116 upb_deftype_t upb_def_type(const upb_def *d) { return d->type; } | 70 upb_deftype_t upb_def_type(const upb_def *d) { return d->type; } |
117 | 71 |
118 const char *upb_def_fullname(const upb_def *d) { return d->fullname; } | 72 const char *upb_def_fullname(const upb_def *d) { return d->fullname; } |
119 | 73 |
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 | |
134 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) { | 74 bool upb_def_setfullname(upb_def *def, const char *fullname, upb_status *s) { |
135 UPB_ASSERT(!upb_def_isfrozen(def)); | 75 assert(!upb_def_isfrozen(def)); |
136 if (!upb_isident(fullname, strlen(fullname), true, s)) { | 76 if (!upb_isident(fullname, strlen(fullname), true, s)) return false; |
137 return false; | 77 free((void*)def->fullname); |
138 } | 78 def->fullname = upb_strdup(fullname); |
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; | |
148 return true; | 79 return true; |
149 } | 80 } |
150 | 81 |
151 const upb_filedef *upb_def_file(const upb_def *d) { return d->file; } | |
152 | |
153 upb_def *upb_def_dup(const upb_def *def, const void *o) { | 82 upb_def *upb_def_dup(const upb_def *def, const void *o) { |
154 switch (def->type) { | 83 switch (def->type) { |
155 case UPB_DEF_MSG: | 84 case UPB_DEF_MSG: |
156 return upb_msgdef_upcast_mutable( | 85 return upb_msgdef_upcast_mutable( |
157 upb_msgdef_dup(upb_downcast_msgdef(def), o)); | 86 upb_msgdef_dup(upb_downcast_msgdef(def), o)); |
158 case UPB_DEF_FIELD: | 87 case UPB_DEF_FIELD: |
159 return upb_fielddef_upcast_mutable( | 88 return upb_fielddef_upcast_mutable( |
160 upb_fielddef_dup(upb_downcast_fielddef(def), o)); | 89 upb_fielddef_dup(upb_downcast_fielddef(def), o)); |
161 case UPB_DEF_ENUM: | 90 case UPB_DEF_ENUM: |
162 return upb_enumdef_upcast_mutable( | 91 return upb_enumdef_upcast_mutable( |
163 upb_enumdef_dup(upb_downcast_enumdef(def), o)); | 92 upb_enumdef_dup(upb_downcast_enumdef(def), o)); |
164 default: UPB_ASSERT(false); return NULL; | 93 default: assert(false); return NULL; |
165 } | 94 } |
166 } | 95 } |
167 | 96 |
168 static bool upb_def_init(upb_def *def, upb_deftype_t type, | 97 static bool upb_def_init(upb_def *def, upb_deftype_t type, |
169 const struct upb_refcounted_vtbl *vtbl, | 98 const struct upb_refcounted_vtbl *vtbl, |
170 const void *owner) { | 99 const void *owner) { |
171 if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return fal
se; | 100 if (!upb_refcounted_init(upb_def_upcast_mutable(def), vtbl, owner)) return fal
se; |
172 def->type = type; | 101 def->type = type; |
173 def->fullname = NULL; | 102 def->fullname = NULL; |
174 def->came_from_user = false; | 103 def->came_from_user = false; |
175 def->file = NULL; | |
176 return true; | 104 return true; |
177 } | 105 } |
178 | 106 |
179 static void upb_def_uninit(upb_def *def) { | 107 static void upb_def_uninit(upb_def *def) { |
180 upb_gfree((void*)def->fullname); | 108 free((void*)def->fullname); |
181 } | 109 } |
182 | 110 |
183 static const char *msgdef_name(const upb_msgdef *m) { | 111 static const char *msgdef_name(const upb_msgdef *m) { |
184 const char *name = upb_def_fullname(upb_msgdef_upcast(m)); | 112 const char *name = upb_def_fullname(upb_msgdef_upcast(m)); |
185 return name ? name : "(anonymous)"; | 113 return name ? name : "(anonymous)"; |
186 } | 114 } |
187 | 115 |
188 static bool upb_validate_field(upb_fielddef *f, upb_status *s) { | 116 static bool upb_validate_field(upb_fielddef *f, upb_status *s) { |
189 if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { | 117 if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { |
190 upb_status_seterrmsg(s, "fielddef must have name and number set"); | 118 upb_status_seterrmsg(s, "fielddef must have name and number set"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 msgdef_name(f->msg.def), upb_fielddef_name(f)); | 153 msgdef_name(f->msg.def), upb_fielddef_name(f)); |
226 return false; | 154 return false; |
227 } | 155 } |
228 } | 156 } |
229 | 157 |
230 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 158 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
231 bool has_default_name = upb_fielddef_enumhasdefaultstr(f); | 159 bool has_default_name = upb_fielddef_enumhasdefaultstr(f); |
232 bool has_default_number = upb_fielddef_enumhasdefaultint32(f); | 160 bool has_default_number = upb_fielddef_enumhasdefaultint32(f); |
233 | 161 |
234 /* Previously verified by upb_validate_enumdef(). */ | 162 /* Previously verified by upb_validate_enumdef(). */ |
235 UPB_ASSERT(upb_enumdef_numvals(upb_fielddef_enumsubdef(f)) > 0); | 163 assert(upb_enumdef_numvals(upb_fielddef_enumsubdef(f)) > 0); |
236 | 164 |
237 /* We've already validated that we have an associated enumdef and that it | 165 /* We've already validated that we have an associated enumdef and that it |
238 * has at least one member, so at least one of these should be true. | 166 * has at least one member, so at least one of these should be true. |
239 * Because if the user didn't set anything, we'll pick up the enum's | 167 * Because if the user didn't set anything, we'll pick up the enum's |
240 * default, but if the user *did* set something we should at least pick up | 168 * default, but if the user *did* set something we should at least pick up |
241 * the one they set (int32 or string). */ | 169 * the one they set (int32 or string). */ |
242 UPB_ASSERT(has_default_name || has_default_number); | 170 assert(has_default_name || has_default_number); |
243 | 171 |
244 if (!has_default_name) { | 172 if (!has_default_name) { |
245 upb_status_seterrf(s, | 173 upb_status_seterrf(s, |
246 "enum default for field %s.%s (%d) is not in the enum", | 174 "enum default for field %s.%s (%d) is not in the enum", |
247 msgdef_name(f->msg.def), upb_fielddef_name(f), | 175 msgdef_name(f->msg.def), upb_fielddef_name(f), |
248 upb_fielddef_defaultint32(f)); | 176 upb_fielddef_defaultint32(f)); |
249 return false; | 177 return false; |
250 } | 178 } |
251 | 179 |
252 if (!has_default_number) { | 180 if (!has_default_number) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 } | 216 } |
289 | 217 |
290 return true; | 218 return true; |
291 } | 219 } |
292 | 220 |
293 /* All submessage fields are lower than all other fields. | 221 /* All submessage fields are lower than all other fields. |
294 * Secondly, fields are increasing in order. */ | 222 * Secondly, fields are increasing in order. */ |
295 uint32_t field_rank(const upb_fielddef *f) { | 223 uint32_t field_rank(const upb_fielddef *f) { |
296 uint32_t ret = upb_fielddef_number(f); | 224 uint32_t ret = upb_fielddef_number(f); |
297 const uint32_t high_bit = 1 << 30; | 225 const uint32_t high_bit = 1 << 30; |
298 UPB_ASSERT(ret < high_bit); | 226 assert(ret < high_bit); |
299 if (!upb_fielddef_issubmsg(f)) | 227 if (!upb_fielddef_issubmsg(f)) |
300 ret |= high_bit; | 228 ret |= high_bit; |
301 return ret; | 229 return ret; |
302 } | 230 } |
303 | 231 |
304 int cmp_fields(const void *p1, const void *p2) { | 232 int cmp_fields(const void *p1, const void *p2) { |
305 const upb_fielddef *f1 = *(upb_fielddef*const*)p1; | 233 const upb_fielddef *f1 = *(upb_fielddef*const*)p1; |
306 const upb_fielddef *f2 = *(upb_fielddef*const*)p2; | 234 const upb_fielddef *f2 = *(upb_fielddef*const*)p2; |
307 return field_rank(f1) - field_rank(f2); | 235 return field_rank(f1) - field_rank(f2); |
308 } | 236 } |
309 | 237 |
310 static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { | 238 static bool assign_msg_indices(upb_msgdef *m, upb_status *s) { |
311 /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the | 239 /* Sort fields. upb internally relies on UPB_TYPE_MESSAGE fields having the |
312 * lowest indexes, but we do not publicly guarantee this. */ | 240 * lowest indexes, but we do not publicly guarantee this. */ |
313 upb_msg_field_iter j; | 241 upb_msg_field_iter j; |
314 int i; | 242 int i; |
315 uint32_t selector; | 243 uint32_t selector; |
316 int n = upb_msgdef_numfields(m); | 244 int n = upb_msgdef_numfields(m); |
317 upb_fielddef **fields; | 245 upb_fielddef **fields = malloc(n * sizeof(*fields)); |
318 | 246 if (!fields) return false; |
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 } | |
330 | 247 |
331 m->submsg_field_count = 0; | 248 m->submsg_field_count = 0; |
332 for(i = 0, upb_msg_field_begin(&j, m); | 249 for(i = 0, upb_msg_field_begin(&j, m); |
333 !upb_msg_field_done(&j); | 250 !upb_msg_field_done(&j); |
334 upb_msg_field_next(&j), i++) { | 251 upb_msg_field_next(&j), i++) { |
335 upb_fielddef *f = upb_msg_iter_field(&j); | 252 upb_fielddef *f = upb_msg_iter_field(&j); |
336 UPB_ASSERT(f->msg.def == m); | 253 assert(f->msg.def == m); |
337 if (!upb_validate_field(f, s)) { | 254 if (!upb_validate_field(f, s)) { |
338 upb_gfree(fields); | 255 free(fields); |
339 return false; | 256 return false; |
340 } | 257 } |
341 if (upb_fielddef_issubmsg(f)) { | 258 if (upb_fielddef_issubmsg(f)) { |
342 m->submsg_field_count++; | 259 m->submsg_field_count++; |
343 } | 260 } |
344 fields[i] = f; | 261 fields[i] = f; |
345 } | 262 } |
346 | 263 |
347 qsort(fields, n, sizeof(*fields), cmp_fields); | 264 qsort(fields, n, sizeof(*fields), cmp_fields); |
348 | 265 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 TRY(UPB_HANDLER_STARTSUBMSG) | 305 TRY(UPB_HANDLER_STARTSUBMSG) |
389 TRY(UPB_HANDLER_ENDSUBMSG) | 306 TRY(UPB_HANDLER_ENDSUBMSG) |
390 TRY(UPB_HANDLER_STARTSEQ) | 307 TRY(UPB_HANDLER_STARTSEQ) |
391 TRY(UPB_HANDLER_ENDSEQ) | 308 TRY(UPB_HANDLER_ENDSEQ) |
392 } | 309 } |
393 upb_inttable_uninit(&t); | 310 upb_inttable_uninit(&t); |
394 } | 311 } |
395 #undef TRY | 312 #undef TRY |
396 #endif | 313 #endif |
397 | 314 |
398 upb_gfree(fields); | 315 free(fields); |
399 return true; | 316 return true; |
400 } | 317 } |
401 | 318 |
402 bool _upb_def_validate(upb_def *const*defs, size_t n, upb_status *s) { | 319 bool upb_def_freeze(upb_def *const* defs, int n, upb_status *s) { |
403 size_t i; | 320 int i; |
| 321 int maxdepth; |
| 322 bool ret; |
| 323 upb_status_clear(s); |
404 | 324 |
405 /* First perform validation, in two passes so we can check that we have a | 325 /* First perform validation, in two passes so we can check that we have a |
406 * transitive closure without needing to search. */ | 326 * transitive closure without needing to search. */ |
407 for (i = 0; i < n; i++) { | 327 for (i = 0; i < n; i++) { |
408 upb_def *def = defs[i]; | 328 upb_def *def = defs[i]; |
409 if (upb_def_isfrozen(def)) { | 329 if (upb_def_isfrozen(def)) { |
410 /* Could relax this requirement if it's annoying. */ | 330 /* Could relax this requirement if it's annoying. */ |
411 upb_status_seterrmsg(s, "def is already frozen"); | 331 upb_status_seterrmsg(s, "def is already frozen"); |
412 goto err; | 332 goto err; |
413 } else if (def->type == UPB_DEF_FIELD) { | 333 } else if (def->type == UPB_DEF_FIELD) { |
414 upb_status_seterrmsg(s, "standalone fielddefs can not be frozen"); | 334 upb_status_seterrmsg(s, "standalone fielddefs can not be frozen"); |
415 goto err; | 335 goto err; |
416 } else if (def->type == UPB_DEF_ENUM) { | 336 } else if (def->type == UPB_DEF_ENUM) { |
417 if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) { | 337 if (!upb_validate_enumdef(upb_dyncast_enumdef(def), s)) { |
418 goto err; | 338 goto err; |
419 } | 339 } |
420 } else { | 340 } else { |
421 /* Set now to detect transitive closure in the second pass. */ | 341 /* Set now to detect transitive closure in the second pass. */ |
422 def->came_from_user = true; | 342 def->came_from_user = true; |
423 } | 343 } |
424 } | 344 } |
425 | 345 |
426 /* Second pass of validation. Also assign selector bases and indexes, and | 346 /* Second pass of validation. Also assign selector bases and indexes, and |
427 * compact tables. */ | 347 * compact tables. */ |
428 for (i = 0; i < n; i++) { | 348 for (i = 0; i < n; i++) { |
429 upb_def *def = defs[i]; | 349 upb_msgdef *m = upb_dyncast_msgdef_mutable(defs[i]); |
430 upb_msgdef *m = upb_dyncast_msgdef_mutable(def); | 350 upb_enumdef *e = upb_dyncast_enumdef_mutable(defs[i]); |
431 upb_enumdef *e = upb_dyncast_enumdef_mutable(def); | |
432 if (m) { | 351 if (m) { |
433 upb_inttable_compact(&m->itof); | 352 upb_inttable_compact(&m->itof); |
434 if (!assign_msg_indices(m, s)) { | 353 if (!assign_msg_indices(m, s)) { |
435 goto err; | 354 goto err; |
436 } | 355 } |
437 } else if (e) { | 356 } else if (e) { |
438 upb_inttable_compact(&e->iton); | 357 upb_inttable_compact(&e->iton); |
439 } | 358 } |
440 } | 359 } |
441 | 360 |
442 return true; | 361 /* Def graph contains FieldDefs between each MessageDef, so double the |
| 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; |
443 | 369 |
444 err: | 370 err: |
445 for (i = 0; i < n; i++) { | 371 for (i = 0; i < n; i++) { |
446 upb_def *def = defs[i]; | 372 defs[i]->came_from_user = false; |
447 def->came_from_user = false; | |
448 } | 373 } |
449 UPB_ASSERT(!(s && upb_ok(s))); | 374 assert(!(s && upb_ok(s))); |
450 return false; | 375 return false; |
451 } | 376 } |
452 | 377 |
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 | |
467 | 378 |
468 /* upb_enumdef ****************************************************************/ | 379 /* upb_enumdef ****************************************************************/ |
469 | 380 |
470 static void visitenum(const upb_refcounted *r, upb_refcounted_visit *visit, | 381 static void upb_enumdef_free(upb_refcounted *r) { |
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) { | |
480 upb_enumdef *e = (upb_enumdef*)r; | 382 upb_enumdef *e = (upb_enumdef*)r; |
481 upb_inttable_iter i; | 383 upb_inttable_iter i; |
482 upb_inttable_begin(&i, &e->iton); | 384 upb_inttable_begin(&i, &e->iton); |
483 for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 385 for( ; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
484 /* To clean up the upb_gstrdup() from upb_enumdef_addval(). */ | 386 /* To clean up the upb_strdup() from upb_enumdef_addval(). */ |
485 upb_gfree(upb_value_getcstr(upb_inttable_iter_value(&i))); | 387 free(upb_value_getcstr(upb_inttable_iter_value(&i))); |
486 } | 388 } |
487 upb_strtable_uninit(&e->ntoi); | 389 upb_strtable_uninit(&e->ntoi); |
488 upb_inttable_uninit(&e->iton); | 390 upb_inttable_uninit(&e->iton); |
489 upb_def_uninit(upb_enumdef_upcast_mutable(e)); | 391 upb_def_uninit(upb_enumdef_upcast_mutable(e)); |
490 upb_gfree(e); | 392 free(e); |
491 } | 393 } |
492 | 394 |
493 const struct upb_refcounted_vtbl upb_enumdef_vtbl = {&visitenum, &freeenum}; | |
494 | |
495 upb_enumdef *upb_enumdef_new(const void *owner) { | 395 upb_enumdef *upb_enumdef_new(const void *owner) { |
496 upb_enumdef *e = upb_gmalloc(sizeof(*e)); | 396 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_enumdef_free}; |
| 397 upb_enumdef *e = malloc(sizeof(*e)); |
497 if (!e) return NULL; | 398 if (!e) return NULL; |
498 | 399 if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM, &vtbl, owner)) |
499 if (!upb_def_init(upb_enumdef_upcast_mutable(e), UPB_DEF_ENUM, | |
500 &upb_enumdef_vtbl, owner)) { | |
501 goto err2; | 400 goto err2; |
502 } | |
503 | |
504 if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2; | 401 if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2; |
505 if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1; | 402 if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1; |
506 return e; | 403 return e; |
507 | 404 |
508 err1: | 405 err1: |
509 upb_strtable_uninit(&e->ntoi); | 406 upb_strtable_uninit(&e->ntoi); |
510 err2: | 407 err2: |
511 upb_gfree(e); | 408 free(e); |
512 return NULL; | 409 return NULL; |
513 } | 410 } |
514 | 411 |
515 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner) { | 412 upb_enumdef *upb_enumdef_dup(const upb_enumdef *e, const void *owner) { |
516 upb_enum_iter i; | 413 upb_enum_iter i; |
517 upb_enumdef *new_e = upb_enumdef_new(owner); | 414 upb_enumdef *new_e = upb_enumdef_new(owner); |
518 if (!new_e) return NULL; | 415 if (!new_e) return NULL; |
519 for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) { | 416 for(upb_enum_begin(&i, e); !upb_enum_done(&i); upb_enum_next(&i)) { |
520 bool success = upb_enumdef_addval( | 417 bool success = upb_enumdef_addval( |
521 new_e, upb_enum_iter_name(&i),upb_enum_iter_number(&i), NULL); | 418 new_e, upb_enum_iter_name(&i),upb_enum_iter_number(&i), NULL); |
522 if (!success) { | 419 if (!success) { |
523 upb_enumdef_unref(new_e, owner); | 420 upb_enumdef_unref(new_e, owner); |
524 return NULL; | 421 return NULL; |
525 } | 422 } |
526 } | 423 } |
527 return new_e; | 424 return new_e; |
528 } | 425 } |
529 | 426 |
530 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) { | 427 bool upb_enumdef_freeze(upb_enumdef *e, upb_status *status) { |
531 upb_def *d = upb_enumdef_upcast_mutable(e); | 428 upb_def *d = upb_enumdef_upcast_mutable(e); |
532 return upb_def_freeze(&d, 1, status); | 429 return upb_def_freeze(&d, 1, status); |
533 } | 430 } |
534 | 431 |
535 const char *upb_enumdef_fullname(const upb_enumdef *e) { | 432 const char *upb_enumdef_fullname(const upb_enumdef *e) { |
536 return upb_def_fullname(upb_enumdef_upcast(e)); | 433 return upb_def_fullname(upb_enumdef_upcast(e)); |
537 } | 434 } |
538 | 435 |
539 const char *upb_enumdef_name(const upb_enumdef *e) { | |
540 return upb_def_name(upb_enumdef_upcast(e)); | |
541 } | |
542 | |
543 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname, | 436 bool upb_enumdef_setfullname(upb_enumdef *e, const char *fullname, |
544 upb_status *s) { | 437 upb_status *s) { |
545 return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s); | 438 return upb_def_setfullname(upb_enumdef_upcast_mutable(e), fullname, s); |
546 } | 439 } |
547 | 440 |
548 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, | 441 bool upb_enumdef_addval(upb_enumdef *e, const char *name, int32_t num, |
549 upb_status *status) { | 442 upb_status *status) { |
550 char *name2; | |
551 | |
552 if (!upb_isident(name, strlen(name), false, status)) { | 443 if (!upb_isident(name, strlen(name), false, status)) { |
553 return false; | 444 return false; |
554 } | 445 } |
555 | |
556 if (upb_enumdef_ntoiz(e, name, NULL)) { | 446 if (upb_enumdef_ntoiz(e, name, NULL)) { |
557 upb_status_seterrf(status, "name '%s' is already defined", name); | 447 upb_status_seterrf(status, "name '%s' is already defined", name); |
558 return false; | 448 return false; |
559 } | 449 } |
560 | |
561 if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) { | 450 if (!upb_strtable_insert(&e->ntoi, name, upb_value_int32(num))) { |
562 upb_status_seterrmsg(status, "out of memory"); | 451 upb_status_seterrmsg(status, "out of memory"); |
563 return false; | 452 return false; |
564 } | 453 } |
565 | 454 if (!upb_inttable_lookup(&e->iton, num, NULL) && |
566 if (!upb_inttable_lookup(&e->iton, num, NULL)) { | 455 !upb_inttable_insert(&e->iton, num, upb_value_cstr(upb_strdup(name)))) { |
567 name2 = upb_gstrdup(name); | 456 upb_status_seterrmsg(status, "out of memory"); |
568 if (!name2 || !upb_inttable_insert(&e->iton, num, upb_value_cstr(name2))) { | 457 upb_strtable_remove(&e->ntoi, name, NULL); |
569 upb_status_seterrmsg(status, "out of memory"); | 458 return false; |
570 upb_strtable_remove(&e->ntoi, name, NULL); | |
571 return false; | |
572 } | |
573 } | 459 } |
574 | |
575 if (upb_enumdef_numvals(e) == 1) { | 460 if (upb_enumdef_numvals(e) == 1) { |
576 bool ok = upb_enumdef_setdefault(e, num, NULL); | 461 bool ok = upb_enumdef_setdefault(e, num, NULL); |
577 UPB_ASSERT(ok); | 462 UPB_ASSERT_VAR(ok, ok); |
578 } | 463 } |
579 | |
580 return true; | 464 return true; |
581 } | 465 } |
582 | 466 |
583 int32_t upb_enumdef_default(const upb_enumdef *e) { | 467 int32_t upb_enumdef_default(const upb_enumdef *e) { |
584 UPB_ASSERT(upb_enumdef_iton(e, e->defaultval)); | 468 assert(upb_enumdef_iton(e, e->defaultval)); |
585 return e->defaultval; | 469 return e->defaultval; |
586 } | 470 } |
587 | 471 |
588 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) { | 472 bool upb_enumdef_setdefault(upb_enumdef *e, int32_t val, upb_status *s) { |
589 UPB_ASSERT(!upb_enumdef_isfrozen(e)); | 473 assert(!upb_enumdef_isfrozen(e)); |
590 if (!upb_enumdef_iton(e, val)) { | 474 if (!upb_enumdef_iton(e, val)) { |
591 upb_status_seterrf(s, "number '%d' is not in the enum.", val); | 475 upb_status_seterrf(s, "number '%d' is not in the enum.", val); |
592 return false; | 476 return false; |
593 } | 477 } |
594 e->defaultval = val; | 478 e->defaultval = val; |
595 return true; | 479 return true; |
596 } | 480 } |
597 | 481 |
598 int upb_enumdef_numvals(const upb_enumdef *e) { | 482 int upb_enumdef_numvals(const upb_enumdef *e) { |
599 return upb_strtable_count(&e->ntoi); | 483 return upb_strtable_count(&e->ntoi); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 | 518 |
635 /* upb_fielddef ***************************************************************/ | 519 /* upb_fielddef ***************************************************************/ |
636 | 520 |
637 static void upb_fielddef_init_default(upb_fielddef *f); | 521 static void upb_fielddef_init_default(upb_fielddef *f); |
638 | 522 |
639 static void upb_fielddef_uninit_default(upb_fielddef *f) { | 523 static void upb_fielddef_uninit_default(upb_fielddef *f) { |
640 if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes) | 524 if (f->type_is_set_ && f->default_is_string && f->defaultval.bytes) |
641 freestr(f->defaultval.bytes); | 525 freestr(f->defaultval.bytes); |
642 } | 526 } |
643 | 527 |
644 const char *upb_fielddef_fullname(const upb_fielddef *e) { | |
645 return upb_def_fullname(upb_fielddef_upcast(e)); | |
646 } | |
647 | |
648 static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit, | 528 static void visitfield(const upb_refcounted *r, upb_refcounted_visit *visit, |
649 void *closure) { | 529 void *closure) { |
650 const upb_fielddef *f = (const upb_fielddef*)r; | 530 const upb_fielddef *f = (const upb_fielddef*)r; |
651 const upb_def *def = upb_fielddef_upcast(f); | |
652 if (upb_fielddef_containingtype(f)) { | 531 if (upb_fielddef_containingtype(f)) { |
653 visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure); | 532 visit(r, upb_msgdef_upcast2(upb_fielddef_containingtype(f)), closure); |
654 } | 533 } |
655 if (upb_fielddef_containingoneof(f)) { | 534 if (upb_fielddef_containingoneof(f)) { |
656 visit(r, upb_oneofdef_upcast(upb_fielddef_containingoneof(f)), closure); | 535 visit(r, upb_oneofdef_upcast2(upb_fielddef_containingoneof(f)), closure); |
657 } | 536 } |
658 if (upb_fielddef_subdef(f)) { | 537 if (upb_fielddef_subdef(f)) { |
659 visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure); | 538 visit(r, upb_def_upcast(upb_fielddef_subdef(f)), closure); |
660 } | 539 } |
661 if (upb_def_file(def)) { | |
662 visit(r, upb_filedef_upcast(upb_def_file(def)), closure); | |
663 } | |
664 } | 540 } |
665 | 541 |
666 static void freefield(upb_refcounted *r) { | 542 static void freefield(upb_refcounted *r) { |
667 upb_fielddef *f = (upb_fielddef*)r; | 543 upb_fielddef *f = (upb_fielddef*)r; |
668 upb_fielddef_uninit_default(f); | 544 upb_fielddef_uninit_default(f); |
669 if (f->subdef_is_symbolic) | 545 if (f->subdef_is_symbolic) |
670 upb_gfree(f->sub.name); | 546 free(f->sub.name); |
671 upb_def_uninit(upb_fielddef_upcast_mutable(f)); | 547 upb_def_uninit(upb_fielddef_upcast_mutable(f)); |
672 upb_gfree(f); | 548 free(f); |
673 } | 549 } |
674 | 550 |
675 static const char *enumdefaultstr(const upb_fielddef *f) { | 551 static const char *enumdefaultstr(const upb_fielddef *f) { |
676 const upb_enumdef *e; | 552 const upb_enumdef *e; |
677 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 553 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
678 e = upb_fielddef_enumsubdef(f); | 554 e = upb_fielddef_enumsubdef(f); |
679 if (f->default_is_string && f->defaultval.bytes) { | 555 if (f->default_is_string && f->defaultval.bytes) { |
680 /* Default was explicitly set as a string. */ | 556 /* Default was explicitly set as a string. */ |
681 str_t *s = f->defaultval.bytes; | 557 str_t *s = f->defaultval.bytes; |
682 return s->str; | 558 return s->str; |
683 } else if (e) { | 559 } else if (e) { |
684 if (!f->default_is_string) { | 560 if (!f->default_is_string) { |
685 /* Default was explicitly set as an integer; look it up in enumdef. */ | 561 /* Default was explicitly set as an integer; look it up in enumdef. */ |
686 const char *name = upb_enumdef_iton(e, f->defaultval.sint); | 562 const char *name = upb_enumdef_iton(e, f->defaultval.sint); |
687 if (name) { | 563 if (name) { |
688 return name; | 564 return name; |
689 } | 565 } |
690 } else { | 566 } else { |
691 /* Default is completely unset; pull enumdef default. */ | 567 /* Default is completely unset; pull enumdef default. */ |
692 if (upb_enumdef_numvals(e) > 0) { | 568 if (upb_enumdef_numvals(e) > 0) { |
693 const char *name = upb_enumdef_iton(e, upb_enumdef_default(e)); | 569 const char *name = upb_enumdef_iton(e, upb_enumdef_default(e)); |
694 UPB_ASSERT(name); | 570 assert(name); |
695 return name; | 571 return name; |
696 } | 572 } |
697 } | 573 } |
698 } | 574 } |
699 return NULL; | 575 return NULL; |
700 } | 576 } |
701 | 577 |
702 static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) { | 578 static bool enumdefaultint32(const upb_fielddef *f, int32_t *val) { |
703 const upb_enumdef *e; | 579 const upb_enumdef *e; |
704 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 580 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
705 e = upb_fielddef_enumsubdef(f); | 581 e = upb_fielddef_enumsubdef(f); |
706 if (!f->default_is_string) { | 582 if (!f->default_is_string) { |
707 /* Default was explicitly set as an integer. */ | 583 /* Default was explicitly set as an integer. */ |
708 *val = f->defaultval.sint; | 584 *val = f->defaultval.sint; |
709 return true; | 585 return true; |
710 } else if (e) { | 586 } else if (e) { |
711 if (f->defaultval.bytes) { | 587 if (f->defaultval.bytes) { |
712 /* Default was explicitly set as a str; try to lookup corresponding int. *
/ | 588 /* Default was explicitly set as a str; try to lookup corresponding int. *
/ |
713 str_t *s = f->defaultval.bytes; | 589 str_t *s = f->defaultval.bytes; |
714 if (upb_enumdef_ntoiz(e, s->str, val)) { | 590 if (upb_enumdef_ntoiz(e, s->str, val)) { |
715 return true; | 591 return true; |
716 } | 592 } |
717 } else { | 593 } else { |
718 /* Default is unset; try to pull in enumdef default. */ | 594 /* Default is unset; try to pull in enumdef default. */ |
719 if (upb_enumdef_numvals(e) > 0) { | 595 if (upb_enumdef_numvals(e) > 0) { |
720 *val = upb_enumdef_default(e); | 596 *val = upb_enumdef_default(e); |
721 return true; | 597 return true; |
722 } | 598 } |
723 } | 599 } |
724 } | 600 } |
725 return false; | 601 return false; |
726 } | 602 } |
727 | 603 |
728 const struct upb_refcounted_vtbl upb_fielddef_vtbl = {visitfield, freefield}; | |
729 | |
730 upb_fielddef *upb_fielddef_new(const void *o) { | 604 upb_fielddef *upb_fielddef_new(const void *o) { |
731 upb_fielddef *f = upb_gmalloc(sizeof(*f)); | 605 static const struct upb_refcounted_vtbl vtbl = {visitfield, freefield}; |
| 606 upb_fielddef *f = malloc(sizeof(*f)); |
732 if (!f) return NULL; | 607 if (!f) return NULL; |
733 if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD, | 608 if (!upb_def_init(upb_fielddef_upcast_mutable(f), UPB_DEF_FIELD, &vtbl, o)) { |
734 &upb_fielddef_vtbl, o)) { | 609 free(f); |
735 upb_gfree(f); | |
736 return NULL; | 610 return NULL; |
737 } | 611 } |
738 f->msg.def = NULL; | 612 f->msg.def = NULL; |
739 f->sub.def = NULL; | 613 f->sub.def = NULL; |
740 f->oneof = NULL; | 614 f->oneof = NULL; |
741 f->subdef_is_symbolic = false; | 615 f->subdef_is_symbolic = false; |
742 f->msg_is_symbolic = false; | 616 f->msg_is_symbolic = false; |
743 f->label_ = UPB_LABEL_OPTIONAL; | 617 f->label_ = UPB_LABEL_OPTIONAL; |
744 f->type_ = UPB_TYPE_INT32; | 618 f->type_ = UPB_TYPE_INT32; |
745 f->number_ = 0; | 619 f->number_ = 0; |
(...skipping 30 matching lines...) Expand all Loading... |
776 newf->default_is_string = f->default_is_string; | 650 newf->default_is_string = f->default_is_string; |
777 newf->defaultval = f->defaultval; | 651 newf->defaultval = f->defaultval; |
778 } | 652 } |
779 | 653 |
780 if (f->subdef_is_symbolic) { | 654 if (f->subdef_is_symbolic) { |
781 srcname = f->sub.name; /* Might be NULL. */ | 655 srcname = f->sub.name; /* Might be NULL. */ |
782 } else { | 656 } else { |
783 srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL; | 657 srcname = f->sub.def ? upb_def_fullname(f->sub.def) : NULL; |
784 } | 658 } |
785 if (srcname) { | 659 if (srcname) { |
786 char *newname = upb_gmalloc(strlen(f->sub.def->fullname) + 2); | 660 char *newname = malloc(strlen(f->sub.def->fullname) + 2); |
787 if (!newname) { | 661 if (!newname) { |
788 upb_fielddef_unref(newf, owner); | 662 upb_fielddef_unref(newf, owner); |
789 return NULL; | 663 return NULL; |
790 } | 664 } |
791 strcpy(newname, "."); | 665 strcpy(newname, "."); |
792 strcat(newname, f->sub.def->fullname); | 666 strcat(newname, f->sub.def->fullname); |
793 upb_fielddef_setsubdefname(newf, newname, NULL); | 667 upb_fielddef_setsubdefname(newf, newname, NULL); |
794 upb_gfree(newname); | 668 free(newname); |
795 } | 669 } |
796 | 670 |
797 return newf; | 671 return newf; |
798 } | 672 } |
799 | 673 |
800 bool upb_fielddef_typeisset(const upb_fielddef *f) { | 674 bool upb_fielddef_typeisset(const upb_fielddef *f) { |
801 return f->type_is_set_; | 675 return f->type_is_set_; |
802 } | 676 } |
803 | 677 |
804 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) { | 678 upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) { |
805 UPB_ASSERT(f->type_is_set_); | 679 assert(f->type_is_set_); |
806 return f->type_; | 680 return f->type_; |
807 } | 681 } |
808 | 682 |
809 uint32_t upb_fielddef_index(const upb_fielddef *f) { | 683 uint32_t upb_fielddef_index(const upb_fielddef *f) { |
810 return f->index_; | 684 return f->index_; |
811 } | 685 } |
812 | 686 |
813 upb_label_t upb_fielddef_label(const upb_fielddef *f) { | 687 upb_label_t upb_fielddef_label(const upb_fielddef *f) { |
814 return f->label_; | 688 return f->label_; |
815 } | 689 } |
(...skipping 19 matching lines...) Expand all Loading... |
835 } | 709 } |
836 | 710 |
837 bool upb_fielddef_packed(const upb_fielddef *f) { | 711 bool upb_fielddef_packed(const upb_fielddef *f) { |
838 return f->packed_; | 712 return f->packed_; |
839 } | 713 } |
840 | 714 |
841 const char *upb_fielddef_name(const upb_fielddef *f) { | 715 const char *upb_fielddef_name(const upb_fielddef *f) { |
842 return upb_def_fullname(upb_fielddef_upcast(f)); | 716 return upb_def_fullname(upb_fielddef_upcast(f)); |
843 } | 717 } |
844 | 718 |
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 | |
884 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { | 719 const upb_msgdef *upb_fielddef_containingtype(const upb_fielddef *f) { |
885 return f->msg_is_symbolic ? NULL : f->msg.def; | 720 return f->msg_is_symbolic ? NULL : f->msg.def; |
886 } | 721 } |
887 | 722 |
888 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { | 723 const upb_oneofdef *upb_fielddef_containingoneof(const upb_fielddef *f) { |
889 return f->oneof; | 724 return f->oneof; |
890 } | 725 } |
891 | 726 |
892 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) { | 727 upb_msgdef *upb_fielddef_containingtype_mutable(upb_fielddef *f) { |
893 return (upb_msgdef*)upb_fielddef_containingtype(f); | 728 return (upb_msgdef*)upb_fielddef_containingtype(f); |
894 } | 729 } |
895 | 730 |
896 const char *upb_fielddef_containingtypename(upb_fielddef *f) { | 731 const char *upb_fielddef_containingtypename(upb_fielddef *f) { |
897 return f->msg_is_symbolic ? f->msg.name : NULL; | 732 return f->msg_is_symbolic ? f->msg.name : NULL; |
898 } | 733 } |
899 | 734 |
900 static void release_containingtype(upb_fielddef *f) { | 735 static void release_containingtype(upb_fielddef *f) { |
901 if (f->msg_is_symbolic) upb_gfree(f->msg.name); | 736 if (f->msg_is_symbolic) free(f->msg.name); |
902 } | 737 } |
903 | 738 |
904 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, | 739 bool upb_fielddef_setcontainingtypename(upb_fielddef *f, const char *name, |
905 upb_status *s) { | 740 upb_status *s) { |
906 char *name_copy; | 741 assert(!upb_fielddef_isfrozen(f)); |
907 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | |
908 if (upb_fielddef_containingtype(f)) { | 742 if (upb_fielddef_containingtype(f)) { |
909 upb_status_seterrmsg(s, "field has already been added to a message."); | 743 upb_status_seterrmsg(s, "field has already been added to a message."); |
910 return false; | 744 return false; |
911 } | 745 } |
912 /* TODO: validate name (upb_isident() doesn't quite work atm because this name | 746 /* TODO: validate name (upb_isident() doesn't quite work atm because this name |
913 * may have a leading "."). */ | 747 * 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 | |
921 release_containingtype(f); | 748 release_containingtype(f); |
922 f->msg.name = name_copy; | 749 f->msg.name = upb_strdup(name); |
923 f->msg_is_symbolic = true; | 750 f->msg_is_symbolic = true; |
924 return true; | 751 return true; |
925 } | 752 } |
926 | 753 |
927 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) { | 754 bool upb_fielddef_setname(upb_fielddef *f, const char *name, upb_status *s) { |
928 if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) { | 755 if (upb_fielddef_containingtype(f) || upb_fielddef_containingoneof(f)) { |
929 upb_status_seterrmsg(s, "Already added to message or oneof"); | 756 upb_status_seterrmsg(s, "Already added to message or oneof"); |
930 return false; | 757 return false; |
931 } | 758 } |
932 return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s); | 759 return upb_def_setfullname(upb_fielddef_upcast_mutable(f), name, s); |
933 } | 760 } |
934 | 761 |
935 static void chkdefaulttype(const upb_fielddef *f, upb_fieldtype_t type) { | 762 static void chkdefaulttype(const upb_fielddef *f, upb_fieldtype_t type) { |
936 UPB_UNUSED(f); | 763 UPB_UNUSED(f); |
937 UPB_UNUSED(type); | 764 UPB_UNUSED(type); |
938 UPB_ASSERT(f->type_is_set_ && upb_fielddef_type(f) == type); | 765 assert(f->type_is_set_ && upb_fielddef_type(f) == type); |
939 } | 766 } |
940 | 767 |
941 int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { | 768 int64_t upb_fielddef_defaultint64(const upb_fielddef *f) { |
942 chkdefaulttype(f, UPB_TYPE_INT64); | 769 chkdefaulttype(f, UPB_TYPE_INT64); |
943 return f->defaultval.sint; | 770 return f->defaultval.sint; |
944 } | 771 } |
945 | 772 |
946 int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { | 773 int32_t upb_fielddef_defaultint32(const upb_fielddef *f) { |
947 if (f->type_is_set_ && upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 774 if (f->type_is_set_ && upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
948 int32_t val; | 775 int32_t val; |
949 bool ok = enumdefaultint32(f, &val); | 776 bool ok = enumdefaultint32(f, &val); |
950 UPB_ASSERT(ok); | 777 UPB_ASSERT_VAR(ok, ok); |
951 return val; | 778 return val; |
952 } else { | 779 } else { |
953 chkdefaulttype(f, UPB_TYPE_INT32); | 780 chkdefaulttype(f, UPB_TYPE_INT32); |
954 return f->defaultval.sint; | 781 return f->defaultval.sint; |
955 } | 782 } |
956 } | 783 } |
957 | 784 |
958 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { | 785 uint64_t upb_fielddef_defaultuint64(const upb_fielddef *f) { |
959 chkdefaulttype(f, UPB_TYPE_UINT64); | 786 chkdefaulttype(f, UPB_TYPE_UINT64); |
960 return f->defaultval.uint; | 787 return f->defaultval.uint; |
(...skipping 13 matching lines...) Expand all Loading... |
974 chkdefaulttype(f, UPB_TYPE_FLOAT); | 801 chkdefaulttype(f, UPB_TYPE_FLOAT); |
975 return f->defaultval.flt; | 802 return f->defaultval.flt; |
976 } | 803 } |
977 | 804 |
978 double upb_fielddef_defaultdouble(const upb_fielddef *f) { | 805 double upb_fielddef_defaultdouble(const upb_fielddef *f) { |
979 chkdefaulttype(f, UPB_TYPE_DOUBLE); | 806 chkdefaulttype(f, UPB_TYPE_DOUBLE); |
980 return f->defaultval.dbl; | 807 return f->defaultval.dbl; |
981 } | 808 } |
982 | 809 |
983 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) { | 810 const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) { |
984 UPB_ASSERT(f->type_is_set_); | 811 assert(f->type_is_set_); |
985 UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_STRING || | 812 assert(upb_fielddef_type(f) == UPB_TYPE_STRING || |
986 upb_fielddef_type(f) == UPB_TYPE_BYTES || | 813 upb_fielddef_type(f) == UPB_TYPE_BYTES || |
987 upb_fielddef_type(f) == UPB_TYPE_ENUM); | 814 upb_fielddef_type(f) == UPB_TYPE_ENUM); |
988 | 815 |
989 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 816 if (upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
990 const char *ret = enumdefaultstr(f); | 817 const char *ret = enumdefaultstr(f); |
991 UPB_ASSERT(ret); | 818 assert(ret); |
992 /* Enum defaults can't have embedded NULLs. */ | 819 /* Enum defaults can't have embedded NULLs. */ |
993 if (len) *len = strlen(ret); | 820 if (len) *len = strlen(ret); |
994 return ret; | 821 return ret; |
995 } | 822 } |
996 | 823 |
997 if (f->default_is_string) { | 824 if (f->default_is_string) { |
998 str_t *str = f->defaultval.bytes; | 825 str_t *str = f->defaultval.bytes; |
999 if (len) *len = str->len; | 826 if (len) *len = str->len; |
1000 return str->str; | 827 return str->str; |
1001 } | 828 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 } | 890 } |
1064 if (number == 0 || number > UPB_MAX_FIELDNUMBER) { | 891 if (number == 0 || number > UPB_MAX_FIELDNUMBER) { |
1065 upb_status_seterrf(s, "invalid field number (%u)", number); | 892 upb_status_seterrf(s, "invalid field number (%u)", number); |
1066 return false; | 893 return false; |
1067 } | 894 } |
1068 f->number_ = number; | 895 f->number_ = number; |
1069 return true; | 896 return true; |
1070 } | 897 } |
1071 | 898 |
1072 void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type) { | 899 void upb_fielddef_settype(upb_fielddef *f, upb_fieldtype_t type) { |
1073 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 900 assert(!upb_fielddef_isfrozen(f)); |
1074 UPB_ASSERT(upb_fielddef_checktype(type)); | 901 assert(upb_fielddef_checktype(type)); |
1075 upb_fielddef_uninit_default(f); | 902 upb_fielddef_uninit_default(f); |
1076 f->type_ = type; | 903 f->type_ = type; |
1077 f->type_is_set_ = true; | 904 f->type_is_set_ = true; |
1078 upb_fielddef_init_default(f); | 905 upb_fielddef_init_default(f); |
1079 } | 906 } |
1080 | 907 |
1081 void upb_fielddef_setdescriptortype(upb_fielddef *f, int type) { | 908 void upb_fielddef_setdescriptortype(upb_fielddef *f, int type) { |
1082 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 909 assert(!upb_fielddef_isfrozen(f)); |
1083 switch (type) { | 910 switch (type) { |
1084 case UPB_DESCRIPTOR_TYPE_DOUBLE: | 911 case UPB_DESCRIPTOR_TYPE_DOUBLE: |
1085 upb_fielddef_settype(f, UPB_TYPE_DOUBLE); | 912 upb_fielddef_settype(f, UPB_TYPE_DOUBLE); |
1086 break; | 913 break; |
1087 case UPB_DESCRIPTOR_TYPE_FLOAT: | 914 case UPB_DESCRIPTOR_TYPE_FLOAT: |
1088 upb_fielddef_settype(f, UPB_TYPE_FLOAT); | 915 upb_fielddef_settype(f, UPB_TYPE_FLOAT); |
1089 break; | 916 break; |
1090 case UPB_DESCRIPTOR_TYPE_INT64: | 917 case UPB_DESCRIPTOR_TYPE_INT64: |
1091 case UPB_DESCRIPTOR_TYPE_SFIXED64: | 918 case UPB_DESCRIPTOR_TYPE_SFIXED64: |
1092 case UPB_DESCRIPTOR_TYPE_SINT64: | 919 case UPB_DESCRIPTOR_TYPE_SINT64: |
(...skipping 21 matching lines...) Expand all Loading... |
1114 case UPB_DESCRIPTOR_TYPE_BYTES: | 941 case UPB_DESCRIPTOR_TYPE_BYTES: |
1115 upb_fielddef_settype(f, UPB_TYPE_BYTES); | 942 upb_fielddef_settype(f, UPB_TYPE_BYTES); |
1116 break; | 943 break; |
1117 case UPB_DESCRIPTOR_TYPE_GROUP: | 944 case UPB_DESCRIPTOR_TYPE_GROUP: |
1118 case UPB_DESCRIPTOR_TYPE_MESSAGE: | 945 case UPB_DESCRIPTOR_TYPE_MESSAGE: |
1119 upb_fielddef_settype(f, UPB_TYPE_MESSAGE); | 946 upb_fielddef_settype(f, UPB_TYPE_MESSAGE); |
1120 break; | 947 break; |
1121 case UPB_DESCRIPTOR_TYPE_ENUM: | 948 case UPB_DESCRIPTOR_TYPE_ENUM: |
1122 upb_fielddef_settype(f, UPB_TYPE_ENUM); | 949 upb_fielddef_settype(f, UPB_TYPE_ENUM); |
1123 break; | 950 break; |
1124 default: UPB_ASSERT(false); | 951 default: assert(false); |
1125 } | 952 } |
1126 | 953 |
1127 if (type == UPB_DESCRIPTOR_TYPE_FIXED64 || | 954 if (type == UPB_DESCRIPTOR_TYPE_FIXED64 || |
1128 type == UPB_DESCRIPTOR_TYPE_FIXED32 || | 955 type == UPB_DESCRIPTOR_TYPE_FIXED32 || |
1129 type == UPB_DESCRIPTOR_TYPE_SFIXED64 || | 956 type == UPB_DESCRIPTOR_TYPE_SFIXED64 || |
1130 type == UPB_DESCRIPTOR_TYPE_SFIXED32) { | 957 type == UPB_DESCRIPTOR_TYPE_SFIXED32) { |
1131 upb_fielddef_setintfmt(f, UPB_INTFMT_FIXED); | 958 upb_fielddef_setintfmt(f, UPB_INTFMT_FIXED); |
1132 } else if (type == UPB_DESCRIPTOR_TYPE_SINT64 || | 959 } else if (type == UPB_DESCRIPTOR_TYPE_SINT64 || |
1133 type == UPB_DESCRIPTOR_TYPE_SINT32) { | 960 type == UPB_DESCRIPTOR_TYPE_SINT32) { |
1134 upb_fielddef_setintfmt(f, UPB_INTFMT_ZIGZAG); | 961 upb_fielddef_setintfmt(f, UPB_INTFMT_ZIGZAG); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1172 case UPB_INTFMT_ZIGZAG: return -1; | 999 case UPB_INTFMT_ZIGZAG: return -1; |
1173 } | 1000 } |
1174 case UPB_TYPE_MESSAGE: | 1001 case UPB_TYPE_MESSAGE: |
1175 return upb_fielddef_istagdelim(f) ? | 1002 return upb_fielddef_istagdelim(f) ? |
1176 UPB_DESCRIPTOR_TYPE_GROUP : UPB_DESCRIPTOR_TYPE_MESSAGE; | 1003 UPB_DESCRIPTOR_TYPE_GROUP : UPB_DESCRIPTOR_TYPE_MESSAGE; |
1177 } | 1004 } |
1178 return 0; | 1005 return 0; |
1179 } | 1006 } |
1180 | 1007 |
1181 void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension) { | 1008 void upb_fielddef_setisextension(upb_fielddef *f, bool is_extension) { |
1182 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1009 assert(!upb_fielddef_isfrozen(f)); |
1183 f->is_extension_ = is_extension; | 1010 f->is_extension_ = is_extension; |
1184 } | 1011 } |
1185 | 1012 |
1186 void upb_fielddef_setlazy(upb_fielddef *f, bool lazy) { | 1013 void upb_fielddef_setlazy(upb_fielddef *f, bool lazy) { |
1187 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1014 assert(!upb_fielddef_isfrozen(f)); |
1188 f->lazy_ = lazy; | 1015 f->lazy_ = lazy; |
1189 } | 1016 } |
1190 | 1017 |
1191 void upb_fielddef_setpacked(upb_fielddef *f, bool packed) { | 1018 void upb_fielddef_setpacked(upb_fielddef *f, bool packed) { |
1192 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1019 assert(!upb_fielddef_isfrozen(f)); |
1193 f->packed_ = packed; | 1020 f->packed_ = packed; |
1194 } | 1021 } |
1195 | 1022 |
1196 void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label) { | 1023 void upb_fielddef_setlabel(upb_fielddef *f, upb_label_t label) { |
1197 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1024 assert(!upb_fielddef_isfrozen(f)); |
1198 UPB_ASSERT(upb_fielddef_checklabel(label)); | 1025 assert(upb_fielddef_checklabel(label)); |
1199 f->label_ = label; | 1026 f->label_ = label; |
1200 } | 1027 } |
1201 | 1028 |
1202 void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt) { | 1029 void upb_fielddef_setintfmt(upb_fielddef *f, upb_intfmt_t fmt) { |
1203 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1030 assert(!upb_fielddef_isfrozen(f)); |
1204 UPB_ASSERT(upb_fielddef_checkintfmt(fmt)); | 1031 assert(upb_fielddef_checkintfmt(fmt)); |
1205 f->intfmt = fmt; | 1032 f->intfmt = fmt; |
1206 } | 1033 } |
1207 | 1034 |
1208 void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim) { | 1035 void upb_fielddef_settagdelim(upb_fielddef *f, bool tag_delim) { |
1209 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1036 assert(!upb_fielddef_isfrozen(f)); |
1210 f->tagdelim = tag_delim; | 1037 f->tagdelim = tag_delim; |
1211 f->tagdelim = tag_delim; | 1038 f->tagdelim = tag_delim; |
1212 } | 1039 } |
1213 | 1040 |
1214 static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) { | 1041 static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) { |
1215 if (!f->type_is_set_ || upb_fielddef_isfrozen(f) || | 1042 if (!f->type_is_set_ || upb_fielddef_isfrozen(f) || |
1216 upb_fielddef_type(f) != type) { | 1043 upb_fielddef_type(f) != type) { |
1217 UPB_ASSERT(false); | 1044 assert(false); |
1218 return false; | 1045 return false; |
1219 } | 1046 } |
1220 if (f->default_is_string) { | 1047 if (f->default_is_string) { |
1221 str_t *s = f->defaultval.bytes; | 1048 str_t *s = f->defaultval.bytes; |
1222 UPB_ASSERT(s || type == UPB_TYPE_ENUM); | 1049 assert(s || type == UPB_TYPE_ENUM); |
1223 if (s) freestr(s); | 1050 if (s) freestr(s); |
1224 } | 1051 } |
1225 f->default_is_string = false; | 1052 f->default_is_string = false; |
1226 return true; | 1053 return true; |
1227 } | 1054 } |
1228 | 1055 |
1229 void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t value) { | 1056 void upb_fielddef_setdefaultint64(upb_fielddef *f, int64_t value) { |
1230 if (checksetdefault(f, UPB_TYPE_INT64)) | 1057 if (checksetdefault(f, UPB_TYPE_INT64)) |
1231 f->defaultval.sint = value; | 1058 f->defaultval.sint = value; |
1232 } | 1059 } |
(...skipping 27 matching lines...) Expand all Loading... |
1260 } | 1087 } |
1261 | 1088 |
1262 void upb_fielddef_setdefaultdouble(upb_fielddef *f, double value) { | 1089 void upb_fielddef_setdefaultdouble(upb_fielddef *f, double value) { |
1263 if (checksetdefault(f, UPB_TYPE_DOUBLE)) | 1090 if (checksetdefault(f, UPB_TYPE_DOUBLE)) |
1264 f->defaultval.dbl = value; | 1091 f->defaultval.dbl = value; |
1265 } | 1092 } |
1266 | 1093 |
1267 bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len, | 1094 bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len, |
1268 upb_status *s) { | 1095 upb_status *s) { |
1269 str_t *str2; | 1096 str_t *str2; |
1270 UPB_ASSERT(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM); | 1097 assert(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM); |
1271 if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s)) | 1098 if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s)) |
1272 return false; | 1099 return false; |
1273 | 1100 |
1274 if (f->default_is_string) { | 1101 if (f->default_is_string) { |
1275 str_t *s = f->defaultval.bytes; | 1102 str_t *s = f->defaultval.bytes; |
1276 UPB_ASSERT(s || f->type_ == UPB_TYPE_ENUM); | 1103 assert(s || f->type_ == UPB_TYPE_ENUM); |
1277 if (s) freestr(s); | 1104 if (s) freestr(s); |
1278 } else { | 1105 } else { |
1279 UPB_ASSERT(f->type_ == UPB_TYPE_ENUM); | 1106 assert(f->type_ == UPB_TYPE_ENUM); |
1280 } | 1107 } |
1281 | 1108 |
1282 str2 = newstr(str, len); | 1109 str2 = newstr(str, len); |
1283 f->defaultval.bytes = str2; | 1110 f->defaultval.bytes = str2; |
1284 f->default_is_string = true; | 1111 f->default_is_string = true; |
1285 return true; | 1112 return true; |
1286 } | 1113 } |
1287 | 1114 |
1288 void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str, | 1115 void upb_fielddef_setdefaultcstr(upb_fielddef *f, const char *str, |
1289 upb_status *s) { | 1116 upb_status *s) { |
1290 UPB_ASSERT(f->type_is_set_); | 1117 assert(f->type_is_set_); |
1291 upb_fielddef_setdefaultstr(f, str, str ? strlen(str) : 0, s); | 1118 upb_fielddef_setdefaultstr(f, str, str ? strlen(str) : 0, s); |
1292 } | 1119 } |
1293 | 1120 |
1294 bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f) { | 1121 bool upb_fielddef_enumhasdefaultint32(const upb_fielddef *f) { |
1295 int32_t val; | 1122 int32_t val; |
1296 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 1123 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
1297 return enumdefaultint32(f, &val); | 1124 return enumdefaultint32(f, &val); |
1298 } | 1125 } |
1299 | 1126 |
1300 bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f) { | 1127 bool upb_fielddef_enumhasdefaultstr(const upb_fielddef *f) { |
1301 UPB_ASSERT(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); | 1128 assert(f->type_is_set_ && f->type_ == UPB_TYPE_ENUM); |
1302 return enumdefaultstr(f) != NULL; | 1129 return enumdefaultstr(f) != NULL; |
1303 } | 1130 } |
1304 | 1131 |
1305 static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef, | 1132 static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef, |
1306 upb_status *s) { | 1133 upb_status *s) { |
1307 if (f->type_ == UPB_TYPE_MESSAGE) { | 1134 if (f->type_ == UPB_TYPE_MESSAGE) { |
1308 if (upb_dyncast_msgdef(subdef)) return true; | 1135 if (upb_dyncast_msgdef(subdef)) return true; |
1309 upb_status_seterrmsg(s, "invalid subdef type for this submessage field"); | 1136 upb_status_seterrmsg(s, "invalid subdef type for this submessage field"); |
1310 return false; | 1137 return false; |
1311 } else if (f->type_ == UPB_TYPE_ENUM) { | 1138 } else if (f->type_ == UPB_TYPE_ENUM) { |
1312 if (upb_dyncast_enumdef(subdef)) return true; | 1139 if (upb_dyncast_enumdef(subdef)) return true; |
1313 upb_status_seterrmsg(s, "invalid subdef type for this enum field"); | 1140 upb_status_seterrmsg(s, "invalid subdef type for this enum field"); |
1314 return false; | 1141 return false; |
1315 } else { | 1142 } else { |
1316 upb_status_seterrmsg(s, "only message and enum fields can have a subdef"); | 1143 upb_status_seterrmsg(s, "only message and enum fields can have a subdef"); |
1317 return false; | 1144 return false; |
1318 } | 1145 } |
1319 } | 1146 } |
1320 | 1147 |
1321 static void release_subdef(upb_fielddef *f) { | 1148 static void release_subdef(upb_fielddef *f) { |
1322 if (f->subdef_is_symbolic) { | 1149 if (f->subdef_is_symbolic) { |
1323 upb_gfree(f->sub.name); | 1150 free(f->sub.name); |
1324 } else if (f->sub.def) { | 1151 } else if (f->sub.def) { |
1325 upb_unref2(f->sub.def, f); | 1152 upb_unref2(f->sub.def, f); |
1326 } | 1153 } |
1327 } | 1154 } |
1328 | 1155 |
1329 bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef, | 1156 bool upb_fielddef_setsubdef(upb_fielddef *f, const upb_def *subdef, |
1330 upb_status *s) { | 1157 upb_status *s) { |
1331 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | 1158 assert(!upb_fielddef_isfrozen(f)); |
1332 UPB_ASSERT(upb_fielddef_hassubdef(f)); | 1159 assert(upb_fielddef_hassubdef(f)); |
1333 if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false; | 1160 if (subdef && !upb_subdef_typecheck(f, subdef, s)) return false; |
1334 release_subdef(f); | 1161 release_subdef(f); |
1335 f->sub.def = subdef; | 1162 f->sub.def = subdef; |
1336 f->subdef_is_symbolic = false; | 1163 f->subdef_is_symbolic = false; |
1337 if (f->sub.def) upb_ref2(f->sub.def, f); | 1164 if (f->sub.def) upb_ref2(f->sub.def, f); |
1338 return true; | 1165 return true; |
1339 } | 1166 } |
1340 | 1167 |
1341 bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef, | 1168 bool upb_fielddef_setmsgsubdef(upb_fielddef *f, const upb_msgdef *subdef, |
1342 upb_status *s) { | 1169 upb_status *s) { |
1343 return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s); | 1170 return upb_fielddef_setsubdef(f, upb_msgdef_upcast(subdef), s); |
1344 } | 1171 } |
1345 | 1172 |
1346 bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef, | 1173 bool upb_fielddef_setenumsubdef(upb_fielddef *f, const upb_enumdef *subdef, |
1347 upb_status *s) { | 1174 upb_status *s) { |
1348 return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s); | 1175 return upb_fielddef_setsubdef(f, upb_enumdef_upcast(subdef), s); |
1349 } | 1176 } |
1350 | 1177 |
1351 bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name, | 1178 bool upb_fielddef_setsubdefname(upb_fielddef *f, const char *name, |
1352 upb_status *s) { | 1179 upb_status *s) { |
1353 char *name_copy; | 1180 assert(!upb_fielddef_isfrozen(f)); |
1354 UPB_ASSERT(!upb_fielddef_isfrozen(f)); | |
1355 if (!upb_fielddef_hassubdef(f)) { | 1181 if (!upb_fielddef_hassubdef(f)) { |
1356 upb_status_seterrmsg(s, "field type does not accept a subdef"); | 1182 upb_status_seterrmsg(s, "field type does not accept a subdef"); |
1357 return false; | 1183 return false; |
1358 } | 1184 } |
1359 | |
1360 name_copy = upb_gstrdup(name); | |
1361 if (!name_copy) { | |
1362 upb_upberr_setoom(s); | |
1363 return false; | |
1364 } | |
1365 | |
1366 /* TODO: validate name (upb_isident() doesn't quite work atm because this name | 1185 /* TODO: validate name (upb_isident() doesn't quite work atm because this name |
1367 * may have a leading "."). */ | 1186 * may have a leading "."). */ |
1368 release_subdef(f); | 1187 release_subdef(f); |
1369 f->sub.name = name_copy; | 1188 f->sub.name = upb_strdup(name); |
1370 f->subdef_is_symbolic = true; | 1189 f->subdef_is_symbolic = true; |
1371 return true; | 1190 return true; |
1372 } | 1191 } |
1373 | 1192 |
1374 bool upb_fielddef_issubmsg(const upb_fielddef *f) { | 1193 bool upb_fielddef_issubmsg(const upb_fielddef *f) { |
1375 return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; | 1194 return upb_fielddef_type(f) == UPB_TYPE_MESSAGE; |
1376 } | 1195 } |
1377 | 1196 |
1378 bool upb_fielddef_isstring(const upb_fielddef *f) { | 1197 bool upb_fielddef_isstring(const upb_fielddef *f) { |
1379 return upb_fielddef_type(f) == UPB_TYPE_STRING || | 1198 return upb_fielddef_type(f) == UPB_TYPE_STRING || |
1380 upb_fielddef_type(f) == UPB_TYPE_BYTES; | 1199 upb_fielddef_type(f) == UPB_TYPE_BYTES; |
1381 } | 1200 } |
1382 | 1201 |
1383 bool upb_fielddef_isseq(const upb_fielddef *f) { | 1202 bool upb_fielddef_isseq(const upb_fielddef *f) { |
1384 return upb_fielddef_label(f) == UPB_LABEL_REPEATED; | 1203 return upb_fielddef_label(f) == UPB_LABEL_REPEATED; |
1385 } | 1204 } |
1386 | 1205 |
1387 bool upb_fielddef_isprimitive(const upb_fielddef *f) { | 1206 bool upb_fielddef_isprimitive(const upb_fielddef *f) { |
1388 return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f); | 1207 return !upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f); |
1389 } | 1208 } |
1390 | 1209 |
1391 bool upb_fielddef_ismap(const upb_fielddef *f) { | 1210 bool upb_fielddef_ismap(const upb_fielddef *f) { |
1392 return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) && | 1211 return upb_fielddef_isseq(f) && upb_fielddef_issubmsg(f) && |
1393 upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); | 1212 upb_msgdef_mapentry(upb_fielddef_msgsubdef(f)); |
1394 } | 1213 } |
1395 | 1214 |
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 | |
1406 bool upb_fielddef_hassubdef(const upb_fielddef *f) { | 1215 bool upb_fielddef_hassubdef(const upb_fielddef *f) { |
1407 return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; | 1216 return upb_fielddef_issubmsg(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM; |
1408 } | 1217 } |
1409 | 1218 |
1410 static bool between(int32_t x, int32_t low, int32_t high) { | 1219 static bool between(int32_t x, int32_t low, int32_t high) { |
1411 return x >= low && x <= high; | 1220 return x >= low && x <= high; |
1412 } | 1221 } |
1413 | 1222 |
1414 bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); } | 1223 bool upb_fielddef_checklabel(int32_t label) { return between(label, 1, 3); } |
1415 bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); } | 1224 bool upb_fielddef_checktype(int32_t type) { return between(type, 1, 11); } |
1416 bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } | 1225 bool upb_fielddef_checkintfmt(int32_t fmt) { return between(fmt, 1, 3); } |
1417 | 1226 |
1418 bool upb_fielddef_checkdescriptortype(int32_t type) { | 1227 bool upb_fielddef_checkdescriptortype(int32_t type) { |
1419 return between(type, 1, 18); | 1228 return between(type, 1, 18); |
1420 } | 1229 } |
1421 | 1230 |
1422 /* upb_msgdef *****************************************************************/ | 1231 /* upb_msgdef *****************************************************************/ |
1423 | 1232 |
1424 static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit, | 1233 static void visitmsg(const upb_refcounted *r, upb_refcounted_visit *visit, |
1425 void *closure) { | 1234 void *closure) { |
1426 upb_msg_oneof_iter o; | 1235 upb_msg_oneof_iter o; |
1427 const upb_msgdef *m = (const upb_msgdef*)r; | 1236 const upb_msgdef *m = (const upb_msgdef*)r; |
1428 const upb_def *def = upb_msgdef_upcast(m); | |
1429 upb_msg_field_iter i; | 1237 upb_msg_field_iter i; |
1430 for(upb_msg_field_begin(&i, m); | 1238 for(upb_msg_field_begin(&i, m); |
1431 !upb_msg_field_done(&i); | 1239 !upb_msg_field_done(&i); |
1432 upb_msg_field_next(&i)) { | 1240 upb_msg_field_next(&i)) { |
1433 upb_fielddef *f = upb_msg_iter_field(&i); | 1241 upb_fielddef *f = upb_msg_iter_field(&i); |
1434 visit(r, upb_fielddef_upcast2(f), closure); | 1242 visit(r, upb_fielddef_upcast2(f), closure); |
1435 } | 1243 } |
1436 for(upb_msg_oneof_begin(&o, m); | 1244 for(upb_msg_oneof_begin(&o, m); |
1437 !upb_msg_oneof_done(&o); | 1245 !upb_msg_oneof_done(&o); |
1438 upb_msg_oneof_next(&o)) { | 1246 upb_msg_oneof_next(&o)) { |
1439 upb_oneofdef *f = upb_msg_iter_oneof(&o); | 1247 upb_oneofdef *f = upb_msg_iter_oneof(&o); |
1440 visit(r, upb_oneofdef_upcast(f), closure); | 1248 visit(r, upb_oneofdef_upcast2(f), closure); |
1441 } | |
1442 if (upb_def_file(def)) { | |
1443 visit(r, upb_filedef_upcast(upb_def_file(def)), closure); | |
1444 } | 1249 } |
1445 } | 1250 } |
1446 | 1251 |
1447 static void freemsg(upb_refcounted *r) { | 1252 static void freemsg(upb_refcounted *r) { |
1448 upb_msgdef *m = (upb_msgdef*)r; | 1253 upb_msgdef *m = (upb_msgdef*)r; |
| 1254 upb_strtable_uninit(&m->ntoo); |
1449 upb_strtable_uninit(&m->ntof); | 1255 upb_strtable_uninit(&m->ntof); |
1450 upb_inttable_uninit(&m->itof); | 1256 upb_inttable_uninit(&m->itof); |
1451 upb_def_uninit(upb_msgdef_upcast_mutable(m)); | 1257 upb_def_uninit(upb_msgdef_upcast_mutable(m)); |
1452 upb_gfree(m); | 1258 free(m); |
1453 } | 1259 } |
1454 | 1260 |
1455 const struct upb_refcounted_vtbl upb_msgdef_vtbl = {visitmsg, freemsg}; | |
1456 | |
1457 upb_msgdef *upb_msgdef_new(const void *owner) { | 1261 upb_msgdef *upb_msgdef_new(const void *owner) { |
1458 upb_msgdef *m = upb_gmalloc(sizeof(*m)); | 1262 static const struct upb_refcounted_vtbl vtbl = {visitmsg, freemsg}; |
| 1263 upb_msgdef *m = malloc(sizeof(*m)); |
1459 if (!m) return NULL; | 1264 if (!m) return NULL; |
1460 | 1265 if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &vtbl, owner)) |
1461 if (!upb_def_init(upb_msgdef_upcast_mutable(m), UPB_DEF_MSG, &upb_msgdef_vtbl, | |
1462 owner)) { | |
1463 goto err2; | 1266 goto err2; |
1464 } | 1267 if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err3; |
1465 | 1268 if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err2; |
1466 if (!upb_inttable_init(&m->itof, UPB_CTYPE_PTR)) goto err2; | 1269 if (!upb_strtable_init(&m->ntoo, UPB_CTYPE_PTR)) goto err1; |
1467 if (!upb_strtable_init(&m->ntof, UPB_CTYPE_PTR)) goto err1; | |
1468 m->map_entry = false; | 1270 m->map_entry = false; |
1469 m->syntax = UPB_SYNTAX_PROTO2; | |
1470 return m; | 1271 return m; |
1471 | 1272 |
1472 err1: | 1273 err1: |
| 1274 upb_strtable_uninit(&m->ntof); |
| 1275 err2: |
1473 upb_inttable_uninit(&m->itof); | 1276 upb_inttable_uninit(&m->itof); |
1474 err2: | 1277 err3: |
1475 upb_gfree(m); | 1278 free(m); |
1476 return NULL; | 1279 return NULL; |
1477 } | 1280 } |
1478 | 1281 |
1479 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) { | 1282 upb_msgdef *upb_msgdef_dup(const upb_msgdef *m, const void *owner) { |
1480 bool ok; | 1283 bool ok; |
1481 upb_msg_field_iter i; | 1284 upb_msg_field_iter i; |
1482 upb_msg_oneof_iter o; | 1285 upb_msg_oneof_iter o; |
1483 | 1286 |
1484 upb_msgdef *newm = upb_msgdef_new(owner); | 1287 upb_msgdef *newm = upb_msgdef_new(owner); |
1485 if (!newm) return NULL; | 1288 if (!newm) return NULL; |
1486 ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm), | 1289 ok = upb_def_setfullname(upb_msgdef_upcast_mutable(newm), |
1487 upb_def_fullname(upb_msgdef_upcast(m)), | 1290 upb_def_fullname(upb_msgdef_upcast(m)), |
1488 NULL); | 1291 NULL); |
1489 newm->map_entry = m->map_entry; | 1292 newm->map_entry = m->map_entry; |
1490 newm->syntax = m->syntax; | 1293 UPB_ASSERT_VAR(ok, ok); |
1491 UPB_ASSERT(ok); | |
1492 for(upb_msg_field_begin(&i, m); | 1294 for(upb_msg_field_begin(&i, m); |
1493 !upb_msg_field_done(&i); | 1295 !upb_msg_field_done(&i); |
1494 upb_msg_field_next(&i)) { | 1296 upb_msg_field_next(&i)) { |
1495 upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f); | 1297 upb_fielddef *f = upb_fielddef_dup(upb_msg_iter_field(&i), &f); |
1496 /* Fields in oneofs are dup'd below. */ | 1298 /* Fields in oneofs are dup'd below. */ |
1497 if (upb_fielddef_containingoneof(f)) continue; | 1299 if (upb_fielddef_containingoneof(f)) continue; |
1498 if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) { | 1300 if (!f || !upb_msgdef_addfield(newm, f, &f, NULL)) { |
1499 upb_msgdef_unref(newm, owner); | 1301 upb_msgdef_unref(newm, owner); |
1500 return NULL; | 1302 return NULL; |
1501 } | 1303 } |
(...skipping 12 matching lines...) Expand all Loading... |
1514 | 1316 |
1515 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) { | 1317 bool upb_msgdef_freeze(upb_msgdef *m, upb_status *status) { |
1516 upb_def *d = upb_msgdef_upcast_mutable(m); | 1318 upb_def *d = upb_msgdef_upcast_mutable(m); |
1517 return upb_def_freeze(&d, 1, status); | 1319 return upb_def_freeze(&d, 1, status); |
1518 } | 1320 } |
1519 | 1321 |
1520 const char *upb_msgdef_fullname(const upb_msgdef *m) { | 1322 const char *upb_msgdef_fullname(const upb_msgdef *m) { |
1521 return upb_def_fullname(upb_msgdef_upcast(m)); | 1323 return upb_def_fullname(upb_msgdef_upcast(m)); |
1522 } | 1324 } |
1523 | 1325 |
1524 const char *upb_msgdef_name(const upb_msgdef *m) { | |
1525 return upb_def_name(upb_msgdef_upcast(m)); | |
1526 } | |
1527 | |
1528 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, | 1326 bool upb_msgdef_setfullname(upb_msgdef *m, const char *fullname, |
1529 upb_status *s) { | 1327 upb_status *s) { |
1530 return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s); | 1328 return upb_def_setfullname(upb_msgdef_upcast_mutable(m), fullname, s); |
1531 } | 1329 } |
1532 | 1330 |
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 | |
1546 /* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error | 1331 /* Helper: check that the field |f| is safe to add to msgdef |m|. Set an error |
1547 * on status |s| and return false if not. */ | 1332 * on status |s| and return false if not. */ |
1548 static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f, | 1333 static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f, |
1549 upb_status *s) { | 1334 upb_status *s) { |
1550 if (upb_fielddef_containingtype(f) != NULL) { | 1335 if (upb_fielddef_containingtype(f) != NULL) { |
1551 upb_status_seterrmsg(s, "fielddef already belongs to a message"); | 1336 upb_status_seterrmsg(s, "fielddef already belongs to a message"); |
1552 return false; | 1337 return false; |
1553 } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { | 1338 } else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) { |
1554 upb_status_seterrmsg(s, "field name or number were not set"); | 1339 upb_status_seterrmsg(s, "field name or number were not set"); |
1555 return false; | 1340 return false; |
1556 } else if (upb_msgdef_itof(m, upb_fielddef_number(f))) { | 1341 } else if (upb_msgdef_ntofz(m, upb_fielddef_name(f)) || |
1557 upb_status_seterrmsg(s, "duplicate field number"); | 1342 upb_msgdef_itof(m, upb_fielddef_number(f))) { |
1558 return false; | 1343 upb_status_seterrmsg(s, "duplicate field name or number for field"); |
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"); | |
1561 return false; | 1344 return false; |
1562 } | 1345 } |
1563 return true; | 1346 return true; |
1564 } | 1347 } |
1565 | 1348 |
1566 static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) { | 1349 static void add_field(upb_msgdef *m, upb_fielddef *f, const void *ref_donor) { |
1567 release_containingtype(f); | 1350 release_containingtype(f); |
1568 f->msg.def = m; | 1351 f->msg.def = m; |
1569 f->msg_is_symbolic = false; | 1352 f->msg_is_symbolic = false; |
1570 upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f)); | 1353 upb_inttable_insert(&m->itof, upb_fielddef_number(f), upb_value_ptr(f)); |
(...skipping 12 matching lines...) Expand all Loading... |
1583 * This also implies that there needs to be a separate lookup-by-name method | 1366 * This also implies that there needs to be a separate lookup-by-name method |
1584 * for extensions. It seems desirable for iteration to return both extensions | 1367 * for extensions. It seems desirable for iteration to return both extensions |
1585 * and non-extensions though. | 1368 * and non-extensions though. |
1586 * | 1369 * |
1587 * We also need to validate that the field number is in an extension range iff | 1370 * We also need to validate that the field number is in an extension range iff |
1588 * it is an extension. | 1371 * it is an extension. |
1589 * | 1372 * |
1590 * This method is idempotent. Check if |f| is already part of this msgdef and | 1373 * This method is idempotent. Check if |f| is already part of this msgdef and |
1591 * return immediately if so. */ | 1374 * return immediately if so. */ |
1592 if (upb_fielddef_containingtype(f) == m) { | 1375 if (upb_fielddef_containingtype(f) == m) { |
1593 if (ref_donor) upb_fielddef_unref(f, ref_donor); | |
1594 return true; | 1376 return true; |
1595 } | 1377 } |
1596 | 1378 |
1597 /* Check constraints for all fields before performing any action. */ | 1379 /* Check constraints for all fields before performing any action. */ |
1598 if (!check_field_add(m, f, s)) { | 1380 if (!check_field_add(m, f, s)) { |
1599 return false; | 1381 return false; |
1600 } else if (upb_fielddef_containingoneof(f) != NULL) { | 1382 } else if (upb_fielddef_containingoneof(f) != NULL) { |
1601 /* Fields in a oneof can only be added by adding the oneof to the msgdef. */ | 1383 /* Fields in a oneof can only be added by adding the oneof to the msgdef. */ |
1602 upb_status_seterrmsg(s, "fielddef is part of a oneof"); | 1384 upb_status_seterrmsg(s, "fielddef is part of a oneof"); |
1603 return false; | 1385 return false; |
1604 } | 1386 } |
1605 | 1387 |
1606 /* Constraint checks ok, perform the action. */ | 1388 /* Constraint checks ok, perform the action. */ |
1607 add_field(m, f, ref_donor); | 1389 add_field(m, f, ref_donor); |
1608 return true; | 1390 return true; |
1609 } | 1391 } |
1610 | 1392 |
1611 bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, | 1393 bool upb_msgdef_addoneof(upb_msgdef *m, upb_oneofdef *o, const void *ref_donor, |
1612 upb_status *s) { | 1394 upb_status *s) { |
1613 upb_oneof_iter it; | 1395 upb_oneof_iter it; |
1614 | 1396 |
1615 /* Check various conditions that would prevent this oneof from being added. */ | 1397 /* Check various conditions that would prevent this oneof from being added. */ |
1616 if (upb_oneofdef_containingtype(o)) { | 1398 if (upb_oneofdef_containingtype(o)) { |
1617 upb_status_seterrmsg(s, "oneofdef already belongs to a message"); | 1399 upb_status_seterrmsg(s, "oneofdef already belongs to a message"); |
1618 return false; | 1400 return false; |
1619 } else if (upb_oneofdef_name(o) == NULL) { | 1401 } else if (upb_oneofdef_name(o) == NULL) { |
1620 upb_status_seterrmsg(s, "oneofdef name was not set"); | 1402 upb_status_seterrmsg(s, "oneofdef name was not set"); |
1621 return false; | 1403 return false; |
1622 } else if (upb_strtable_lookup(&m->ntof, upb_oneofdef_name(o), NULL)) { | 1404 } else if (upb_msgdef_ntooz(m, upb_oneofdef_name(o))) { |
1623 upb_status_seterrmsg(s, "name conflicts with existing field or oneof"); | 1405 upb_status_seterrmsg(s, "duplicate oneof name"); |
1624 return false; | 1406 return false; |
1625 } | 1407 } |
1626 | 1408 |
1627 /* Check that all of the oneof's fields do not conflict with names or numbers | 1409 /* Check that all of the oneof's fields do not conflict with names or numbers |
1628 * of fields already in the message. */ | 1410 * of fields already in the message. */ |
1629 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { | 1411 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { |
1630 const upb_fielddef *f = upb_oneof_iter_field(&it); | 1412 const upb_fielddef *f = upb_oneof_iter_field(&it); |
1631 if (!check_field_add(m, f, s)) { | 1413 if (!check_field_add(m, f, s)) { |
1632 return false; | 1414 return false; |
1633 } | 1415 } |
1634 } | 1416 } |
1635 | 1417 |
1636 /* Everything checks out -- commit now. */ | 1418 /* Everything checks out -- commit now. */ |
1637 | 1419 |
1638 /* Add oneof itself first. */ | 1420 /* Add oneof itself first. */ |
1639 o->parent = m; | 1421 o->parent = m; |
1640 upb_strtable_insert(&m->ntof, upb_oneofdef_name(o), upb_value_ptr(o)); | 1422 upb_strtable_insert(&m->ntoo, upb_oneofdef_name(o), upb_value_ptr(o)); |
1641 upb_ref2(o, m); | 1423 upb_ref2(o, m); |
1642 upb_ref2(m, o); | 1424 upb_ref2(m, o); |
1643 | 1425 |
1644 /* Add each field of the oneof directly to the msgdef. */ | 1426 /* Add each field of the oneof directly to the msgdef. */ |
1645 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { | 1427 for (upb_oneof_begin(&it, o); !upb_oneof_done(&it); upb_oneof_next(&it)) { |
1646 upb_fielddef *f = upb_oneof_iter_field(&it); | 1428 upb_fielddef *f = upb_oneof_iter_field(&it); |
1647 add_field(m, f, NULL); | 1429 add_field(m, f, NULL); |
1648 } | 1430 } |
1649 | 1431 |
1650 if (ref_donor) upb_oneofdef_unref(o, ref_donor); | 1432 if (ref_donor) upb_oneofdef_unref(o, ref_donor); |
1651 | 1433 |
1652 return true; | 1434 return true; |
1653 } | 1435 } |
1654 | 1436 |
1655 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { | 1437 const upb_fielddef *upb_msgdef_itof(const upb_msgdef *m, uint32_t i) { |
1656 upb_value val; | 1438 upb_value val; |
1657 return upb_inttable_lookup32(&m->itof, i, &val) ? | 1439 return upb_inttable_lookup32(&m->itof, i, &val) ? |
1658 upb_value_getptr(val) : NULL; | 1440 upb_value_getptr(val) : NULL; |
1659 } | 1441 } |
1660 | 1442 |
1661 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, | 1443 const upb_fielddef *upb_msgdef_ntof(const upb_msgdef *m, const char *name, |
1662 size_t len) { | 1444 size_t len) { |
1663 upb_value val; | 1445 upb_value val; |
1664 | 1446 return upb_strtable_lookup2(&m->ntof, name, len, &val) ? |
1665 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { | 1447 upb_value_getptr(val) : NULL; |
1666 return NULL; | |
1667 } | |
1668 | |
1669 return upb_trygetfield(upb_value_getptr(val)); | |
1670 } | 1448 } |
1671 | 1449 |
1672 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, | 1450 const upb_oneofdef *upb_msgdef_ntoo(const upb_msgdef *m, const char *name, |
1673 size_t len) { | 1451 size_t len) { |
1674 upb_value val; | 1452 upb_value val; |
1675 | 1453 return upb_strtable_lookup2(&m->ntoo, name, len, &val) ? |
1676 if (!upb_strtable_lookup2(&m->ntof, name, len, &val)) { | 1454 upb_value_getptr(val) : NULL; |
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; | |
1695 } | 1455 } |
1696 | 1456 |
1697 int upb_msgdef_numfields(const upb_msgdef *m) { | 1457 int upb_msgdef_numfields(const upb_msgdef *m) { |
1698 /* The number table contains only fields. */ | 1458 return upb_strtable_count(&m->ntof); |
1699 return upb_inttable_count(&m->itof); | |
1700 } | 1459 } |
1701 | 1460 |
1702 int upb_msgdef_numoneofs(const upb_msgdef *m) { | 1461 int upb_msgdef_numoneofs(const upb_msgdef *m) { |
1703 /* The name table includes oneofs, and the number table does not. */ | 1462 return upb_strtable_count(&m->ntoo); |
1704 return upb_strtable_count(&m->ntof) - upb_inttable_count(&m->itof); | |
1705 } | 1463 } |
1706 | 1464 |
1707 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) { | 1465 void upb_msgdef_setmapentry(upb_msgdef *m, bool map_entry) { |
1708 UPB_ASSERT(!upb_msgdef_isfrozen(m)); | 1466 assert(!upb_msgdef_isfrozen(m)); |
1709 m->map_entry = map_entry; | 1467 m->map_entry = map_entry; |
1710 } | 1468 } |
1711 | 1469 |
1712 bool upb_msgdef_mapentry(const upb_msgdef *m) { | 1470 bool upb_msgdef_mapentry(const upb_msgdef *m) { |
1713 return m->map_entry; | 1471 return m->map_entry; |
1714 } | 1472 } |
1715 | 1473 |
1716 void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { | 1474 void upb_msg_field_begin(upb_msg_field_iter *iter, const upb_msgdef *m) { |
1717 upb_inttable_begin(iter, &m->itof); | 1475 upb_inttable_begin(iter, &m->itof); |
1718 } | 1476 } |
1719 | 1477 |
1720 void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); } | 1478 void upb_msg_field_next(upb_msg_field_iter *iter) { upb_inttable_next(iter); } |
1721 | 1479 |
1722 bool upb_msg_field_done(const upb_msg_field_iter *iter) { | 1480 bool upb_msg_field_done(const upb_msg_field_iter *iter) { |
1723 return upb_inttable_done(iter); | 1481 return upb_inttable_done(iter); |
1724 } | 1482 } |
1725 | 1483 |
1726 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) { | 1484 upb_fielddef *upb_msg_iter_field(const upb_msg_field_iter *iter) { |
1727 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); | 1485 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); |
1728 } | 1486 } |
1729 | 1487 |
1730 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) { | 1488 void upb_msg_field_iter_setdone(upb_msg_field_iter *iter) { |
1731 upb_inttable_iter_setdone(iter); | 1489 upb_inttable_iter_setdone(iter); |
1732 } | 1490 } |
1733 | 1491 |
1734 void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) { | 1492 void upb_msg_oneof_begin(upb_msg_oneof_iter *iter, const upb_msgdef *m) { |
1735 upb_strtable_begin(iter, &m->ntof); | 1493 upb_strtable_begin(iter, &m->ntoo); |
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 } | |
1741 } | 1494 } |
1742 | 1495 |
1743 void upb_msg_oneof_next(upb_msg_oneof_iter *iter) { | 1496 void upb_msg_oneof_next(upb_msg_oneof_iter *iter) { upb_strtable_next(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 } | |
1750 | 1497 |
1751 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) { | 1498 bool upb_msg_oneof_done(const upb_msg_oneof_iter *iter) { |
1752 return upb_strtable_done(iter); | 1499 return upb_strtable_done(iter); |
1753 } | 1500 } |
1754 | 1501 |
1755 upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) { | 1502 upb_oneofdef *upb_msg_iter_oneof(const upb_msg_oneof_iter *iter) { |
1756 return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter)); | 1503 return (upb_oneofdef*)upb_value_getptr(upb_strtable_iter_value(iter)); |
1757 } | 1504 } |
1758 | 1505 |
1759 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) { | 1506 void upb_msg_oneof_iter_setdone(upb_msg_oneof_iter *iter) { |
(...skipping 12 matching lines...) Expand all Loading... |
1772 } | 1519 } |
1773 if (o->parent) { | 1520 if (o->parent) { |
1774 visit(r, upb_msgdef_upcast2(o->parent), closure); | 1521 visit(r, upb_msgdef_upcast2(o->parent), closure); |
1775 } | 1522 } |
1776 } | 1523 } |
1777 | 1524 |
1778 static void freeoneof(upb_refcounted *r) { | 1525 static void freeoneof(upb_refcounted *r) { |
1779 upb_oneofdef *o = (upb_oneofdef*)r; | 1526 upb_oneofdef *o = (upb_oneofdef*)r; |
1780 upb_strtable_uninit(&o->ntof); | 1527 upb_strtable_uninit(&o->ntof); |
1781 upb_inttable_uninit(&o->itof); | 1528 upb_inttable_uninit(&o->itof); |
1782 upb_gfree((void*)o->name); | 1529 upb_def_uninit(upb_oneofdef_upcast_mutable(o)); |
1783 upb_gfree(o); | 1530 free(o); |
1784 } | 1531 } |
1785 | 1532 |
1786 const struct upb_refcounted_vtbl upb_oneofdef_vtbl = {visitoneof, freeoneof}; | |
1787 | |
1788 upb_oneofdef *upb_oneofdef_new(const void *owner) { | 1533 upb_oneofdef *upb_oneofdef_new(const void *owner) { |
1789 upb_oneofdef *o = upb_gmalloc(sizeof(*o)); | 1534 static const struct upb_refcounted_vtbl vtbl = {visitoneof, freeoneof}; |
1790 | 1535 upb_oneofdef *o = malloc(sizeof(*o)); |
1791 if (!o) { | |
1792 return NULL; | |
1793 } | |
1794 | |
1795 o->parent = NULL; | 1536 o->parent = NULL; |
1796 o->name = NULL; | 1537 if (!o) return NULL; |
1797 | 1538 if (!upb_def_init(upb_oneofdef_upcast_mutable(o), UPB_DEF_ONEOF, &vtbl, |
1798 if (!upb_refcounted_init(upb_oneofdef_upcast_mutable(o), &upb_oneofdef_vtbl, | 1539 owner)) |
1799 owner)) { | |
1800 goto err2; | 1540 goto err2; |
1801 } | |
1802 | |
1803 if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2; | 1541 if (!upb_inttable_init(&o->itof, UPB_CTYPE_PTR)) goto err2; |
1804 if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1; | 1542 if (!upb_strtable_init(&o->ntof, UPB_CTYPE_PTR)) goto err1; |
1805 | |
1806 return o; | 1543 return o; |
1807 | 1544 |
1808 err1: | 1545 err1: |
1809 upb_inttable_uninit(&o->itof); | 1546 upb_inttable_uninit(&o->itof); |
1810 err2: | 1547 err2: |
1811 upb_gfree(o); | 1548 free(o); |
1812 return NULL; | 1549 return NULL; |
1813 } | 1550 } |
1814 | 1551 |
1815 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner) { | 1552 upb_oneofdef *upb_oneofdef_dup(const upb_oneofdef *o, const void *owner) { |
1816 bool ok; | 1553 bool ok; |
1817 upb_oneof_iter i; | 1554 upb_oneof_iter i; |
1818 upb_oneofdef *newo = upb_oneofdef_new(owner); | 1555 upb_oneofdef *newo = upb_oneofdef_new(owner); |
1819 if (!newo) return NULL; | 1556 if (!newo) return NULL; |
1820 ok = upb_oneofdef_setname(newo, upb_oneofdef_name(o), NULL); | 1557 ok = upb_def_setfullname(upb_oneofdef_upcast_mutable(newo), |
1821 UPB_ASSERT(ok); | 1558 upb_def_fullname(upb_oneofdef_upcast(o)), NULL); |
| 1559 UPB_ASSERT_VAR(ok, ok); |
1822 for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) { | 1560 for (upb_oneof_begin(&i, o); !upb_oneof_done(&i); upb_oneof_next(&i)) { |
1823 upb_fielddef *f = upb_fielddef_dup(upb_oneof_iter_field(&i), &f); | 1561 upb_fielddef *f = upb_fielddef_dup(upb_oneof_iter_field(&i), &f); |
1824 if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) { | 1562 if (!f || !upb_oneofdef_addfield(newo, f, &f, NULL)) { |
1825 upb_oneofdef_unref(newo, owner); | 1563 upb_oneofdef_unref(newo, owner); |
1826 return NULL; | 1564 return NULL; |
1827 } | 1565 } |
1828 } | 1566 } |
1829 return newo; | 1567 return newo; |
1830 } | 1568 } |
1831 | 1569 |
1832 const char *upb_oneofdef_name(const upb_oneofdef *o) { return o->name; } | 1570 const char *upb_oneofdef_name(const upb_oneofdef *o) { |
| 1571 return upb_def_fullname(upb_oneofdef_upcast(o)); |
| 1572 } |
1833 | 1573 |
1834 bool upb_oneofdef_setname(upb_oneofdef *o, const char *name, upb_status *s) { | 1574 bool upb_oneofdef_setname(upb_oneofdef *o, const char *fullname, |
1835 UPB_ASSERT(!upb_oneofdef_isfrozen(o)); | 1575 upb_status *s) { |
1836 if (upb_oneofdef_containingtype(o)) { | 1576 if (upb_oneofdef_containingtype(o)) { |
1837 upb_status_seterrmsg(s, "oneof already added to a message"); | 1577 upb_status_seterrmsg(s, "oneof already added to a message"); |
1838 return false; | 1578 return false; |
1839 } | 1579 } |
1840 | 1580 return upb_def_setfullname(upb_oneofdef_upcast_mutable(o), fullname, s); |
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; | |
1854 } | 1581 } |
1855 | 1582 |
1856 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { | 1583 const upb_msgdef *upb_oneofdef_containingtype(const upb_oneofdef *o) { |
1857 return o->parent; | 1584 return o->parent; |
1858 } | 1585 } |
1859 | 1586 |
1860 int upb_oneofdef_numfields(const upb_oneofdef *o) { | 1587 int upb_oneofdef_numfields(const upb_oneofdef *o) { |
1861 return upb_strtable_count(&o->ntof); | 1588 return upb_strtable_count(&o->ntof); |
1862 } | 1589 } |
1863 | 1590 |
1864 bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f, | 1591 bool upb_oneofdef_addfield(upb_oneofdef *o, upb_fielddef *f, |
1865 const void *ref_donor, | 1592 const void *ref_donor, |
1866 upb_status *s) { | 1593 upb_status *s) { |
1867 UPB_ASSERT(!upb_oneofdef_isfrozen(o)); | 1594 assert(!upb_oneofdef_isfrozen(o)); |
1868 UPB_ASSERT(!o->parent || !upb_msgdef_isfrozen(o->parent)); | 1595 assert(!o->parent || !upb_msgdef_isfrozen(o->parent)); |
1869 | 1596 |
1870 /* This method is idempotent. Check if |f| is already part of this oneofdef | 1597 /* This method is idempotent. Check if |f| is already part of this oneofdef |
1871 * and return immediately if so. */ | 1598 * and return immediately if so. */ |
1872 if (upb_fielddef_containingoneof(f) == o) { | 1599 if (upb_fielddef_containingoneof(f) == o) { |
1873 return true; | 1600 return true; |
1874 } | 1601 } |
1875 | 1602 |
1876 /* The field must have an OPTIONAL label. */ | 1603 /* The field must have an OPTIONAL label. */ |
1877 if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) { | 1604 if (upb_fielddef_label(f) != UPB_LABEL_OPTIONAL) { |
1878 upb_status_seterrmsg(s, "fields in oneof must have OPTIONAL label"); | 1605 upb_status_seterrmsg(s, "fields in oneof must have OPTIONAL label"); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 } | 1689 } |
1963 | 1690 |
1964 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) { | 1691 upb_fielddef *upb_oneof_iter_field(const upb_oneof_iter *iter) { |
1965 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); | 1692 return (upb_fielddef*)upb_value_getptr(upb_inttable_iter_value(iter)); |
1966 } | 1693 } |
1967 | 1694 |
1968 void upb_oneof_iter_setdone(upb_oneof_iter *iter) { | 1695 void upb_oneof_iter_setdone(upb_oneof_iter *iter) { |
1969 upb_inttable_iter_setdone(iter); | 1696 upb_inttable_iter_setdone(iter); |
1970 } | 1697 } |
1971 | 1698 |
1972 /* upb_filedef ****************************************************************/ | 1699 |
1973 | 1700 #include <stdlib.h> |
1974 static void visitfiledef(const upb_refcounted *r, upb_refcounted_visit *visit, | 1701 #include <stdio.h> |
1975 void *closure) { | 1702 #include <string.h> |
1976 const upb_filedef *f = (const upb_filedef*)r; | 1703 |
1977 size_t i; | 1704 typedef struct cleanup_ent { |
1978 | 1705 upb_cleanup_func *cleanup; |
1979 for(i = 0; i < upb_filedef_defcount(f); i++) { | 1706 void *ud; |
1980 visit(r, upb_def_upcast(upb_filedef_def(f, i)), closure); | 1707 struct cleanup_ent *next; |
1981 } | 1708 } cleanup_ent; |
1982 } | 1709 |
1983 | 1710 static void *seeded_alloc(void *ud, void *ptr, size_t oldsize, size_t size); |
1984 static void freefiledef(upb_refcounted *r) { | 1711 |
1985 upb_filedef *f = (upb_filedef*)r; | 1712 /* Default allocator **********************************************************/ |
1986 size_t i; | 1713 |
1987 | 1714 /* Just use realloc, keeping all allocated blocks in a linked list to destroy at |
1988 for(i = 0; i < upb_filedef_depcount(f); i++) { | 1715 * the end. */ |
1989 upb_filedef_unref(upb_filedef_dep(f, i), f); | 1716 |
1990 } | 1717 typedef struct mem_block { |
1991 | 1718 /* List is doubly-linked, because in cases where realloc() moves an existing |
1992 upb_inttable_uninit(&f->defs); | 1719 * block, we need to be able to remove the old pointer from the list |
1993 upb_inttable_uninit(&f->deps); | 1720 * efficiently. */ |
1994 upb_gfree((void*)f->name); | 1721 struct mem_block *prev, *next; |
1995 upb_gfree((void*)f->package); | 1722 #ifndef NDEBUG |
1996 upb_gfree(f); | 1723 size_t size; /* Doesn't include mem_block structure. */ |
1997 } | 1724 #endif |
1998 | 1725 } mem_block; |
1999 const struct upb_refcounted_vtbl upb_filedef_vtbl = {visitfiledef, freefiledef}; | 1726 |
2000 | 1727 typedef struct { |
2001 upb_filedef *upb_filedef_new(const void *owner) { | 1728 mem_block *head; |
2002 upb_filedef *f = upb_gmalloc(sizeof(*f)); | 1729 } default_alloc_ud; |
2003 | 1730 |
2004 if (!f) { | 1731 static void *default_alloc(void *_ud, void *ptr, size_t oldsize, size_t size) { |
2005 return NULL; | 1732 default_alloc_ud *ud = _ud; |
2006 } | 1733 mem_block *from, *block; |
2007 | 1734 void *ret; |
2008 f->package = NULL; | 1735 UPB_UNUSED(oldsize); |
2009 f->name = NULL; | 1736 |
2010 f->syntax = UPB_SYNTAX_PROTO2; | 1737 from = ptr ? (void*)((char*)ptr - sizeof(mem_block)) : NULL; |
2011 | 1738 |
2012 if (!upb_refcounted_init(upb_filedef_upcast_mutable(f), &upb_filedef_vtbl, | 1739 #ifndef NDEBUG |
2013 owner)) { | 1740 if (from) { |
2014 goto err; | 1741 assert(oldsize <= from->size); |
2015 } | 1742 } |
2016 | 1743 #endif |
2017 if (!upb_inttable_init(&f->defs, UPB_CTYPE_CONSTPTR)) { | 1744 |
2018 goto err; | 1745 /* TODO(haberman): we probably need to provide even better alignment here, |
2019 } | 1746 * like 16-byte alignment of the returned data pointer. */ |
2020 | 1747 block = realloc(from, size + sizeof(mem_block)); |
2021 if (!upb_inttable_init(&f->deps, UPB_CTYPE_CONSTPTR)) { | 1748 if (!block) return NULL; |
2022 goto err2; | 1749 ret = (char*)block + sizeof(*block); |
2023 } | 1750 |
2024 | 1751 #ifndef NDEBUG |
2025 return f; | 1752 block->size = size; |
2026 | 1753 #endif |
2027 | 1754 |
2028 err2: | 1755 if (from) { |
2029 upb_inttable_uninit(&f->defs); | 1756 if (block != from) { |
2030 | 1757 /* The block was moved, so pointers in next and prev blocks must be |
2031 err: | 1758 * updated to its new location. */ |
2032 upb_gfree(f); | 1759 if (block->next) block->next->prev = block; |
2033 return NULL; | 1760 if (block->prev) block->prev->next = block; |
2034 } | 1761 if (ud->head == from) ud->head = block; |
2035 | 1762 } |
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 { | 1763 } else { |
2062 return NULL; | 1764 /* Insert at head of linked list. */ |
2063 } | 1765 block->prev = NULL; |
2064 } | 1766 block->next = ud->head; |
2065 | 1767 if (block->next) block->next->prev = block; |
2066 const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) { | 1768 ud->head = block; |
2067 upb_value v; | 1769 } |
2068 | 1770 |
2069 if (upb_inttable_lookup32(&f->deps, i, &v)) { | 1771 return ret; |
2070 return upb_value_getconstptr(v); | 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 |
| 1866 return true; |
| 1867 } |
| 1868 |
| 1869 void *upb_env_malloc(upb_env *e, size_t size) { |
| 1870 e->bytes_allocated += size; |
| 1871 if (e->alloc == seeded_alloc) { |
| 1872 /* This is equivalent to the next branch, but allows inlining for a |
| 1873 * measurable perf benefit. */ |
| 1874 return seeded_alloc(e->alloc_ud, NULL, 0, size); |
2071 } else { | 1875 } else { |
2072 return NULL; | 1876 return e->alloc(e->alloc_ud, NULL, 0, size); |
2073 } | 1877 } |
2074 } | 1878 } |
2075 | 1879 |
2076 bool upb_filedef_setname(upb_filedef *f, const char *name, upb_status *s) { | 1880 void *upb_env_realloc(upb_env *e, void *ptr, size_t oldsize, size_t size) { |
2077 name = upb_gstrdup(name); | 1881 char *ret; |
2078 if (!name) { | 1882 assert(oldsize <= size); |
2079 upb_upberr_setoom(s); | 1883 ret = e->alloc(e->alloc_ud, ptr, oldsize, size); |
2080 return false; | 1884 |
2081 } | 1885 #ifndef NDEBUG |
2082 upb_gfree((void*)f->name); | 1886 /* Overwrite non-preserved memory to ensure callers are passing the oldsize |
2083 f->name = name; | 1887 * that they truly require. */ |
2084 return true; | 1888 memset(ret + oldsize, 0xff, size - oldsize); |
2085 } | 1889 #endif |
2086 | 1890 |
2087 bool upb_filedef_setpackage(upb_filedef *f, const char *package, | 1891 return ret; |
2088 upb_status *s) { | 1892 } |
2089 if (!upb_isident(package, strlen(package), true, s)) return false; | 1893 |
2090 package = upb_gstrdup(package); | 1894 size_t upb_env_bytesallocated(const upb_env *e) { |
2091 if (!package) { | 1895 return e->bytes_allocated; |
2092 upb_upberr_setoom(s); | 1896 } |
2093 return false; | 1897 |
2094 } | 1898 |
2095 upb_gfree((void*)f->package); | 1899 /* upb_seededalloc ************************************************************/ |
2096 f->package = package; | 1900 |
2097 return true; | 1901 /* Be conservative and choose 16 in case anyone is using SSE. */ |
2098 } | 1902 static const size_t maxalign = 16; |
2099 | 1903 |
2100 bool upb_filedef_setsyntax(upb_filedef *f, upb_syntax_t syntax, | 1904 static size_t align_up(size_t size) { |
2101 upb_status *s) { | 1905 return ((size + maxalign - 1) / maxalign) * maxalign; |
2102 UPB_UNUSED(s); | 1906 } |
2103 if (syntax != UPB_SYNTAX_PROTO2 && | 1907 |
2104 syntax != UPB_SYNTAX_PROTO3) { | 1908 UPB_FORCEINLINE static void *seeded_alloc(void *ud, void *ptr, size_t oldsize, |
2105 upb_status_seterrmsg(s, "Unknown syntax value."); | 1909 size_t size) { |
2106 return false; | 1910 upb_seededalloc *a = ud; |
2107 } | 1911 |
2108 f->syntax = syntax; | 1912 size = align_up(size); |
2109 | 1913 |
2110 { | 1914 assert(a->mem_limit >= a->mem_ptr); |
2111 /* Set all messages in this file to match. */ | 1915 |
2112 size_t i; | 1916 if (oldsize == 0 && size <= (size_t)(a->mem_limit - a->mem_ptr)) { |
2113 for (i = 0; i < upb_filedef_defcount(f); i++) { | 1917 /* Fast path: we can satisfy from the initial allocation. */ |
2114 /* Casting const away is safe since all defs in mutable filedef must | 1918 void *ret = a->mem_ptr; |
2115 * also be mutable. */ | 1919 a->mem_ptr += size; |
2116 upb_def *def = (upb_def*)upb_filedef_def(f, i); | 1920 return ret; |
2117 | 1921 } else { |
2118 upb_msgdef *m = upb_dyncast_msgdef_mutable(def); | 1922 char *chptr = ptr; |
2119 if (m) { | 1923 /* Slow path: fallback to other allocator. */ |
2120 m->syntax = syntax; | 1924 a->need_cleanup = true; |
2121 } | 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); |
2122 } | 1935 } |
2123 } | 1936 } |
2124 | 1937 } |
2125 return true; | 1938 |
2126 } | 1939 void upb_seededalloc_init(upb_seededalloc *a, void *mem, size_t len) { |
2127 | 1940 default_alloc_ud *ud = (default_alloc_ud*)&a->default_alloc_ud; |
2128 bool upb_filedef_adddef(upb_filedef *f, upb_def *def, const void *ref_donor, | 1941 a->mem_base = mem; |
2129 upb_status *s) { | 1942 a->mem_ptr = mem; |
2130 if (def->file) { | 1943 a->mem_limit = (char*)mem + len; |
2131 upb_status_seterrmsg(s, "Def is already part of another filedef."); | 1944 a->need_cleanup = false; |
2132 return false; | 1945 a->returned_allocfunc = false; |
2133 } | 1946 |
2134 | 1947 ud->head = NULL; |
2135 if (upb_inttable_push(&f->defs, upb_value_constptr(def))) { | 1948 |
2136 def->file = f; | 1949 upb_seededalloc_setfallbackalloc(a, default_alloc, ud); |
2137 upb_ref2(def, f); | 1950 } |
2138 upb_ref2(f, def); | 1951 |
2139 if (ref_donor) upb_def_unref(def, ref_donor); | 1952 void upb_seededalloc_uninit(upb_seededalloc *a) { |
2140 if (def->type == UPB_DEF_MSG) { | 1953 if (a->alloc == default_alloc && a->need_cleanup) { |
2141 upb_downcast_msgdef_mutable(def)->syntax = f->syntax; | 1954 default_alloc_cleanup(a->alloc_ud); |
2142 } | 1955 } |
2143 return true; | 1956 } |
2144 } else { | 1957 |
2145 upb_upberr_setoom(s); | 1958 UPB_FORCEINLINE void upb_seededalloc_setfallbackalloc(upb_seededalloc *a, |
2146 return false; | 1959 upb_alloc_func *alloc, |
2147 } | 1960 void *ud) { |
2148 } | 1961 assert(!a->returned_allocfunc); |
2149 | 1962 a->alloc = alloc; |
2150 bool upb_filedef_adddep(upb_filedef *f, const upb_filedef *dep) { | 1963 a->alloc_ud = ud; |
2151 if (upb_inttable_push(&f->deps, upb_value_constptr(dep))) { | 1964 } |
2152 /* Regular ref instead of ref2 because files can't form cycles. */ | 1965 |
2153 upb_filedef_ref(dep, f); | 1966 upb_alloc_func *upb_seededalloc_getallocfunc(upb_seededalloc *a) { |
2154 return true; | 1967 a->returned_allocfunc = true; |
2155 } else { | 1968 return seeded_alloc; |
2156 return false; | |
2157 } | |
2158 } | 1969 } |
2159 /* | 1970 /* |
2160 ** TODO(haberman): it's unclear whether a lot of the consistency checks should | 1971 ** TODO(haberman): it's unclear whether a lot of the consistency checks should |
2161 ** UPB_ASSERT() or return false. | 1972 ** assert() or return false. |
2162 */ | 1973 */ |
2163 | 1974 |
2164 | 1975 |
| 1976 #include <stdlib.h> |
2165 #include <string.h> | 1977 #include <string.h> |
2166 | 1978 |
2167 | 1979 |
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 } | |
2175 | 1980 |
2176 /* Defined for the sole purpose of having a unique pointer value for | 1981 /* Defined for the sole purpose of having a unique pointer value for |
2177 * UPB_NO_CLOSURE. */ | 1982 * UPB_NO_CLOSURE. */ |
2178 char _upb_noclosure; | 1983 char _upb_noclosure; |
2179 | 1984 |
2180 static void freehandlers(upb_refcounted *r) { | 1985 static void freehandlers(upb_refcounted *r) { |
2181 upb_handlers *h = (upb_handlers*)r; | 1986 upb_handlers *h = (upb_handlers*)r; |
2182 | 1987 |
2183 upb_inttable_iter i; | 1988 upb_inttable_iter i; |
2184 upb_inttable_begin(&i, &h->cleanup_); | 1989 upb_inttable_begin(&i, &h->cleanup_); |
2185 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 1990 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
2186 void *val = (void*)upb_inttable_iter_key(&i); | 1991 void *val = (void*)upb_inttable_iter_key(&i); |
2187 upb_value func_val = upb_inttable_iter_value(&i); | 1992 upb_value func_val = upb_inttable_iter_value(&i); |
2188 upb_handlerfree *func = upb_value_getfptr(func_val); | 1993 upb_handlerfree *func = upb_value_getfptr(func_val); |
2189 func(val); | 1994 func(val); |
2190 } | 1995 } |
2191 | 1996 |
2192 upb_inttable_uninit(&h->cleanup_); | 1997 upb_inttable_uninit(&h->cleanup_); |
2193 upb_msgdef_unref(h->msg, h); | 1998 upb_msgdef_unref(h->msg, h); |
2194 upb_gfree(h->sub); | 1999 free(h->sub); |
2195 upb_gfree(h); | 2000 free(h); |
2196 } | 2001 } |
2197 | 2002 |
2198 static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit, | 2003 static void visithandlers(const upb_refcounted *r, upb_refcounted_visit *visit, |
2199 void *closure) { | 2004 void *closure) { |
2200 const upb_handlers *h = (const upb_handlers*)r; | 2005 const upb_handlers *h = (const upb_handlers*)r; |
2201 upb_msg_field_iter i; | 2006 upb_msg_field_iter i; |
2202 for(upb_msg_field_begin(&i, h->msg); | 2007 for(upb_msg_field_begin(&i, h->msg); |
2203 !upb_msg_field_done(&i); | 2008 !upb_msg_field_done(&i); |
2204 upb_msg_field_next(&i)) { | 2009 upb_msg_field_next(&i)) { |
2205 upb_fielddef *f = upb_msg_iter_field(&i); | 2010 upb_fielddef *f = upb_msg_iter_field(&i); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2261 /* Given a selector for a STARTSUBMSG handler, resolves to a pointer to the | 2066 /* Given a selector for a STARTSUBMSG handler, resolves to a pointer to the |
2262 * subhandlers for this submessage field. */ | 2067 * subhandlers for this submessage field. */ |
2263 #define SUBH(h, selector) (h->sub[selector]) | 2068 #define SUBH(h, selector) (h->sub[selector]) |
2264 | 2069 |
2265 /* The selector for a submessage field is the field index. */ | 2070 /* The selector for a submessage field is the field index. */ |
2266 #define SUBH_F(h, f) SUBH(h, f->index_) | 2071 #define SUBH_F(h, f) SUBH(h, f->index_) |
2267 | 2072 |
2268 static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f, | 2073 static int32_t trygetsel(upb_handlers *h, const upb_fielddef *f, |
2269 upb_handlertype_t type) { | 2074 upb_handlertype_t type) { |
2270 upb_selector_t sel; | 2075 upb_selector_t sel; |
2271 UPB_ASSERT(!upb_handlers_isfrozen(h)); | 2076 assert(!upb_handlers_isfrozen(h)); |
2272 if (upb_handlers_msgdef(h) != upb_fielddef_containingtype(f)) { | 2077 if (upb_handlers_msgdef(h) != upb_fielddef_containingtype(f)) { |
2273 upb_status_seterrf( | 2078 upb_status_seterrf( |
2274 &h->status_, "type mismatch: field %s does not belong to message %s", | 2079 &h->status_, "type mismatch: field %s does not belong to message %s", |
2275 upb_fielddef_name(f), upb_msgdef_fullname(upb_handlers_msgdef(h))); | 2080 upb_fielddef_name(f), upb_msgdef_fullname(upb_handlers_msgdef(h))); |
2276 return -1; | 2081 return -1; |
2277 } | 2082 } |
2278 if (!upb_handlers_getselector(f, type, &sel)) { | 2083 if (!upb_handlers_getselector(f, type, &sel)) { |
2279 upb_status_seterrf( | 2084 upb_status_seterrf( |
2280 &h->status_, | 2085 &h->status_, |
2281 "type mismatch: cannot register handler type %d for field %s", | 2086 "type mismatch: cannot register handler type %d for field %s", |
2282 type, upb_fielddef_name(f)); | 2087 type, upb_fielddef_name(f)); |
2283 return -1; | 2088 return -1; |
2284 } | 2089 } |
2285 return sel; | 2090 return sel; |
2286 } | 2091 } |
2287 | 2092 |
2288 static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f, | 2093 static upb_selector_t handlers_getsel(upb_handlers *h, const upb_fielddef *f, |
2289 upb_handlertype_t type) { | 2094 upb_handlertype_t type) { |
2290 int32_t sel = trygetsel(h, f, type); | 2095 int32_t sel = trygetsel(h, f, type); |
2291 UPB_ASSERT(sel >= 0); | 2096 assert(sel >= 0); |
2292 return sel; | 2097 return sel; |
2293 } | 2098 } |
2294 | 2099 |
2295 static const void **returntype(upb_handlers *h, const upb_fielddef *f, | 2100 static const void **returntype(upb_handlers *h, const upb_fielddef *f, |
2296 upb_handlertype_t type) { | 2101 upb_handlertype_t type) { |
2297 return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_; | 2102 return &h->table[handlers_getsel(h, f, type)].attr.return_closure_type_; |
2298 } | 2103 } |
2299 | 2104 |
2300 static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f, | 2105 static bool doset(upb_handlers *h, int32_t sel, const upb_fielddef *f, |
2301 upb_handlertype_t type, upb_func *func, | 2106 upb_handlertype_t type, upb_func *func, |
2302 upb_handlerattr *attr) { | 2107 upb_handlerattr *attr) { |
2303 upb_handlerattr set_attr = UPB_HANDLERATTR_INITIALIZER; | 2108 upb_handlerattr set_attr = UPB_HANDLERATTR_INITIALIZER; |
2304 const void *closure_type; | 2109 const void *closure_type; |
2305 const void **context_closure_type; | 2110 const void **context_closure_type; |
2306 | 2111 |
2307 UPB_ASSERT(!upb_handlers_isfrozen(h)); | 2112 assert(!upb_handlers_isfrozen(h)); |
2308 | 2113 |
2309 if (sel < 0) { | 2114 if (sel < 0) { |
2310 upb_status_seterrmsg(&h->status_, | 2115 upb_status_seterrmsg(&h->status_, |
2311 "incorrect handler type for this field."); | 2116 "incorrect handler type for this field."); |
2312 return false; | 2117 return false; |
2313 } | 2118 } |
2314 | 2119 |
2315 if (h->table[sel].func) { | 2120 if (h->table[sel].func) { |
2316 upb_status_seterrmsg(&h->status_, | 2121 upb_status_seterrmsg(&h->status_, |
2317 "cannot change handler once it has been set."); | 2122 "cannot change handler once it has been set."); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 * from outer frames if this frame has no START* handler). Not implemented for | 2182 * from outer frames if this frame has no START* handler). Not implemented for |
2378 * UPB_HANDLER_STRING at the moment since this is not needed. Returns NULL is | 2183 * UPB_HANDLER_STRING at the moment since this is not needed. Returns NULL is |
2379 * the effective closure type is unspecified (either no handler was registered | 2184 * the effective closure type is unspecified (either no handler was registered |
2380 * to specify it or the handler that was registered did not specify the closure | 2185 * to specify it or the handler that was registered did not specify the closure |
2381 * type). */ | 2186 * type). */ |
2382 const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f, | 2187 const void *effective_closure_type(upb_handlers *h, const upb_fielddef *f, |
2383 upb_handlertype_t type) { | 2188 upb_handlertype_t type) { |
2384 const void *ret; | 2189 const void *ret; |
2385 upb_selector_t sel; | 2190 upb_selector_t sel; |
2386 | 2191 |
2387 UPB_ASSERT(type != UPB_HANDLER_STRING); | 2192 assert(type != UPB_HANDLER_STRING); |
2388 ret = h->top_closure_type; | 2193 ret = h->top_closure_type; |
2389 | 2194 |
2390 if (upb_fielddef_isseq(f) && | 2195 if (upb_fielddef_isseq(f) && |
2391 type != UPB_HANDLER_STARTSEQ && | 2196 type != UPB_HANDLER_STARTSEQ && |
2392 type != UPB_HANDLER_ENDSEQ && | 2197 type != UPB_HANDLER_ENDSEQ && |
2393 h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) { | 2198 h->table[sel = handlers_getsel(h, f, UPB_HANDLER_STARTSEQ)].func) { |
2394 ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr); | 2199 ret = upb_handlerattr_returnclosuretype(&h->table[sel].attr); |
2395 } | 2200 } |
2396 | 2201 |
2397 if (type == UPB_HANDLER_STRING && | 2202 if (type == UPB_HANDLER_STRING && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2432 } | 2237 } |
2433 return true; | 2238 return true; |
2434 } | 2239 } |
2435 | 2240 |
2436 /* Public interface ***********************************************************/ | 2241 /* Public interface ***********************************************************/ |
2437 | 2242 |
2438 upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) { | 2243 upb_handlers *upb_handlers_new(const upb_msgdef *md, const void *owner) { |
2439 int extra; | 2244 int extra; |
2440 upb_handlers *h; | 2245 upb_handlers *h; |
2441 | 2246 |
2442 UPB_ASSERT(upb_msgdef_isfrozen(md)); | 2247 assert(upb_msgdef_isfrozen(md)); |
2443 | 2248 |
2444 extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1); | 2249 extra = sizeof(upb_handlers_tabent) * (md->selector_count - 1); |
2445 h = upb_calloc(sizeof(*h) + extra); | 2250 h = calloc(sizeof(*h) + extra, 1); |
2446 if (!h) return NULL; | 2251 if (!h) return NULL; |
2447 | 2252 |
2448 h->msg = md; | 2253 h->msg = md; |
2449 upb_msgdef_ref(h->msg, h); | 2254 upb_msgdef_ref(h->msg, h); |
2450 upb_status_clear(&h->status_); | 2255 upb_status_clear(&h->status_); |
2451 | 2256 h->sub = calloc(md->submsg_field_count, sizeof(*h->sub)); |
2452 if (md->submsg_field_count > 0) { | 2257 if (!h->sub) goto oom; |
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 | |
2459 if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner)) | 2258 if (!upb_refcounted_init(upb_handlers_upcast_mutable(h), &vtbl, owner)) |
2460 goto oom; | 2259 goto oom; |
2461 if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom; | 2260 if (!upb_inttable_init(&h->cleanup_, UPB_CTYPE_FPTR)) goto oom; |
2462 | 2261 |
2463 /* calloc() above initialized all handlers to NULL. */ | 2262 /* calloc() above initialized all handlers to NULL. */ |
2464 return h; | 2263 return h; |
2465 | 2264 |
2466 oom: | 2265 oom: |
2467 freehandlers(upb_handlers_upcast_mutable(h)); | 2266 freehandlers(upb_handlers_upcast_mutable(h)); |
2468 return NULL; | 2267 return NULL; |
(...skipping 12 matching lines...) Expand all Loading... |
2481 state.closure = closure; | 2280 state.closure = closure; |
2482 if (!upb_inttable_init(&state.tab, UPB_CTYPE_PTR)) return NULL; | 2281 if (!upb_inttable_init(&state.tab, UPB_CTYPE_PTR)) return NULL; |
2483 | 2282 |
2484 ret = newformsg(m, owner, &state); | 2283 ret = newformsg(m, owner, &state); |
2485 | 2284 |
2486 upb_inttable_uninit(&state.tab); | 2285 upb_inttable_uninit(&state.tab); |
2487 if (!ret) return NULL; | 2286 if (!ret) return NULL; |
2488 | 2287 |
2489 r = upb_handlers_upcast_mutable(ret); | 2288 r = upb_handlers_upcast_mutable(ret); |
2490 ok = upb_refcounted_freeze(&r, 1, NULL, UPB_MAX_HANDLER_DEPTH); | 2289 ok = upb_refcounted_freeze(&r, 1, NULL, UPB_MAX_HANDLER_DEPTH); |
2491 UPB_ASSERT(ok); | 2290 UPB_ASSERT_VAR(ok, ok); |
2492 | 2291 |
2493 return ret; | 2292 return ret; |
2494 } | 2293 } |
2495 | 2294 |
2496 const upb_status *upb_handlers_status(upb_handlers *h) { | 2295 const upb_status *upb_handlers_status(upb_handlers *h) { |
2497 UPB_ASSERT(!upb_handlers_isfrozen(h)); | 2296 assert(!upb_handlers_isfrozen(h)); |
2498 return &h->status_; | 2297 return &h->status_; |
2499 } | 2298 } |
2500 | 2299 |
2501 void upb_handlers_clearerr(upb_handlers *h) { | 2300 void upb_handlers_clearerr(upb_handlers *h) { |
2502 UPB_ASSERT(!upb_handlers_isfrozen(h)); | 2301 assert(!upb_handlers_isfrozen(h)); |
2503 upb_status_clear(&h->status_); | 2302 upb_status_clear(&h->status_); |
2504 } | 2303 } |
2505 | 2304 |
2506 #define SETTER(name, handlerctype, handlertype) \ | 2305 #define SETTER(name, handlerctype, handlertype) \ |
2507 bool upb_handlers_set ## name(upb_handlers *h, const upb_fielddef *f, \ | 2306 bool upb_handlers_set ## name(upb_handlers *h, const upb_fielddef *f, \ |
2508 handlerctype func, upb_handlerattr *attr) { \ | 2307 handlerctype func, upb_handlerattr *attr) { \ |
2509 int32_t sel = trygetsel(h, f, handlertype); \ | 2308 int32_t sel = trygetsel(h, f, handlertype); \ |
2510 return doset(h, sel, f, handlertype, (upb_func*)func, attr); \ | 2309 return doset(h, sel, f, handlertype, (upb_func*)func, attr); \ |
2511 } | 2310 } |
2512 | 2311 |
(...skipping 15 matching lines...) Expand all Loading... |
2528 #undef SETTER | 2327 #undef SETTER |
2529 | 2328 |
2530 bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func, | 2329 bool upb_handlers_setstartmsg(upb_handlers *h, upb_startmsg_handlerfunc *func, |
2531 upb_handlerattr *attr) { | 2330 upb_handlerattr *attr) { |
2532 return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32, | 2331 return doset(h, UPB_STARTMSG_SELECTOR, NULL, UPB_HANDLER_INT32, |
2533 (upb_func *)func, attr); | 2332 (upb_func *)func, attr); |
2534 } | 2333 } |
2535 | 2334 |
2536 bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func, | 2335 bool upb_handlers_setendmsg(upb_handlers *h, upb_endmsg_handlerfunc *func, |
2537 upb_handlerattr *attr) { | 2336 upb_handlerattr *attr) { |
2538 UPB_ASSERT(!upb_handlers_isfrozen(h)); | 2337 assert(!upb_handlers_isfrozen(h)); |
2539 return doset(h, UPB_ENDMSG_SELECTOR, NULL, UPB_HANDLER_INT32, | 2338 return doset(h, UPB_ENDMSG_SELECTOR, NULL, UPB_HANDLER_INT32, |
2540 (upb_func *)func, attr); | 2339 (upb_func *)func, attr); |
2541 } | 2340 } |
2542 | 2341 |
2543 bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f, | 2342 bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f, |
2544 const upb_handlers *sub) { | 2343 const upb_handlers *sub) { |
2545 UPB_ASSERT(sub); | 2344 assert(sub); |
2546 UPB_ASSERT(!upb_handlers_isfrozen(h)); | 2345 assert(!upb_handlers_isfrozen(h)); |
2547 UPB_ASSERT(upb_fielddef_issubmsg(f)); | 2346 assert(upb_fielddef_issubmsg(f)); |
2548 if (SUBH_F(h, f)) return false; /* Can't reset. */ | 2347 if (SUBH_F(h, f)) return false; /* Can't reset. */ |
2549 if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) { | 2348 if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) { |
2550 return false; | 2349 return false; |
2551 } | 2350 } |
2552 SUBH_F(h, f) = sub; | 2351 SUBH_F(h, f) = sub; |
2553 upb_ref2(sub, h); | 2352 upb_ref2(sub, h); |
2554 return true; | 2353 return true; |
2555 } | 2354 } |
2556 | 2355 |
2557 const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h, | 2356 const upb_handlers *upb_handlers_getsubhandlers(const upb_handlers *h, |
2558 const upb_fielddef *f) { | 2357 const upb_fielddef *f) { |
2559 UPB_ASSERT(upb_fielddef_issubmsg(f)); | 2358 assert(upb_fielddef_issubmsg(f)); |
2560 return SUBH_F(h, f); | 2359 return SUBH_F(h, f); |
2561 } | 2360 } |
2562 | 2361 |
2563 bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t sel, | 2362 bool upb_handlers_getattr(const upb_handlers *h, upb_selector_t sel, |
2564 upb_handlerattr *attr) { | 2363 upb_handlerattr *attr) { |
2565 if (!upb_handlers_gethandler(h, sel)) | 2364 if (!upb_handlers_gethandler(h, sel)) |
2566 return false; | 2365 return false; |
2567 *attr = h->table[sel].attr; | 2366 *attr = h->table[sel].attr; |
2568 return true; | 2367 return true; |
2569 } | 2368 } |
2570 | 2369 |
2571 const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h, | 2370 const upb_handlers *upb_handlers_getsubhandlers_sel(const upb_handlers *h, |
2572 upb_selector_t sel) { | 2371 upb_selector_t sel) { |
2573 /* STARTSUBMSG selector in sel is the field's selector base. */ | 2372 /* STARTSUBMSG selector in sel is the field's selector base. */ |
2574 return SUBH(h, sel - UPB_STATIC_SELECTOR_COUNT); | 2373 return SUBH(h, sel - UPB_STATIC_SELECTOR_COUNT); |
2575 } | 2374 } |
2576 | 2375 |
2577 const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h) { return h->msg; } | 2376 const upb_msgdef *upb_handlers_msgdef(const upb_handlers *h) { return h->msg; } |
2578 | 2377 |
2579 bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func) { | 2378 bool upb_handlers_addcleanup(upb_handlers *h, void *p, upb_handlerfree *func) { |
2580 bool ok; | 2379 bool ok; |
2581 if (upb_inttable_lookupptr(&h->cleanup_, p, NULL)) { | 2380 if (upb_inttable_lookupptr(&h->cleanup_, p, NULL)) { |
2582 return false; | 2381 return false; |
2583 } | 2382 } |
2584 ok = upb_inttable_insertptr(&h->cleanup_, p, upb_value_fptr(func)); | 2383 ok = upb_inttable_insertptr(&h->cleanup_, p, upb_value_fptr(func)); |
2585 UPB_ASSERT(ok); | 2384 UPB_ASSERT_VAR(ok, ok); |
2586 return true; | 2385 return true; |
2587 } | 2386 } |
2588 | 2387 |
2589 | 2388 |
2590 /* "Static" methods ***********************************************************/ | 2389 /* "Static" methods ***********************************************************/ |
2591 | 2390 |
2592 bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) { | 2391 bool upb_handlers_freeze(upb_handlers *const*handlers, int n, upb_status *s) { |
2593 /* TODO: verify we have a transitive closure. */ | 2392 /* TODO: verify we have a transitive closure. */ |
2594 int i; | 2393 int i; |
2595 for (i = 0; i < n; i++) { | 2394 for (i = 0; i < n; i++) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2676 upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f) { | 2475 upb_handlertype_t upb_handlers_getprimitivehandlertype(const upb_fielddef *f) { |
2677 switch (upb_fielddef_type(f)) { | 2476 switch (upb_fielddef_type(f)) { |
2678 case UPB_TYPE_INT32: | 2477 case UPB_TYPE_INT32: |
2679 case UPB_TYPE_ENUM: return UPB_HANDLER_INT32; | 2478 case UPB_TYPE_ENUM: return UPB_HANDLER_INT32; |
2680 case UPB_TYPE_INT64: return UPB_HANDLER_INT64; | 2479 case UPB_TYPE_INT64: return UPB_HANDLER_INT64; |
2681 case UPB_TYPE_UINT32: return UPB_HANDLER_UINT32; | 2480 case UPB_TYPE_UINT32: return UPB_HANDLER_UINT32; |
2682 case UPB_TYPE_UINT64: return UPB_HANDLER_UINT64; | 2481 case UPB_TYPE_UINT64: return UPB_HANDLER_UINT64; |
2683 case UPB_TYPE_FLOAT: return UPB_HANDLER_FLOAT; | 2482 case UPB_TYPE_FLOAT: return UPB_HANDLER_FLOAT; |
2684 case UPB_TYPE_DOUBLE: return UPB_HANDLER_DOUBLE; | 2483 case UPB_TYPE_DOUBLE: return UPB_HANDLER_DOUBLE; |
2685 case UPB_TYPE_BOOL: return UPB_HANDLER_BOOL; | 2484 case UPB_TYPE_BOOL: return UPB_HANDLER_BOOL; |
2686 default: UPB_ASSERT(false); return -1; /* Invalid input. */ | 2485 default: assert(false); return -1; /* Invalid input. */ |
2687 } | 2486 } |
2688 } | 2487 } |
2689 | 2488 |
2690 bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, | 2489 bool upb_handlers_getselector(const upb_fielddef *f, upb_handlertype_t type, |
2691 upb_selector_t *s) { | 2490 upb_selector_t *s) { |
2692 switch (type) { | 2491 switch (type) { |
2693 case UPB_HANDLER_INT32: | 2492 case UPB_HANDLER_INT32: |
2694 case UPB_HANDLER_INT64: | 2493 case UPB_HANDLER_INT64: |
2695 case UPB_HANDLER_UINT32: | 2494 case UPB_HANDLER_UINT32: |
2696 case UPB_HANDLER_UINT64: | 2495 case UPB_HANDLER_UINT64: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 * selector can also be used as an index into the "sub" array of | 2538 * selector can also be used as an index into the "sub" array of |
2740 * subhandlers. The indexes for the two into these two tables are the | 2539 * subhandlers. The indexes for the two into these two tables are the |
2741 * same, except that in the handler table the static selectors come first.
*/ | 2540 * same, except that in the handler table the static selectors come first.
*/ |
2742 *s = f->index_ + UPB_STATIC_SELECTOR_COUNT; | 2541 *s = f->index_ + UPB_STATIC_SELECTOR_COUNT; |
2743 break; | 2542 break; |
2744 case UPB_HANDLER_ENDSUBMSG: | 2543 case UPB_HANDLER_ENDSUBMSG: |
2745 if (!upb_fielddef_issubmsg(f)) return false; | 2544 if (!upb_fielddef_issubmsg(f)) return false; |
2746 *s = f->selector_base; | 2545 *s = f->selector_base; |
2747 break; | 2546 break; |
2748 } | 2547 } |
2749 UPB_ASSERT((size_t)*s < upb_fielddef_containingtype(f)->selector_count); | 2548 assert((size_t)*s < upb_fielddef_containingtype(f)->selector_count); |
2750 return true; | 2549 return true; |
2751 } | 2550 } |
2752 | 2551 |
2753 uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) { | 2552 uint32_t upb_handlers_selectorbaseoffset(const upb_fielddef *f) { |
2754 return upb_fielddef_isseq(f) ? 2 : 0; | 2553 return upb_fielddef_isseq(f) ? 2 : 0; |
2755 } | 2554 } |
2756 | 2555 |
2757 uint32_t upb_handlers_selectorcount(const upb_fielddef *f) { | 2556 uint32_t upb_handlers_selectorcount(const upb_fielddef *f) { |
2758 uint32_t ret = 1; | 2557 uint32_t ret = 1; |
2759 if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */ | 2558 if (upb_fielddef_isseq(f)) ret += 2; /* STARTSEQ/ENDSEQ */ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2863 ** 3. for mutable objects "from" and "to", if there exists a ref2(to, from) | 2662 ** 3. for mutable objects "from" and "to", if there exists a ref2(to, from) |
2864 ** this implies group(from) == group(to). (In practice, what we implement | 2663 ** this implies group(from) == group(to). (In practice, what we implement |
2865 ** is even stronger; "from" and "to" will share a group if there has *ever* | 2664 ** is even stronger; "from" and "to" will share a group if there has *ever* |
2866 ** been a ref2(to, from), but all that is necessary for correctness is the | 2665 ** been a ref2(to, from), but all that is necessary for correctness is the |
2867 ** weaker one). | 2666 ** weaker one). |
2868 ** 4. mutable and immutable objects are never in the same group. | 2667 ** 4. mutable and immutable objects are never in the same group. |
2869 */ | 2668 */ |
2870 | 2669 |
2871 | 2670 |
2872 #include <setjmp.h> | 2671 #include <setjmp.h> |
| 2672 #include <stdlib.h> |
2873 | 2673 |
2874 static void freeobj(upb_refcounted *o); | 2674 static void freeobj(upb_refcounted *o); |
2875 | 2675 |
2876 const char untracked_val; | 2676 const char untracked_val; |
2877 const void *UPB_UNTRACKED_REF = &untracked_val; | 2677 const void *UPB_UNTRACKED_REF = &untracked_val; |
2878 | 2678 |
2879 /* arch-specific atomic primitives *******************************************/ | 2679 /* arch-specific atomic primitives *******************************************/ |
2880 | 2680 |
2881 #ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/ | 2681 #ifdef UPB_THREAD_UNSAFE /*---------------------------------------------------*/ |
2882 | 2682 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2938 /* User must define functions that lock/unlock a global mutex and link this | 2738 /* User must define functions that lock/unlock a global mutex and link this |
2939 * file against them. */ | 2739 * file against them. */ |
2940 void upb_lock(); | 2740 void upb_lock(); |
2941 void upb_unlock(); | 2741 void upb_unlock(); |
2942 | 2742 |
2943 #endif | 2743 #endif |
2944 | 2744 |
2945 /* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some | 2745 /* UPB_DEBUG_REFS mode counts on being able to malloc() memory in some |
2946 * code-paths that can normally never fail, like upb_refcounted_ref(). Since | 2746 * code-paths that can normally never fail, like upb_refcounted_ref(). Since |
2947 * we have no way to propagage out-of-memory errors back to the user, and since | 2747 * we have no way to propagage out-of-memory errors back to the user, and since |
2948 * these errors can only occur in UPB_DEBUG_REFS mode, we use an allocator that | 2748 * these errors can only occur in UPB_DEBUG_REFS mode, we immediately fail. */ |
2949 * immediately aborts on failure (avoiding the global allocator, which might | 2749 #define CHECK_OOM(predicate) if (!(predicate)) { assert(predicate); exit(1); } |
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}; | |
2973 | 2750 |
2974 typedef struct { | 2751 typedef struct { |
2975 int count; /* How many refs there are (duplicates only allowed for ref2). */ | 2752 int count; /* How many refs there are (duplicates only allowed for ref2). */ |
2976 bool is_ref2; | 2753 bool is_ref2; |
2977 } trackedref; | 2754 } trackedref; |
2978 | 2755 |
2979 static trackedref *trackedref_new(bool is_ref2) { | 2756 static trackedref *trackedref_new(bool is_ref2) { |
2980 trackedref *ret = upb_malloc(&upb_alloc_debugrefs, sizeof(*ret)); | 2757 trackedref *ret = malloc(sizeof(*ret)); |
| 2758 CHECK_OOM(ret); |
2981 ret->count = 1; | 2759 ret->count = 1; |
2982 ret->is_ref2 = is_ref2; | 2760 ret->is_ref2 = is_ref2; |
2983 return ret; | 2761 return ret; |
2984 } | 2762 } |
2985 | 2763 |
2986 static void track(const upb_refcounted *r, const void *owner, bool ref2) { | 2764 static void track(const upb_refcounted *r, const void *owner, bool ref2) { |
2987 upb_value v; | 2765 upb_value v; |
2988 | 2766 |
2989 UPB_ASSERT(owner); | 2767 assert(owner); |
2990 if (owner == UPB_UNTRACKED_REF) return; | 2768 if (owner == UPB_UNTRACKED_REF) return; |
2991 | 2769 |
2992 upb_lock(); | 2770 upb_lock(); |
2993 if (upb_inttable_lookupptr(r->refs, owner, &v)) { | 2771 if (upb_inttable_lookupptr(r->refs, owner, &v)) { |
2994 trackedref *ref = upb_value_getptr(v); | 2772 trackedref *ref = upb_value_getptr(v); |
2995 /* Since we allow multiple ref2's for the same to/from pair without | 2773 /* Since we allow multiple ref2's for the same to/from pair without |
2996 * allocating separate memory for each one, we lose the fine-grained | 2774 * allocating separate memory for each one, we lose the fine-grained |
2997 * tracking behavior we get with regular refs. Since ref2s only happen | 2775 * tracking behavior we get with regular refs. Since ref2s only happen |
2998 * inside upb, we'll accept this limitation until/unless there is a really | 2776 * inside upb, we'll accept this limitation until/unless there is a really |
2999 * difficult upb-internal bug that can't be figured out without it. */ | 2777 * difficult upb-internal bug that can't be figured out without it. */ |
3000 UPB_ASSERT(ref2); | 2778 assert(ref2); |
3001 UPB_ASSERT(ref->is_ref2); | 2779 assert(ref->is_ref2); |
3002 ref->count++; | 2780 ref->count++; |
3003 } else { | 2781 } else { |
3004 trackedref *ref = trackedref_new(ref2); | 2782 trackedref *ref = trackedref_new(ref2); |
3005 upb_inttable_insertptr2(r->refs, owner, upb_value_ptr(ref), | 2783 bool ok = upb_inttable_insertptr(r->refs, owner, upb_value_ptr(ref)); |
3006 &upb_alloc_debugrefs); | 2784 CHECK_OOM(ok); |
3007 if (ref2) { | 2785 if (ref2) { |
3008 /* We know this cast is safe when it is a ref2, because it's coming from | 2786 /* We know this cast is safe when it is a ref2, because it's coming from |
3009 * another refcounted object. */ | 2787 * another refcounted object. */ |
3010 const upb_refcounted *from = owner; | 2788 const upb_refcounted *from = owner; |
3011 UPB_ASSERT(!upb_inttable_lookupptr(from->ref2s, r, NULL)); | 2789 assert(!upb_inttable_lookupptr(from->ref2s, r, NULL)); |
3012 upb_inttable_insertptr2(from->ref2s, r, upb_value_ptr(NULL), | 2790 ok = upb_inttable_insertptr(from->ref2s, r, upb_value_ptr(NULL)); |
3013 &upb_alloc_debugrefs); | 2791 CHECK_OOM(ok); |
3014 } | 2792 } |
3015 } | 2793 } |
3016 upb_unlock(); | 2794 upb_unlock(); |
3017 } | 2795 } |
3018 | 2796 |
3019 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { | 2797 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { |
3020 upb_value v; | 2798 upb_value v; |
3021 bool found; | 2799 bool found; |
3022 trackedref *ref; | 2800 trackedref *ref; |
3023 | 2801 |
3024 UPB_ASSERT(owner); | 2802 assert(owner); |
3025 if (owner == UPB_UNTRACKED_REF) return; | 2803 if (owner == UPB_UNTRACKED_REF) return; |
3026 | 2804 |
3027 upb_lock(); | 2805 upb_lock(); |
3028 found = upb_inttable_lookupptr(r->refs, owner, &v); | 2806 found = upb_inttable_lookupptr(r->refs, owner, &v); |
3029 /* This assert will fail if an owner attempts to release a ref it didn't have.
*/ | 2807 /* This assert will fail if an owner attempts to release a ref it didn't have.
*/ |
3030 UPB_ASSERT(found); | 2808 UPB_ASSERT_VAR(found, found); |
3031 ref = upb_value_getptr(v); | 2809 ref = upb_value_getptr(v); |
3032 UPB_ASSERT(ref->is_ref2 == ref2); | 2810 assert(ref->is_ref2 == ref2); |
3033 if (--ref->count == 0) { | 2811 if (--ref->count == 0) { |
3034 free(ref); | 2812 free(ref); |
3035 upb_inttable_removeptr(r->refs, owner, NULL); | 2813 upb_inttable_removeptr(r->refs, owner, NULL); |
3036 if (ref2) { | 2814 if (ref2) { |
3037 /* We know this cast is safe when it is a ref2, because it's coming from | 2815 /* We know this cast is safe when it is a ref2, because it's coming from |
3038 * another refcounted object. */ | 2816 * another refcounted object. */ |
3039 const upb_refcounted *from = owner; | 2817 const upb_refcounted *from = owner; |
3040 bool removed = upb_inttable_removeptr(from->ref2s, r, NULL); | 2818 bool removed = upb_inttable_removeptr(from->ref2s, r, NULL); |
3041 UPB_ASSERT(removed); | 2819 assert(removed); |
3042 } | 2820 } |
3043 } | 2821 } |
3044 upb_unlock(); | 2822 upb_unlock(); |
3045 } | 2823 } |
3046 | 2824 |
3047 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { | 2825 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { |
3048 upb_value v; | 2826 upb_value v; |
3049 bool found; | 2827 bool found; |
3050 trackedref *ref; | 2828 trackedref *ref; |
3051 | 2829 |
3052 upb_lock(); | 2830 upb_lock(); |
3053 found = upb_inttable_lookupptr(r->refs, owner, &v); | 2831 found = upb_inttable_lookupptr(r->refs, owner, &v); |
3054 UPB_ASSERT(found); | 2832 UPB_ASSERT_VAR(found, found); |
3055 ref = upb_value_getptr(v); | 2833 ref = upb_value_getptr(v); |
3056 UPB_ASSERT(ref->is_ref2 == ref2); | 2834 assert(ref->is_ref2 == ref2); |
3057 upb_unlock(); | 2835 upb_unlock(); |
3058 } | 2836 } |
3059 | 2837 |
3060 /* Populates the given UPB_CTYPE_INT32 inttable with counts of ref2's that | 2838 /* Populates the given UPB_CTYPE_INT32 inttable with counts of ref2's that |
3061 * originate from the given owner. */ | 2839 * originate from the given owner. */ |
3062 static void getref2s(const upb_refcounted *owner, upb_inttable *tab) { | 2840 static void getref2s(const upb_refcounted *owner, upb_inttable *tab) { |
3063 upb_inttable_iter i; | 2841 upb_inttable_iter i; |
3064 | 2842 |
3065 upb_lock(); | 2843 upb_lock(); |
3066 upb_inttable_begin(&i, owner->ref2s); | 2844 upb_inttable_begin(&i, owner->ref2s); |
3067 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 2845 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
3068 upb_value v; | 2846 upb_value v; |
3069 upb_value count; | 2847 upb_value count; |
3070 trackedref *ref; | 2848 trackedref *ref; |
| 2849 bool ok; |
3071 bool found; | 2850 bool found; |
3072 | 2851 |
3073 upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i); | 2852 upb_refcounted *to = (upb_refcounted*)upb_inttable_iter_key(&i); |
3074 | 2853 |
3075 /* To get the count we need to look in the target's table. */ | 2854 /* To get the count we need to look in the target's table. */ |
3076 found = upb_inttable_lookupptr(to->refs, owner, &v); | 2855 found = upb_inttable_lookupptr(to->refs, owner, &v); |
3077 UPB_ASSERT(found); | 2856 assert(found); |
3078 ref = upb_value_getptr(v); | 2857 ref = upb_value_getptr(v); |
3079 count = upb_value_int32(ref->count); | 2858 count = upb_value_int32(ref->count); |
3080 | 2859 |
3081 upb_inttable_insertptr2(tab, to, count, &upb_alloc_debugrefs); | 2860 ok = upb_inttable_insertptr(tab, to, count); |
| 2861 CHECK_OOM(ok); |
3082 } | 2862 } |
3083 upb_unlock(); | 2863 upb_unlock(); |
3084 } | 2864 } |
3085 | 2865 |
3086 typedef struct { | 2866 typedef struct { |
3087 upb_inttable ref2; | 2867 upb_inttable ref2; |
3088 const upb_refcounted *obj; | 2868 const upb_refcounted *obj; |
3089 } check_state; | 2869 } check_state; |
3090 | 2870 |
3091 static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj, | 2871 static void visit_check(const upb_refcounted *obj, const upb_refcounted *subobj, |
3092 void *closure) { | 2872 void *closure) { |
3093 check_state *s = closure; | 2873 check_state *s = closure; |
3094 upb_inttable *ref2 = &s->ref2; | 2874 upb_inttable *ref2 = &s->ref2; |
3095 upb_value v; | 2875 upb_value v; |
3096 bool removed; | 2876 bool removed; |
3097 int32_t newcount; | 2877 int32_t newcount; |
3098 | 2878 |
3099 UPB_ASSERT(obj == s->obj); | 2879 assert(obj == s->obj); |
3100 UPB_ASSERT(subobj); | 2880 assert(subobj); |
3101 removed = upb_inttable_removeptr(ref2, subobj, &v); | 2881 removed = upb_inttable_removeptr(ref2, subobj, &v); |
3102 /* The following assertion will fail if the visit() function visits a subobj | 2882 /* The following assertion will fail if the visit() function visits a subobj |
3103 * that it did not have a ref2 on, or visits the same subobj too many times. *
/ | 2883 * that it did not have a ref2 on, or visits the same subobj too many times. *
/ |
3104 UPB_ASSERT(removed); | 2884 assert(removed); |
3105 newcount = upb_value_getint32(v) - 1; | 2885 newcount = upb_value_getint32(v) - 1; |
3106 if (newcount > 0) { | 2886 if (newcount > 0) { |
3107 upb_inttable_insert2(ref2, (uintptr_t)subobj, upb_value_int32(newcount), | 2887 upb_inttable_insert(ref2, (uintptr_t)subobj, upb_value_int32(newcount)); |
3108 &upb_alloc_debugrefs); | |
3109 } | 2888 } |
3110 } | 2889 } |
3111 | 2890 |
3112 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, | 2891 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, |
3113 void *closure) { | 2892 void *closure) { |
| 2893 bool ok; |
| 2894 |
3114 /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know | 2895 /* In DEBUG_REFS mode we know what existing ref2 refs there are, so we know |
3115 * exactly the set of nodes that visit() should visit. So we verify visit()'s | 2896 * exactly the set of nodes that visit() should visit. So we verify visit()'s |
3116 * correctness here. */ | 2897 * correctness here. */ |
3117 check_state state; | 2898 check_state state; |
3118 state.obj = r; | 2899 state.obj = r; |
3119 upb_inttable_init2(&state.ref2, UPB_CTYPE_INT32, &upb_alloc_debugrefs); | 2900 ok = upb_inttable_init(&state.ref2, UPB_CTYPE_INT32); |
| 2901 CHECK_OOM(ok); |
3120 getref2s(r, &state.ref2); | 2902 getref2s(r, &state.ref2); |
3121 | 2903 |
3122 /* This should visit any children in the ref2 table. */ | 2904 /* This should visit any children in the ref2 table. */ |
3123 if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state); | 2905 if (r->vtbl->visit) r->vtbl->visit(r, visit_check, &state); |
3124 | 2906 |
3125 /* This assertion will fail if the visit() function missed any children. */ | 2907 /* This assertion will fail if the visit() function missed any children. */ |
3126 UPB_ASSERT(upb_inttable_count(&state.ref2) == 0); | 2908 assert(upb_inttable_count(&state.ref2) == 0); |
3127 upb_inttable_uninit2(&state.ref2, &upb_alloc_debugrefs); | 2909 upb_inttable_uninit(&state.ref2); |
3128 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); | 2910 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); |
3129 } | 2911 } |
3130 | 2912 |
3131 static void trackinit(upb_refcounted *r) { | 2913 static bool trackinit(upb_refcounted *r) { |
3132 r->refs = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->refs)); | 2914 r->refs = malloc(sizeof(*r->refs)); |
3133 r->ref2s = upb_malloc(&upb_alloc_debugrefs, sizeof(*r->ref2s)); | 2915 r->ref2s = malloc(sizeof(*r->ref2s)); |
3134 upb_inttable_init2(r->refs, UPB_CTYPE_PTR, &upb_alloc_debugrefs); | 2916 if (!r->refs || !r->ref2s) goto err1; |
3135 upb_inttable_init2(r->ref2s, UPB_CTYPE_PTR, &upb_alloc_debugrefs); | 2917 |
| 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; |
3136 } | 2928 } |
3137 | 2929 |
3138 static void trackfree(const upb_refcounted *r) { | 2930 static void trackfree(const upb_refcounted *r) { |
3139 upb_inttable_uninit2(r->refs, &upb_alloc_debugrefs); | 2931 upb_inttable_uninit(r->refs); |
3140 upb_inttable_uninit2(r->ref2s, &upb_alloc_debugrefs); | 2932 upb_inttable_uninit(r->ref2s); |
3141 upb_free(&upb_alloc_debugrefs, r->refs); | 2933 free(r->refs); |
3142 upb_free(&upb_alloc_debugrefs, r->ref2s); | 2934 free(r->ref2s); |
3143 } | 2935 } |
3144 | 2936 |
3145 #else | 2937 #else |
3146 | 2938 |
3147 static void track(const upb_refcounted *r, const void *owner, bool ref2) { | 2939 static void track(const upb_refcounted *r, const void *owner, bool ref2) { |
3148 UPB_UNUSED(r); | 2940 UPB_UNUSED(r); |
3149 UPB_UNUSED(owner); | 2941 UPB_UNUSED(owner); |
3150 UPB_UNUSED(ref2); | 2942 UPB_UNUSED(ref2); |
3151 } | 2943 } |
3152 | 2944 |
3153 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { | 2945 static void untrack(const upb_refcounted *r, const void *owner, bool ref2) { |
3154 UPB_UNUSED(r); | 2946 UPB_UNUSED(r); |
3155 UPB_UNUSED(owner); | 2947 UPB_UNUSED(owner); |
3156 UPB_UNUSED(ref2); | 2948 UPB_UNUSED(ref2); |
3157 } | 2949 } |
3158 | 2950 |
3159 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { | 2951 static void checkref(const upb_refcounted *r, const void *owner, bool ref2) { |
3160 UPB_UNUSED(r); | 2952 UPB_UNUSED(r); |
3161 UPB_UNUSED(owner); | 2953 UPB_UNUSED(owner); |
3162 UPB_UNUSED(ref2); | 2954 UPB_UNUSED(ref2); |
3163 } | 2955 } |
3164 | 2956 |
3165 static void trackinit(upb_refcounted *r) { | 2957 static bool trackinit(upb_refcounted *r) { |
3166 UPB_UNUSED(r); | 2958 UPB_UNUSED(r); |
| 2959 return true; |
3167 } | 2960 } |
3168 | 2961 |
3169 static void trackfree(const upb_refcounted *r) { | 2962 static void trackfree(const upb_refcounted *r) { |
3170 UPB_UNUSED(r); | 2963 UPB_UNUSED(r); |
3171 } | 2964 } |
3172 | 2965 |
3173 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, | 2966 static void visit(const upb_refcounted *r, upb_refcounted_visit *v, |
3174 void *closure) { | 2967 void *closure) { |
3175 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); | 2968 if (r->vtbl->visit) r->vtbl->visit(r, v, closure); |
3176 } | 2969 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3223 | 3016 |
3224 static uint64_t trygetattr(const tarjan *t, const upb_refcounted *r) { | 3017 static uint64_t trygetattr(const tarjan *t, const upb_refcounted *r) { |
3225 upb_value v; | 3018 upb_value v; |
3226 return upb_inttable_lookupptr(&t->objattr, r, &v) ? | 3019 return upb_inttable_lookupptr(&t->objattr, r, &v) ? |
3227 upb_value_getuint64(v) : 0; | 3020 upb_value_getuint64(v) : 0; |
3228 } | 3021 } |
3229 | 3022 |
3230 static uint64_t getattr(const tarjan *t, const upb_refcounted *r) { | 3023 static uint64_t getattr(const tarjan *t, const upb_refcounted *r) { |
3231 upb_value v; | 3024 upb_value v; |
3232 bool found = upb_inttable_lookupptr(&t->objattr, r, &v); | 3025 bool found = upb_inttable_lookupptr(&t->objattr, r, &v); |
3233 UPB_ASSERT(found); | 3026 UPB_ASSERT_VAR(found, found); |
3234 return upb_value_getuint64(v); | 3027 return upb_value_getuint64(v); |
3235 } | 3028 } |
3236 | 3029 |
3237 static void setattr(tarjan *t, const upb_refcounted *r, uint64_t attr) { | 3030 static void setattr(tarjan *t, const upb_refcounted *r, uint64_t attr) { |
3238 upb_inttable_removeptr(&t->objattr, r, NULL); | 3031 upb_inttable_removeptr(&t->objattr, r, NULL); |
3239 upb_inttable_insertptr(&t->objattr, r, upb_value_uint64(attr)); | 3032 upb_inttable_insertptr(&t->objattr, r, upb_value_uint64(attr)); |
3240 } | 3033 } |
3241 | 3034 |
3242 static color_t color(tarjan *t, const upb_refcounted *r) { | 3035 static color_t color(tarjan *t, const upb_refcounted *r) { |
3243 return trygetattr(t, r) & 0x3; /* Color is always stored in the low 2 bits. *
/ | 3036 return trygetattr(t, r) & 0x3; /* Color is always stored in the low 2 bits. *
/ |
3244 } | 3037 } |
3245 | 3038 |
3246 static void set_gray(tarjan *t, const upb_refcounted *r) { | 3039 static void set_gray(tarjan *t, const upb_refcounted *r) { |
3247 UPB_ASSERT(color(t, r) == BLACK); | 3040 assert(color(t, r) == BLACK); |
3248 setattr(t, r, GRAY); | 3041 setattr(t, r, GRAY); |
3249 } | 3042 } |
3250 | 3043 |
3251 /* Pushes an obj onto the Tarjan stack and sets it to GREEN. */ | 3044 /* Pushes an obj onto the Tarjan stack and sets it to GREEN. */ |
3252 static void push(tarjan *t, const upb_refcounted *r) { | 3045 static void push(tarjan *t, const upb_refcounted *r) { |
3253 UPB_ASSERT(color(t, r) == BLACK || color(t, r) == GRAY); | 3046 assert(color(t, r) == BLACK || color(t, r) == GRAY); |
3254 /* This defines the attr layout for the GREEN state. "index" and "lowlink" | 3047 /* This defines the attr layout for the GREEN state. "index" and "lowlink" |
3255 * get 31 bits, which is plenty (limit of 2B objects frozen at a time). */ | 3048 * get 31 bits, which is plenty (limit of 2B objects frozen at a time). */ |
3256 setattr(t, r, GREEN | (t->index << 2) | (t->index << 33)); | 3049 setattr(t, r, GREEN | (t->index << 2) | (t->index << 33)); |
3257 if (++t->index == 0x80000000) { | 3050 if (++t->index == 0x80000000) { |
3258 upb_status_seterrmsg(t->status, "too many objects to freeze"); | 3051 upb_status_seterrmsg(t->status, "too many objects to freeze"); |
3259 err(t); | 3052 err(t); |
3260 } | 3053 } |
3261 upb_inttable_push(&t->stack, upb_value_ptr((void*)r)); | 3054 upb_inttable_push(&t->stack, upb_value_ptr((void*)r)); |
3262 } | 3055 } |
3263 | 3056 |
3264 /* Pops an obj from the Tarjan stack and sets it to WHITE, with a ptr to its | 3057 /* Pops an obj from the Tarjan stack and sets it to WHITE, with a ptr to its |
3265 * SCC group. */ | 3058 * SCC group. */ |
3266 static upb_refcounted *pop(tarjan *t) { | 3059 static upb_refcounted *pop(tarjan *t) { |
3267 upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack)); | 3060 upb_refcounted *r = upb_value_getptr(upb_inttable_pop(&t->stack)); |
3268 UPB_ASSERT(color(t, r) == GREEN); | 3061 assert(color(t, r) == GREEN); |
3269 /* This defines the attr layout for nodes in the WHITE state. | 3062 /* This defines the attr layout for nodes in the WHITE state. |
3270 * Top of group stack is [group, NULL]; we point at group. */ | 3063 * Top of group stack is [group, NULL]; we point at group. */ |
3271 setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8); | 3064 setattr(t, r, WHITE | (upb_inttable_count(&t->groups) - 2) << 8); |
3272 return r; | 3065 return r; |
3273 } | 3066 } |
3274 | 3067 |
3275 static void tarjan_newgroup(tarjan *t) { | 3068 static void tarjan_newgroup(tarjan *t) { |
3276 uint32_t *group = upb_gmalloc(sizeof(*group)); | 3069 uint32_t *group = malloc(sizeof(*group)); |
3277 if (!group) oom(t); | 3070 if (!group) oom(t); |
3278 /* Push group and empty group leader (we'll fill in leader later). */ | 3071 /* Push group and empty group leader (we'll fill in leader later). */ |
3279 if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) || | 3072 if (!upb_inttable_push(&t->groups, upb_value_ptr(group)) || |
3280 !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) { | 3073 !upb_inttable_push(&t->groups, upb_value_ptr(NULL))) { |
3281 upb_gfree(group); | 3074 free(group); |
3282 oom(t); | 3075 oom(t); |
3283 } | 3076 } |
3284 *group = 0; | 3077 *group = 0; |
3285 } | 3078 } |
3286 | 3079 |
3287 static uint32_t idx(tarjan *t, const upb_refcounted *r) { | 3080 static uint32_t idx(tarjan *t, const upb_refcounted *r) { |
3288 UPB_ASSERT(color(t, r) == GREEN); | 3081 assert(color(t, r) == GREEN); |
3289 return (getattr(t, r) >> 2) & 0x7FFFFFFF; | 3082 return (getattr(t, r) >> 2) & 0x7FFFFFFF; |
3290 } | 3083 } |
3291 | 3084 |
3292 static uint32_t lowlink(tarjan *t, const upb_refcounted *r) { | 3085 static uint32_t lowlink(tarjan *t, const upb_refcounted *r) { |
3293 if (color(t, r) == GREEN) { | 3086 if (color(t, r) == GREEN) { |
3294 return getattr(t, r) >> 33; | 3087 return getattr(t, r) >> 33; |
3295 } else { | 3088 } else { |
3296 return UINT32_MAX; | 3089 return UINT32_MAX; |
3297 } | 3090 } |
3298 } | 3091 } |
3299 | 3092 |
3300 static void set_lowlink(tarjan *t, const upb_refcounted *r, uint32_t lowlink) { | 3093 static void set_lowlink(tarjan *t, const upb_refcounted *r, uint32_t lowlink) { |
3301 UPB_ASSERT(color(t, r) == GREEN); | 3094 assert(color(t, r) == GREEN); |
3302 setattr(t, r, ((uint64_t)lowlink << 33) | (getattr(t, r) & 0x1FFFFFFFF)); | 3095 setattr(t, r, ((uint64_t)lowlink << 33) | (getattr(t, r) & 0x1FFFFFFFF)); |
3303 } | 3096 } |
3304 | 3097 |
3305 static uint32_t *group(tarjan *t, upb_refcounted *r) { | 3098 static uint32_t *group(tarjan *t, upb_refcounted *r) { |
3306 uint64_t groupnum; | 3099 uint64_t groupnum; |
3307 upb_value v; | 3100 upb_value v; |
3308 bool found; | 3101 bool found; |
3309 | 3102 |
3310 UPB_ASSERT(color(t, r) == WHITE); | 3103 assert(color(t, r) == WHITE); |
3311 groupnum = getattr(t, r) >> 8; | 3104 groupnum = getattr(t, r) >> 8; |
3312 found = upb_inttable_lookup(&t->groups, groupnum, &v); | 3105 found = upb_inttable_lookup(&t->groups, groupnum, &v); |
3313 UPB_ASSERT(found); | 3106 UPB_ASSERT_VAR(found, found); |
3314 return upb_value_getptr(v); | 3107 return upb_value_getptr(v); |
3315 } | 3108 } |
3316 | 3109 |
3317 /* If the group leader for this object's group has not previously been set, | 3110 /* If the group leader for this object's group has not previously been set, |
3318 * the given object is assigned to be its leader. */ | 3111 * the given object is assigned to be its leader. */ |
3319 static upb_refcounted *groupleader(tarjan *t, upb_refcounted *r) { | 3112 static upb_refcounted *groupleader(tarjan *t, upb_refcounted *r) { |
3320 uint64_t leader_slot; | 3113 uint64_t leader_slot; |
3321 upb_value v; | 3114 upb_value v; |
3322 bool found; | 3115 bool found; |
3323 | 3116 |
3324 UPB_ASSERT(color(t, r) == WHITE); | 3117 assert(color(t, r) == WHITE); |
3325 leader_slot = (getattr(t, r) >> 8) + 1; | 3118 leader_slot = (getattr(t, r) >> 8) + 1; |
3326 found = upb_inttable_lookup(&t->groups, leader_slot, &v); | 3119 found = upb_inttable_lookup(&t->groups, leader_slot, &v); |
3327 UPB_ASSERT(found); | 3120 UPB_ASSERT_VAR(found, found); |
3328 if (upb_value_getptr(v)) { | 3121 if (upb_value_getptr(v)) { |
3329 return upb_value_getptr(v); | 3122 return upb_value_getptr(v); |
3330 } else { | 3123 } else { |
3331 upb_inttable_remove(&t->groups, leader_slot, NULL); | 3124 upb_inttable_remove(&t->groups, leader_slot, NULL); |
3332 upb_inttable_insert(&t->groups, leader_slot, upb_value_ptr(r)); | 3125 upb_inttable_insert(&t->groups, leader_slot, upb_value_ptr(r)); |
3333 return r; | 3126 return r; |
3334 } | 3127 } |
3335 } | 3128 } |
3336 | 3129 |
3337 | 3130 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3377 ; | 3170 ; |
3378 } | 3171 } |
3379 } | 3172 } |
3380 | 3173 |
3381 | 3174 |
3382 /* freeze() ------------------------------------------------------------------*/ | 3175 /* freeze() ------------------------------------------------------------------*/ |
3383 | 3176 |
3384 static void crossref(const upb_refcounted *r, const upb_refcounted *subobj, | 3177 static void crossref(const upb_refcounted *r, const upb_refcounted *subobj, |
3385 void *_t) { | 3178 void *_t) { |
3386 tarjan *t = _t; | 3179 tarjan *t = _t; |
3387 UPB_ASSERT(color(t, r) > BLACK); | 3180 assert(color(t, r) > BLACK); |
3388 if (color(t, subobj) > BLACK && r->group != subobj->group) { | 3181 if (color(t, subobj) > BLACK && r->group != subobj->group) { |
3389 /* Previously this ref was not reflected in subobj->group because they | 3182 /* Previously this ref was not reflected in subobj->group because they |
3390 * were in the same group; now that they are split a ref must be taken. */ | 3183 * were in the same group; now that they are split a ref must be taken. */ |
3391 refgroup(subobj->group); | 3184 refgroup(subobj->group); |
3392 } | 3185 } |
3393 } | 3186 } |
3394 | 3187 |
3395 static bool freeze(upb_refcounted *const*roots, int n, upb_status *s, | 3188 static bool freeze(upb_refcounted *const*roots, int n, upb_status *s, |
3396 int maxdepth) { | 3189 int maxdepth) { |
3397 volatile bool ret = false; | 3190 volatile bool ret = false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3445 * change it to be the node we are currently operating on, so with a | 3238 * change it to be the node we are currently operating on, so with a |
3446 * while() loop we guarantee ourselves the chance to remove each node. *
/ | 3239 * while() loop we guarantee ourselves the chance to remove each node. *
/ |
3447 while (color(&t, obj->next) == WHITE && | 3240 while (color(&t, obj->next) == WHITE && |
3448 group(&t, obj->next) != obj->next->group) { | 3241 group(&t, obj->next) != obj->next->group) { |
3449 upb_refcounted *leader; | 3242 upb_refcounted *leader; |
3450 | 3243 |
3451 /* Remove from old group. */ | 3244 /* Remove from old group. */ |
3452 upb_refcounted *move = obj->next; | 3245 upb_refcounted *move = obj->next; |
3453 if (obj == move) { | 3246 if (obj == move) { |
3454 /* Removing the last object from a group. */ | 3247 /* Removing the last object from a group. */ |
3455 UPB_ASSERT(*obj->group == obj->individual_count); | 3248 assert(*obj->group == obj->individual_count); |
3456 upb_gfree(obj->group); | 3249 free(obj->group); |
3457 } else { | 3250 } else { |
3458 obj->next = move->next; | 3251 obj->next = move->next; |
3459 /* This may decrease to zero; we'll collect GRAY objects (if any) that | 3252 /* This may decrease to zero; we'll collect GRAY objects (if any) that |
3460 * remain in the group in the third pass. */ | 3253 * remain in the group in the third pass. */ |
3461 UPB_ASSERT(*move->group >= move->individual_count); | 3254 assert(*move->group >= move->individual_count); |
3462 *move->group -= move->individual_count; | 3255 *move->group -= move->individual_count; |
3463 } | 3256 } |
3464 | 3257 |
3465 /* Add to new group. */ | 3258 /* Add to new group. */ |
3466 leader = groupleader(&t, move); | 3259 leader = groupleader(&t, move); |
3467 if (move == leader) { | 3260 if (move == leader) { |
3468 /* First object added to new group is its leader. */ | 3261 /* First object added to new group is its leader. */ |
3469 move->group = group(&t, move); | 3262 move->group = group(&t, move); |
3470 move->next = move; | 3263 move->next = move; |
3471 *move->group = move->individual_count; | 3264 *move->group = move->individual_count; |
3472 } else { | 3265 } else { |
3473 /* Group already has at least one object in it. */ | 3266 /* Group already has at least one object in it. */ |
3474 UPB_ASSERT(leader->group == group(&t, move)); | 3267 assert(leader->group == group(&t, move)); |
3475 move->group = group(&t, move); | 3268 move->group = group(&t, move); |
3476 move->next = leader->next; | 3269 move->next = leader->next; |
3477 leader->next = move; | 3270 leader->next = move; |
3478 *move->group += move->individual_count; | 3271 *move->group += move->individual_count; |
3479 } | 3272 } |
3480 | 3273 |
3481 move->is_frozen = true; | 3274 move->is_frozen = true; |
3482 } | 3275 } |
3483 } | 3276 } |
3484 | 3277 |
(...skipping 17 matching lines...) Expand all Loading... |
3502 upb_inttable_begin(&iter, &t.objattr); | 3295 upb_inttable_begin(&iter, &t.objattr); |
3503 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) { | 3296 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) { |
3504 upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter); | 3297 upb_refcounted *obj = (upb_refcounted*)upb_inttable_iter_key(&iter); |
3505 if (obj->group == NULL || *obj->group == 0) { | 3298 if (obj->group == NULL || *obj->group == 0) { |
3506 if (obj->group) { | 3299 if (obj->group) { |
3507 upb_refcounted *o; | 3300 upb_refcounted *o; |
3508 | 3301 |
3509 /* We eagerly free() the group's count (since we can't easily determine | 3302 /* We eagerly free() the group's count (since we can't easily determine |
3510 * the group's remaining size it's the easiest way to ensure it gets | 3303 * the group's remaining size it's the easiest way to ensure it gets |
3511 * done). */ | 3304 * done). */ |
3512 upb_gfree(obj->group); | 3305 free(obj->group); |
3513 | 3306 |
3514 /* Visit to release ref2's (done in a separate pass since release_ref2 | 3307 /* Visit to release ref2's (done in a separate pass since release_ref2 |
3515 * depends on o->group being unmodified so it can test merged()). */ | 3308 * depends on o->group being unmodified so it can test merged()). */ |
3516 o = obj; | 3309 o = obj; |
3517 do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj); | 3310 do { visit(o, release_ref2, NULL); } while ((o = o->next) != obj); |
3518 | 3311 |
3519 /* Mark "group" fields as NULL so we know to free the objects later in | 3312 /* Mark "group" fields as NULL so we know to free the objects later in |
3520 * this loop, but also don't try to delete the group twice. */ | 3313 * this loop, but also don't try to delete the group twice. */ |
3521 o = obj; | 3314 o = obj; |
3522 do { o->group = NULL; } while ((o = o->next) != obj); | 3315 do { o->group = NULL; } while ((o = o->next) != obj); |
3523 } | 3316 } |
3524 freeobj(obj); | 3317 freeobj(obj); |
3525 } | 3318 } |
3526 } | 3319 } |
3527 | 3320 |
3528 err4: | 3321 err4: |
3529 if (!ret) { | 3322 if (!ret) { |
3530 upb_inttable_begin(&iter, &t.groups); | 3323 upb_inttable_begin(&iter, &t.groups); |
3531 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) | 3324 for(; !upb_inttable_done(&iter); upb_inttable_next(&iter)) |
3532 upb_gfree(upb_value_getptr(upb_inttable_iter_value(&iter))); | 3325 free(upb_value_getptr(upb_inttable_iter_value(&iter))); |
3533 } | 3326 } |
3534 upb_inttable_uninit(&t.groups); | 3327 upb_inttable_uninit(&t.groups); |
3535 err3: | 3328 err3: |
3536 upb_inttable_uninit(&t.stack); | 3329 upb_inttable_uninit(&t.stack); |
3537 err2: | 3330 err2: |
3538 upb_inttable_uninit(&t.objattr); | 3331 upb_inttable_uninit(&t.objattr); |
3539 err1: | 3332 err1: |
3540 return ret; | 3333 return ret; |
3541 } | 3334 } |
3542 | 3335 |
3543 | 3336 |
3544 /* Misc internal functions ***************************************************/ | 3337 /* Misc internal functions ***************************************************/ |
3545 | 3338 |
3546 static bool merged(const upb_refcounted *r, const upb_refcounted *r2) { | 3339 static bool merged(const upb_refcounted *r, const upb_refcounted *r2) { |
3547 return r->group == r2->group; | 3340 return r->group == r2->group; |
3548 } | 3341 } |
3549 | 3342 |
3550 static void merge(upb_refcounted *r, upb_refcounted *from) { | 3343 static void merge(upb_refcounted *r, upb_refcounted *from) { |
3551 upb_refcounted *base; | 3344 upb_refcounted *base; |
3552 upb_refcounted *tmp; | 3345 upb_refcounted *tmp; |
3553 | 3346 |
3554 if (merged(r, from)) return; | 3347 if (merged(r, from)) return; |
3555 *r->group += *from->group; | 3348 *r->group += *from->group; |
3556 upb_gfree(from->group); | 3349 free(from->group); |
3557 base = from; | 3350 base = from; |
3558 | 3351 |
3559 /* Set all refcount pointers in the "from" chain to the merged refcount. | 3352 /* Set all refcount pointers in the "from" chain to the merged refcount. |
3560 * | 3353 * |
3561 * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound | 3354 * TODO(haberman): this linear algorithm can result in an overall O(n^2) bound |
3562 * if the user continuously extends a group by one object. Prevent this by | 3355 * if the user continuously extends a group by one object. Prevent this by |
3563 * using one of the techniques in this paper: | 3356 * using one of the techniques in this paper: |
3564 * http://bioinfo.ict.ac.cn/~dbu/AlgorithmCourses/Lectures/Union-Find-Tarj
an.pdf */ | 3357 * ftp://www.ncedc.org/outgoing/geomorph/dino/orals/p245-tarjan.pdf */ |
3565 do { from->group = r->group; } while ((from = from->next) != base); | 3358 do { from->group = r->group; } while ((from = from->next) != base); |
3566 | 3359 |
3567 /* Merge the two circularly linked lists by swapping their next pointers. */ | 3360 /* Merge the two circularly linked lists by swapping their next pointers. */ |
3568 tmp = r->next; | 3361 tmp = r->next; |
3569 r->next = base->next; | 3362 r->next = base->next; |
3570 base->next = tmp; | 3363 base->next = tmp; |
3571 } | 3364 } |
3572 | 3365 |
3573 static void unref(const upb_refcounted *r); | 3366 static void unref(const upb_refcounted *r); |
3574 | 3367 |
3575 static void release_ref2(const upb_refcounted *obj, | 3368 static void release_ref2(const upb_refcounted *obj, |
3576 const upb_refcounted *subobj, | 3369 const upb_refcounted *subobj, |
3577 void *closure) { | 3370 void *closure) { |
3578 UPB_UNUSED(closure); | 3371 UPB_UNUSED(closure); |
3579 untrack(subobj, obj, true); | 3372 untrack(subobj, obj, true); |
3580 if (!merged(obj, subobj)) { | 3373 if (!merged(obj, subobj)) { |
3581 UPB_ASSERT(subobj->is_frozen); | 3374 assert(subobj->is_frozen); |
3582 unref(subobj); | 3375 unref(subobj); |
3583 } | 3376 } |
3584 } | 3377 } |
3585 | 3378 |
3586 static void unref(const upb_refcounted *r) { | 3379 static void unref(const upb_refcounted *r) { |
3587 if (unrefgroup(r->group)) { | 3380 if (unrefgroup(r->group)) { |
3588 const upb_refcounted *o; | 3381 const upb_refcounted *o; |
3589 | 3382 |
3590 upb_gfree(r->group); | 3383 free(r->group); |
3591 | 3384 |
3592 /* In two passes, since release_ref2 needs a guarantee that any subobjs | 3385 /* In two passes, since release_ref2 needs a guarantee that any subobjs |
3593 * are alive. */ | 3386 * are alive. */ |
3594 o = r; | 3387 o = r; |
3595 do { visit(o, release_ref2, NULL); } while((o = o->next) != r); | 3388 do { visit(o, release_ref2, NULL); } while((o = o->next) != r); |
3596 | 3389 |
3597 o = r; | 3390 o = r; |
3598 do { | 3391 do { |
3599 const upb_refcounted *next = o->next; | 3392 const upb_refcounted *next = o->next; |
3600 UPB_ASSERT(o->is_frozen || o->individual_count == 0); | 3393 assert(o->is_frozen || o->individual_count == 0); |
3601 freeobj((upb_refcounted*)o); | 3394 freeobj((upb_refcounted*)o); |
3602 o = next; | 3395 o = next; |
3603 } while(o != r); | 3396 } while(o != r); |
3604 } | 3397 } |
3605 } | 3398 } |
3606 | 3399 |
3607 static void freeobj(upb_refcounted *o) { | 3400 static void freeobj(upb_refcounted *o) { |
3608 trackfree(o); | 3401 trackfree(o); |
3609 o->vtbl->free((upb_refcounted*)o); | 3402 o->vtbl->free((upb_refcounted*)o); |
3610 } | 3403 } |
3611 | 3404 |
3612 | 3405 |
3613 /* Public interface ***********************************************************/ | 3406 /* Public interface ***********************************************************/ |
3614 | 3407 |
3615 bool upb_refcounted_init(upb_refcounted *r, | 3408 bool upb_refcounted_init(upb_refcounted *r, |
3616 const struct upb_refcounted_vtbl *vtbl, | 3409 const struct upb_refcounted_vtbl *vtbl, |
3617 const void *owner) { | 3410 const void *owner) { |
3618 #ifndef NDEBUG | 3411 #ifndef NDEBUG |
3619 /* Endianness check. This is unrelated to upb_refcounted, it's just a | 3412 /* Endianness check. This is unrelated to upb_refcounted, it's just a |
3620 * convenient place to put the check that we can be assured will run for | 3413 * convenient place to put the check that we can be assured will run for |
3621 * basically every program using upb. */ | 3414 * basically every program using upb. */ |
3622 const int x = 1; | 3415 const int x = 1; |
3623 #ifdef UPB_BIG_ENDIAN | 3416 #ifdef UPB_BIG_ENDIAN |
3624 UPB_ASSERT(*(char*)&x != 1); | 3417 assert(*(char*)&x != 1); |
3625 #else | 3418 #else |
3626 UPB_ASSERT(*(char*)&x == 1); | 3419 assert(*(char*)&x == 1); |
3627 #endif | 3420 #endif |
3628 #endif | 3421 #endif |
3629 | 3422 |
3630 r->next = r; | 3423 r->next = r; |
3631 r->vtbl = vtbl; | 3424 r->vtbl = vtbl; |
3632 r->individual_count = 0; | 3425 r->individual_count = 0; |
3633 r->is_frozen = false; | 3426 r->is_frozen = false; |
3634 r->group = upb_gmalloc(sizeof(*r->group)); | 3427 r->group = malloc(sizeof(*r->group)); |
3635 if (!r->group) return false; | 3428 if (!r->group) return false; |
3636 *r->group = 0; | 3429 *r->group = 0; |
3637 trackinit(r); | 3430 if (!trackinit(r)) { |
| 3431 free(r->group); |
| 3432 return false; |
| 3433 } |
3638 upb_refcounted_ref(r, owner); | 3434 upb_refcounted_ref(r, owner); |
3639 return true; | 3435 return true; |
3640 } | 3436 } |
3641 | 3437 |
3642 bool upb_refcounted_isfrozen(const upb_refcounted *r) { | 3438 bool upb_refcounted_isfrozen(const upb_refcounted *r) { |
3643 return r->is_frozen; | 3439 return r->is_frozen; |
3644 } | 3440 } |
3645 | 3441 |
3646 void upb_refcounted_ref(const upb_refcounted *r, const void *owner) { | 3442 void upb_refcounted_ref(const upb_refcounted *r, const void *owner) { |
3647 track(r, owner, false); | 3443 track(r, owner, false); |
3648 if (!r->is_frozen) | 3444 if (!r->is_frozen) |
3649 ((upb_refcounted*)r)->individual_count++; | 3445 ((upb_refcounted*)r)->individual_count++; |
3650 refgroup(r->group); | 3446 refgroup(r->group); |
3651 } | 3447 } |
3652 | 3448 |
3653 void upb_refcounted_unref(const upb_refcounted *r, const void *owner) { | 3449 void upb_refcounted_unref(const upb_refcounted *r, const void *owner) { |
3654 untrack(r, owner, false); | 3450 untrack(r, owner, false); |
3655 if (!r->is_frozen) | 3451 if (!r->is_frozen) |
3656 ((upb_refcounted*)r)->individual_count--; | 3452 ((upb_refcounted*)r)->individual_count--; |
3657 unref(r); | 3453 unref(r); |
3658 } | 3454 } |
3659 | 3455 |
3660 void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from) { | 3456 void upb_refcounted_ref2(const upb_refcounted *r, upb_refcounted *from) { |
3661 UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */ | 3457 assert(!from->is_frozen); /* Non-const pointer implies this. */ |
3662 track(r, from, true); | 3458 track(r, from, true); |
3663 if (r->is_frozen) { | 3459 if (r->is_frozen) { |
3664 refgroup(r->group); | 3460 refgroup(r->group); |
3665 } else { | 3461 } else { |
3666 merge((upb_refcounted*)r, from); | 3462 merge((upb_refcounted*)r, from); |
3667 } | 3463 } |
3668 } | 3464 } |
3669 | 3465 |
3670 void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from) { | 3466 void upb_refcounted_unref2(const upb_refcounted *r, upb_refcounted *from) { |
3671 UPB_ASSERT(!from->is_frozen); /* Non-const pointer implies this. */ | 3467 assert(!from->is_frozen); /* Non-const pointer implies this. */ |
3672 untrack(r, from, true); | 3468 untrack(r, from, true); |
3673 if (r->is_frozen) { | 3469 if (r->is_frozen) { |
3674 unref(r); | 3470 unref(r); |
3675 } else { | 3471 } else { |
3676 UPB_ASSERT(merged(r, from)); | 3472 assert(merged(r, from)); |
3677 } | 3473 } |
3678 } | 3474 } |
3679 | 3475 |
3680 void upb_refcounted_donateref( | 3476 void upb_refcounted_donateref( |
3681 const upb_refcounted *r, const void *from, const void *to) { | 3477 const upb_refcounted *r, const void *from, const void *to) { |
3682 UPB_ASSERT(from != to); | 3478 assert(from != to); |
3683 if (to != NULL) | 3479 if (to != NULL) |
3684 upb_refcounted_ref(r, to); | 3480 upb_refcounted_ref(r, to); |
3685 if (from != NULL) | 3481 if (from != NULL) |
3686 upb_refcounted_unref(r, from); | 3482 upb_refcounted_unref(r, from); |
3687 } | 3483 } |
3688 | 3484 |
3689 void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) { | 3485 void upb_refcounted_checkref(const upb_refcounted *r, const void *owner) { |
3690 checkref(r, owner, false); | 3486 checkref(r, owner, false); |
3691 } | 3487 } |
3692 | 3488 |
3693 bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s, | 3489 bool upb_refcounted_freeze(upb_refcounted *const*roots, int n, upb_status *s, |
3694 int maxdepth) { | 3490 int maxdepth) { |
3695 int i; | 3491 int i; |
3696 bool ret; | |
3697 for (i = 0; i < n; i++) { | 3492 for (i = 0; i < n; i++) { |
3698 UPB_ASSERT(!roots[i]->is_frozen); | 3493 assert(!roots[i]->is_frozen); |
3699 } | 3494 } |
3700 ret = freeze(roots, n, s, maxdepth); | 3495 return freeze(roots, n, s, maxdepth); |
3701 UPB_ASSERT(!s || ret == upb_ok(s)); | |
3702 return ret; | |
3703 } | 3496 } |
3704 | 3497 |
3705 | 3498 |
| 3499 #include <stdlib.h> |
| 3500 |
3706 /* Fallback implementation if the shim is not specialized by the JIT. */ | 3501 /* Fallback implementation if the shim is not specialized by the JIT. */ |
3707 #define SHIM_WRITER(type, ctype) \ | 3502 #define SHIM_WRITER(type, ctype) \ |
3708 bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \ | 3503 bool upb_shim_set ## type (void *c, const void *hd, ctype val) { \ |
3709 uint8_t *m = c; \ | 3504 uint8_t *m = c; \ |
3710 const upb_shim_data *d = hd; \ | 3505 const upb_shim_data *d = hd; \ |
3711 if (d->hasbit > 0) \ | 3506 if (d->hasbit > 0) \ |
3712 *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ | 3507 *(uint8_t*)&m[d->hasbit / 8] |= 1 << (d->hasbit % 8); \ |
3713 *(ctype*)&m[d->offset] = val; \ | 3508 *(ctype*)&m[d->offset] = val; \ |
3714 return true; \ | 3509 return true; \ |
3715 } \ | 3510 } \ |
3716 | 3511 |
3717 SHIM_WRITER(double, double) | 3512 SHIM_WRITER(double, double) |
3718 SHIM_WRITER(float, float) | 3513 SHIM_WRITER(float, float) |
3719 SHIM_WRITER(int32, int32_t) | 3514 SHIM_WRITER(int32, int32_t) |
3720 SHIM_WRITER(int64, int64_t) | 3515 SHIM_WRITER(int64, int64_t) |
3721 SHIM_WRITER(uint32, uint32_t) | 3516 SHIM_WRITER(uint32, uint32_t) |
3722 SHIM_WRITER(uint64, uint64_t) | 3517 SHIM_WRITER(uint64, uint64_t) |
3723 SHIM_WRITER(bool, bool) | 3518 SHIM_WRITER(bool, bool) |
3724 #undef SHIM_WRITER | 3519 #undef SHIM_WRITER |
3725 | 3520 |
3726 bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, | 3521 bool upb_shim_set(upb_handlers *h, const upb_fielddef *f, size_t offset, |
3727 int32_t hasbit) { | 3522 int32_t hasbit) { |
3728 upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; | 3523 upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER; |
3729 bool ok; | 3524 bool ok; |
3730 | 3525 |
3731 upb_shim_data *d = upb_gmalloc(sizeof(*d)); | 3526 upb_shim_data *d = malloc(sizeof(*d)); |
3732 if (!d) return false; | 3527 if (!d) return false; |
3733 d->offset = offset; | 3528 d->offset = offset; |
3734 d->hasbit = hasbit; | 3529 d->hasbit = hasbit; |
3735 | 3530 |
3736 upb_handlerattr_sethandlerdata(&attr, d); | 3531 upb_handlerattr_sethandlerdata(&attr, d); |
3737 upb_handlerattr_setalwaysok(&attr, true); | 3532 upb_handlerattr_setalwaysok(&attr, true); |
3738 upb_handlers_addcleanup(h, d, upb_gfree); | 3533 upb_handlers_addcleanup(h, d, free); |
3739 | 3534 |
3740 #define TYPE(u, l) \ | 3535 #define TYPE(u, l) \ |
3741 case UPB_TYPE_##u: \ | 3536 case UPB_TYPE_##u: \ |
3742 ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break; | 3537 ok = upb_handlers_set##l(h, f, upb_shim_set##l, &attr); break; |
3743 | 3538 |
3744 ok = false; | 3539 ok = false; |
3745 | 3540 |
3746 switch (upb_fielddef_type(f)) { | 3541 switch (upb_fielddef_type(f)) { |
3747 TYPE(INT64, int64); | 3542 TYPE(INT64, int64); |
3748 TYPE(INT32, int32); | 3543 TYPE(INT32, int32); |
3749 TYPE(ENUM, int32); | 3544 TYPE(ENUM, int32); |
3750 TYPE(UINT64, uint64); | 3545 TYPE(UINT64, uint64); |
3751 TYPE(UINT32, uint32); | 3546 TYPE(UINT32, uint32); |
3752 TYPE(DOUBLE, double); | 3547 TYPE(DOUBLE, double); |
3753 TYPE(FLOAT, float); | 3548 TYPE(FLOAT, float); |
3754 TYPE(BOOL, bool); | 3549 TYPE(BOOL, bool); |
3755 default: UPB_ASSERT(false); break; | 3550 default: assert(false); break; |
3756 } | 3551 } |
3757 #undef TYPE | 3552 #undef TYPE |
3758 | 3553 |
3759 upb_handlerattr_uninit(&attr); | 3554 upb_handlerattr_uninit(&attr); |
3760 return ok; | 3555 return ok; |
3761 } | 3556 } |
3762 | 3557 |
3763 const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, | 3558 const upb_shim_data *upb_shim_getdata(const upb_handlers *h, upb_selector_t s, |
3764 upb_fieldtype_t *type) { | 3559 upb_fieldtype_t *type) { |
3765 upb_func *f = upb_handlers_gethandler(h, s); | 3560 upb_func *f = upb_handlers_gethandler(h, s); |
(...skipping 13 matching lines...) Expand all Loading... |
3779 } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) { | 3574 } else if ((upb_bool_handlerfunc*)f == upb_shim_setbool) { |
3780 *type = UPB_TYPE_BOOL; | 3575 *type = UPB_TYPE_BOOL; |
3781 } else { | 3576 } else { |
3782 return NULL; | 3577 return NULL; |
3783 } | 3578 } |
3784 | 3579 |
3785 return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s); | 3580 return (const upb_shim_data*)upb_handlers_gethandlerdata(h, s); |
3786 } | 3581 } |
3787 | 3582 |
3788 | 3583 |
| 3584 #include <stdlib.h> |
3789 #include <string.h> | 3585 #include <string.h> |
3790 | 3586 |
3791 static void upb_symtab_free(upb_refcounted *r) { | 3587 static void upb_symtab_free(upb_refcounted *r) { |
3792 upb_symtab *s = (upb_symtab*)r; | 3588 upb_symtab *s = (upb_symtab*)r; |
3793 upb_strtable_iter i; | 3589 upb_strtable_iter i; |
3794 upb_strtable_begin(&i, &s->symtab); | 3590 upb_strtable_begin(&i, &s->symtab); |
3795 for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { | 3591 for (; !upb_strtable_done(&i); upb_strtable_next(&i)) { |
3796 const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i)); | 3592 const upb_def *def = upb_value_getptr(upb_strtable_iter_value(&i)); |
3797 upb_def_unref(def, s); | 3593 upb_def_unref(def, s); |
3798 } | 3594 } |
3799 upb_strtable_uninit(&s->symtab); | 3595 upb_strtable_uninit(&s->symtab); |
3800 upb_gfree(s); | 3596 free(s); |
3801 } | 3597 } |
3802 | 3598 |
| 3599 |
3803 upb_symtab *upb_symtab_new(const void *owner) { | 3600 upb_symtab *upb_symtab_new(const void *owner) { |
3804 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free}; | 3601 static const struct upb_refcounted_vtbl vtbl = {NULL, &upb_symtab_free}; |
3805 | 3602 upb_symtab *s = malloc(sizeof(*s)); |
3806 upb_symtab *s = upb_gmalloc(sizeof(*s)); | |
3807 if (!s) { | |
3808 return NULL; | |
3809 } | |
3810 | |
3811 upb_refcounted_init(upb_symtab_upcast_mutable(s), &vtbl, owner); | 3603 upb_refcounted_init(upb_symtab_upcast_mutable(s), &vtbl, owner); |
3812 upb_strtable_init(&s->symtab, UPB_CTYPE_PTR); | 3604 upb_strtable_init(&s->symtab, UPB_CTYPE_PTR); |
3813 return s; | 3605 return s; |
3814 } | 3606 } |
3815 | 3607 |
3816 void upb_symtab_freeze(upb_symtab *s) { | 3608 void upb_symtab_freeze(upb_symtab *s) { |
3817 upb_refcounted *r; | 3609 upb_refcounted *r; |
3818 bool ok; | 3610 bool ok; |
3819 | 3611 |
3820 UPB_ASSERT(!upb_symtab_isfrozen(s)); | 3612 assert(!upb_symtab_isfrozen(s)); |
3821 r = upb_symtab_upcast_mutable(s); | 3613 r = upb_symtab_upcast_mutable(s); |
3822 /* The symtab does not take ref2's (see refcounted.h) on the defs, because | 3614 /* The symtab does not take ref2's (see refcounted.h) on the defs, because |
3823 * defs cannot refer back to the table and therefore cannot create cycles. So | 3615 * defs cannot refer back to the table and therefore cannot create cycles. So |
3824 * 0 will suffice for maxdepth here. */ | 3616 * 0 will suffice for maxdepth here. */ |
3825 ok = upb_refcounted_freeze(&r, 1, NULL, 0); | 3617 ok = upb_refcounted_freeze(&r, 1, NULL, 0); |
3826 UPB_ASSERT(ok); | 3618 UPB_ASSERT_VAR(ok, ok); |
3827 } | 3619 } |
3828 | 3620 |
3829 const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) { | 3621 const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) { |
3830 upb_value v; | 3622 upb_value v; |
3831 upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ? | 3623 upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ? |
3832 upb_value_getptr(v) : NULL; | 3624 upb_value_getptr(v) : NULL; |
3833 return ret; | 3625 return ret; |
3834 } | 3626 } |
3835 | 3627 |
3836 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { | 3628 const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { |
(...skipping 17 matching lines...) Expand all Loading... |
3854 if(strlen(sym) == 0) return NULL; | 3646 if(strlen(sym) == 0) return NULL; |
3855 if(sym[0] == '.') { | 3647 if(sym[0] == '.') { |
3856 /* Symbols starting with '.' are absolute, so we do a single lookup. | 3648 /* Symbols starting with '.' are absolute, so we do a single lookup. |
3857 * Slice to omit the leading '.' */ | 3649 * Slice to omit the leading '.' */ |
3858 upb_value v; | 3650 upb_value v; |
3859 return upb_strtable_lookup(t, sym + 1, &v) ? upb_value_getptr(v) : NULL; | 3651 return upb_strtable_lookup(t, sym + 1, &v) ? upb_value_getptr(v) : NULL; |
3860 } else { | 3652 } else { |
3861 /* Remove components from base until we find an entry or run out. | 3653 /* Remove components from base until we find an entry or run out. |
3862 * TODO: This branch is totally broken, but currently not used. */ | 3654 * TODO: This branch is totally broken, but currently not used. */ |
3863 (void)base; | 3655 (void)base; |
3864 UPB_ASSERT(false); | 3656 assert(false); |
3865 return NULL; | 3657 return NULL; |
3866 } | 3658 } |
3867 } | 3659 } |
3868 | 3660 |
3869 const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, | 3661 const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, |
3870 const char *sym) { | 3662 const char *sym) { |
3871 upb_def *ret = upb_resolvename(&s->symtab, base, sym); | 3663 upb_def *ret = upb_resolvename(&s->symtab, base, sym); |
3872 return ret; | 3664 return ret; |
3873 } | 3665 } |
3874 | 3666 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3916 if (upb_inttable_lookupptr(seen, memoize_key, &v)) | 3708 if (upb_inttable_lookupptr(seen, memoize_key, &v)) |
3917 return upb_value_getbool(v); | 3709 return upb_value_getbool(v); |
3918 | 3710 |
3919 /* Visit submessages for all messages in the SCC. */ | 3711 /* Visit submessages for all messages in the SCC. */ |
3920 need_dup = false; | 3712 need_dup = false; |
3921 base = def; | 3713 base = def; |
3922 do { | 3714 do { |
3923 upb_value v; | 3715 upb_value v; |
3924 const upb_msgdef *m; | 3716 const upb_msgdef *m; |
3925 | 3717 |
3926 UPB_ASSERT(upb_def_isfrozen(def)); | 3718 assert(upb_def_isfrozen(def)); |
3927 if (def->type == UPB_DEF_FIELD) continue; | 3719 if (def->type == UPB_DEF_FIELD) continue; |
3928 if (upb_strtable_lookup(addtab, upb_def_fullname(def), &v)) { | 3720 if (upb_strtable_lookup(addtab, upb_def_fullname(def), &v)) { |
3929 need_dup = true; | 3721 need_dup = true; |
3930 } | 3722 } |
3931 | 3723 |
3932 /* For messages, continue the recursion by visiting all subdefs, but only | 3724 /* For messages, continue the recursion by visiting all subdefs, but only |
3933 * ones in different SCCs. */ | 3725 * ones in different SCCs. */ |
3934 m = upb_dyncast_msgdef(def); | 3726 m = upb_dyncast_msgdef(def); |
3935 if (m) { | 3727 if (m) { |
3936 upb_msg_field_iter i; | 3728 upb_msg_field_iter i; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3974 upb_inttable_insertptr(seen, memoize_key, upb_value_bool(need_dup)); | 3766 upb_inttable_insertptr(seen, memoize_key, upb_value_bool(need_dup)); |
3975 return need_dup; | 3767 return need_dup; |
3976 | 3768 |
3977 oom: | 3769 oom: |
3978 upb_status_seterrmsg(s, "out of memory"); | 3770 upb_status_seterrmsg(s, "out of memory"); |
3979 return false; | 3771 return false; |
3980 } | 3772 } |
3981 | 3773 |
3982 /* TODO(haberman): we need a lot more testing of error conditions. | 3774 /* TODO(haberman): we need a lot more testing of error conditions. |
3983 * The came_from_user stuff in particular is not tested. */ | 3775 * The came_from_user stuff in particular is not tested. */ |
3984 static bool symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, | 3776 bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, int n, void *ref_donor, |
3985 void *ref_donor, upb_refcounted *freeze_also, | 3777 upb_status *status) { |
3986 upb_status *status) { | 3778 int i; |
3987 size_t i; | |
3988 size_t add_n; | |
3989 size_t freeze_n; | |
3990 upb_strtable_iter iter; | 3779 upb_strtable_iter iter; |
3991 upb_refcounted **add_objs = NULL; | |
3992 upb_def **add_defs = NULL; | 3780 upb_def **add_defs = NULL; |
3993 size_t add_objs_size; | |
3994 upb_strtable addtab; | 3781 upb_strtable addtab; |
3995 upb_inttable seen; | 3782 upb_inttable seen; |
3996 | 3783 |
3997 if (n == 0 && !freeze_also) { | 3784 assert(!upb_symtab_isfrozen(s)); |
3998 return true; | |
3999 } | |
4000 | |
4001 UPB_ASSERT(!upb_symtab_isfrozen(s)); | |
4002 if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) { | 3785 if (!upb_strtable_init(&addtab, UPB_CTYPE_PTR)) { |
4003 upb_status_seterrmsg(status, "out of memory"); | 3786 upb_status_seterrmsg(status, "out of memory"); |
4004 return false; | 3787 return false; |
4005 } | 3788 } |
4006 | 3789 |
4007 /* Add new defs to our "add" set. */ | 3790 /* Add new defs to our "add" set. */ |
4008 for (i = 0; i < n; i++) { | 3791 for (i = 0; i < n; i++) { |
4009 upb_def *def = defs[i]; | 3792 upb_def *def = defs[i]; |
4010 const char *fullname; | 3793 const char *fullname; |
4011 upb_fielddef *f; | 3794 upb_fielddef *f; |
4012 | 3795 |
4013 if (upb_def_isfrozen(def)) { | 3796 if (upb_def_isfrozen(def)) { |
4014 upb_status_seterrmsg(status, "added defs must be mutable"); | 3797 upb_status_seterrmsg(status, "added defs must be mutable"); |
4015 goto err; | 3798 goto err; |
4016 } | 3799 } |
4017 UPB_ASSERT(!upb_def_isfrozen(def)); | 3800 assert(!upb_def_isfrozen(def)); |
4018 fullname = upb_def_fullname(def); | 3801 fullname = upb_def_fullname(def); |
4019 if (!fullname) { | 3802 if (!fullname) { |
4020 upb_status_seterrmsg( | 3803 upb_status_seterrmsg( |
4021 status, "Anonymous defs cannot be added to a symtab"); | 3804 status, "Anonymous defs cannot be added to a symtab"); |
4022 goto err; | 3805 goto err; |
4023 } | 3806 } |
4024 | 3807 |
4025 f = upb_dyncast_fielddef_mutable(def); | 3808 f = upb_dyncast_fielddef_mutable(def); |
4026 | 3809 |
4027 if (f) { | 3810 if (f) { |
(...skipping 23 matching lines...) Expand all Loading... |
4051 for (i = 0; i < n; i++) { | 3834 for (i = 0; i < n; i++) { |
4052 upb_def *def = defs[i]; | 3835 upb_def *def = defs[i]; |
4053 upb_fielddef *f = upb_dyncast_fielddef_mutable(def); | 3836 upb_fielddef *f = upb_dyncast_fielddef_mutable(def); |
4054 const char *msgname; | 3837 const char *msgname; |
4055 upb_value v; | 3838 upb_value v; |
4056 upb_msgdef *m; | 3839 upb_msgdef *m; |
4057 | 3840 |
4058 if (!f) continue; | 3841 if (!f) continue; |
4059 msgname = upb_fielddef_containingtypename(f); | 3842 msgname = upb_fielddef_containingtypename(f); |
4060 /* We validated this earlier in this function. */ | 3843 /* We validated this earlier in this function. */ |
4061 UPB_ASSERT(msgname); | 3844 assert(msgname); |
4062 | 3845 |
4063 /* If the extendee name is absolutely qualified, move past the initial ".". | 3846 /* If the extendee name is absolutely qualified, move past the initial ".". |
4064 * TODO(haberman): it is not obvious what it would mean if this was not | 3847 * TODO(haberman): it is not obvious what it would mean if this was not |
4065 * absolutely qualified. */ | 3848 * absolutely qualified. */ |
4066 if (msgname[0] == '.') { | 3849 if (msgname[0] == '.') { |
4067 msgname++; | 3850 msgname++; |
4068 } | 3851 } |
4069 | 3852 |
4070 if (upb_strtable_lookup(&addtab, msgname, &v)) { | 3853 if (upb_strtable_lookup(&addtab, msgname, &v)) { |
4071 /* Extendee is in the set of defs the user asked us to add. */ | 3854 /* 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... |
4132 upb_status_seterrf( | 3915 upb_status_seterrf( |
4133 status, "couldn't resolve name '%s' in message '%s'", name, base); | 3916 status, "couldn't resolve name '%s' in message '%s'", name, base); |
4134 goto err; | 3917 goto err; |
4135 } else if (!upb_fielddef_setsubdef(f, subdef, status)) { | 3918 } else if (!upb_fielddef_setsubdef(f, subdef, status)) { |
4136 goto err; | 3919 goto err; |
4137 } | 3920 } |
4138 } | 3921 } |
4139 } | 3922 } |
4140 } | 3923 } |
4141 | 3924 |
4142 /* We need an array of the defs in addtab, for passing to | 3925 /* We need an array of the defs in addtab, for passing to upb_def_freeze. */ |
4143 * upb_refcounted_freeze(). */ | 3926 add_defs = malloc(sizeof(void*) * upb_strtable_count(&addtab)); |
4144 add_objs_size = upb_strtable_count(&addtab); | 3927 if (add_defs == NULL) goto oom_err; |
4145 if (freeze_also) { | 3928 upb_strtable_begin(&iter, &addtab); |
4146 add_objs_size++; | 3929 for (n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { |
| 3930 add_defs[n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); |
4147 } | 3931 } |
4148 | 3932 |
4149 add_defs = upb_gmalloc(sizeof(void*) * add_objs_size); | 3933 if (!upb_def_freeze(add_defs, n, status)) goto err; |
4150 if (add_defs == NULL) goto oom_err; | |
4151 upb_strtable_begin(&iter, &addtab); | |
4152 for (add_n = 0; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { | |
4153 add_defs[add_n++] = upb_value_getptr(upb_strtable_iter_value(&iter)); | |
4154 } | |
4155 | |
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 } | |
4174 | 3934 |
4175 /* This must be delayed until all errors have been detected, since error | 3935 /* This must be delayed until all errors have been detected, since error |
4176 * recovery code uses this table to cleanup defs. */ | 3936 * recovery code uses this table to cleanup defs. */ |
4177 upb_strtable_uninit(&addtab); | 3937 upb_strtable_uninit(&addtab); |
4178 | 3938 |
4179 /* TODO(haberman) we don't properly handle errors after this point (like | 3939 /* TODO(haberman) we don't properly handle errors after this point (like |
4180 * OOM in upb_strtable_insert() below). */ | 3940 * OOM in upb_strtable_insert() below). */ |
4181 for (i = 0; i < add_n; i++) { | 3941 for (i = 0; i < n; i++) { |
4182 upb_def *def = (upb_def*)add_objs[i]; | 3942 upb_def *def = add_defs[i]; |
4183 const char *name = upb_def_fullname(def); | 3943 const char *name = upb_def_fullname(def); |
4184 upb_value v; | 3944 upb_value v; |
4185 bool success; | 3945 bool success; |
4186 | 3946 |
4187 if (upb_strtable_remove(&s->symtab, name, &v)) { | 3947 if (upb_strtable_remove(&s->symtab, name, &v)) { |
4188 const upb_def *def = upb_value_getptr(v); | 3948 const upb_def *def = upb_value_getptr(v); |
4189 upb_def_unref(def, s); | 3949 upb_def_unref(def, s); |
4190 } | 3950 } |
4191 success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def)); | 3951 success = upb_strtable_insert(&s->symtab, name, upb_value_ptr(def)); |
4192 UPB_ASSERT(success == true); | 3952 UPB_ASSERT_VAR(success, success == true); |
4193 } | 3953 } |
4194 upb_gfree(add_defs); | 3954 free(add_defs); |
4195 return true; | 3955 return true; |
4196 | 3956 |
4197 oom_err: | 3957 oom_err: |
4198 upb_status_seterrmsg(status, "out of memory"); | 3958 upb_status_seterrmsg(status, "out of memory"); |
4199 err: { | 3959 err: { |
4200 /* For defs the user passed in, we need to donate the refs back. For defs | 3960 /* For defs the user passed in, we need to donate the refs back. For defs |
4201 * we dup'd, we need to just unref them. */ | 3961 * we dup'd, we need to just unref them. */ |
4202 upb_strtable_begin(&iter, &addtab); | 3962 upb_strtable_begin(&iter, &addtab); |
4203 for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { | 3963 for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) { |
4204 upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter)); | 3964 upb_def *def = upb_value_getptr(upb_strtable_iter_value(&iter)); |
4205 bool came_from_user = def->came_from_user; | 3965 bool came_from_user = def->came_from_user; |
4206 def->came_from_user = false; | 3966 def->came_from_user = false; |
4207 if (came_from_user) { | 3967 if (came_from_user) { |
4208 upb_def_donateref(def, s, ref_donor); | 3968 upb_def_donateref(def, s, ref_donor); |
4209 } else { | 3969 } else { |
4210 upb_def_unref(def, s); | 3970 upb_def_unref(def, s); |
4211 } | 3971 } |
4212 } | 3972 } |
4213 } | 3973 } |
4214 upb_strtable_uninit(&addtab); | 3974 upb_strtable_uninit(&addtab); |
4215 upb_gfree(add_defs); | 3975 free(add_defs); |
4216 UPB_ASSERT(!upb_ok(status)); | 3976 assert(!upb_ok(status)); |
4217 return false; | 3977 return false; |
4218 } | 3978 } |
4219 | 3979 |
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 | |
4249 /* Iteration. */ | 3980 /* Iteration. */ |
4250 | 3981 |
4251 static void advance_to_matching(upb_symtab_iter *iter) { | 3982 static void advance_to_matching(upb_symtab_iter *iter) { |
4252 if (iter->type == UPB_DEF_ANY) | 3983 if (iter->type == UPB_DEF_ANY) |
4253 return; | 3984 return; |
4254 | 3985 |
4255 while (!upb_strtable_done(&iter->iter) && | 3986 while (!upb_strtable_done(&iter->iter) && |
4256 iter->type != upb_symtab_iter_def(iter)->type) { | 3987 iter->type != upb_symtab_iter_def(iter)->type) { |
4257 upb_strtable_next(&iter->iter); | 3988 upb_strtable_next(&iter->iter); |
4258 } | 3989 } |
(...skipping 18 matching lines...) Expand all Loading... |
4277 const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) { | 4008 const upb_def *upb_symtab_iter_def(const upb_symtab_iter *iter) { |
4278 return upb_value_getptr(upb_strtable_iter_value(&iter->iter)); | 4009 return upb_value_getptr(upb_strtable_iter_value(&iter->iter)); |
4279 } | 4010 } |
4280 /* | 4011 /* |
4281 ** upb_table Implementation | 4012 ** upb_table Implementation |
4282 ** | 4013 ** |
4283 ** Implementation is heavily inspired by Lua's ltable.c. | 4014 ** Implementation is heavily inspired by Lua's ltable.c. |
4284 */ | 4015 */ |
4285 | 4016 |
4286 | 4017 |
| 4018 #include <stdlib.h> |
4287 #include <string.h> | 4019 #include <string.h> |
4288 | 4020 |
4289 #define UPB_MAXARRSIZE 16 /* 64k. */ | 4021 #define UPB_MAXARRSIZE 16 /* 64k. */ |
4290 | 4022 |
4291 /* From Chromium. */ | 4023 /* From Chromium. */ |
4292 #define ARRAY_SIZE(x) \ | 4024 #define ARRAY_SIZE(x) \ |
4293 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) | 4025 ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x]))))) |
4294 | 4026 |
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 | |
4301 static const double MAX_LOAD = 0.85; | 4027 static const double MAX_LOAD = 0.85; |
4302 | 4028 |
4303 /* The minimum utilization of the array part of a mixed hash/array table. This | 4029 /* The minimum utilization of the array part of a mixed hash/array table. This |
4304 * is a speed/memory-usage tradeoff (though it's not straightforward because of | 4030 * is a speed/memory-usage tradeoff (though it's not straightforward because of |
4305 * cache effects). The lower this is, the more memory we'll use. */ | 4031 * cache effects). The lower this is, the more memory we'll use. */ |
4306 static const double MIN_DENSITY = 0.1; | 4032 static const double MIN_DENSITY = 0.1; |
4307 | 4033 |
4308 bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } | 4034 bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; } |
4309 | 4035 |
4310 int log2ceil(uint64_t v) { | 4036 int log2ceil(uint64_t v) { |
4311 int ret = 0; | 4037 int ret = 0; |
4312 bool pow2 = is_pow2(v); | 4038 bool pow2 = is_pow2(v); |
4313 while (v >>= 1) ret++; | 4039 while (v >>= 1) ret++; |
4314 ret = pow2 ? ret : ret + 1; /* Ceiling. */ | 4040 ret = pow2 ? ret : ret + 1; /* Ceiling. */ |
4315 return UPB_MIN(UPB_MAXARRSIZE, ret); | 4041 return UPB_MIN(UPB_MAXARRSIZE, ret); |
4316 } | 4042 } |
4317 | 4043 |
4318 char *upb_strdup(const char *s, upb_alloc *a) { | 4044 char *upb_strdup(const char *s) { |
4319 return upb_strdup2(s, strlen(s), a); | 4045 return upb_strdup2(s, strlen(s)); |
4320 } | 4046 } |
4321 | 4047 |
4322 char *upb_strdup2(const char *s, size_t len, upb_alloc *a) { | 4048 char *upb_strdup2(const char *s, size_t len) { |
4323 size_t n; | 4049 size_t n; |
4324 char *p; | 4050 char *p; |
4325 | 4051 |
4326 /* Prevent overflow errors. */ | 4052 /* Prevent overflow errors. */ |
4327 if (len == SIZE_MAX) return NULL; | 4053 if (len == SIZE_MAX) return NULL; |
4328 /* Always null-terminate, even if binary data; but don't rely on the input to | 4054 /* Always null-terminate, even if binary data; but don't rely on the input to |
4329 * have a null-terminating byte since it may be a raw binary buffer. */ | 4055 * have a null-terminating byte since it may be a raw binary buffer. */ |
4330 n = len + 1; | 4056 n = len + 1; |
4331 p = upb_malloc(a, n); | 4057 p = malloc(n); |
4332 if (p) { | 4058 if (p) { |
4333 memcpy(p, s, len); | 4059 memcpy(p, s, len); |
4334 p[len] = 0; | 4060 p[len] = 0; |
4335 } | 4061 } |
4336 return p; | 4062 return p; |
4337 } | 4063 } |
4338 | 4064 |
4339 /* A type to represent the lookup key of either a strtable or an inttable. */ | 4065 /* A type to represent the lookup key of either a strtable or an inttable. */ |
4340 typedef union { | 4066 typedef union { |
4341 uintptr_t num; | 4067 uintptr_t num; |
(...skipping 20 matching lines...) Expand all Loading... |
4362 typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); | 4088 typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2); |
4363 | 4089 |
4364 /* Base table (shared code) ***************************************************/ | 4090 /* Base table (shared code) ***************************************************/ |
4365 | 4091 |
4366 /* For when we need to cast away const. */ | 4092 /* For when we need to cast away const. */ |
4367 static upb_tabent *mutable_entries(upb_table *t) { | 4093 static upb_tabent *mutable_entries(upb_table *t) { |
4368 return (upb_tabent*)t->entries; | 4094 return (upb_tabent*)t->entries; |
4369 } | 4095 } |
4370 | 4096 |
4371 static bool isfull(upb_table *t) { | 4097 static bool isfull(upb_table *t) { |
4372 if (upb_table_size(t) == 0) { | 4098 return (double)(t->count + 1) / upb_table_size(t) > MAX_LOAD; |
4373 return true; | |
4374 } else { | |
4375 return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD; | |
4376 } | |
4377 } | 4099 } |
4378 | 4100 |
4379 static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2, | 4101 static bool init(upb_table *t, upb_ctype_t ctype, uint8_t size_lg2) { |
4380 upb_alloc *a) { | |
4381 size_t bytes; | 4102 size_t bytes; |
4382 | 4103 |
4383 t->count = 0; | 4104 t->count = 0; |
4384 t->ctype = ctype; | 4105 t->ctype = ctype; |
4385 t->size_lg2 = size_lg2; | 4106 t->size_lg2 = size_lg2; |
4386 t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; | 4107 t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0; |
4387 #ifndef NDEBUG | |
4388 t->alloc = a; | |
4389 #endif | |
4390 bytes = upb_table_size(t) * sizeof(upb_tabent); | 4108 bytes = upb_table_size(t) * sizeof(upb_tabent); |
4391 if (bytes > 0) { | 4109 if (bytes > 0) { |
4392 t->entries = upb_malloc(a, bytes); | 4110 t->entries = malloc(bytes); |
4393 if (!t->entries) return false; | 4111 if (!t->entries) return false; |
4394 memset(mutable_entries(t), 0, bytes); | 4112 memset(mutable_entries(t), 0, bytes); |
4395 } else { | 4113 } else { |
4396 t->entries = NULL; | 4114 t->entries = NULL; |
4397 } | 4115 } |
4398 return true; | 4116 return true; |
4399 } | 4117 } |
4400 | 4118 |
4401 static void uninit(upb_table *t, upb_alloc *a) { | 4119 static void uninit(upb_table *t) { free(mutable_entries(t)); } |
4402 upb_check_alloc(t, a); | |
4403 upb_free(a, mutable_entries(t)); | |
4404 } | |
4405 | 4120 |
4406 static upb_tabent *emptyent(upb_table *t) { | 4121 static upb_tabent *emptyent(upb_table *t) { |
4407 upb_tabent *e = mutable_entries(t) + upb_table_size(t); | 4122 upb_tabent *e = mutable_entries(t) + upb_table_size(t); |
4408 while (1) { if (upb_tabent_isempty(--e)) return e; UPB_ASSERT(e > t->entries);
} | 4123 while (1) { if (upb_tabent_isempty(--e)) return e; assert(e > t->entries); } |
4409 } | 4124 } |
4410 | 4125 |
4411 static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) { | 4126 static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) { |
4412 return (upb_tabent*)upb_getentry(t, hash); | 4127 return (upb_tabent*)upb_getentry(t, hash); |
4413 } | 4128 } |
4414 | 4129 |
4415 static const upb_tabent *findentry(const upb_table *t, lookupkey_t key, | 4130 static const upb_tabent *findentry(const upb_table *t, lookupkey_t key, |
4416 uint32_t hash, eqlfunc_t *eql) { | 4131 uint32_t hash, eqlfunc_t *eql) { |
4417 const upb_tabent *e; | 4132 const upb_tabent *e; |
4418 | 4133 |
(...skipping 24 matching lines...) Expand all Loading... |
4443 } | 4158 } |
4444 } | 4159 } |
4445 | 4160 |
4446 /* The given key must not already exist in the table. */ | 4161 /* The given key must not already exist in the table. */ |
4447 static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, | 4162 static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey, |
4448 upb_value val, uint32_t hash, | 4163 upb_value val, uint32_t hash, |
4449 hashfunc_t *hashfunc, eqlfunc_t *eql) { | 4164 hashfunc_t *hashfunc, eqlfunc_t *eql) { |
4450 upb_tabent *mainpos_e; | 4165 upb_tabent *mainpos_e; |
4451 upb_tabent *our_e; | 4166 upb_tabent *our_e; |
4452 | 4167 |
4453 UPB_ASSERT(findentry(t, key, hash, eql) == NULL); | 4168 UPB_UNUSED(eql); |
4454 UPB_ASSERT_DEBUGVAR(val.ctype == t->ctype); | 4169 UPB_UNUSED(key); |
| 4170 assert(findentry(t, key, hash, eql) == NULL); |
| 4171 assert(val.ctype == t->ctype); |
4455 | 4172 |
4456 t->count++; | 4173 t->count++; |
4457 mainpos_e = getentry_mutable(t, hash); | 4174 mainpos_e = getentry_mutable(t, hash); |
4458 our_e = mainpos_e; | 4175 our_e = mainpos_e; |
4459 | 4176 |
4460 if (upb_tabent_isempty(mainpos_e)) { | 4177 if (upb_tabent_isempty(mainpos_e)) { |
4461 /* Our main position is empty; use it. */ | 4178 /* Our main position is empty; use it. */ |
4462 our_e->next = NULL; | 4179 our_e->next = NULL; |
4463 } else { | 4180 } else { |
4464 /* Collision. */ | 4181 /* Collision. */ |
4465 upb_tabent *new_e = emptyent(t); | 4182 upb_tabent *new_e = emptyent(t); |
4466 /* Head of collider's chain. */ | 4183 /* Head of collider's chain. */ |
4467 upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key)); | 4184 upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key)); |
4468 if (chain == mainpos_e) { | 4185 if (chain == mainpos_e) { |
4469 /* Existing ent is in its main posisiton (it has the same hash as us, and | 4186 /* Existing ent is in its main posisiton (it has the same hash as us, and |
4470 * is the head of our chain). Insert to new ent and append to this chain.
*/ | 4187 * is the head of our chain). Insert to new ent and append to this chain.
*/ |
4471 new_e->next = mainpos_e->next; | 4188 new_e->next = mainpos_e->next; |
4472 mainpos_e->next = new_e; | 4189 mainpos_e->next = new_e; |
4473 our_e = new_e; | 4190 our_e = new_e; |
4474 } else { | 4191 } else { |
4475 /* Existing ent is not in its main position (it is a node in some other | 4192 /* Existing ent is not in its main position (it is a node in some other |
4476 * chain). This implies that no existing ent in the table has our hash. | 4193 * chain). This implies that no existing ent in the table has our hash. |
4477 * Evict it (updating its chain) and use its ent for head of our chain. */ | 4194 * Evict it (updating its chain) and use its ent for head of our chain. */ |
4478 *new_e = *mainpos_e; /* copies next. */ | 4195 *new_e = *mainpos_e; /* copies next. */ |
4479 while (chain->next != mainpos_e) { | 4196 while (chain->next != mainpos_e) { |
4480 chain = (upb_tabent*)chain->next; | 4197 chain = (upb_tabent*)chain->next; |
4481 UPB_ASSERT(chain); | 4198 assert(chain); |
4482 } | 4199 } |
4483 chain->next = new_e; | 4200 chain->next = new_e; |
4484 our_e = mainpos_e; | 4201 our_e = mainpos_e; |
4485 our_e->next = NULL; | 4202 our_e->next = NULL; |
4486 } | 4203 } |
4487 } | 4204 } |
4488 our_e->key = tabkey; | 4205 our_e->key = tabkey; |
4489 our_e->val.val = val.val; | 4206 our_e->val.val = val.val; |
4490 UPB_ASSERT(findentry(t, key, hash, eql) == our_e); | 4207 assert(findentry(t, key, hash, eql) == our_e); |
4491 } | 4208 } |
4492 | 4209 |
4493 static bool rm(upb_table *t, lookupkey_t key, upb_value *val, | 4210 static bool rm(upb_table *t, lookupkey_t key, upb_value *val, |
4494 upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) { | 4211 upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) { |
4495 upb_tabent *chain = getentry_mutable(t, hash); | 4212 upb_tabent *chain = getentry_mutable(t, hash); |
4496 if (upb_tabent_isempty(chain)) return false; | 4213 if (upb_tabent_isempty(chain)) return false; |
4497 if (eql(chain->key, key)) { | 4214 if (eql(chain->key, key)) { |
4498 /* Element to remove is at the head of its chain. */ | 4215 /* Element to remove is at the head of its chain. */ |
4499 t->count--; | 4216 t->count--; |
4500 if (val) _upb_value_setval(val, chain->val.val, t->ctype); | 4217 if (val) { |
4501 if (removed) *removed = chain->key; | 4218 _upb_value_setval(val, chain->val.val, t->ctype); |
| 4219 } |
4502 if (chain->next) { | 4220 if (chain->next) { |
4503 upb_tabent *move = (upb_tabent*)chain->next; | 4221 upb_tabent *move = (upb_tabent*)chain->next; |
4504 *chain = *move; | 4222 *chain = *move; |
| 4223 if (removed) *removed = move->key; |
4505 move->key = 0; /* Make the slot empty. */ | 4224 move->key = 0; /* Make the slot empty. */ |
4506 } else { | 4225 } else { |
| 4226 if (removed) *removed = chain->key; |
4507 chain->key = 0; /* Make the slot empty. */ | 4227 chain->key = 0; /* Make the slot empty. */ |
4508 } | 4228 } |
4509 return true; | 4229 return true; |
4510 } else { | 4230 } else { |
4511 /* Element to remove is either in a non-head position or not in the | 4231 /* Element to remove is either in a non-head position or not in the |
4512 * table. */ | 4232 * table. */ |
4513 while (chain->next && !eql(chain->next->key, key)) { | 4233 while (chain->next && !eql(chain->next->key, key)) |
4514 chain = (upb_tabent*)chain->next; | 4234 chain = (upb_tabent*)chain->next; |
4515 } | |
4516 if (chain->next) { | 4235 if (chain->next) { |
4517 /* Found element to remove. */ | 4236 /* Found element to remove. */ |
4518 upb_tabent *rm = (upb_tabent*)chain->next; | 4237 upb_tabent *rm; |
| 4238 |
| 4239 if (val) { |
| 4240 _upb_value_setval(val, chain->next->val.val, t->ctype); |
| 4241 } |
| 4242 rm = (upb_tabent*)chain->next; |
| 4243 if (removed) *removed = rm->key; |
| 4244 rm->key = 0; |
| 4245 chain->next = rm->next; |
4519 t->count--; | 4246 t->count--; |
4520 if (val) _upb_value_setval(val, chain->next->val.val, t->ctype); | |
4521 if (removed) *removed = rm->key; | |
4522 rm->key = 0; /* Make the slot empty. */ | |
4523 chain->next = rm->next; | |
4524 return true; | 4247 return true; |
4525 } else { | 4248 } else { |
4526 /* Element to remove is not in the table. */ | |
4527 return false; | 4249 return false; |
4528 } | 4250 } |
4529 } | 4251 } |
4530 } | 4252 } |
4531 | 4253 |
4532 static size_t next(const upb_table *t, size_t i) { | 4254 static size_t next(const upb_table *t, size_t i) { |
4533 do { | 4255 do { |
4534 if (++i >= upb_table_size(t)) | 4256 if (++i >= upb_table_size(t)) |
4535 return SIZE_MAX; | 4257 return SIZE_MAX; |
4536 } while(upb_tabent_isempty(&t->entries[i])); | 4258 } while(upb_tabent_isempty(&t->entries[i])); |
4537 | 4259 |
4538 return i; | 4260 return i; |
4539 } | 4261 } |
4540 | 4262 |
4541 static size_t begin(const upb_table *t) { | 4263 static size_t begin(const upb_table *t) { |
4542 return next(t, -1); | 4264 return next(t, -1); |
4543 } | 4265 } |
4544 | 4266 |
4545 | 4267 |
4546 /* upb_strtable ***************************************************************/ | 4268 /* upb_strtable ***************************************************************/ |
4547 | 4269 |
4548 /* A simple "subclass" of upb_table that only adds a hash function for strings.
*/ | 4270 /* A simple "subclass" of upb_table that only adds a hash function for strings.
*/ |
4549 | 4271 |
4550 static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) { | 4272 static upb_tabkey strcopy(lookupkey_t k2) { |
4551 char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1); | 4273 char *str = malloc(k2.str.len + sizeof(uint32_t) + 1); |
4552 if (str == NULL) return 0; | 4274 if (str == NULL) return 0; |
4553 memcpy(str, &k2.str.len, sizeof(uint32_t)); | 4275 memcpy(str, &k2.str.len, sizeof(uint32_t)); |
4554 memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); | 4276 memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len + 1); |
4555 return (uintptr_t)str; | 4277 return (uintptr_t)str; |
4556 } | 4278 } |
4557 | 4279 |
4558 static uint32_t strhash(upb_tabkey key) { | 4280 static uint32_t strhash(upb_tabkey key) { |
4559 uint32_t len; | 4281 uint32_t len; |
4560 char *str = upb_tabstr(key, &len); | 4282 char *str = upb_tabstr(key, &len); |
4561 return MurmurHash2(str, len, 0); | 4283 return MurmurHash2(str, len, 0); |
4562 } | 4284 } |
4563 | 4285 |
4564 static bool streql(upb_tabkey k1, lookupkey_t k2) { | 4286 static bool streql(upb_tabkey k1, lookupkey_t k2) { |
4565 uint32_t len; | 4287 uint32_t len; |
4566 char *str = upb_tabstr(k1, &len); | 4288 char *str = upb_tabstr(k1, &len); |
4567 return len == k2.str.len && memcmp(str, k2.str.str, len) == 0; | 4289 return len == k2.str.len && memcmp(str, k2.str.str, len) == 0; |
4568 } | 4290 } |
4569 | 4291 |
4570 bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) { | 4292 bool upb_strtable_init(upb_strtable *t, upb_ctype_t ctype) { |
4571 return init(&t->t, ctype, 2, a); | 4293 return init(&t->t, ctype, 2); |
4572 } | 4294 } |
4573 | 4295 |
4574 void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) { | 4296 void upb_strtable_uninit(upb_strtable *t) { |
4575 size_t i; | 4297 size_t i; |
4576 for (i = 0; i < upb_table_size(&t->t); i++) | 4298 for (i = 0; i < upb_table_size(&t->t); i++) |
4577 upb_free(a, (void*)t->t.entries[i].key); | 4299 free((void*)t->t.entries[i].key); |
4578 uninit(&t->t, a); | 4300 uninit(&t->t); |
4579 } | 4301 } |
4580 | 4302 |
4581 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) { | 4303 bool upb_strtable_resize(upb_strtable *t, size_t size_lg2) { |
4582 upb_strtable new_table; | 4304 upb_strtable new_table; |
4583 upb_strtable_iter i; | 4305 upb_strtable_iter i; |
4584 | 4306 |
4585 upb_check_alloc(&t->t, a); | 4307 if (!init(&new_table.t, t->t.ctype, size_lg2)) |
4586 | |
4587 if (!init(&new_table.t, t->t.ctype, size_lg2, a)) | |
4588 return false; | 4308 return false; |
4589 upb_strtable_begin(&i, t); | 4309 upb_strtable_begin(&i, t); |
4590 for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { | 4310 for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) { |
4591 upb_strtable_insert3( | 4311 upb_strtable_insert2( |
4592 &new_table, | 4312 &new_table, |
4593 upb_strtable_iter_key(&i), | 4313 upb_strtable_iter_key(&i), |
4594 upb_strtable_iter_keylength(&i), | 4314 upb_strtable_iter_keylength(&i), |
4595 upb_strtable_iter_value(&i), | 4315 upb_strtable_iter_value(&i)); |
4596 a); | |
4597 } | 4316 } |
4598 upb_strtable_uninit2(t, a); | 4317 upb_strtable_uninit(t); |
4599 *t = new_table; | 4318 *t = new_table; |
4600 return true; | 4319 return true; |
4601 } | 4320 } |
4602 | 4321 |
4603 bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len, | 4322 bool upb_strtable_insert2(upb_strtable *t, const char *k, size_t len, |
4604 upb_value v, upb_alloc *a) { | 4323 upb_value v) { |
4605 lookupkey_t key; | 4324 lookupkey_t key; |
4606 upb_tabkey tabkey; | 4325 upb_tabkey tabkey; |
4607 uint32_t hash; | 4326 uint32_t hash; |
4608 | 4327 |
4609 upb_check_alloc(&t->t, a); | |
4610 | |
4611 if (isfull(&t->t)) { | 4328 if (isfull(&t->t)) { |
4612 /* Need to resize. New table of double the size, add old elements to it. */ | 4329 /* Need to resize. New table of double the size, add old elements to it. */ |
4613 if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) { | 4330 if (!upb_strtable_resize(t, t->t.size_lg2 + 1)) { |
4614 return false; | 4331 return false; |
4615 } | 4332 } |
4616 } | 4333 } |
4617 | 4334 |
4618 key = strkey2(k, len); | 4335 key = strkey2(k, len); |
4619 tabkey = strcopy(key, a); | 4336 tabkey = strcopy(key); |
4620 if (tabkey == 0) return false; | 4337 if (tabkey == 0) return false; |
4621 | 4338 |
4622 hash = MurmurHash2(key.str.str, key.str.len, 0); | 4339 hash = MurmurHash2(key.str.str, key.str.len, 0); |
4623 insert(&t->t, key, tabkey, v, hash, &strhash, &streql); | 4340 insert(&t->t, key, tabkey, v, hash, &strhash, &streql); |
4624 return true; | 4341 return true; |
4625 } | 4342 } |
4626 | 4343 |
4627 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, | 4344 bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len, |
4628 upb_value *v) { | 4345 upb_value *v) { |
4629 uint32_t hash = MurmurHash2(key, len, 0); | 4346 uint32_t hash = MurmurHash2(key, len, 0); |
4630 return lookup(&t->t, strkey2(key, len), v, hash, &streql); | 4347 return lookup(&t->t, strkey2(key, len), v, hash, &streql); |
4631 } | 4348 } |
4632 | 4349 |
4633 bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len, | 4350 bool upb_strtable_remove2(upb_strtable *t, const char *key, size_t len, |
4634 upb_value *val, upb_alloc *alloc) { | 4351 upb_value *val) { |
4635 uint32_t hash = MurmurHash2(key, len, 0); | 4352 uint32_t hash = MurmurHash2(key, strlen(key), 0); |
4636 upb_tabkey tabkey; | 4353 upb_tabkey tabkey; |
4637 if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) { | 4354 if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) { |
4638 upb_free(alloc, (void*)tabkey); | 4355 free((void*)tabkey); |
4639 return true; | 4356 return true; |
4640 } else { | 4357 } else { |
4641 return false; | 4358 return false; |
4642 } | 4359 } |
4643 } | 4360 } |
4644 | 4361 |
4645 /* Iteration */ | 4362 /* Iteration */ |
4646 | 4363 |
4647 static const upb_tabent *str_tabent(const upb_strtable_iter *i) { | 4364 static const upb_tabent *str_tabent(const upb_strtable_iter *i) { |
4648 return &i->t->t.entries[i->index]; | 4365 return &i->t->t.entries[i->index]; |
4649 } | 4366 } |
4650 | 4367 |
4651 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) { | 4368 void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) { |
4652 i->t = t; | 4369 i->t = t; |
4653 i->index = begin(&t->t); | 4370 i->index = begin(&t->t); |
4654 } | 4371 } |
4655 | 4372 |
4656 void upb_strtable_next(upb_strtable_iter *i) { | 4373 void upb_strtable_next(upb_strtable_iter *i) { |
4657 i->index = next(&i->t->t, i->index); | 4374 i->index = next(&i->t->t, i->index); |
4658 } | 4375 } |
4659 | 4376 |
4660 bool upb_strtable_done(const upb_strtable_iter *i) { | 4377 bool upb_strtable_done(const upb_strtable_iter *i) { |
4661 return i->index >= upb_table_size(&i->t->t) || | 4378 return i->index >= upb_table_size(&i->t->t) || |
4662 upb_tabent_isempty(str_tabent(i)); | 4379 upb_tabent_isempty(str_tabent(i)); |
4663 } | 4380 } |
4664 | 4381 |
4665 const char *upb_strtable_iter_key(const upb_strtable_iter *i) { | 4382 const char *upb_strtable_iter_key(upb_strtable_iter *i) { |
4666 UPB_ASSERT(!upb_strtable_done(i)); | 4383 assert(!upb_strtable_done(i)); |
4667 return upb_tabstr(str_tabent(i)->key, NULL); | 4384 return upb_tabstr(str_tabent(i)->key, NULL); |
4668 } | 4385 } |
4669 | 4386 |
4670 size_t upb_strtable_iter_keylength(const upb_strtable_iter *i) { | 4387 size_t upb_strtable_iter_keylength(upb_strtable_iter *i) { |
4671 uint32_t len; | 4388 uint32_t len; |
4672 UPB_ASSERT(!upb_strtable_done(i)); | 4389 assert(!upb_strtable_done(i)); |
4673 upb_tabstr(str_tabent(i)->key, &len); | 4390 upb_tabstr(str_tabent(i)->key, &len); |
4674 return len; | 4391 return len; |
4675 } | 4392 } |
4676 | 4393 |
4677 upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { | 4394 upb_value upb_strtable_iter_value(const upb_strtable_iter *i) { |
4678 UPB_ASSERT(!upb_strtable_done(i)); | 4395 assert(!upb_strtable_done(i)); |
4679 return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype); | 4396 return _upb_value_val(str_tabent(i)->val.val, i->t->t.ctype); |
4680 } | 4397 } |
4681 | 4398 |
4682 void upb_strtable_iter_setdone(upb_strtable_iter *i) { | 4399 void upb_strtable_iter_setdone(upb_strtable_iter *i) { |
4683 i->index = SIZE_MAX; | 4400 i->index = SIZE_MAX; |
4684 } | 4401 } |
4685 | 4402 |
4686 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, | 4403 bool upb_strtable_iter_isequal(const upb_strtable_iter *i1, |
4687 const upb_strtable_iter *i2) { | 4404 const upb_strtable_iter *i2) { |
4688 if (upb_strtable_done(i1) && upb_strtable_done(i2)) | 4405 if (upb_strtable_done(i1) && upb_strtable_done(i2)) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4727 | 4444 |
4728 static void check(upb_inttable *t) { | 4445 static void check(upb_inttable *t) { |
4729 UPB_UNUSED(t); | 4446 UPB_UNUSED(t); |
4730 #if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) | 4447 #if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG) |
4731 { | 4448 { |
4732 /* This check is very expensive (makes inserts/deletes O(N)). */ | 4449 /* This check is very expensive (makes inserts/deletes O(N)). */ |
4733 size_t count = 0; | 4450 size_t count = 0; |
4734 upb_inttable_iter i; | 4451 upb_inttable_iter i; |
4735 upb_inttable_begin(&i, t); | 4452 upb_inttable_begin(&i, t); |
4736 for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { | 4453 for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) { |
4737 UPB_ASSERT(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL)); | 4454 assert(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL)); |
4738 } | 4455 } |
4739 UPB_ASSERT(count == upb_inttable_count(t)); | 4456 assert(count == upb_inttable_count(t)); |
4740 } | 4457 } |
4741 #endif | 4458 #endif |
4742 } | 4459 } |
4743 | 4460 |
4744 bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, | 4461 bool upb_inttable_sizedinit(upb_inttable *t, upb_ctype_t ctype, |
4745 size_t asize, int hsize_lg2, upb_alloc *a) { | 4462 size_t asize, int hsize_lg2) { |
4746 size_t array_bytes; | 4463 size_t array_bytes; |
4747 | 4464 |
4748 if (!init(&t->t, ctype, hsize_lg2, a)) return false; | 4465 if (!init(&t->t, ctype, hsize_lg2)) return false; |
4749 /* Always make the array part at least 1 long, so that we know key 0 | 4466 /* Always make the array part at least 1 long, so that we know key 0 |
4750 * won't be in the hash part, which simplifies things. */ | 4467 * won't be in the hash part, which simplifies things. */ |
4751 t->array_size = UPB_MAX(1, asize); | 4468 t->array_size = UPB_MAX(1, asize); |
4752 t->array_count = 0; | 4469 t->array_count = 0; |
4753 array_bytes = t->array_size * sizeof(upb_value); | 4470 array_bytes = t->array_size * sizeof(upb_value); |
4754 t->array = upb_malloc(a, array_bytes); | 4471 t->array = malloc(array_bytes); |
4755 if (!t->array) { | 4472 if (!t->array) { |
4756 uninit(&t->t, a); | 4473 uninit(&t->t); |
4757 return false; | 4474 return false; |
4758 } | 4475 } |
4759 memset(mutable_array(t), 0xff, array_bytes); | 4476 memset(mutable_array(t), 0xff, array_bytes); |
4760 check(t); | 4477 check(t); |
4761 return true; | 4478 return true; |
4762 } | 4479 } |
4763 | 4480 |
4764 bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) { | 4481 bool upb_inttable_init(upb_inttable *t, upb_ctype_t ctype) { |
4765 return upb_inttable_sizedinit(t, ctype, 0, 4, a); | 4482 return upb_inttable_sizedinit(t, ctype, 0, 4); |
4766 } | 4483 } |
4767 | 4484 |
4768 void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) { | 4485 void upb_inttable_uninit(upb_inttable *t) { |
4769 uninit(&t->t, a); | 4486 uninit(&t->t); |
4770 upb_free(a, mutable_array(t)); | 4487 free(mutable_array(t)); |
4771 } | 4488 } |
4772 | 4489 |
4773 bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val, | 4490 bool upb_inttable_insert(upb_inttable *t, uintptr_t key, upb_value val) { |
4774 upb_alloc *a) { | 4491 /* XXX: Table can't store value (uint64_t)-1. Need to somehow statically |
| 4492 * guarantee that this is not necessary, or fix the limitation. */ |
4775 upb_tabval tabval; | 4493 upb_tabval tabval; |
4776 tabval.val = val.val; | 4494 tabval.val = val.val; |
4777 UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this.
*/ | 4495 UPB_UNUSED(tabval); |
4778 | 4496 assert(upb_arrhas(tabval)); |
4779 upb_check_alloc(&t->t, a); | |
4780 | 4497 |
4781 if (key < t->array_size) { | 4498 if (key < t->array_size) { |
4782 UPB_ASSERT(!upb_arrhas(t->array[key])); | 4499 assert(!upb_arrhas(t->array[key])); |
4783 t->array_count++; | 4500 t->array_count++; |
4784 mutable_array(t)[key].val = val.val; | 4501 mutable_array(t)[key].val = val.val; |
4785 } else { | 4502 } else { |
4786 if (isfull(&t->t)) { | 4503 if (isfull(&t->t)) { |
4787 /* Need to resize the hash part, but we re-use the array part. */ | 4504 /* Need to resize the hash part, but we re-use the array part. */ |
4788 size_t i; | 4505 size_t i; |
4789 upb_table new_table; | 4506 upb_table new_table; |
4790 | 4507 if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1)) |
4791 if (!init(&new_table, t->t.ctype, t->t.size_lg2 + 1, a)) { | |
4792 return false; | 4508 return false; |
4793 } | |
4794 | |
4795 for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { | 4509 for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) { |
4796 const upb_tabent *e = &t->t.entries[i]; | 4510 const upb_tabent *e = &t->t.entries[i]; |
4797 uint32_t hash; | 4511 uint32_t hash; |
4798 upb_value v; | 4512 upb_value v; |
4799 | 4513 |
4800 _upb_value_setval(&v, e->val.val, t->t.ctype); | 4514 _upb_value_setval(&v, e->val.val, t->t.ctype); |
4801 hash = upb_inthash(e->key); | 4515 hash = upb_inthash(e->key); |
4802 insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); | 4516 insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql); |
4803 } | 4517 } |
4804 | 4518 |
4805 UPB_ASSERT(t->t.count == new_table.count); | 4519 assert(t->t.count == new_table.count); |
4806 | 4520 |
4807 uninit(&t->t, a); | 4521 uninit(&t->t); |
4808 t->t = new_table; | 4522 t->t = new_table; |
4809 } | 4523 } |
4810 insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); | 4524 insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql); |
4811 } | 4525 } |
4812 check(t); | 4526 check(t); |
4813 return true; | 4527 return true; |
4814 } | 4528 } |
4815 | 4529 |
4816 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) { | 4530 bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) { |
4817 const upb_tabval *table_v = inttable_val_const(t, key); | 4531 const upb_tabval *table_v = inttable_val_const(t, key); |
(...skipping 17 matching lines...) Expand all Loading... |
4835 t->array_count--; | 4549 t->array_count--; |
4836 if (val) { | 4550 if (val) { |
4837 _upb_value_setval(val, t->array[key].val, t->t.ctype); | 4551 _upb_value_setval(val, t->array[key].val, t->t.ctype); |
4838 } | 4552 } |
4839 mutable_array(t)[key] = empty; | 4553 mutable_array(t)[key] = empty; |
4840 success = true; | 4554 success = true; |
4841 } else { | 4555 } else { |
4842 success = false; | 4556 success = false; |
4843 } | 4557 } |
4844 } else { | 4558 } else { |
4845 success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql); | 4559 upb_tabkey removed; |
| 4560 uint32_t hash = upb_inthash(key); |
| 4561 success = rm(&t->t, intkey(key), val, &removed, hash, &inteql); |
4846 } | 4562 } |
4847 check(t); | 4563 check(t); |
4848 return success; | 4564 return success; |
4849 } | 4565 } |
4850 | 4566 |
4851 bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) { | 4567 bool upb_inttable_push(upb_inttable *t, upb_value val) { |
4852 upb_check_alloc(&t->t, a); | 4568 return upb_inttable_insert(t, upb_inttable_count(t), val); |
4853 return upb_inttable_insert2(t, upb_inttable_count(t), val, a); | |
4854 } | 4569 } |
4855 | 4570 |
4856 upb_value upb_inttable_pop(upb_inttable *t) { | 4571 upb_value upb_inttable_pop(upb_inttable *t) { |
4857 upb_value val; | 4572 upb_value val; |
4858 bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val); | 4573 bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val); |
4859 UPB_ASSERT(ok); | 4574 UPB_ASSERT_VAR(ok, ok); |
4860 return val; | 4575 return val; |
4861 } | 4576 } |
4862 | 4577 |
4863 bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val, | 4578 bool upb_inttable_insertptr(upb_inttable *t, const void *key, upb_value val) { |
4864 upb_alloc *a) { | 4579 return upb_inttable_insert(t, (uintptr_t)key, val); |
4865 upb_check_alloc(&t->t, a); | |
4866 return upb_inttable_insert2(t, (uintptr_t)key, val, a); | |
4867 } | 4580 } |
4868 | 4581 |
4869 bool upb_inttable_lookupptr(const upb_inttable *t, const void *key, | 4582 bool upb_inttable_lookupptr(const upb_inttable *t, const void *key, |
4870 upb_value *v) { | 4583 upb_value *v) { |
4871 return upb_inttable_lookup(t, (uintptr_t)key, v); | 4584 return upb_inttable_lookup(t, (uintptr_t)key, v); |
4872 } | 4585 } |
4873 | 4586 |
4874 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) { | 4587 bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) { |
4875 return upb_inttable_remove(t, (uintptr_t)key, val); | 4588 return upb_inttable_remove(t, (uintptr_t)key, val); |
4876 } | 4589 } |
4877 | 4590 |
4878 void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) { | 4591 void upb_inttable_compact(upb_inttable *t) { |
4879 /* A power-of-two histogram of the table keys. */ | 4592 /* Create a power-of-two histogram of the table keys. */ |
4880 size_t counts[UPB_MAXARRSIZE + 1] = {0}; | 4593 int counts[UPB_MAXARRSIZE + 1] = {0}; |
4881 | 4594 uintptr_t max_key = 0; |
4882 /* The max key in each bucket. */ | |
4883 uintptr_t max[UPB_MAXARRSIZE + 1] = {0}; | |
4884 | |
4885 upb_inttable_iter i; | 4595 upb_inttable_iter i; |
4886 size_t arr_count; | 4596 size_t arr_size; |
4887 int size_lg2; | 4597 int arr_count; |
4888 upb_inttable new_t; | 4598 upb_inttable new_t; |
4889 | 4599 |
4890 upb_check_alloc(&t->t, a); | |
4891 | |
4892 upb_inttable_begin(&i, t); | 4600 upb_inttable_begin(&i, t); |
4893 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 4601 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
4894 uintptr_t key = upb_inttable_iter_key(&i); | 4602 uintptr_t key = upb_inttable_iter_key(&i); |
4895 int bucket = log2ceil(key); | 4603 if (key > max_key) { |
4896 max[bucket] = UPB_MAX(max[bucket], key); | 4604 max_key = key; |
4897 counts[bucket]++; | 4605 } |
| 4606 counts[log2ceil(key)]++; |
4898 } | 4607 } |
4899 | 4608 |
4900 /* Find the largest power of two that satisfies the MIN_DENSITY | 4609 arr_size = 1; |
4901 * definition (while actually having some keys). */ | |
4902 arr_count = upb_inttable_count(t); | 4610 arr_count = upb_inttable_count(t); |
4903 | 4611 |
4904 for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) { | 4612 if (upb_inttable_count(t) >= max_key * MIN_DENSITY) { |
4905 if (counts[size_lg2] == 0) { | 4613 /* We can put 100% of the entries in the array part. */ |
4906 /* We can halve again without losing any entries. */ | 4614 arr_size = max_key + 1; |
4907 continue; | 4615 } else { |
4908 } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) { | 4616 /* Find the largest power of two that satisfies the MIN_DENSITY |
4909 break; | 4617 * definition. */ |
| 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 } |
4910 } | 4625 } |
4911 | |
4912 arr_count -= counts[size_lg2]; | |
4913 } | 4626 } |
4914 | 4627 |
4915 UPB_ASSERT(arr_count <= upb_inttable_count(t)); | 4628 /* Array part must always be at least 1 entry large to catch lookups of key |
| 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); |
4916 | 4632 |
4917 { | 4633 { |
4918 /* Insert all elements into new, perfectly-sized table. */ | 4634 /* Insert all elements into new, perfectly-sized table. */ |
4919 size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */ | 4635 int hash_count = upb_inttable_count(t) - arr_count; |
4920 size_t hash_count = upb_inttable_count(t) - arr_count; | 4636 int hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; |
4921 size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0; | 4637 int hashsize_lg2 = log2ceil(hash_size); |
4922 size_t hashsize_lg2 = log2ceil(hash_size); | |
4923 | 4638 |
4924 upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2, a); | 4639 assert(hash_count >= 0); |
| 4640 upb_inttable_sizedinit(&new_t, t->t.ctype, arr_size, hashsize_lg2); |
4925 upb_inttable_begin(&i, t); | 4641 upb_inttable_begin(&i, t); |
4926 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 4642 for (; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
4927 uintptr_t k = upb_inttable_iter_key(&i); | 4643 uintptr_t k = upb_inttable_iter_key(&i); |
4928 upb_inttable_insert2(&new_t, k, upb_inttable_iter_value(&i), a); | 4644 upb_inttable_insert(&new_t, k, upb_inttable_iter_value(&i)); |
4929 } | 4645 } |
4930 UPB_ASSERT(new_t.array_size == arr_size); | 4646 assert(new_t.array_size == arr_size); |
4931 UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2); | 4647 assert(new_t.t.size_lg2 == hashsize_lg2); |
4932 } | 4648 } |
4933 upb_inttable_uninit2(t, a); | 4649 upb_inttable_uninit(t); |
4934 *t = new_t; | 4650 *t = new_t; |
4935 } | 4651 } |
4936 | 4652 |
4937 /* Iteration. */ | 4653 /* Iteration. */ |
4938 | 4654 |
4939 static const upb_tabent *int_tabent(const upb_inttable_iter *i) { | 4655 static const upb_tabent *int_tabent(const upb_inttable_iter *i) { |
4940 UPB_ASSERT(!i->array_part); | 4656 assert(!i->array_part); |
4941 return &i->t->t.entries[i->index]; | 4657 return &i->t->t.entries[i->index]; |
4942 } | 4658 } |
4943 | 4659 |
4944 static upb_tabval int_arrent(const upb_inttable_iter *i) { | 4660 static upb_tabval int_arrent(const upb_inttable_iter *i) { |
4945 UPB_ASSERT(i->array_part); | 4661 assert(i->array_part); |
4946 return i->t->array[i->index]; | 4662 return i->t->array[i->index]; |
4947 } | 4663 } |
4948 | 4664 |
4949 void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) { | 4665 void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) { |
4950 i->t = t; | 4666 i->t = t; |
4951 i->index = -1; | 4667 i->index = -1; |
4952 i->array_part = true; | 4668 i->array_part = true; |
4953 upb_inttable_next(i); | 4669 upb_inttable_next(i); |
4954 } | 4670 } |
4955 | 4671 |
(...skipping 16 matching lines...) Expand all Loading... |
4972 if (i->array_part) { | 4688 if (i->array_part) { |
4973 return i->index >= i->t->array_size || | 4689 return i->index >= i->t->array_size || |
4974 !upb_arrhas(int_arrent(i)); | 4690 !upb_arrhas(int_arrent(i)); |
4975 } else { | 4691 } else { |
4976 return i->index >= upb_table_size(&i->t->t) || | 4692 return i->index >= upb_table_size(&i->t->t) || |
4977 upb_tabent_isempty(int_tabent(i)); | 4693 upb_tabent_isempty(int_tabent(i)); |
4978 } | 4694 } |
4979 } | 4695 } |
4980 | 4696 |
4981 uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) { | 4697 uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) { |
4982 UPB_ASSERT(!upb_inttable_done(i)); | 4698 assert(!upb_inttable_done(i)); |
4983 return i->array_part ? i->index : int_tabent(i)->key; | 4699 return i->array_part ? i->index : int_tabent(i)->key; |
4984 } | 4700 } |
4985 | 4701 |
4986 upb_value upb_inttable_iter_value(const upb_inttable_iter *i) { | 4702 upb_value upb_inttable_iter_value(const upb_inttable_iter *i) { |
4987 UPB_ASSERT(!upb_inttable_done(i)); | 4703 assert(!upb_inttable_done(i)); |
4988 return _upb_value_val( | 4704 return _upb_value_val( |
4989 i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val, | 4705 i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val, |
4990 i->t->t.ctype); | 4706 i->t->t.ctype); |
4991 } | 4707 } |
4992 | 4708 |
4993 void upb_inttable_iter_setdone(upb_inttable_iter *i) { | 4709 void upb_inttable_iter_setdone(upb_inttable_iter *i) { |
4994 i->index = SIZE_MAX; | 4710 i->index = SIZE_MAX; |
4995 i->array_part = false; | 4711 i->array_part = false; |
4996 } | 4712 } |
4997 | 4713 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5195 return false; | 4911 return false; |
5196 } | 4912 } |
5197 | 4913 |
5198 /* Guarantee null-termination and provide ellipsis truncation. | 4914 /* Guarantee null-termination and provide ellipsis truncation. |
5199 * It may be tempting to "optimize" this by initializing these final | 4915 * It may be tempting to "optimize" this by initializing these final |
5200 * four bytes up-front and then being careful never to overwrite them, | 4916 * four bytes up-front and then being careful never to overwrite them, |
5201 * this is safer and simpler. */ | 4917 * this is safer and simpler. */ |
5202 static void nullz(upb_status *status) { | 4918 static void nullz(upb_status *status) { |
5203 const char *ellipsis = "..."; | 4919 const char *ellipsis = "..."; |
5204 size_t len = strlen(ellipsis); | 4920 size_t len = strlen(ellipsis); |
5205 UPB_ASSERT(sizeof(status->msg) > len); | 4921 assert(sizeof(status->msg) > len); |
5206 memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); | 4922 memcpy(status->msg + sizeof(status->msg) - len, ellipsis, len); |
5207 } | 4923 } |
5208 | 4924 |
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 | |
5222 void upb_status_clear(upb_status *status) { | 4925 void upb_status_clear(upb_status *status) { |
5223 if (!status) return; | 4926 if (!status) return; |
5224 status->ok_ = true; | 4927 status->ok_ = true; |
5225 status->code_ = 0; | 4928 status->code_ = 0; |
5226 status->msg[0] = '\0'; | 4929 status->msg[0] = '\0'; |
5227 } | 4930 } |
5228 | 4931 |
5229 bool upb_ok(const upb_status *status) { return status->ok_; } | 4932 bool upb_ok(const upb_status *status) { return status->ok_; } |
5230 | 4933 |
5231 upb_errorspace *upb_status_errspace(const upb_status *status) { | 4934 upb_errorspace *upb_status_errspace(const upb_status *status) { |
(...skipping 18 matching lines...) Expand all Loading... |
5250 va_end(args); | 4953 va_end(args); |
5251 } | 4954 } |
5252 | 4955 |
5253 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { | 4956 void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) { |
5254 if (!status) return; | 4957 if (!status) return; |
5255 status->ok_ = false; | 4958 status->ok_ = false; |
5256 _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); | 4959 _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args); |
5257 nullz(status); | 4960 nullz(status); |
5258 } | 4961 } |
5259 | 4962 |
| 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 |
5260 void upb_status_copy(upb_status *to, const upb_status *from) { | 4972 void upb_status_copy(upb_status *to, const upb_status *from) { |
5261 if (!to) return; | 4973 if (!to) return; |
5262 *to = *from; | 4974 *to = *from; |
5263 } | 4975 } |
5264 | 4976 /* This file was generated by upbc (the upb compiler). |
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 * | |
5512 * Do not edit -- your changes will be discarded when the file is | 4977 * Do not edit -- your changes will be discarded when the file is |
5513 * regenerated. */ | 4978 * regenerated. */ |
5514 | 4979 |
5515 | 4980 |
5516 static const upb_msgdef msgs[22]; | 4981 static const upb_msgdef msgs[20]; |
5517 static const upb_fielddef fields[105]; | 4982 static const upb_fielddef fields[81]; |
5518 static const upb_enumdef enums[5]; | 4983 static const upb_enumdef enums[4]; |
5519 static const upb_tabent strentries[236]; | 4984 static const upb_tabent strentries[236]; |
5520 static const upb_tabent intentries[18]; | 4985 static const upb_tabent intentries[14]; |
5521 static const upb_tabval arrays[184]; | 4986 static const upb_tabval arrays[232]; |
5522 | 4987 |
5523 #ifdef UPB_DEBUG_REFS | 4988 #ifdef UPB_DEBUG_REFS |
5524 static upb_inttable reftables[264]; | 4989 static upb_inttable reftables[212]; |
5525 #endif | 4990 #endif |
5526 | 4991 |
5527 static const upb_msgdef msgs[22] = { | 4992 static const upb_msgdef msgs[20] = { |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | |
5550 }; | 5013 }; |
5551 | 5014 |
5552 static const upb_fielddef fields[105] = { | 5015 static const upb_fielddef fields[81] = { |
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]), | 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]), |
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]
), | 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]
), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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])
, |
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]), | 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]), |
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]), | 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]), |
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]
), | 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]), |
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])
, | 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]), |
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
]), | 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]), |
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]), | 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])
, |
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])
, | 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]), |
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
]), | 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]), |
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])
, | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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])
, | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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
]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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
]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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
]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | |
5658 }; | 5097 }; |
5659 | 5098 |
5660 static const upb_enumdef enums[5] = { | 5099 static const upb_enumdef enums[4] = { |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | 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]), |
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]), | |
5666 }; | 5104 }; |
5667 | 5105 |
5668 static const upb_tabent strentries[236] = { | 5106 static const upb_tabent strentries[236] = { |
5669 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[22]), NULL}, | 5107 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[14]), NULL}, |
5670 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5108 {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}, | 5109 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5672 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[52]), NULL}, | 5110 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[38]), NULL}, |
5673 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5111 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5674 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5112 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5675 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5113 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5676 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INI
T(&fields[25]), &strentries[12]}, | 5114 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "field"), UPB_TABVALUE_PTR_INI
T(&fields[16]), NULL}, |
5677 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVAL
UE_PTR_INIT(&fields[24]), &strentries[14]}, | 5115 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "extension_range"), UPB_TABVAL
UE_PTR_INIT(&fields[15]), NULL}, |
5678 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5116 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5679 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_P
TR_INIT(&fields[60]), NULL}, | 5117 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "nested_type"), UPB_TABVALUE_P
TR_INIT(&fields[44]), NULL}, |
5680 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5118 {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}, | 5119 {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}, | 5120 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5683 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "oneof_decl"), UPB_TABVALUE_PT
R_INIT(&fields[65]), NULL}, | 5121 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[49]), NULL}, |
5684 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR
_INIT(&fields[19]), &strentries[13]}, | 5122 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR
_INIT(&fields[9]), &strentries[14]}, |
5685 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INI
T(&fields[89]), NULL}, | 5123 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "start"), UPB_TABVALUE_PTR_INI
T(&fields[66]), NULL}, |
5686 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(
&fields[18]), NULL}, | 5124 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(
&fields[8]), NULL}, |
5687 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5125 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5688 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5126 {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}, | 5127 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5690 {UPB_TABKEY_STR("\003", "\000", "\000", "\000", "end"), UPB_TABVALUE_PTR_INIT(
&fields[17]), NULL}, | 5128 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INI
T(&fields[78]), NULL}, |
5691 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5129 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[50]), NULL}, |
5692 {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]}, |
5693 {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}, |
5694 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "value"), UPB_TABVALUE_PTR_INI
T(&fields[102]), NULL}, | 5132 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, 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}, | |
5699 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_P
TR_INIT(&fields[1]), NULL}, | 5133 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "allow_alias"), UPB_TABVALUE_P
TR_INIT(&fields[1]), NULL}, |
5700 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5134 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5701 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN
IT(&fields[62]), NULL}, | 5135 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN
IT(&fields[47]), NULL}, |
5702 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5136 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5703 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[73]), NULL}, | 5137 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[52]), NULL}, |
5704 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[53]), &strentries[34]}, | 5138 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[37]), &strentries[30]}, |
5705 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[97]), NULL}, | 5139 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[71]), NULL}, |
5706 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[15]), NULL}, | 5140 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5707 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5141 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5708 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5142 {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}, | 5143 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5710 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INI
T(&fields[40]), NULL}, | 5144 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "label"), UPB_TABVALUE_PTR_INI
T(&fields[27]), NULL}, |
5711 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5145 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5712 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[55]), NULL}, | 5146 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[41]), NULL}, |
5713 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5147 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5714 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5148 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5715 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5149 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5716 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5150 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5717 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN
IT(&fields[63]), &strentries[53]}, | 5151 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "number"), UPB_TABVALUE_PTR_IN
IT(&fields[46]), &strentries[49]}, |
5718 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5152 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5719 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_
INIT(&fields[21]), NULL}, | 5153 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5720 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR
_INIT(&fields[94]), NULL}, | 5154 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "type_name"), UPB_TABVALUE_PTR
_INIT(&fields[70]), NULL}, |
5721 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "json_name"), UPB_TABVALUE_PTR
_INIT(&fields[38]), NULL}, | 5155 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "extendee"), UPB_TABVALUE_PTR_
INIT(&fields[12]), NULL}, |
5722 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT
(&fields[93]), &strentries[50]}, | 5156 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "type"), UPB_TABVALUE_PTR_INIT
(&fields[69]), &strentries[48]}, |
5723 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE
_PTR_INIT(&fields[7]), NULL}, | 5157 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "default_value"), UPB_TABVALUE
_PTR_INIT(&fields[4]), NULL}, |
5724 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[71]), NULL}, | 5158 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[51]), NULL}, |
5725 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[99]), NULL}, | 5159 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "experimental_map_key"), UPB_T
ABVALUE_PTR_INIT(&fields[11]), &strentries[67]}, |
5726 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5160 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5727 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT
(&fields[103]), NULL}, | 5161 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "weak"), UPB_TABVALUE_PTR_INIT
(&fields[79]), NULL}, |
5728 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5162 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5729 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5163 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5730 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5164 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5731 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5165 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5732 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_IN
IT(&fields[77]), NULL}, | 5166 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "packed"), UPB_TABVALUE_PTR_IN
IT(&fields[58]), NULL}, |
5733 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT
(&fields[41]), NULL}, | 5167 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "lazy"), UPB_TABVALUE_PTR_INIT
(&fields[28]), NULL}, |
5734 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5168 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5735 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INI
T(&fields[6]), NULL}, | 5169 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "ctype"), UPB_TABVALUE_PTR_INI
T(&fields[3]), NULL}, |
5736 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5170 {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}, | 5171 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5738 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[10]), NULL}, | 5172 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[6]), NULL}, |
5739 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5173 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5740 {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}, |
5741 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[23]), NULL}, | 5175 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "extension"), UPB_TABVALUE_PTR
_INIT(&fields[13]), NULL}, |
5742 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVAL
UE_PTR_INIT(&fields[104]), NULL}, | 5176 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "weak_dependency"), UPB_TABVAL
UE_PTR_INIT(&fields[80]), NULL}, |
5743 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5177 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5744 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[54]), NULL}, | 5178 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[34]), NULL}, |
5745 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_I
NIT(&fields[85]), NULL}, | 5179 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "service"), UPB_TABVALUE_PTR_I
NIT(&fields[63]), NULL}, |
5746 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5180 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5747 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVA
LUE_PTR_INIT(&fields[86]), NULL}, | 5181 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "source_code_info"), UPB_TABVA
LUE_PTR_INIT(&fields[64]), NULL}, |
5748 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5182 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5749 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5183 {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}, | 5184 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5751 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PT
R_INIT(&fields[8]), NULL}, | 5185 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "dependency"), UPB_TABVALUE_PT
R_INIT(&fields[5]), NULL}, |
5752 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_
PTR_INIT(&fields[47]), NULL}, | 5186 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "message_type"), UPB_TABVALUE_
PTR_INIT(&fields[32]), NULL}, |
5753 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_I
NIT(&fields[76]), NULL}, | 5187 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "package"), UPB_TABVALUE_PTR_I
NIT(&fields[57]), NULL}, |
5754 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[69]), &strentries[86]}, | 5188 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[53]), &strentries[82]}, |
5755 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR
_INIT(&fields[20]), NULL}, | 5189 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "enum_type"), UPB_TABVALUE_PTR
_INIT(&fields[10]), NULL}, |
5756 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABV
ALUE_PTR_INIT(&fields[80]), &strentries[85]}, | 5190 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "public_dependency"), UPB_TABV
ALUE_PTR_INIT(&fields[61]), &strentries[81]}, |
5757 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5191 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5758 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT
(&fields[26]), NULL}, | 5192 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "file"), UPB_TABVALUE_PTR_INIT
(&fields[17]), NULL}, |
5759 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5193 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5760 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5194 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5761 {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}, |
5762 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5196 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5763 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TA
BVALUE_PTR_INIT(&fields[3]), NULL}, | 5197 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "cc_generic_services"), UPB_TA
BVALUE_PTR_INIT(&fields[2]), NULL}, |
5764 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "csharp_namespace"), UPB_TABVA
LUE_PTR_INIT(&fields[5]), NULL}, | 5198 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5765 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5199 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TA
BVALUE_PTR_INIT(&fields[24]), NULL}, |
5766 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5200 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5767 {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]}, |
5768 {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}, |
5769 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5203 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5770 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5204 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5771 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5205 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5772 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PT
R_INIT(&fields[27]), NULL}, | 5206 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "go_package"), UPB_TABVALUE_PT
R_INIT(&fields[18]), NULL}, |
5773 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_
PTR_INIT(&fields[35]), &strentries[120]}, | 5207 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "java_package"), UPB_TABVALUE_
PTR_INIT(&fields[26]), NULL}, |
5774 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5208 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_
PTR_INIT(&fields[48]), NULL}, |
5775 {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}, |
5776 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_T
ABVALUE_PTR_INIT(&fields[34]), NULL}, | 5210 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "java_outer_classname"), UPB_T
ABVALUE_PTR_INIT(&fields[25]), NULL}, |
5777 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[95]), NULL}, | 5211 {UPB_TABKEY_STR("\027", "\000", "\000", "\000", "message_set_wire_format"), UP
B_TABVALUE_PTR_INIT(&fields[31]), &strentries[106]}, |
5778 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5212 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5779 {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}, |
5780 {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}, |
5781 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "java_multiple_files"), UPB_TA
BVALUE_PTR_INIT(&fields[33]), &strentries[117]}, | 5215 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5782 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5216 {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]}, | 5217 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5784 {UPB_TABKEY_STR("\035", "\000", "\000", "\000", "java_generate_equals_and_hash
"), UPB_TABVALUE_PTR_INIT(&fields[31]), NULL}, | 5218 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[39]), NULL}, |
5785 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5219 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "input_type"), UPB_TABVALUE_PT
R_INIT(&fields[20]), NULL}, |
5786 {UPB_TABKEY_STR("\037", "\000", "\000", "\000", "javanano_use_deprecated_packa
ge"), UPB_TABVALUE_PTR_INIT(&fields[37]), &strentries[123]}, | 5220 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5787 {UPB_TABKEY_STR("\023", "\000", "\000", "\000", "py_generic_services"), UPB_TA
BVALUE_PTR_INIT(&fields[81]), NULL}, | 5221 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "output_type"), UPB_TABVALUE_P
TR_INIT(&fields[56]), NULL}, |
5788 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "optimize_for"), UPB_TABVALUE_
PTR_INIT(&fields[67]), NULL}, | 5222 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[55]), NULL}, |
5789 {UPB_TABKEY_STR("\026", "\000", "\000", "\000", "java_string_check_utf8"), UPB
_TABVALUE_PTR_INIT(&fields[36]), NULL}, | 5223 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[74]), NULL}, |
5790 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[12]), &strentries[119]}, | 5224 {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}, | 5225 {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}, | 5226 {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]}, | 5227 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5794 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5228 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[54]), &strentries[122]}, |
5795 {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}, |
5796 {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]}, |
5797 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[96]), NULL}, | 5231 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[72]), NULL}, |
5798 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[9]), NULL}, | 5232 {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}, | 5233 {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}, | 5234 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5801 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5235 {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}, | 5236 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5803 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "server_streaming"), UPB_TABVA
LUE_PTR_INIT(&fields[84]), NULL}, | 5237 {UPB_TABKEY_STR("\010", "\000", "\000", "\000", "location"), UPB_TABVALUE_PTR_
INIT(&fields[30]), NULL}, |
5804 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[56]), NULL}, | 5238 {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}, | 5239 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5806 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5240 {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}, | 5241 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5808 {UPB_TABKEY_STR("\007", "\000", "\000", "\000", "options"), UPB_TABVALUE_PTR_I
NIT(&fields[70]), NULL}, | 5242 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "span"), UPB_TABVALUE_PTR_INIT
(&fields[65]), &strentries[139]}, |
5809 {UPB_TABKEY_STR("\024", "\000", "\000", "\000", "uninterpreted_option"), UPB_T
ABVALUE_PTR_INIT(&fields[100]), NULL}, | 5243 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5810 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "deprecated"), UPB_TABVALUE_PT
R_INIT(&fields[11]), NULL}, | 5244 {UPB_TABKEY_STR("\021", "\000", "\000", "\000", "trailing_comments"), UPB_TABV
ALUE_PTR_INIT(&fields[68]), NULL}, |
5811 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5245 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "leading_comments"), UPB_TABVA
LUE_PTR_INIT(&fields[29]), &strentries[137]}, |
5812 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5246 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "path"), UPB_TABVALUE_PTR_INIT
(&fields[59]), NULL}, |
5813 {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}, |
5814 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5248 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5815 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5249 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5816 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[50]), NULL}, | 5250 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[36]), NULL}, |
5817 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5251 {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]}, | 5252 {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}, | 5253 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5820 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "name"), UPB_TABVALUE_PTR_INIT
(&fields[57]), &strentries[149]}, | 5254 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "negative_int_value"), UPB_TAB
VALUE_PTR_INIT(&fields[43]), NULL}, |
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}, | |
5845 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVAL
UE_PTR_INIT(&fields[0]), NULL}, | 5255 {UPB_TABKEY_STR("\017", "\000", "\000", "\000", "aggregate_value"), UPB_TABVAL
UE_PTR_INIT(&fields[0]), NULL}, |
5846 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5256 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5847 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5257 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5848 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5258 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5849 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5259 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5850 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TAB
VALUE_PTR_INIT(&fields[79]), NULL}, | 5260 {UPB_TABKEY_STR("\022", "\000", "\000", "\000", "positive_int_value"), UPB_TAB
VALUE_PTR_INIT(&fields[60]), NULL}, |
5851 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVA
LUE_PTR_INIT(&fields[28]), NULL}, | 5261 {UPB_TABKEY_STR("\020", "\000", "\000", "\000", "identifier_value"), UPB_TABVA
LUE_PTR_INIT(&fields[19]), NULL}, |
5852 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_
PTR_INIT(&fields[90]), &strentries[182]}, | 5262 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "string_value"), UPB_TABVALUE_
PTR_INIT(&fields[67]), &strentries[154]}, |
5853 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5263 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5854 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5264 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5855 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_
PTR_INIT(&fields[30]), NULL}, | 5265 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "is_extension"), UPB_TABVALUE_
PTR_INIT(&fields[21]), NULL}, |
5856 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR
_INIT(&fields[58]), NULL}, | 5266 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "name_part"), UPB_TABVALUE_PTR
_INIT(&fields[42]), NULL}, |
5857 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALU
E_INT_INIT(2), &strentries[190]}, | 5267 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REQUIRED"), UPB_TABVALU
E_INT_INIT(2), &strentries[162]}, |
5858 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5268 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5859 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALU
E_INT_INIT(3), NULL}, | 5269 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_REPEATED"), UPB_TABVALU
E_INT_INIT(3), NULL}, |
5860 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALU
E_INT_INIT(1), NULL}, | 5270 {UPB_TABKEY_STR("\016", "\000", "\000", "\000", "LABEL_OPTIONAL"), UPB_TABVALU
E_INT_INIT(1), NULL}, |
5861 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_
INT_INIT(6), NULL}, | 5271 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED64"), UPB_TABVALUE_
INT_INIT(6), NULL}, |
5862 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5272 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5863 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5273 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5864 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5274 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5865 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5275 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5866 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_I
NT_INIT(9), NULL}, | 5276 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_STRING"), UPB_TABVALUE_I
NT_INIT(9), NULL}, |
5867 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_IN
T_INIT(2), &strentries[221]}, | 5277 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_FLOAT"), UPB_TABVALUE_IN
T_INIT(2), &strentries[193]}, |
5868 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_I
NT_INIT(1), NULL}, | 5278 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_DOUBLE"), UPB_TABVALUE_I
NT_INIT(1), NULL}, |
5869 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5279 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5870 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_IN
T_INIT(5), NULL}, | 5280 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT32"), UPB_TABVALUE_IN
T_INIT(5), NULL}, |
5871 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE
_INT_INIT(15), NULL}, | 5281 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED32"), UPB_TABVALUE
_INT_INIT(15), NULL}, |
5872 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_
INT_INIT(7), NULL}, | 5282 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_FIXED32"), UPB_TABVALUE_
INT_INIT(7), NULL}, |
5873 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5283 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5874 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_
INT_INIT(11), &strentries[222]}, | 5284 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "TYPE_MESSAGE"), UPB_TABVALUE_
INT_INIT(11), &strentries[194]}, |
5875 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5285 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5876 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5286 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5877 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_IN
T_INIT(3), &strentries[219]}, | 5287 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_INT64"), UPB_TABVALUE_IN
T_INIT(3), &strentries[191]}, |
5878 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5288 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5879 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5289 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5880 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5290 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5881 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5291 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5882 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT
_INIT(14), NULL}, | 5292 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_ENUM"), UPB_TABVALUE_INT
_INIT(14), NULL}, |
5883 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_I
NT_INIT(13), NULL}, | 5293 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT32"), UPB_TABVALUE_I
NT_INIT(13), NULL}, |
5884 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5294 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5885 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_I
NT_INIT(4), &strentries[218]}, | 5295 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_UINT64"), UPB_TABVALUE_I
NT_INIT(4), &strentries[190]}, |
5886 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5296 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5887 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE
_INT_INIT(16), NULL}, | 5297 {UPB_TABKEY_STR("\015", "\000", "\000", "\000", "TYPE_SFIXED64"), UPB_TABVALUE
_INT_INIT(16), NULL}, |
5888 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_IN
T_INIT(12), NULL}, | 5298 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_BYTES"), UPB_TABVALUE_IN
T_INIT(12), NULL}, |
5889 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT64"), UPB_TABVALUE_I
NT_INIT(18), NULL}, | 5299 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT64"), UPB_TABVALUE_I
NT_INIT(18), NULL}, |
5890 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_BOOL"), UPB_TABVALUE_INT
_INIT(8), NULL}, | 5300 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "TYPE_BOOL"), UPB_TABVALUE_INT
_INIT(8), NULL}, |
5891 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_GROUP"), UPB_TABVALUE_IN
T_INIT(10), NULL}, | 5301 {UPB_TABKEY_STR("\012", "\000", "\000", "\000", "TYPE_GROUP"), UPB_TABVALUE_IN
T_INIT(10), NULL}, |
5892 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_I
NT_INIT(17), NULL}, | 5302 {UPB_TABKEY_STR("\013", "\000", "\000", "\000", "TYPE_SINT32"), UPB_TABVALUE_I
NT_INIT(17), NULL}, |
5893 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5303 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5894 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT
(1), NULL}, | 5304 {UPB_TABKEY_STR("\004", "\000", "\000", "\000", "CORD"), UPB_TABVALUE_INT_INIT
(1), NULL}, |
5895 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_IN
IT(0), &strentries[225]}, | 5305 {UPB_TABKEY_STR("\006", "\000", "\000", "\000", "STRING"), UPB_TABVALUE_INT_IN
IT(0), &strentries[197]}, |
5896 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "STRING_PIECE"), UPB_TABVALUE_
INT_INIT(2), NULL}, | 5306 {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}, | |
5901 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT
_INIT(2), NULL}, | 5307 {UPB_TABKEY_STR("\011", "\000", "\000", "\000", "CODE_SIZE"), UPB_TABVALUE_INT
_INIT(2), NULL}, |
5902 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INI
T(1), &strentries[235]}, | 5308 {UPB_TABKEY_STR("\005", "\000", "\000", "\000", "SPEED"), UPB_TABVALUE_INT_INI
T(1), &strentries[203]}, |
5903 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5309 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5904 {UPB_TABKEY_STR("\014", "\000", "\000", "\000", "LITE_RUNTIME"), UPB_TABVALUE_
INT_INIT(3), NULL}, | 5310 {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}, |
5905 }; | 5343 }; |
5906 | 5344 |
5907 static const upb_tabent intentries[18] = { | 5345 static const upb_tabent intentries[14] = { |
5908 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5346 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5909 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[98]), NULL}, | 5347 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[73]), NULL}, |
5910 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5348 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5911 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[97]), NULL}, | 5349 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[71]), NULL}, |
5912 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5350 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5913 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[99]), NULL}, | 5351 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[77]), NULL}, |
5914 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5352 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5915 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[95]), NULL}, | 5353 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[75]), NULL}, |
5916 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5354 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5917 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[96]), NULL}, | 5355 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[76]), NULL}, |
5918 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5356 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5919 {UPB_TABKEY_NUM(33), UPB_TABVALUE_PTR_INIT(&fields[11]), NULL}, | 5357 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[74]), NULL}, |
5920 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, | 5358 {UPB_TABKEY_NONE, UPB_TABVALUE_EMPTY_INIT, NULL}, |
5921 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[100]), NULL}, | 5359 {UPB_TABKEY_NUM(999), UPB_TABVALUE_PTR_INIT(&fields[72]), 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}, | |
5926 }; | 5360 }; |
5927 | 5361 |
5928 static const upb_tabval arrays[184] = { | 5362 static const upb_tabval arrays[232] = { |
5929 UPB_TABVALUE_EMPTY_INIT, | 5363 UPB_TABVALUE_EMPTY_INIT, |
| 5364 UPB_TABVALUE_PTR_INIT(&fields[38]), |
| 5365 UPB_TABVALUE_PTR_INIT(&fields[16]), |
| 5366 UPB_TABVALUE_PTR_INIT(&fields[44]), |
| 5367 UPB_TABVALUE_PTR_INIT(&fields[9]), |
| 5368 UPB_TABVALUE_PTR_INIT(&fields[15]), |
| 5369 UPB_TABVALUE_PTR_INIT(&fields[14]), |
| 5370 UPB_TABVALUE_PTR_INIT(&fields[49]), |
| 5371 UPB_TABVALUE_EMPTY_INIT, |
| 5372 UPB_TABVALUE_PTR_INIT(&fields[66]), |
| 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, |
| 5379 UPB_TABVALUE_EMPTY_INIT, |
| 5380 UPB_TABVALUE_PTR_INIT(&fields[1]), |
| 5381 UPB_TABVALUE_EMPTY_INIT, |
| 5382 UPB_TABVALUE_EMPTY_INIT, |
| 5383 UPB_TABVALUE_EMPTY_INIT, |
| 5384 UPB_TABVALUE_EMPTY_INIT, |
| 5385 UPB_TABVALUE_EMPTY_INIT, |
| 5386 UPB_TABVALUE_EMPTY_INIT, |
| 5387 UPB_TABVALUE_PTR_INIT(&fields[37]), |
| 5388 UPB_TABVALUE_PTR_INIT(&fields[47]), |
5930 UPB_TABVALUE_PTR_INIT(&fields[52]), | 5389 UPB_TABVALUE_PTR_INIT(&fields[52]), |
5931 UPB_TABVALUE_PTR_INIT(&fields[25]), | 5390 UPB_TABVALUE_EMPTY_INIT, |
5932 UPB_TABVALUE_PTR_INIT(&fields[60]), | 5391 UPB_TABVALUE_EMPTY_INIT, |
5933 UPB_TABVALUE_PTR_INIT(&fields[19]), | 5392 UPB_TABVALUE_EMPTY_INIT, |
5934 UPB_TABVALUE_PTR_INIT(&fields[24]), | 5393 UPB_TABVALUE_EMPTY_INIT, |
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, | |
5947 UPB_TABVALUE_PTR_INIT(&fields[49]), | |
5948 UPB_TABVALUE_PTR_INIT(&fields[102]), | |
5949 UPB_TABVALUE_PTR_INIT(&fields[74]), | |
5950 UPB_TABVALUE_EMPTY_INIT, | |
5951 UPB_TABVALUE_EMPTY_INIT, | |
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, | 5394 UPB_TABVALUE_EMPTY_INIT, |
5976 UPB_TABVALUE_PTR_INIT(&fields[41]), | 5395 UPB_TABVALUE_PTR_INIT(&fields[41]), |
5977 UPB_TABVALUE_PTR_INIT(&fields[39]), | 5396 UPB_TABVALUE_PTR_INIT(&fields[12]), |
5978 UPB_TABVALUE_EMPTY_INIT, | 5397 UPB_TABVALUE_PTR_INIT(&fields[46]), |
5979 UPB_TABVALUE_EMPTY_INIT, | 5398 UPB_TABVALUE_PTR_INIT(&fields[27]), |
5980 UPB_TABVALUE_EMPTY_INIT, | |
5981 UPB_TABVALUE_PTR_INIT(&fields[103]), | |
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]), | 5399 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]), | |
5995 UPB_TABVALUE_EMPTY_INIT, | |
5996 UPB_TABVALUE_PTR_INIT(&fields[26]), | |
5997 UPB_TABVALUE_EMPTY_INIT, | |
5998 UPB_TABVALUE_PTR_INIT(&fields[35]), | |
5999 UPB_TABVALUE_EMPTY_INIT, | |
6000 UPB_TABVALUE_EMPTY_INIT, | |
6001 UPB_TABVALUE_EMPTY_INIT, | |
6002 UPB_TABVALUE_EMPTY_INIT, | |
6003 UPB_TABVALUE_EMPTY_INIT, | |
6004 UPB_TABVALUE_EMPTY_INIT, | |
6005 UPB_TABVALUE_PTR_INIT(&fields[34]), | |
6006 UPB_TABVALUE_PTR_INIT(&fields[67]), | |
6007 UPB_TABVALUE_PTR_INIT(&fields[33]), | |
6008 UPB_TABVALUE_PTR_INIT(&fields[27]), | |
6009 UPB_TABVALUE_EMPTY_INIT, | |
6010 UPB_TABVALUE_EMPTY_INIT, | |
6011 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]), | |
6018 UPB_TABVALUE_EMPTY_INIT, | |
6019 UPB_TABVALUE_EMPTY_INIT, | |
6020 UPB_TABVALUE_PTR_INIT(&fields[12]), | |
6021 UPB_TABVALUE_EMPTY_INIT, | |
6022 UPB_TABVALUE_EMPTY_INIT, | |
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]), | |
6029 UPB_TABVALUE_EMPTY_INIT, | |
6030 UPB_TABVALUE_EMPTY_INIT, | |
6031 UPB_TABVALUE_EMPTY_INIT, | |
6032 UPB_TABVALUE_EMPTY_INIT, | |
6033 UPB_TABVALUE_PTR_INIT(&fields[64]), | |
6034 UPB_TABVALUE_PTR_INIT(&fields[5]), | |
6035 UPB_TABVALUE_PTR_INIT(&fields[37]), | |
6036 UPB_TABVALUE_EMPTY_INIT, | |
6037 UPB_TABVALUE_PTR_INIT(&fields[46]), | |
6038 UPB_TABVALUE_PTR_INIT(&fields[61]), | |
6039 UPB_TABVALUE_PTR_INIT(&fields[9]), | |
6040 UPB_TABVALUE_EMPTY_INIT, | |
6041 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]), | 5400 UPB_TABVALUE_PTR_INIT(&fields[70]), |
6049 UPB_TABVALUE_PTR_INIT(&fields[4]), | 5401 UPB_TABVALUE_PTR_INIT(&fields[4]), |
6050 UPB_TABVALUE_PTR_INIT(&fields[84]), | 5402 UPB_TABVALUE_PTR_INIT(&fields[51]), |
6051 UPB_TABVALUE_EMPTY_INIT, | 5403 UPB_TABVALUE_EMPTY_INIT, |
6052 UPB_TABVALUE_EMPTY_INIT, | 5404 UPB_TABVALUE_PTR_INIT(&fields[3]), |
6053 UPB_TABVALUE_PTR_INIT(&fields[50]), | 5405 UPB_TABVALUE_PTR_INIT(&fields[58]), |
6054 UPB_TABVALUE_EMPTY_INIT, | 5406 UPB_TABVALUE_PTR_INIT(&fields[6]), |
| 5407 UPB_TABVALUE_EMPTY_INIT, |
| 5408 UPB_TABVALUE_PTR_INIT(&fields[28]), |
| 5409 UPB_TABVALUE_EMPTY_INIT, |
| 5410 UPB_TABVALUE_EMPTY_INIT, |
| 5411 UPB_TABVALUE_EMPTY_INIT, |
| 5412 UPB_TABVALUE_PTR_INIT(&fields[11]), |
| 5413 UPB_TABVALUE_PTR_INIT(&fields[79]), |
| 5414 UPB_TABVALUE_EMPTY_INIT, |
| 5415 UPB_TABVALUE_EMPTY_INIT, |
| 5416 UPB_TABVALUE_EMPTY_INIT, |
| 5417 UPB_TABVALUE_EMPTY_INIT, |
| 5418 UPB_TABVALUE_EMPTY_INIT, |
| 5419 UPB_TABVALUE_EMPTY_INIT, |
| 5420 UPB_TABVALUE_EMPTY_INIT, |
| 5421 UPB_TABVALUE_EMPTY_INIT, |
| 5422 UPB_TABVALUE_EMPTY_INIT, |
| 5423 UPB_TABVALUE_EMPTY_INIT, |
| 5424 UPB_TABVALUE_EMPTY_INIT, |
| 5425 UPB_TABVALUE_EMPTY_INIT, |
| 5426 UPB_TABVALUE_EMPTY_INIT, |
| 5427 UPB_TABVALUE_EMPTY_INIT, |
| 5428 UPB_TABVALUE_EMPTY_INIT, |
| 5429 UPB_TABVALUE_EMPTY_INIT, |
| 5430 UPB_TABVALUE_EMPTY_INIT, |
| 5431 UPB_TABVALUE_EMPTY_INIT, |
| 5432 UPB_TABVALUE_EMPTY_INIT, |
| 5433 UPB_TABVALUE_EMPTY_INIT, |
| 5434 UPB_TABVALUE_EMPTY_INIT, |
| 5435 UPB_TABVALUE_EMPTY_INIT, |
| 5436 UPB_TABVALUE_PTR_INIT(&fields[34]), |
6055 UPB_TABVALUE_PTR_INIT(&fields[57]), | 5437 UPB_TABVALUE_PTR_INIT(&fields[57]), |
| 5438 UPB_TABVALUE_PTR_INIT(&fields[5]), |
| 5439 UPB_TABVALUE_PTR_INIT(&fields[32]), |
| 5440 UPB_TABVALUE_PTR_INIT(&fields[10]), |
| 5441 UPB_TABVALUE_PTR_INIT(&fields[63]), |
| 5442 UPB_TABVALUE_PTR_INIT(&fields[13]), |
| 5443 UPB_TABVALUE_PTR_INIT(&fields[53]), |
| 5444 UPB_TABVALUE_PTR_INIT(&fields[64]), |
| 5445 UPB_TABVALUE_PTR_INIT(&fields[61]), |
| 5446 UPB_TABVALUE_PTR_INIT(&fields[80]), |
| 5447 UPB_TABVALUE_EMPTY_INIT, |
| 5448 UPB_TABVALUE_PTR_INIT(&fields[17]), |
| 5449 UPB_TABVALUE_EMPTY_INIT, |
| 5450 UPB_TABVALUE_PTR_INIT(&fields[26]), |
| 5451 UPB_TABVALUE_EMPTY_INIT, |
| 5452 UPB_TABVALUE_EMPTY_INIT, |
| 5453 UPB_TABVALUE_EMPTY_INIT, |
| 5454 UPB_TABVALUE_EMPTY_INIT, |
| 5455 UPB_TABVALUE_EMPTY_INIT, |
| 5456 UPB_TABVALUE_EMPTY_INIT, |
| 5457 UPB_TABVALUE_PTR_INIT(&fields[25]), |
6056 UPB_TABVALUE_PTR_INIT(&fields[48]), | 5458 UPB_TABVALUE_PTR_INIT(&fields[48]), |
6057 UPB_TABVALUE_PTR_INIT(&fields[72]), | 5459 UPB_TABVALUE_PTR_INIT(&fields[24]), |
6058 UPB_TABVALUE_EMPTY_INIT, | 5460 UPB_TABVALUE_PTR_INIT(&fields[18]), |
6059 UPB_TABVALUE_EMPTY_INIT, | 5461 UPB_TABVALUE_EMPTY_INIT, |
6060 UPB_TABVALUE_PTR_INIT(&fields[44]), | 5462 UPB_TABVALUE_EMPTY_INIT, |
6061 UPB_TABVALUE_EMPTY_INIT, | 5463 UPB_TABVALUE_EMPTY_INIT, |
6062 UPB_TABVALUE_PTR_INIT(&fields[78]), | 5464 UPB_TABVALUE_EMPTY_INIT, |
6063 UPB_TABVALUE_PTR_INIT(&fields[87]), | 5465 UPB_TABVALUE_PTR_INIT(&fields[2]), |
| 5466 UPB_TABVALUE_PTR_INIT(&fields[23]), |
| 5467 UPB_TABVALUE_PTR_INIT(&fields[62]), |
| 5468 UPB_TABVALUE_EMPTY_INIT, |
| 5469 UPB_TABVALUE_PTR_INIT(&fields[22]), |
| 5470 UPB_TABVALUE_EMPTY_INIT, |
| 5471 UPB_TABVALUE_EMPTY_INIT, |
| 5472 UPB_TABVALUE_EMPTY_INIT, |
| 5473 UPB_TABVALUE_EMPTY_INIT, |
| 5474 UPB_TABVALUE_EMPTY_INIT, |
| 5475 UPB_TABVALUE_EMPTY_INIT, |
| 5476 UPB_TABVALUE_EMPTY_INIT, |
| 5477 UPB_TABVALUE_EMPTY_INIT, |
| 5478 UPB_TABVALUE_EMPTY_INIT, |
| 5479 UPB_TABVALUE_EMPTY_INIT, |
| 5480 UPB_TABVALUE_EMPTY_INIT, |
| 5481 UPB_TABVALUE_EMPTY_INIT, |
| 5482 UPB_TABVALUE_EMPTY_INIT, |
| 5483 UPB_TABVALUE_EMPTY_INIT, |
| 5484 UPB_TABVALUE_EMPTY_INIT, |
| 5485 UPB_TABVALUE_EMPTY_INIT, |
| 5486 UPB_TABVALUE_EMPTY_INIT, |
| 5487 UPB_TABVALUE_EMPTY_INIT, |
| 5488 UPB_TABVALUE_EMPTY_INIT, |
| 5489 UPB_TABVALUE_EMPTY_INIT, |
| 5490 UPB_TABVALUE_EMPTY_INIT, |
| 5491 UPB_TABVALUE_EMPTY_INIT, |
| 5492 UPB_TABVALUE_EMPTY_INIT, |
| 5493 UPB_TABVALUE_EMPTY_INIT, |
| 5494 UPB_TABVALUE_EMPTY_INIT, |
| 5495 UPB_TABVALUE_EMPTY_INIT, |
| 5496 UPB_TABVALUE_EMPTY_INIT, |
| 5497 UPB_TABVALUE_EMPTY_INIT, |
| 5498 UPB_TABVALUE_EMPTY_INIT, |
| 5499 UPB_TABVALUE_EMPTY_INIT, |
| 5500 UPB_TABVALUE_EMPTY_INIT, |
| 5501 UPB_TABVALUE_EMPTY_INIT, |
| 5502 UPB_TABVALUE_EMPTY_INIT, |
| 5503 UPB_TABVALUE_EMPTY_INIT, |
| 5504 UPB_TABVALUE_EMPTY_INIT, |
| 5505 UPB_TABVALUE_EMPTY_INIT, |
| 5506 UPB_TABVALUE_EMPTY_INIT, |
| 5507 UPB_TABVALUE_EMPTY_INIT, |
| 5508 UPB_TABVALUE_EMPTY_INIT, |
| 5509 UPB_TABVALUE_EMPTY_INIT, |
| 5510 UPB_TABVALUE_EMPTY_INIT, |
| 5511 UPB_TABVALUE_EMPTY_INIT, |
| 5512 UPB_TABVALUE_EMPTY_INIT, |
| 5513 UPB_TABVALUE_EMPTY_INIT, |
| 5514 UPB_TABVALUE_PTR_INIT(&fields[31]), |
| 5515 UPB_TABVALUE_PTR_INIT(&fields[45]), |
| 5516 UPB_TABVALUE_EMPTY_INIT, |
| 5517 UPB_TABVALUE_EMPTY_INIT, |
| 5518 UPB_TABVALUE_EMPTY_INIT, |
| 5519 UPB_TABVALUE_EMPTY_INIT, |
| 5520 UPB_TABVALUE_EMPTY_INIT, |
| 5521 UPB_TABVALUE_EMPTY_INIT, |
| 5522 UPB_TABVALUE_EMPTY_INIT, |
| 5523 UPB_TABVALUE_EMPTY_INIT, |
| 5524 UPB_TABVALUE_EMPTY_INIT, |
| 5525 UPB_TABVALUE_EMPTY_INIT, |
| 5526 UPB_TABVALUE_EMPTY_INIT, |
| 5527 UPB_TABVALUE_EMPTY_INIT, |
| 5528 UPB_TABVALUE_EMPTY_INIT, |
| 5529 UPB_TABVALUE_EMPTY_INIT, |
| 5530 UPB_TABVALUE_PTR_INIT(&fields[39]), |
| 5531 UPB_TABVALUE_PTR_INIT(&fields[20]), |
| 5532 UPB_TABVALUE_PTR_INIT(&fields[56]), |
| 5533 UPB_TABVALUE_PTR_INIT(&fields[55]), |
| 5534 UPB_TABVALUE_EMPTY_INIT, |
| 5535 UPB_TABVALUE_EMPTY_INIT, |
| 5536 UPB_TABVALUE_EMPTY_INIT, |
| 5537 UPB_TABVALUE_EMPTY_INIT, |
| 5538 UPB_TABVALUE_EMPTY_INIT, |
| 5539 UPB_TABVALUE_PTR_INIT(&fields[35]), |
| 5540 UPB_TABVALUE_PTR_INIT(&fields[33]), |
| 5541 UPB_TABVALUE_PTR_INIT(&fields[54]), |
| 5542 UPB_TABVALUE_EMPTY_INIT, |
| 5543 UPB_TABVALUE_EMPTY_INIT, |
| 5544 UPB_TABVALUE_EMPTY_INIT, |
| 5545 UPB_TABVALUE_EMPTY_INIT, |
| 5546 UPB_TABVALUE_EMPTY_INIT, |
| 5547 UPB_TABVALUE_PTR_INIT(&fields[30]), |
| 5548 UPB_TABVALUE_EMPTY_INIT, |
| 5549 UPB_TABVALUE_PTR_INIT(&fields[59]), |
| 5550 UPB_TABVALUE_PTR_INIT(&fields[65]), |
| 5551 UPB_TABVALUE_PTR_INIT(&fields[29]), |
| 5552 UPB_TABVALUE_PTR_INIT(&fields[68]), |
| 5553 UPB_TABVALUE_EMPTY_INIT, |
| 5554 UPB_TABVALUE_EMPTY_INIT, |
| 5555 UPB_TABVALUE_PTR_INIT(&fields[36]), |
| 5556 UPB_TABVALUE_PTR_INIT(&fields[19]), |
| 5557 UPB_TABVALUE_PTR_INIT(&fields[60]), |
| 5558 UPB_TABVALUE_PTR_INIT(&fields[43]), |
| 5559 UPB_TABVALUE_PTR_INIT(&fields[7]), |
| 5560 UPB_TABVALUE_PTR_INIT(&fields[67]), |
| 5561 UPB_TABVALUE_PTR_INIT(&fields[0]), |
| 5562 UPB_TABVALUE_EMPTY_INIT, |
6064 UPB_TABVALUE_PTR_INIT(&fields[42]), | 5563 UPB_TABVALUE_PTR_INIT(&fields[42]), |
6065 UPB_TABVALUE_PTR_INIT(&fields[92]), | 5564 UPB_TABVALUE_PTR_INIT(&fields[21]), |
6066 UPB_TABVALUE_EMPTY_INIT, | |
6067 UPB_TABVALUE_PTR_INIT(&fields[43]), | |
6068 UPB_TABVALUE_EMPTY_INIT, | |
6069 UPB_TABVALUE_EMPTY_INIT, | |
6070 UPB_TABVALUE_PTR_INIT(&fields[51]), | |
6071 UPB_TABVALUE_PTR_INIT(&fields[28]), | |
6072 UPB_TABVALUE_PTR_INIT(&fields[79]), | |
6073 UPB_TABVALUE_PTR_INIT(&fields[59]), | |
6074 UPB_TABVALUE_PTR_INIT(&fields[16]), | |
6075 UPB_TABVALUE_PTR_INIT(&fields[90]), | |
6076 UPB_TABVALUE_PTR_INIT(&fields[0]), | |
6077 UPB_TABVALUE_EMPTY_INIT, | |
6078 UPB_TABVALUE_PTR_INIT(&fields[58]), | |
6079 UPB_TABVALUE_PTR_INIT(&fields[30]), | |
6080 UPB_TABVALUE_EMPTY_INIT, | 5565 UPB_TABVALUE_EMPTY_INIT, |
6081 UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"), | 5566 UPB_TABVALUE_PTR_INIT("LABEL_OPTIONAL"), |
6082 UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"), | 5567 UPB_TABVALUE_PTR_INIT("LABEL_REQUIRED"), |
6083 UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"), | 5568 UPB_TABVALUE_PTR_INIT("LABEL_REPEATED"), |
6084 UPB_TABVALUE_EMPTY_INIT, | 5569 UPB_TABVALUE_EMPTY_INIT, |
6085 UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"), | 5570 UPB_TABVALUE_PTR_INIT("TYPE_DOUBLE"), |
6086 UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"), | 5571 UPB_TABVALUE_PTR_INIT("TYPE_FLOAT"), |
6087 UPB_TABVALUE_PTR_INIT("TYPE_INT64"), | 5572 UPB_TABVALUE_PTR_INIT("TYPE_INT64"), |
6088 UPB_TABVALUE_PTR_INIT("TYPE_UINT64"), | 5573 UPB_TABVALUE_PTR_INIT("TYPE_UINT64"), |
6089 UPB_TABVALUE_PTR_INIT("TYPE_INT32"), | 5574 UPB_TABVALUE_PTR_INIT("TYPE_INT32"), |
6090 UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"), | 5575 UPB_TABVALUE_PTR_INIT("TYPE_FIXED64"), |
6091 UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"), | 5576 UPB_TABVALUE_PTR_INIT("TYPE_FIXED32"), |
6092 UPB_TABVALUE_PTR_INIT("TYPE_BOOL"), | 5577 UPB_TABVALUE_PTR_INIT("TYPE_BOOL"), |
6093 UPB_TABVALUE_PTR_INIT("TYPE_STRING"), | 5578 UPB_TABVALUE_PTR_INIT("TYPE_STRING"), |
6094 UPB_TABVALUE_PTR_INIT("TYPE_GROUP"), | 5579 UPB_TABVALUE_PTR_INIT("TYPE_GROUP"), |
6095 UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"), | 5580 UPB_TABVALUE_PTR_INIT("TYPE_MESSAGE"), |
6096 UPB_TABVALUE_PTR_INIT("TYPE_BYTES"), | 5581 UPB_TABVALUE_PTR_INIT("TYPE_BYTES"), |
6097 UPB_TABVALUE_PTR_INIT("TYPE_UINT32"), | 5582 UPB_TABVALUE_PTR_INIT("TYPE_UINT32"), |
6098 UPB_TABVALUE_PTR_INIT("TYPE_ENUM"), | 5583 UPB_TABVALUE_PTR_INIT("TYPE_ENUM"), |
6099 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"), | 5584 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED32"), |
6100 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"), | 5585 UPB_TABVALUE_PTR_INIT("TYPE_SFIXED64"), |
6101 UPB_TABVALUE_PTR_INIT("TYPE_SINT32"), | 5586 UPB_TABVALUE_PTR_INIT("TYPE_SINT32"), |
6102 UPB_TABVALUE_PTR_INIT("TYPE_SINT64"), | 5587 UPB_TABVALUE_PTR_INIT("TYPE_SINT64"), |
6103 UPB_TABVALUE_PTR_INIT("STRING"), | 5588 UPB_TABVALUE_PTR_INIT("STRING"), |
6104 UPB_TABVALUE_PTR_INIT("CORD"), | 5589 UPB_TABVALUE_PTR_INIT("CORD"), |
6105 UPB_TABVALUE_PTR_INIT("STRING_PIECE"), | 5590 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"), | |
6109 UPB_TABVALUE_EMPTY_INIT, | 5591 UPB_TABVALUE_EMPTY_INIT, |
6110 UPB_TABVALUE_PTR_INIT("SPEED"), | 5592 UPB_TABVALUE_PTR_INIT("SPEED"), |
6111 UPB_TABVALUE_PTR_INIT("CODE_SIZE"), | 5593 UPB_TABVALUE_PTR_INIT("CODE_SIZE"), |
6112 UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"), | 5594 UPB_TABVALUE_PTR_INIT("LITE_RUNTIME"), |
6113 }; | 5595 }; |
6114 | 5596 |
| 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 |
6115 #ifdef UPB_DEBUG_REFS | 5604 #ifdef UPB_DEBUG_REFS |
6116 static upb_inttable reftables[264] = { | 5605 static upb_inttable reftables[212] = { |
6117 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5606 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6118 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5607 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6119 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5608 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), | |
6172 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5609 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6173 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5610 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6174 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5611 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6175 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5612 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6176 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5613 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6177 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5614 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6178 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5615 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6179 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5616 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6180 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5617 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6181 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5618 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6374 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5811 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6375 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5812 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6376 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5813 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6377 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5814 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6378 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5815 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6379 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5816 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6380 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), | 5817 UPB_EMPTY_INTTABLE_INIT(UPB_CTYPE_PTR), |
6381 }; | 5818 }; |
6382 #endif | 5819 #endif |
6383 | 5820 |
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); } | |
6423 /* | 5821 /* |
6424 ** XXX: The routines in this file that consume a string do not currently | 5822 ** XXX: The routines in this file that consume a string do not currently |
6425 ** support having the string span buffers. In the future, as upb_sink and | 5823 ** support having the string span buffers. In the future, as upb_sink and |
6426 ** its buffering/sharing functionality evolve there should be an easy and | 5824 ** its buffering/sharing functionality evolve there should be an easy and |
6427 ** idiomatic way of correctly handling this case. For now, we accept this | 5825 ** idiomatic way of correctly handling this case. For now, we accept this |
6428 ** limitation since we currently only parse descriptors from single strings. | 5826 ** limitation since we currently only parse descriptors from single strings. |
6429 */ | 5827 */ |
6430 | 5828 |
6431 | 5829 |
6432 #include <errno.h> | 5830 #include <errno.h> |
6433 #include <stdlib.h> | 5831 #include <stdlib.h> |
6434 #include <string.h> | 5832 #include <string.h> |
6435 | 5833 |
6436 /* Compares a NULL-terminated string with a non-NULL-terminated string. */ | 5834 /* upb_deflist is an internal-only dynamic array for storing a growing list of |
6437 static bool upb_streq(const char *str, const char *buf, size_t n) { | 5835 * upb_defs. */ |
6438 return strlen(str) == n && memcmp(str, buf, n) == 0; | 5836 typedef struct { |
6439 } | 5837 upb_def **defs; |
| 5838 size_t len; |
| 5839 size_t size; |
| 5840 bool owned; |
| 5841 } upb_deflist; |
6440 | 5842 |
6441 /* We keep a stack of all the messages scopes we are currently in, as well as | 5843 /* We keep a stack of all the messages scopes we are currently in, as well as |
6442 * the top-level file scope. This is necessary to correctly qualify the | 5844 * the top-level file scope. This is necessary to correctly qualify the |
6443 * definitions that are contained inside. "name" tracks the name of the | 5845 * definitions that are contained inside. "name" tracks the name of the |
6444 * message or package (a bare name -- not qualified by any enclosing scopes). */ | 5846 * message or package (a bare name -- not qualified by any enclosing scopes). */ |
6445 typedef struct { | 5847 typedef struct { |
6446 char *name; | 5848 char *name; |
6447 /* Index of the first def that is under this scope. For msgdefs, the | 5849 /* Index of the first def that is under this scope. For msgdefs, the |
6448 * msgdef itself is at start-1. */ | 5850 * msgdef itself is at start-1. */ |
6449 int start; | 5851 int start; |
6450 uint32_t oneof_start; | |
6451 uint32_t oneof_index; | |
6452 } upb_descreader_frame; | 5852 } upb_descreader_frame; |
6453 | 5853 |
6454 /* The maximum number of nested declarations that are allowed, ie. | 5854 /* The maximum number of nested declarations that are allowed, ie. |
6455 * message Foo { | 5855 * message Foo { |
6456 * message Bar { | 5856 * message Bar { |
6457 * message Baz { | 5857 * message Baz { |
6458 * } | 5858 * } |
6459 * } | 5859 * } |
6460 * } | 5860 * } |
6461 * | 5861 * |
6462 * This is a resource limit that affects how big our runtime stack can grow. | 5862 * This is a resource limit that affects how big our runtime stack can grow. |
6463 * TODO: make this a runtime-settable property of the Reader instance. */ | 5863 * TODO: make this a runtime-settable property of the Reader instance. */ |
6464 #define UPB_MAX_MESSAGE_NESTING 64 | 5864 #define UPB_MAX_MESSAGE_NESTING 64 |
6465 | 5865 |
6466 struct upb_descreader { | 5866 struct upb_descreader { |
6467 upb_sink sink; | 5867 upb_sink sink; |
6468 upb_inttable files; | 5868 upb_deflist defs; |
6469 upb_filedef *file; /* The last file in files. */ | |
6470 upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; | 5869 upb_descreader_frame stack[UPB_MAX_MESSAGE_NESTING]; |
6471 int stack_len; | 5870 int stack_len; |
6472 upb_inttable oneofs; | |
6473 | 5871 |
6474 uint32_t number; | 5872 uint32_t number; |
6475 char *name; | 5873 char *name; |
6476 bool saw_number; | 5874 bool saw_number; |
6477 bool saw_name; | 5875 bool saw_name; |
6478 | 5876 |
6479 char *default_string; | 5877 char *default_string; |
6480 | 5878 |
6481 upb_fielddef *f; | 5879 upb_fielddef *f; |
6482 }; | 5880 }; |
6483 | 5881 |
6484 static char *upb_strndup(const char *buf, size_t n) { | 5882 static char *upb_strndup(const char *buf, size_t n) { |
6485 char *ret = upb_gmalloc(n + 1); | 5883 char *ret = malloc(n + 1); |
6486 if (!ret) return NULL; | 5884 if (!ret) return NULL; |
6487 memcpy(ret, buf, n); | 5885 memcpy(ret, buf, n); |
6488 ret[n] = '\0'; | 5886 ret[n] = '\0'; |
6489 return ret; | 5887 return ret; |
6490 } | 5888 } |
6491 | 5889 |
6492 /* Returns a newly allocated string that joins input strings together, for | 5890 /* Returns a newly allocated string that joins input strings together, for |
6493 * example: | 5891 * example: |
6494 * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz" | 5892 * join("Foo.Bar", "Baz") -> "Foo.Bar.Baz" |
6495 * join("", "Baz") -> "Baz" | 5893 * join("", "Baz") -> "Baz" |
6496 * Caller owns a ref on the returned string. */ | 5894 * Caller owns a ref on the returned string. */ |
6497 static char *upb_join(const char *base, const char *name) { | 5895 static char *upb_join(const char *base, const char *name) { |
6498 if (!base || strlen(base) == 0) { | 5896 if (!base || strlen(base) == 0) { |
6499 return upb_gstrdup(name); | 5897 return upb_strdup(name); |
6500 } else { | 5898 } else { |
6501 char *ret = upb_gmalloc(strlen(base) + strlen(name) + 2); | 5899 char *ret = malloc(strlen(base) + strlen(name) + 2); |
6502 if (!ret) { | |
6503 return NULL; | |
6504 } | |
6505 ret[0] = '\0'; | 5900 ret[0] = '\0'; |
6506 strcat(ret, base); | 5901 strcat(ret, base); |
6507 strcat(ret, "."); | 5902 strcat(ret, "."); |
6508 strcat(ret, name); | 5903 strcat(ret, name); |
6509 return ret; | 5904 return ret; |
6510 } | 5905 } |
6511 } | 5906 } |
6512 | 5907 |
| 5908 |
| 5909 /* upb_deflist ****************************************************************/ |
| 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; |
| 5920 if (l->owned) |
| 5921 for(i = 0; i < l->len; i++) |
| 5922 upb_def_unref(l->defs[i], l); |
| 5923 free(l->defs); |
| 5924 } |
| 5925 |
| 5926 bool upb_deflist_push(upb_deflist *l, upb_def *d) { |
| 5927 if(++l->len >= l->size) { |
| 5928 size_t new_size = UPB_MAX(l->size, 4); |
| 5929 new_size *= 2; |
| 5930 l->defs = realloc(l->defs, new_size * sizeof(void *)); |
| 5931 if (!l->defs) return false; |
| 5932 l->size = new_size; |
| 5933 } |
| 5934 l->defs[l->len - 1] = d; |
| 5935 return true; |
| 5936 } |
| 5937 |
| 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 |
| 5946 static upb_def *upb_deflist_last(upb_deflist *l) { |
| 5947 return l->defs[l->len-1]; |
| 5948 } |
| 5949 |
6513 /* Qualify the defname for all defs starting with offset "start" with "str". */ | 5950 /* Qualify the defname for all defs starting with offset "start" with "str". */ |
6514 static bool upb_descreader_qualify(upb_filedef *f, char *str, int32_t start) { | 5951 static void upb_deflist_qualify(upb_deflist *l, char *str, int32_t start) { |
6515 size_t i; | 5952 uint32_t i; |
6516 for (i = start; i < upb_filedef_defcount(f); i++) { | 5953 for (i = start; i < l->len; i++) { |
6517 upb_def *def = upb_filedef_mutabledef(f, i); | 5954 upb_def *def = l->defs[i]; |
6518 char *name = upb_join(str, upb_def_fullname(def)); | 5955 char *name = upb_join(str, upb_def_fullname(def)); |
6519 if (!name) { | |
6520 /* Need better logic here; at this point we've qualified some names but | |
6521 * not others. */ | |
6522 return false; | |
6523 } | |
6524 upb_def_setfullname(def, name, NULL); | 5956 upb_def_setfullname(def, name, NULL); |
6525 upb_gfree(name); | 5957 free(name); |
6526 } | 5958 } |
6527 return true; | |
6528 } | 5959 } |
6529 | 5960 |
6530 | 5961 |
6531 /* upb_descreader ************************************************************/ | 5962 /* upb_descreader ************************************************************/ |
6532 | 5963 |
6533 static upb_msgdef *upb_descreader_top(upb_descreader *r) { | 5964 static upb_msgdef *upb_descreader_top(upb_descreader *r) { |
6534 int index; | 5965 int index; |
6535 UPB_ASSERT(r->stack_len > 1); | 5966 assert(r->stack_len > 1); |
6536 index = r->stack[r->stack_len-1].start - 1; | 5967 index = r->stack[r->stack_len-1].start - 1; |
6537 UPB_ASSERT(index >= 0); | 5968 assert(index >= 0); |
6538 return upb_downcast_msgdef_mutable(upb_filedef_mutabledef(r->file, index)); | 5969 return upb_downcast_msgdef_mutable(r->defs.defs[index]); |
6539 } | 5970 } |
6540 | 5971 |
6541 static upb_def *upb_descreader_last(upb_descreader *r) { | 5972 static upb_def *upb_descreader_last(upb_descreader *r) { |
6542 return upb_filedef_mutabledef(r->file, upb_filedef_defcount(r->file) - 1); | 5973 return upb_deflist_last(&r->defs); |
6543 } | 5974 } |
6544 | 5975 |
6545 /* Start/end handlers for FileDescriptorProto and DescriptorProto (the two | 5976 /* Start/end handlers for FileDescriptorProto and DescriptorProto (the two |
6546 * entities that have names and can contain sub-definitions. */ | 5977 * entities that have names and can contain sub-definitions. */ |
6547 void upb_descreader_startcontainer(upb_descreader *r) { | 5978 void upb_descreader_startcontainer(upb_descreader *r) { |
6548 upb_descreader_frame *f = &r->stack[r->stack_len++]; | 5979 upb_descreader_frame *f = &r->stack[r->stack_len++]; |
6549 f->start = upb_filedef_defcount(r->file); | 5980 f->start = r->defs.len; |
6550 f->oneof_start = upb_inttable_count(&r->oneofs); | |
6551 f->oneof_index = 0; | |
6552 f->name = NULL; | 5981 f->name = NULL; |
6553 } | 5982 } |
6554 | 5983 |
6555 bool upb_descreader_endcontainer(upb_descreader *r) { | 5984 void upb_descreader_endcontainer(upb_descreader *r) { |
6556 upb_descreader_frame *f = &r->stack[r->stack_len - 1]; | 5985 upb_descreader_frame *f = &r->stack[--r->stack_len]; |
6557 | 5986 upb_deflist_qualify(&r->defs, f->name, f->start); |
6558 while (upb_inttable_count(&r->oneofs) > f->oneof_start) { | 5987 free(f->name); |
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); | |
6568 f->name = NULL; | 5988 f->name = NULL; |
6569 | |
6570 r->stack_len--; | |
6571 return true; | |
6572 } | 5989 } |
6573 | 5990 |
6574 void upb_descreader_setscopename(upb_descreader *r, char *str) { | 5991 void upb_descreader_setscopename(upb_descreader *r, char *str) { |
6575 upb_descreader_frame *f = &r->stack[r->stack_len-1]; | 5992 upb_descreader_frame *f = &r->stack[r->stack_len-1]; |
6576 upb_gfree(f->name); | 5993 free(f->name); |
6577 f->name = str; | 5994 f->name = str; |
6578 } | 5995 } |
6579 | 5996 |
6580 static upb_oneofdef *upb_descreader_getoneof(upb_descreader *r, | 5997 /* Handlers for google.protobuf.FileDescriptorProto. */ |
6581 uint32_t index) { | 5998 static bool file_startmsg(void *r, const void *hd) { |
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; | |
6614 UPB_UNUSED(hd); | 5999 UPB_UNUSED(hd); |
6615 upb_descreader_startcontainer(r); | 6000 upb_descreader_startcontainer(r); |
6616 return true; | 6001 return true; |
6617 } | 6002 } |
6618 | 6003 |
6619 static bool file_end(void *closure, const void *hd, upb_status *status) { | 6004 static bool file_endmsg(void *closure, const void *hd, upb_status *status) { |
6620 upb_descreader *r = closure; | 6005 upb_descreader *r = closure; |
6621 UPB_UNUSED(hd); | 6006 UPB_UNUSED(hd); |
6622 UPB_UNUSED(status); | 6007 UPB_UNUSED(status); |
6623 return upb_descreader_endcontainer(r); | 6008 upb_descreader_endcontainer(r); |
6624 } | 6009 return true; |
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; | |
6640 } | 6010 } |
6641 | 6011 |
6642 static size_t file_onpackage(void *closure, const void *hd, const char *buf, | 6012 static size_t file_onpackage(void *closure, const void *hd, const char *buf, |
6643 size_t n, const upb_bufhandle *handle) { | 6013 size_t n, const upb_bufhandle *handle) { |
6644 upb_descreader *r = closure; | 6014 upb_descreader *r = closure; |
6645 char *package; | |
6646 bool ok; | |
6647 UPB_UNUSED(hd); | 6015 UPB_UNUSED(hd); |
6648 UPB_UNUSED(handle); | 6016 UPB_UNUSED(handle); |
6649 | |
6650 package = upb_strndup(buf, n); | |
6651 /* XXX: see comment at the top of the file. */ | 6017 /* XXX: see comment at the top of the file. */ |
6652 upb_descreader_setscopename(r, package); | 6018 upb_descreader_setscopename(r, upb_strndup(buf, n)); |
6653 ok = upb_filedef_setpackage(r->file, package, NULL); | |
6654 UPB_ASSERT(ok); | |
6655 return n; | 6019 return n; |
6656 } | 6020 } |
6657 | 6021 |
6658 static size_t file_onsyntax(void *closure, const void *hd, const char *buf, | 6022 /* Handlers for google.protobuf.EnumValueDescriptorProto. */ |
6659 size_t n, const upb_bufhandle *handle) { | |
6660 upb_descreader *r = closure; | |
6661 bool ok; | |
6662 UPB_UNUSED(hd); | |
6663 UPB_UNUSED(handle); | |
6664 /* XXX: see comment at the top of the file. */ | |
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); | |
6674 return n; | |
6675 } | |
6676 | |
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 | |
6707 static bool enumval_startmsg(void *closure, const void *hd) { | 6023 static bool enumval_startmsg(void *closure, const void *hd) { |
6708 upb_descreader *r = closure; | 6024 upb_descreader *r = closure; |
6709 UPB_UNUSED(hd); | 6025 UPB_UNUSED(hd); |
6710 r->saw_number = false; | 6026 r->saw_number = false; |
6711 r->saw_name = false; | 6027 r->saw_name = false; |
6712 return true; | 6028 return true; |
6713 } | 6029 } |
6714 | 6030 |
6715 static size_t enumval_onname(void *closure, const void *hd, const char *buf, | 6031 static size_t enumval_onname(void *closure, const void *hd, const char *buf, |
6716 size_t n, const upb_bufhandle *handle) { | 6032 size_t n, const upb_bufhandle *handle) { |
6717 upb_descreader *r = closure; | 6033 upb_descreader *r = closure; |
6718 UPB_UNUSED(hd); | 6034 UPB_UNUSED(hd); |
6719 UPB_UNUSED(handle); | 6035 UPB_UNUSED(handle); |
6720 /* XXX: see comment at the top of the file. */ | 6036 /* XXX: see comment at the top of the file. */ |
6721 upb_gfree(r->name); | 6037 free(r->name); |
6722 r->name = upb_strndup(buf, n); | 6038 r->name = upb_strndup(buf, n); |
6723 r->saw_name = true; | 6039 r->saw_name = true; |
6724 return n; | 6040 return n; |
6725 } | 6041 } |
6726 | 6042 |
6727 static bool enumval_onnumber(void *closure, const void *hd, int32_t val) { | 6043 static bool enumval_onnumber(void *closure, const void *hd, int32_t val) { |
6728 upb_descreader *r = closure; | 6044 upb_descreader *r = closure; |
6729 UPB_UNUSED(hd); | 6045 UPB_UNUSED(hd); |
6730 r->number = val; | 6046 r->number = val; |
6731 r->saw_number = true; | 6047 r->saw_number = true; |
6732 return true; | 6048 return true; |
6733 } | 6049 } |
6734 | 6050 |
6735 static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) { | 6051 static bool enumval_endmsg(void *closure, const void *hd, upb_status *status) { |
6736 upb_descreader *r = closure; | 6052 upb_descreader *r = closure; |
6737 upb_enumdef *e; | 6053 upb_enumdef *e; |
6738 UPB_UNUSED(hd); | 6054 UPB_UNUSED(hd); |
6739 | 6055 |
6740 if(!r->saw_number || !r->saw_name) { | 6056 if(!r->saw_number || !r->saw_name) { |
6741 upb_status_seterrmsg(status, "Enum value missing name or number."); | 6057 upb_status_seterrmsg(status, "Enum value missing name or number."); |
6742 return false; | 6058 return false; |
6743 } | 6059 } |
6744 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); | 6060 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); |
6745 upb_enumdef_addval(e, r->name, r->number, status); | 6061 upb_enumdef_addval(e, r->name, r->number, status); |
6746 upb_gfree(r->name); | 6062 free(r->name); |
6747 r->name = NULL; | 6063 r->name = NULL; |
6748 return true; | 6064 return true; |
6749 } | 6065 } |
6750 | 6066 |
6751 /** Handlers for google.protobuf.EnumDescriptorProto. *************************/ | 6067 |
| 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 } |
6752 | 6076 |
6753 static bool enum_endmsg(void *closure, const void *hd, upb_status *status) { | 6077 static bool enum_endmsg(void *closure, const void *hd, upb_status *status) { |
6754 upb_descreader *r = closure; | 6078 upb_descreader *r = closure; |
6755 upb_enumdef *e; | 6079 upb_enumdef *e; |
6756 UPB_UNUSED(hd); | 6080 UPB_UNUSED(hd); |
6757 | 6081 |
6758 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); | 6082 e = upb_downcast_enumdef_mutable(upb_descreader_last(r)); |
6759 if (upb_def_fullname(upb_descreader_last(r)) == NULL) { | 6083 if (upb_def_fullname(upb_descreader_last(r)) == NULL) { |
6760 upb_status_seterrmsg(status, "Enum had no name."); | 6084 upb_status_seterrmsg(status, "Enum had no name."); |
6761 return false; | 6085 return false; |
6762 } | 6086 } |
6763 if (upb_enumdef_numvals(e) == 0) { | 6087 if (upb_enumdef_numvals(e) == 0) { |
6764 upb_status_seterrmsg(status, "Enum had no values."); | 6088 upb_status_seterrmsg(status, "Enum had no values."); |
6765 return false; | 6089 return false; |
6766 } | 6090 } |
6767 return true; | 6091 return true; |
6768 } | 6092 } |
6769 | 6093 |
6770 static size_t enum_onname(void *closure, const void *hd, const char *buf, | 6094 static size_t enum_onname(void *closure, const void *hd, const char *buf, |
6771 size_t n, const upb_bufhandle *handle) { | 6095 size_t n, const upb_bufhandle *handle) { |
6772 upb_descreader *r = closure; | 6096 upb_descreader *r = closure; |
6773 char *fullname = upb_strndup(buf, n); | 6097 char *fullname = upb_strndup(buf, n); |
6774 UPB_UNUSED(hd); | 6098 UPB_UNUSED(hd); |
6775 UPB_UNUSED(handle); | 6099 UPB_UNUSED(handle); |
6776 /* XXX: see comment at the top of the file. */ | 6100 /* XXX: see comment at the top of the file. */ |
6777 upb_def_setfullname(upb_descreader_last(r), fullname, NULL); | 6101 upb_def_setfullname(upb_descreader_last(r), fullname, NULL); |
6778 upb_gfree(fullname); | 6102 free(fullname); |
6779 return n; | 6103 return n; |
6780 } | 6104 } |
6781 | 6105 |
6782 /** Handlers for google.protobuf.FieldDescriptorProto *************************/ | 6106 /* Handlers for google.protobuf.FieldDescriptorProto */ |
6783 | |
6784 static bool field_startmsg(void *closure, const void *hd) { | 6107 static bool field_startmsg(void *closure, const void *hd) { |
6785 upb_descreader *r = closure; | 6108 upb_descreader *r = closure; |
6786 UPB_UNUSED(hd); | 6109 UPB_UNUSED(hd); |
6787 UPB_ASSERT(r->f); | 6110 r->f = upb_fielddef_new(&r->defs); |
6788 upb_gfree(r->default_string); | 6111 free(r->default_string); |
6789 r->default_string = NULL; | 6112 r->default_string = NULL; |
6790 | 6113 |
6791 /* fielddefs default to packed, but descriptors default to non-packed. */ | 6114 /* fielddefs default to packed, but descriptors default to non-packed. */ |
6792 upb_fielddef_setpacked(r->f, false); | 6115 upb_fielddef_setpacked(r->f, false); |
6793 return true; | 6116 return true; |
6794 } | 6117 } |
6795 | 6118 |
6796 /* Converts the default value in string "str" into "d". Passes a ref on str. | 6119 /* Converts the default value in string "str" into "d". Passes a ref on str. |
6797 * Returns true on success. */ | 6120 * Returns true on success. */ |
6798 static bool parse_default(char *str, upb_fielddef *f) { | 6121 static bool parse_default(char *str, upb_fielddef *f) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6863 } | 6186 } |
6864 return success; | 6187 return success; |
6865 } | 6188 } |
6866 | 6189 |
6867 static bool field_endmsg(void *closure, const void *hd, upb_status *status) { | 6190 static bool field_endmsg(void *closure, const void *hd, upb_status *status) { |
6868 upb_descreader *r = closure; | 6191 upb_descreader *r = closure; |
6869 upb_fielddef *f = r->f; | 6192 upb_fielddef *f = r->f; |
6870 UPB_UNUSED(hd); | 6193 UPB_UNUSED(hd); |
6871 | 6194 |
6872 /* TODO: verify that all required fields were present. */ | 6195 /* TODO: verify that all required fields were present. */ |
6873 UPB_ASSERT(upb_fielddef_number(f) != 0); | 6196 assert(upb_fielddef_number(f) != 0); |
6874 UPB_ASSERT(upb_fielddef_name(f) != NULL); | 6197 assert(upb_fielddef_name(f) != NULL); |
6875 UPB_ASSERT((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f)); | 6198 assert((upb_fielddef_subdefname(f) != NULL) == upb_fielddef_hassubdef(f)); |
6876 | 6199 |
6877 if (r->default_string) { | 6200 if (r->default_string) { |
6878 if (upb_fielddef_issubmsg(f)) { | 6201 if (upb_fielddef_issubmsg(f)) { |
6879 upb_status_seterrmsg(status, "Submessages cannot have defaults."); | 6202 upb_status_seterrmsg(status, "Submessages cannot have defaults."); |
6880 return false; | 6203 return false; |
6881 } | 6204 } |
6882 if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) { | 6205 if (upb_fielddef_isstring(f) || upb_fielddef_type(f) == UPB_TYPE_ENUM) { |
6883 upb_fielddef_setdefaultcstr(f, r->default_string, NULL); | 6206 upb_fielddef_setdefaultcstr(f, r->default_string, NULL); |
6884 } else { | 6207 } else { |
6885 if (r->default_string && !parse_default(r->default_string, f)) { | 6208 if (r->default_string && !parse_default(r->default_string, f)) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6920 static bool field_onlabel(void *closure, const void *hd, int32_t val) { | 6243 static bool field_onlabel(void *closure, const void *hd, int32_t val) { |
6921 upb_descreader *r = closure; | 6244 upb_descreader *r = closure; |
6922 UPB_UNUSED(hd); | 6245 UPB_UNUSED(hd); |
6923 | 6246 |
6924 upb_fielddef_setlabel(r->f, val); | 6247 upb_fielddef_setlabel(r->f, val); |
6925 return true; | 6248 return true; |
6926 } | 6249 } |
6927 | 6250 |
6928 static bool field_onnumber(void *closure, const void *hd, int32_t val) { | 6251 static bool field_onnumber(void *closure, const void *hd, int32_t val) { |
6929 upb_descreader *r = closure; | 6252 upb_descreader *r = closure; |
6930 bool ok; | 6253 bool ok = upb_fielddef_setnumber(r->f, val, NULL); |
6931 UPB_UNUSED(hd); | 6254 UPB_UNUSED(hd); |
6932 | 6255 |
6933 ok = upb_fielddef_setnumber(r->f, val, NULL); | 6256 UPB_ASSERT_VAR(ok, ok); |
6934 UPB_ASSERT(ok); | |
6935 return true; | 6257 return true; |
6936 } | 6258 } |
6937 | 6259 |
6938 static size_t field_onname(void *closure, const void *hd, const char *buf, | 6260 static size_t field_onname(void *closure, const void *hd, const char *buf, |
6939 size_t n, const upb_bufhandle *handle) { | 6261 size_t n, const upb_bufhandle *handle) { |
6940 upb_descreader *r = closure; | 6262 upb_descreader *r = closure; |
6941 char *name = upb_strndup(buf, n); | 6263 char *name = upb_strndup(buf, n); |
6942 UPB_UNUSED(hd); | 6264 UPB_UNUSED(hd); |
6943 UPB_UNUSED(handle); | 6265 UPB_UNUSED(handle); |
6944 | 6266 |
6945 /* XXX: see comment at the top of the file. */ | 6267 /* XXX: see comment at the top of the file. */ |
6946 upb_fielddef_setname(r->f, name, NULL); | 6268 upb_fielddef_setname(r->f, name, NULL); |
6947 upb_gfree(name); | 6269 free(name); |
6948 return n; | 6270 return n; |
6949 } | 6271 } |
6950 | 6272 |
6951 static size_t field_ontypename(void *closure, const void *hd, const char *buf, | 6273 static size_t field_ontypename(void *closure, const void *hd, const char *buf, |
6952 size_t n, const upb_bufhandle *handle) { | 6274 size_t n, const upb_bufhandle *handle) { |
6953 upb_descreader *r = closure; | 6275 upb_descreader *r = closure; |
6954 char *name = upb_strndup(buf, n); | 6276 char *name = upb_strndup(buf, n); |
6955 UPB_UNUSED(hd); | 6277 UPB_UNUSED(hd); |
6956 UPB_UNUSED(handle); | 6278 UPB_UNUSED(handle); |
6957 | 6279 |
6958 /* XXX: see comment at the top of the file. */ | 6280 /* XXX: see comment at the top of the file. */ |
6959 upb_fielddef_setsubdefname(r->f, name, NULL); | 6281 upb_fielddef_setsubdefname(r->f, name, NULL); |
6960 upb_gfree(name); | 6282 free(name); |
6961 return n; | 6283 return n; |
6962 } | 6284 } |
6963 | 6285 |
6964 static size_t field_onextendee(void *closure, const void *hd, const char *buf, | 6286 static size_t field_onextendee(void *closure, const void *hd, const char *buf, |
6965 size_t n, const upb_bufhandle *handle) { | 6287 size_t n, const upb_bufhandle *handle) { |
6966 upb_descreader *r = closure; | 6288 upb_descreader *r = closure; |
6967 char *name = upb_strndup(buf, n); | 6289 char *name = upb_strndup(buf, n); |
6968 UPB_UNUSED(hd); | 6290 UPB_UNUSED(hd); |
6969 UPB_UNUSED(handle); | 6291 UPB_UNUSED(handle); |
6970 | 6292 |
6971 /* XXX: see comment at the top of the file. */ | 6293 /* XXX: see comment at the top of the file. */ |
6972 upb_fielddef_setcontainingtypename(r->f, name, NULL); | 6294 upb_fielddef_setcontainingtypename(r->f, name, NULL); |
6973 upb_gfree(name); | 6295 free(name); |
6974 return n; | 6296 return n; |
6975 } | 6297 } |
6976 | 6298 |
6977 static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, | 6299 static size_t field_ondefaultval(void *closure, const void *hd, const char *buf, |
6978 size_t n, const upb_bufhandle *handle) { | 6300 size_t n, const upb_bufhandle *handle) { |
6979 upb_descreader *r = closure; | 6301 upb_descreader *r = closure; |
6980 UPB_UNUSED(hd); | 6302 UPB_UNUSED(hd); |
6981 UPB_UNUSED(handle); | 6303 UPB_UNUSED(handle); |
6982 | 6304 |
6983 /* Have to convert from string to the correct type, but we might not know the | 6305 /* Have to convert from string to the correct type, but we might not know the |
6984 * type yet, so we save it as a string until the end of the field. | 6306 * type yet, so we save it as a string until the end of the field. |
6985 * XXX: see comment at the top of the file. */ | 6307 * XXX: see comment at the top of the file. */ |
6986 upb_gfree(r->default_string); | 6308 free(r->default_string); |
6987 r->default_string = upb_strndup(buf, n); | 6309 r->default_string = upb_strndup(buf, n); |
6988 return n; | 6310 return n; |
6989 } | 6311 } |
6990 | 6312 |
6991 static bool field_ononeofindex(void *closure, const void *hd, int32_t index) { | 6313 /* Handlers for google.protobuf.DescriptorProto (representing a message). */ |
6992 upb_descreader *r = closure; | 6314 static bool msg_startmsg(void *closure, const void *hd) { |
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) { | |
7021 upb_descreader *r = closure; | 6315 upb_descreader *r = closure; |
7022 UPB_UNUSED(hd); | 6316 UPB_UNUSED(hd); |
7023 | 6317 |
| 6318 upb_deflist_push(&r->defs, |
| 6319 upb_msgdef_upcast_mutable(upb_msgdef_new(&r->defs))); |
7024 upb_descreader_startcontainer(r); | 6320 upb_descreader_startcontainer(r); |
7025 return true; | 6321 return true; |
7026 } | 6322 } |
7027 | 6323 |
7028 static bool msg_end(void *closure, const void *hd, upb_status *status) { | 6324 static bool msg_endmsg(void *closure, const void *hd, upb_status *status) { |
7029 upb_descreader *r = closure; | 6325 upb_descreader *r = closure; |
7030 upb_msgdef *m = upb_descreader_top(r); | 6326 upb_msgdef *m = upb_descreader_top(r); |
7031 UPB_UNUSED(hd); | 6327 UPB_UNUSED(hd); |
7032 | 6328 |
7033 if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) { | 6329 if(!upb_def_fullname(upb_msgdef_upcast_mutable(m))) { |
7034 upb_status_seterrmsg(status, "Encountered message with no name."); | 6330 upb_status_seterrmsg(status, "Encountered message with no name."); |
7035 return false; | 6331 return false; |
7036 } | 6332 } |
7037 return upb_descreader_endcontainer(r); | 6333 upb_descreader_endcontainer(r); |
| 6334 return true; |
7038 } | 6335 } |
7039 | 6336 |
7040 static size_t msg_name(void *closure, const void *hd, const char *buf, | 6337 static size_t msg_onname(void *closure, const void *hd, const char *buf, |
7041 size_t n, const upb_bufhandle *handle) { | 6338 size_t n, const upb_bufhandle *handle) { |
7042 upb_descreader *r = closure; | 6339 upb_descreader *r = closure; |
7043 upb_msgdef *m = upb_descreader_top(r); | 6340 upb_msgdef *m = upb_descreader_top(r); |
7044 /* XXX: see comment at the top of the file. */ | 6341 /* XXX: see comment at the top of the file. */ |
7045 char *name = upb_strndup(buf, n); | 6342 char *name = upb_strndup(buf, n); |
7046 UPB_UNUSED(hd); | 6343 UPB_UNUSED(hd); |
7047 UPB_UNUSED(handle); | 6344 UPB_UNUSED(handle); |
7048 | 6345 |
7049 upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); | 6346 upb_def_setfullname(upb_msgdef_upcast_mutable(m), name, NULL); |
7050 upb_descreader_setscopename(r, name); /* Passes ownership of name. */ | 6347 upb_descreader_setscopename(r, name); /* Passes ownership of name. */ |
7051 return n; | 6348 return n; |
7052 } | 6349 } |
7053 | 6350 |
7054 static void *msg_startmsg(void *closure, const void *hd) { | 6351 static bool msg_onendfield(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; | 6352 upb_descreader *r = closure; |
7083 upb_msgdef *m = upb_descreader_top(r); | 6353 upb_msgdef *m = upb_descreader_top(r); |
7084 bool ok; | |
7085 UPB_UNUSED(hd); | 6354 UPB_UNUSED(hd); |
7086 | 6355 |
7087 /* Oneof fields are added to the msgdef through their oneof, so don't need to | 6356 upb_msgdef_addfield(m, r->f, &r->defs, NULL); |
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; | 6357 r->f = NULL; |
7094 return true; | 6358 return true; |
7095 } | 6359 } |
7096 | 6360 |
7097 static bool msg_onmapentry(void *closure, const void *hd, bool mapentry) { | 6361 static bool pushextension(void *closure, const void *hd) { |
7098 upb_descreader *r = closure; | 6362 upb_descreader *r = closure; |
7099 upb_msgdef *m = upb_descreader_top(r); | |
7100 UPB_UNUSED(hd); | 6363 UPB_UNUSED(hd); |
7101 | 6364 |
7102 upb_msgdef_setmapentry(m, mapentry); | 6365 assert(upb_fielddef_containingtypename(r->f)); |
| 6366 upb_fielddef_setisextension(r->f, true); |
| 6367 upb_deflist_push(&r->defs, upb_fielddef_upcast_mutable(r->f)); |
7103 r->f = NULL; | 6368 r->f = NULL; |
7104 return true; | 6369 return true; |
7105 } | 6370 } |
7106 | 6371 |
7107 | 6372 #define D(name) upbdefs_google_protobuf_ ## name(s) |
7108 | |
7109 /** Code to register handlers *************************************************/ | |
7110 | |
7111 #define F(msg, field) upbdefs_google_protobuf_ ## msg ## _f_ ## field(m) | |
7112 | 6373 |
7113 static void reghandlers(const void *closure, upb_handlers *h) { | 6374 static void reghandlers(const void *closure, upb_handlers *h) { |
| 6375 const upb_symtab *s = closure; |
7114 const upb_msgdef *m = upb_handlers_msgdef(h); | 6376 const upb_msgdef *m = upb_handlers_msgdef(h); |
7115 UPB_UNUSED(closure); | |
7116 | 6377 |
7117 if (upbdefs_google_protobuf_FileDescriptorSet_is(m)) { | 6378 if (m == D(DescriptorProto)) { |
7118 upb_handlers_setstartsubmsg(h, F(FileDescriptorSet, file), | 6379 upb_handlers_setstartmsg(h, &msg_startmsg, NULL); |
7119 &fileset_startfile, NULL); | 6380 upb_handlers_setendmsg(h, &msg_endmsg, NULL); |
7120 } else if (upbdefs_google_protobuf_DescriptorProto_is(m)) { | 6381 upb_handlers_setstring(h, D(DescriptorProto_name), &msg_onname, NULL); |
7121 upb_handlers_setstartmsg(h, &msg_start, NULL); | 6382 upb_handlers_setendsubmsg(h, D(DescriptorProto_field), &msg_onendfield, |
7122 upb_handlers_setendmsg(h, &msg_end, NULL); | 6383 NULL); |
7123 upb_handlers_setstring(h, F(DescriptorProto, name), &msg_name, NULL); | 6384 upb_handlers_setendsubmsg(h, D(DescriptorProto_extension), &pushextension, |
7124 upb_handlers_setstartsubmsg(h, F(DescriptorProto, extension), &msg_startext, | 6385 NULL); |
7125 NULL); | 6386 } else if (m == D(FileDescriptorProto)) { |
7126 upb_handlers_setstartsubmsg(h, F(DescriptorProto, nested_type), | 6387 upb_handlers_setstartmsg(h, &file_startmsg, NULL); |
7127 &msg_startmsg, NULL); | 6388 upb_handlers_setendmsg(h, &file_endmsg, NULL); |
7128 upb_handlers_setstartsubmsg(h, F(DescriptorProto, field), | 6389 upb_handlers_setstring(h, D(FileDescriptorProto_package), &file_onpackage, |
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); | 6390 NULL); |
7139 upb_handlers_setstring(h, F(FileDescriptorProto, package), &file_onpackage, | 6391 upb_handlers_setendsubmsg(h, D(FileDescriptorProto_extension), &pushextensio
n, |
7140 NULL); | 6392 NULL); |
7141 upb_handlers_setstring(h, F(FileDescriptorProto, syntax), &file_onsyntax, | 6393 } else if (m == D(EnumValueDescriptorProto)) { |
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); | 6394 upb_handlers_setstartmsg(h, &enumval_startmsg, NULL); |
7151 upb_handlers_setendmsg(h, &enumval_endmsg, NULL); | 6395 upb_handlers_setendmsg(h, &enumval_endmsg, NULL); |
7152 upb_handlers_setstring(h, F(EnumValueDescriptorProto, name), &enumval_onname
, NULL); | 6396 upb_handlers_setstring(h, D(EnumValueDescriptorProto_name), &enumval_onname,
NULL); |
7153 upb_handlers_setint32(h, F(EnumValueDescriptorProto, number), &enumval_onnum
ber, | 6397 upb_handlers_setint32(h, D(EnumValueDescriptorProto_number), &enumval_onnumb
er, |
7154 NULL); | 6398 NULL); |
7155 } else if (upbdefs_google_protobuf_EnumDescriptorProto_is(m)) { | 6399 } else if (m == D(EnumDescriptorProto)) { |
| 6400 upb_handlers_setstartmsg(h, &enum_startmsg, NULL); |
7156 upb_handlers_setendmsg(h, &enum_endmsg, NULL); | 6401 upb_handlers_setendmsg(h, &enum_endmsg, NULL); |
7157 upb_handlers_setstring(h, F(EnumDescriptorProto, name), &enum_onname, NULL); | 6402 upb_handlers_setstring(h, D(EnumDescriptorProto_name), &enum_onname, NULL); |
7158 } else if (upbdefs_google_protobuf_FieldDescriptorProto_is(m)) { | 6403 } else if (m == D(FieldDescriptorProto)) { |
7159 upb_handlers_setstartmsg(h, &field_startmsg, NULL); | 6404 upb_handlers_setstartmsg(h, &field_startmsg, NULL); |
7160 upb_handlers_setendmsg(h, &field_endmsg, NULL); | 6405 upb_handlers_setendmsg(h, &field_endmsg, NULL); |
7161 upb_handlers_setint32(h, F(FieldDescriptorProto, type), &field_ontype, | 6406 upb_handlers_setint32(h, D(FieldDescriptorProto_type), &field_ontype, |
7162 NULL); | 6407 NULL); |
7163 upb_handlers_setint32(h, F(FieldDescriptorProto, label), &field_onlabel, | 6408 upb_handlers_setint32(h, D(FieldDescriptorProto_label), &field_onlabel, |
7164 NULL); | 6409 NULL); |
7165 upb_handlers_setint32(h, F(FieldDescriptorProto, number), &field_onnumber, | 6410 upb_handlers_setint32(h, D(FieldDescriptorProto_number), &field_onnumber, |
7166 NULL); | 6411 NULL); |
7167 upb_handlers_setstring(h, F(FieldDescriptorProto, name), &field_onname, | 6412 upb_handlers_setstring(h, D(FieldDescriptorProto_name), &field_onname, |
7168 NULL); | 6413 NULL); |
7169 upb_handlers_setstring(h, F(FieldDescriptorProto, type_name), | 6414 upb_handlers_setstring(h, D(FieldDescriptorProto_type_name), |
7170 &field_ontypename, NULL); | 6415 &field_ontypename, NULL); |
7171 upb_handlers_setstring(h, F(FieldDescriptorProto, extendee), | 6416 upb_handlers_setstring(h, D(FieldDescriptorProto_extendee), |
7172 &field_onextendee, NULL); | 6417 &field_onextendee, NULL); |
7173 upb_handlers_setstring(h, F(FieldDescriptorProto, default_value), | 6418 upb_handlers_setstring(h, D(FieldDescriptorProto_default_value), |
7174 &field_ondefaultval, NULL); | 6419 &field_ondefaultval, NULL); |
7175 upb_handlers_setint32(h, F(FieldDescriptorProto, oneof_index), | 6420 } else if (m == D(FieldOptions)) { |
7176 &field_ononeofindex, NULL); | 6421 upb_handlers_setbool(h, D(FieldOptions_lazy), &field_onlazy, NULL); |
7177 } else if (upbdefs_google_protobuf_OneofDescriptorProto_is(m)) { | 6422 upb_handlers_setbool(h, D(FieldOptions_packed), &field_onpacked, NULL); |
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 } | 6423 } |
7185 | |
7186 UPB_ASSERT(upb_ok(upb_handlers_status(h))); | |
7187 } | 6424 } |
7188 | 6425 |
7189 #undef F | 6426 #undef D |
7190 | 6427 |
7191 void descreader_cleanup(void *_r) { | 6428 void descreader_cleanup(void *_r) { |
7192 upb_descreader *r = _r; | 6429 upb_descreader *r = _r; |
7193 size_t i; | 6430 free(r->name); |
7194 | 6431 upb_deflist_uninit(&r->defs); |
7195 for (i = 0; i < upb_descreader_filecount(r); i++) { | 6432 free(r->default_string); |
7196 upb_filedef_unref(upb_descreader_file(r, i), &r->files); | |
7197 } | |
7198 | |
7199 upb_gfree(r->name); | |
7200 upb_inttable_uninit(&r->files); | |
7201 upb_inttable_uninit(&r->oneofs); | |
7202 upb_gfree(r->default_string); | |
7203 while (r->stack_len > 0) { | 6433 while (r->stack_len > 0) { |
7204 upb_descreader_frame *f = &r->stack[--r->stack_len]; | 6434 upb_descreader_frame *f = &r->stack[--r->stack_len]; |
7205 upb_gfree(f->name); | 6435 free(f->name); |
7206 } | 6436 } |
7207 } | 6437 } |
7208 | 6438 |
7209 | 6439 |
7210 /* Public API ****************************************************************/ | 6440 /* Public API ****************************************************************/ |
7211 | 6441 |
7212 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) { | 6442 upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h) { |
7213 upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader)); | 6443 upb_descreader *r = upb_env_malloc(e, sizeof(upb_descreader)); |
7214 if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) { | 6444 if (!r || !upb_env_addcleanup(e, descreader_cleanup, r)) { |
7215 return NULL; | 6445 return NULL; |
7216 } | 6446 } |
7217 | 6447 |
7218 upb_inttable_init(&r->files, UPB_CTYPE_PTR); | 6448 upb_deflist_init(&r->defs); |
7219 upb_inttable_init(&r->oneofs, UPB_CTYPE_PTR); | |
7220 upb_sink_reset(upb_descreader_input(r), h, r); | 6449 upb_sink_reset(upb_descreader_input(r), h, r); |
7221 r->stack_len = 0; | 6450 r->stack_len = 0; |
7222 r->name = NULL; | 6451 r->name = NULL; |
7223 r->default_string = NULL; | 6452 r->default_string = NULL; |
7224 | 6453 |
7225 return r; | 6454 return r; |
7226 } | 6455 } |
7227 | 6456 |
7228 size_t upb_descreader_filecount(const upb_descreader *r) { | 6457 upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n) { |
7229 return upb_inttable_count(&r->files); | 6458 *n = r->defs.len; |
7230 } | 6459 upb_deflist_donaterefs(&r->defs, owner); |
7231 | 6460 return r->defs.defs; |
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 } | |
7239 } | 6461 } |
7240 | 6462 |
7241 upb_sink *upb_descreader_input(upb_descreader *r) { | 6463 upb_sink *upb_descreader_input(upb_descreader *r) { |
7242 return &r->sink; | 6464 return &r->sink; |
7243 } | 6465 } |
7244 | 6466 |
7245 const upb_handlers *upb_descreader_newhandlers(const void *owner) { | 6467 const upb_handlers *upb_descreader_newhandlers(const void *owner) { |
7246 const upb_msgdef *m = upbdefs_google_protobuf_FileDescriptorSet_get(&m); | 6468 const upb_symtab *s = upbdefs_google_protobuf_descriptor(&s); |
7247 const upb_handlers *h = upb_handlers_newfrozen(m, owner, reghandlers, NULL); | 6469 const upb_handlers *h = upb_handlers_newfrozen( |
7248 upb_msgdef_unref(m, &m); | 6470 upbdefs_google_protobuf_FileDescriptorSet(s), owner, reghandlers, s); |
| 6471 upb_symtab_unref(s, &s); |
7249 return h; | 6472 return h; |
7250 } | 6473 } |
7251 /* | 6474 /* |
7252 ** protobuf decoder bytecode compiler | 6475 ** protobuf decoder bytecode compiler |
7253 ** | 6476 ** |
7254 ** Code to compile a upb::Handlers into bytecode for decoding a protobuf | 6477 ** Code to compile a upb::Handlers into bytecode for decoding a protobuf |
7255 ** according to that specific schema and destination handlers. | 6478 ** according to that specific schema and destination handlers. |
7256 ** | 6479 ** |
7257 ** Compiling to bytecode is always the first step. If we are using the | 6480 ** Compiling to bytecode is always the first step. If we are using the |
7258 ** interpreted decoder we leave it as bytecode and interpret that. If we are | 6481 ** interpreted decoder we leave it as bytecode and interpret that. If we are |
(...skipping 13 matching lines...) Expand all Loading... |
7272 #define EMPTYLABEL -1 | 6495 #define EMPTYLABEL -1 |
7273 | 6496 |
7274 /* mgroup *********************************************************************/ | 6497 /* mgroup *********************************************************************/ |
7275 | 6498 |
7276 static void freegroup(upb_refcounted *r) { | 6499 static void freegroup(upb_refcounted *r) { |
7277 mgroup *g = (mgroup*)r; | 6500 mgroup *g = (mgroup*)r; |
7278 upb_inttable_uninit(&g->methods); | 6501 upb_inttable_uninit(&g->methods); |
7279 #ifdef UPB_USE_JIT_X64 | 6502 #ifdef UPB_USE_JIT_X64 |
7280 upb_pbdecoder_freejit(g); | 6503 upb_pbdecoder_freejit(g); |
7281 #endif | 6504 #endif |
7282 upb_gfree(g->bytecode); | 6505 free(g->bytecode); |
7283 upb_gfree(g); | 6506 free(g); |
7284 } | 6507 } |
7285 | 6508 |
7286 static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit, | 6509 static void visitgroup(const upb_refcounted *r, upb_refcounted_visit *visit, |
7287 void *closure) { | 6510 void *closure) { |
7288 const mgroup *g = (const mgroup*)r; | 6511 const mgroup *g = (const mgroup*)r; |
7289 upb_inttable_iter i; | 6512 upb_inttable_iter i; |
7290 upb_inttable_begin(&i, &g->methods); | 6513 upb_inttable_begin(&i, &g->methods); |
7291 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { | 6514 for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { |
7292 upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i)); | 6515 upb_pbdecodermethod *method = upb_value_getptr(upb_inttable_iter_value(&i)); |
7293 visit(r, upb_pbdecodermethod_upcast(method), closure); | 6516 visit(r, upb_pbdecodermethod_upcast(method), closure); |
7294 } | 6517 } |
7295 } | 6518 } |
7296 | 6519 |
7297 mgroup *newgroup(const void *owner) { | 6520 mgroup *newgroup(const void *owner) { |
7298 mgroup *g = upb_gmalloc(sizeof(*g)); | 6521 mgroup *g = malloc(sizeof(*g)); |
7299 static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup}; | 6522 static const struct upb_refcounted_vtbl vtbl = {visitgroup, freegroup}; |
7300 upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner); | 6523 upb_refcounted_init(mgroup_upcast_mutable(g), &vtbl, owner); |
7301 upb_inttable_init(&g->methods, UPB_CTYPE_PTR); | 6524 upb_inttable_init(&g->methods, UPB_CTYPE_PTR); |
7302 g->bytecode = NULL; | 6525 g->bytecode = NULL; |
7303 g->bytecode_end = NULL; | 6526 g->bytecode_end = NULL; |
7304 return g; | 6527 return g; |
7305 } | 6528 } |
7306 | 6529 |
7307 | 6530 |
7308 /* upb_pbdecodermethod ********************************************************/ | 6531 /* upb_pbdecodermethod ********************************************************/ |
7309 | 6532 |
7310 static void freemethod(upb_refcounted *r) { | 6533 static void freemethod(upb_refcounted *r) { |
7311 upb_pbdecodermethod *method = (upb_pbdecodermethod*)r; | 6534 upb_pbdecodermethod *method = (upb_pbdecodermethod*)r; |
7312 | 6535 |
7313 if (method->dest_handlers_) { | 6536 if (method->dest_handlers_) { |
7314 upb_handlers_unref(method->dest_handlers_, method); | 6537 upb_handlers_unref(method->dest_handlers_, method); |
7315 } | 6538 } |
7316 | 6539 |
7317 upb_inttable_uninit(&method->dispatch); | 6540 upb_inttable_uninit(&method->dispatch); |
7318 upb_gfree(method); | 6541 free(method); |
7319 } | 6542 } |
7320 | 6543 |
7321 static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit, | 6544 static void visitmethod(const upb_refcounted *r, upb_refcounted_visit *visit, |
7322 void *closure) { | 6545 void *closure) { |
7323 const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r; | 6546 const upb_pbdecodermethod *m = (const upb_pbdecodermethod*)r; |
7324 visit(r, m->group, closure); | 6547 visit(r, m->group, closure); |
7325 } | 6548 } |
7326 | 6549 |
7327 static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers, | 6550 static upb_pbdecodermethod *newmethod(const upb_handlers *dest_handlers, |
7328 mgroup *group) { | 6551 mgroup *group) { |
7329 static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod}; | 6552 static const struct upb_refcounted_vtbl vtbl = {visitmethod, freemethod}; |
7330 upb_pbdecodermethod *ret = upb_gmalloc(sizeof(*ret)); | 6553 upb_pbdecodermethod *ret = malloc(sizeof(*ret)); |
7331 upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret); | 6554 upb_refcounted_init(upb_pbdecodermethod_upcast_mutable(ret), &vtbl, &ret); |
7332 upb_byteshandler_init(&ret->input_handler_); | 6555 upb_byteshandler_init(&ret->input_handler_); |
7333 | 6556 |
7334 /* The method references the group and vice-versa, in a circular reference. */ | 6557 /* The method references the group and vice-versa, in a circular reference. */ |
7335 upb_ref2(ret, group); | 6558 upb_ref2(ret, group); |
7336 upb_ref2(group, ret); | 6559 upb_ref2(group, ret); |
7337 upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret)); | 6560 upb_inttable_insertptr(&group->methods, dest_handlers, upb_value_ptr(ret)); |
7338 upb_pbdecodermethod_unref(ret, &ret); | 6561 upb_pbdecodermethod_unref(ret, &ret); |
7339 | 6562 |
7340 ret->group = mgroup_upcast_mutable(group); | 6563 ret->group = mgroup_upcast_mutable(group); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7383 | 6606 |
7384 uint32_t *pc; | 6607 uint32_t *pc; |
7385 int fwd_labels[MAXLABEL]; | 6608 int fwd_labels[MAXLABEL]; |
7386 int back_labels[MAXLABEL]; | 6609 int back_labels[MAXLABEL]; |
7387 | 6610 |
7388 /* For fields marked "lazy", parse them lazily or eagerly? */ | 6611 /* For fields marked "lazy", parse them lazily or eagerly? */ |
7389 bool lazy; | 6612 bool lazy; |
7390 } compiler; | 6613 } compiler; |
7391 | 6614 |
7392 static compiler *newcompiler(mgroup *group, bool lazy) { | 6615 static compiler *newcompiler(mgroup *group, bool lazy) { |
7393 compiler *ret = upb_gmalloc(sizeof(*ret)); | 6616 compiler *ret = malloc(sizeof(*ret)); |
7394 int i; | 6617 int i; |
7395 | 6618 |
7396 ret->group = group; | 6619 ret->group = group; |
7397 ret->lazy = lazy; | 6620 ret->lazy = lazy; |
7398 for (i = 0; i < MAXLABEL; i++) { | 6621 for (i = 0; i < MAXLABEL; i++) { |
7399 ret->fwd_labels[i] = EMPTYLABEL; | 6622 ret->fwd_labels[i] = EMPTYLABEL; |
7400 ret->back_labels[i] = EMPTYLABEL; | 6623 ret->back_labels[i] = EMPTYLABEL; |
7401 } | 6624 } |
7402 return ret; | 6625 return ret; |
7403 } | 6626 } |
7404 | 6627 |
7405 static void freecompiler(compiler *c) { | 6628 static void freecompiler(compiler *c) { |
7406 upb_gfree(c); | 6629 free(c); |
7407 } | 6630 } |
7408 | 6631 |
7409 const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); | 6632 const size_t ptr_words = sizeof(void*) / sizeof(uint32_t); |
7410 | 6633 |
7411 /* How many words an instruction is. */ | 6634 /* How many words an instruction is. */ |
7412 static int instruction_len(uint32_t instr) { | 6635 static int instruction_len(uint32_t instr) { |
7413 switch (getop(instr)) { | 6636 switch (getop(instr)) { |
7414 case OP_SETDISPATCH: return 1 + ptr_words; | 6637 case OP_SETDISPATCH: return 1 + ptr_words; |
7415 case OP_TAGN: return 3; | 6638 case OP_TAGN: return 3; |
7416 case OP_SETBIGGROUPNUM: return 2; | 6639 case OP_SETBIGGROUPNUM: return 2; |
7417 default: return 1; | 6640 default: return 1; |
7418 } | 6641 } |
7419 } | 6642 } |
7420 | 6643 |
7421 bool op_has_longofs(int32_t instruction) { | 6644 bool op_has_longofs(int32_t instruction) { |
7422 switch (getop(instruction)) { | 6645 switch (getop(instruction)) { |
7423 case OP_CALL: | 6646 case OP_CALL: |
7424 case OP_BRANCH: | 6647 case OP_BRANCH: |
7425 case OP_CHECKDELIM: | 6648 case OP_CHECKDELIM: |
7426 return true; | 6649 return true; |
7427 /* The "tag" instructions only have 8 bytes available for the jump target, | 6650 /* The "tag" instructions only have 8 bytes available for the jump target, |
7428 * but that is ok because these opcodes only require short jumps. */ | 6651 * but that is ok because these opcodes only require short jumps. */ |
7429 case OP_TAG1: | 6652 case OP_TAG1: |
7430 case OP_TAG2: | 6653 case OP_TAG2: |
7431 case OP_TAGN: | 6654 case OP_TAGN: |
7432 return false; | 6655 return false; |
7433 default: | 6656 default: |
7434 UPB_ASSERT(false); | 6657 assert(false); |
7435 return false; | 6658 return false; |
7436 } | 6659 } |
7437 } | 6660 } |
7438 | 6661 |
7439 static int32_t getofs(uint32_t instruction) { | 6662 static int32_t getofs(uint32_t instruction) { |
7440 if (op_has_longofs(instruction)) { | 6663 if (op_has_longofs(instruction)) { |
7441 return (int32_t)instruction >> 8; | 6664 return (int32_t)instruction >> 8; |
7442 } else { | 6665 } else { |
7443 return (int8_t)(instruction >> 8); | 6666 return (int8_t)(instruction >> 8); |
7444 } | 6667 } |
7445 } | 6668 } |
7446 | 6669 |
7447 static void setofs(uint32_t *instruction, int32_t ofs) { | 6670 static void setofs(uint32_t *instruction, int32_t ofs) { |
7448 if (op_has_longofs(*instruction)) { | 6671 if (op_has_longofs(*instruction)) { |
7449 *instruction = getop(*instruction) | ofs << 8; | 6672 *instruction = getop(*instruction) | ofs << 8; |
7450 } else { | 6673 } else { |
7451 *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8); | 6674 *instruction = (*instruction & ~0xff00) | ((ofs & 0xff) << 8); |
7452 } | 6675 } |
7453 UPB_ASSERT(getofs(*instruction) == ofs); /* Would fail in cases of overflow.
*/ | 6676 assert(getofs(*instruction) == ofs); /* Would fail in cases of overflow. */ |
7454 } | 6677 } |
7455 | 6678 |
7456 static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } | 6679 static uint32_t pcofs(compiler *c) { return c->pc - c->group->bytecode; } |
7457 | 6680 |
7458 /* Defines a local label at the current PC location. All previous forward | 6681 /* Defines a local label at the current PC location. All previous forward |
7459 * references are updated to point to this location. The location is noted | 6682 * references are updated to point to this location. The location is noted |
7460 * for any future backward references. */ | 6683 * for any future backward references. */ |
7461 static void label(compiler *c, unsigned int label) { | 6684 static void label(compiler *c, unsigned int label) { |
7462 int val; | 6685 int val; |
7463 uint32_t *codep; | 6686 uint32_t *codep; |
7464 | 6687 |
7465 UPB_ASSERT(label < MAXLABEL); | 6688 assert(label < MAXLABEL); |
7466 val = c->fwd_labels[label]; | 6689 val = c->fwd_labels[label]; |
7467 codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; | 6690 codep = (val == EMPTYLABEL) ? NULL : c->group->bytecode + val; |
7468 while (codep) { | 6691 while (codep) { |
7469 int ofs = getofs(*codep); | 6692 int ofs = getofs(*codep); |
7470 setofs(codep, c->pc - codep - instruction_len(*codep)); | 6693 setofs(codep, c->pc - codep - instruction_len(*codep)); |
7471 codep = ofs ? codep + ofs : NULL; | 6694 codep = ofs ? codep + ofs : NULL; |
7472 } | 6695 } |
7473 c->fwd_labels[label] = EMPTYLABEL; | 6696 c->fwd_labels[label] = EMPTYLABEL; |
7474 c->back_labels[label] = pcofs(c); | 6697 c->back_labels[label] = pcofs(c); |
7475 } | 6698 } |
7476 | 6699 |
7477 /* Creates a reference to a numbered label; either a forward reference | 6700 /* Creates a reference to a numbered label; either a forward reference |
7478 * (positive arg) or backward reference (negative arg). For forward references | 6701 * (positive arg) or backward reference (negative arg). For forward references |
7479 * the value returned now is actually a "next" pointer into a linked list of all | 6702 * the value returned now is actually a "next" pointer into a linked list of all |
7480 * instructions that use this label and will be patched later when the label is | 6703 * instructions that use this label and will be patched later when the label is |
7481 * defined with label(). | 6704 * defined with label(). |
7482 * | 6705 * |
7483 * The returned value is the offset that should be written into the instruction. | 6706 * The returned value is the offset that should be written into the instruction. |
7484 */ | 6707 */ |
7485 static int32_t labelref(compiler *c, int label) { | 6708 static int32_t labelref(compiler *c, int label) { |
7486 UPB_ASSERT(label < MAXLABEL); | 6709 assert(label < MAXLABEL); |
7487 if (label == LABEL_DISPATCH) { | 6710 if (label == LABEL_DISPATCH) { |
7488 /* No resolving required. */ | 6711 /* No resolving required. */ |
7489 return 0; | 6712 return 0; |
7490 } else if (label < 0) { | 6713 } else if (label < 0) { |
7491 /* Backward local label. Relative to the next instruction. */ | 6714 /* Backward local label. Relative to the next instruction. */ |
7492 uint32_t from = (c->pc + 1) - c->group->bytecode; | 6715 uint32_t from = (c->pc + 1) - c->group->bytecode; |
7493 return c->back_labels[-label] - from; | 6716 return c->back_labels[-label] - from; |
7494 } else { | 6717 } else { |
7495 /* Forward local label: prepend to (possibly-empty) linked list. */ | 6718 /* Forward local label: prepend to (possibly-empty) linked list. */ |
7496 int *lptr = &c->fwd_labels[label]; | 6719 int *lptr = &c->fwd_labels[label]; |
7497 int32_t ret = (*lptr == EMPTYLABEL) ? 0 : *lptr - pcofs(c); | 6720 int32_t ret = (*lptr == EMPTYLABEL) ? 0 : *lptr - pcofs(c); |
7498 *lptr = pcofs(c); | 6721 *lptr = pcofs(c); |
7499 return ret; | 6722 return ret; |
7500 } | 6723 } |
7501 } | 6724 } |
7502 | 6725 |
7503 static void put32(compiler *c, uint32_t v) { | 6726 static void put32(compiler *c, uint32_t v) { |
7504 mgroup *g = c->group; | 6727 mgroup *g = c->group; |
7505 if (c->pc == g->bytecode_end) { | 6728 if (c->pc == g->bytecode_end) { |
7506 int ofs = pcofs(c); | 6729 int ofs = pcofs(c); |
7507 size_t oldsize = g->bytecode_end - g->bytecode; | 6730 size_t oldsize = g->bytecode_end - g->bytecode; |
7508 size_t newsize = UPB_MAX(oldsize * 2, 64); | 6731 size_t newsize = UPB_MAX(oldsize * 2, 64); |
7509 /* TODO(haberman): handle OOM. */ | 6732 /* TODO(haberman): handle OOM. */ |
7510 g->bytecode = upb_grealloc(g->bytecode, oldsize * sizeof(uint32_t), | 6733 g->bytecode = realloc(g->bytecode, newsize * sizeof(uint32_t)); |
7511 newsize * sizeof(uint32_t)); | |
7512 g->bytecode_end = g->bytecode + newsize; | 6734 g->bytecode_end = g->bytecode + newsize; |
7513 c->pc = g->bytecode + ofs; | 6735 c->pc = g->bytecode + ofs; |
7514 } | 6736 } |
7515 *c->pc++ = v; | 6737 *c->pc++ = v; |
7516 } | 6738 } |
7517 | 6739 |
7518 static void putop(compiler *c, opcode op, ...) { | 6740 static void putop(compiler *c, opcode op, ...) { |
7519 va_list ap; | 6741 va_list ap; |
7520 va_start(ap, op); | 6742 va_start(ap, op); |
7521 | 6743 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7576 int label = va_arg(ap, int); | 6798 int label = va_arg(ap, int); |
7577 setofs(&instruction, labelref(c, label)); | 6799 setofs(&instruction, labelref(c, label)); |
7578 put32(c, instruction); | 6800 put32(c, instruction); |
7579 break; | 6801 break; |
7580 } | 6802 } |
7581 case OP_TAG1: | 6803 case OP_TAG1: |
7582 case OP_TAG2: { | 6804 case OP_TAG2: { |
7583 int label = va_arg(ap, int); | 6805 int label = va_arg(ap, int); |
7584 uint64_t tag = va_arg(ap, uint64_t); | 6806 uint64_t tag = va_arg(ap, uint64_t); |
7585 uint32_t instruction = op | (tag << 16); | 6807 uint32_t instruction = op | (tag << 16); |
7586 UPB_ASSERT(tag <= 0xffff); | 6808 assert(tag <= 0xffff); |
7587 setofs(&instruction, labelref(c, label)); | 6809 setofs(&instruction, labelref(c, label)); |
7588 put32(c, instruction); | 6810 put32(c, instruction); |
7589 break; | 6811 break; |
7590 } | 6812 } |
7591 case OP_TAGN: { | 6813 case OP_TAGN: { |
7592 int label = va_arg(ap, int); | 6814 int label = va_arg(ap, int); |
7593 uint64_t tag = va_arg(ap, uint64_t); | 6815 uint64_t tag = va_arg(ap, uint64_t); |
7594 uint32_t instruction = op | (upb_value_size(tag) << 16); | 6816 uint32_t instruction = op | (upb_value_size(tag) << 16); |
7595 setofs(&instruction, labelref(c, label)); | 6817 setofs(&instruction, labelref(c, label)); |
7596 put32(c, instruction); | 6818 put32(c, instruction); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7713 fputs("\n", f); | 6935 fputs("\n", f); |
7714 } | 6936 } |
7715 } | 6937 } |
7716 | 6938 |
7717 #endif | 6939 #endif |
7718 | 6940 |
7719 static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) { | 6941 static uint64_t get_encoded_tag(const upb_fielddef *f, int wire_type) { |
7720 uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type; | 6942 uint32_t tag = (upb_fielddef_number(f) << 3) | wire_type; |
7721 uint64_t encoded_tag = upb_vencode32(tag); | 6943 uint64_t encoded_tag = upb_vencode32(tag); |
7722 /* No tag should be greater than 5 bytes. */ | 6944 /* No tag should be greater than 5 bytes. */ |
7723 UPB_ASSERT(encoded_tag <= 0xffffffffff); | 6945 assert(encoded_tag <= 0xffffffffff); |
7724 return encoded_tag; | 6946 return encoded_tag; |
7725 } | 6947 } |
7726 | 6948 |
7727 static void putchecktag(compiler *c, const upb_fielddef *f, | 6949 static void putchecktag(compiler *c, const upb_fielddef *f, |
7728 int wire_type, int dest) { | 6950 int wire_type, int dest) { |
7729 uint64_t tag = get_encoded_tag(f, wire_type); | 6951 uint64_t tag = get_encoded_tag(f, wire_type); |
7730 switch (upb_value_size(tag)) { | 6952 switch (upb_value_size(tag)) { |
7731 case 1: | 6953 case 1: |
7732 putop(c, OP_TAG1, dest, tag); | 6954 putop(c, OP_TAG1, dest, tag); |
7733 break; | 6955 break; |
7734 case 2: | 6956 case 2: |
7735 putop(c, OP_TAG2, dest, tag); | 6957 putop(c, OP_TAG2, dest, tag); |
7736 break; | 6958 break; |
7737 default: | 6959 default: |
7738 putop(c, OP_TAGN, dest, tag); | 6960 putop(c, OP_TAGN, dest, tag); |
7739 break; | 6961 break; |
7740 } | 6962 } |
7741 } | 6963 } |
7742 | 6964 |
7743 static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) { | 6965 static upb_selector_t getsel(const upb_fielddef *f, upb_handlertype_t type) { |
7744 upb_selector_t selector; | 6966 upb_selector_t selector; |
7745 bool ok = upb_handlers_getselector(f, type, &selector); | 6967 bool ok = upb_handlers_getselector(f, type, &selector); |
7746 UPB_ASSERT(ok); | 6968 UPB_ASSERT_VAR(ok, ok); |
7747 return selector; | 6969 return selector; |
7748 } | 6970 } |
7749 | 6971 |
7750 /* Takes an existing, primary dispatch table entry and repacks it with a | 6972 /* Takes an existing, primary dispatch table entry and repacks it with a |
7751 * different alternate wire type. Called when we are inserting a secondary | 6973 * different alternate wire type. Called when we are inserting a secondary |
7752 * dispatch table entry for an alternate wire type. */ | 6974 * dispatch table entry for an alternate wire type. */ |
7753 static uint64_t repack(uint64_t dispatch, int new_wt2) { | 6975 static uint64_t repack(uint64_t dispatch, int new_wt2) { |
7754 uint64_t ofs; | 6976 uint64_t ofs; |
7755 uint8_t wt1; | 6977 uint8_t wt1; |
7756 uint8_t old_wt2; | 6978 uint8_t old_wt2; |
7757 upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2); | 6979 upb_pbdecoder_unpackdispatch(dispatch, &ofs, &wt1, &old_wt2); |
7758 UPB_ASSERT(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */ | 6980 assert(old_wt2 == NO_WIRE_TYPE); /* wt2 should not be set yet. */ |
7759 return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2); | 6981 return upb_pbdecoder_packdispatch(ofs, wt1, new_wt2); |
7760 } | 6982 } |
7761 | 6983 |
7762 /* Marks the current bytecode position as the dispatch target for this message, | 6984 /* Marks the current bytecode position as the dispatch target for this message, |
7763 * field, and wire type. */ | 6985 * field, and wire type. */ |
7764 static void dispatchtarget(compiler *c, upb_pbdecodermethod *method, | 6986 static void dispatchtarget(compiler *c, upb_pbdecodermethod *method, |
7765 const upb_fielddef *f, int wire_type) { | 6987 const upb_fielddef *f, int wire_type) { |
7766 /* Offset is relative to msg base. */ | 6988 /* Offset is relative to msg base. */ |
7767 uint64_t ofs = pcofs(c) - method->code_base.ofs; | 6989 uint64_t ofs = pcofs(c) - method->code_base.ofs; |
7768 uint32_t fn = upb_fielddef_number(f); | 6990 uint32_t fn = upb_fielddef_number(f); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7838 | 7060 |
7839 /* Generates bytecode to parse a single non-lazy message field. */ | 7061 /* Generates bytecode to parse a single non-lazy message field. */ |
7840 static void generate_msgfield(compiler *c, const upb_fielddef *f, | 7062 static void generate_msgfield(compiler *c, const upb_fielddef *f, |
7841 upb_pbdecodermethod *method) { | 7063 upb_pbdecodermethod *method) { |
7842 const upb_handlers *h = upb_pbdecodermethod_desthandlers(method); | 7064 const upb_handlers *h = upb_pbdecodermethod_desthandlers(method); |
7843 const upb_pbdecodermethod *sub_m = find_submethod(c, method, f); | 7065 const upb_pbdecodermethod *sub_m = find_submethod(c, method, f); |
7844 int wire_type; | 7066 int wire_type; |
7845 | 7067 |
7846 if (!sub_m) { | 7068 if (!sub_m) { |
7847 /* Don't emit any code for this field at all; it will be parsed as an | 7069 /* Don't emit any code for this field at all; it will be parsed as an |
7848 * unknown field. | 7070 * 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. */ | |
7854 return; | 7071 return; |
7855 } | 7072 } |
7856 | 7073 |
7857 label(c, LABEL_FIELD); | 7074 label(c, LABEL_FIELD); |
7858 | 7075 |
7859 wire_type = | 7076 wire_type = |
7860 (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) | 7077 (upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_MESSAGE) |
7861 ? UPB_WIRE_TYPE_DELIMITED | 7078 ? UPB_WIRE_TYPE_DELIMITED |
7862 : UPB_WIRE_TYPE_START_GROUP; | 7079 : UPB_WIRE_TYPE_START_GROUP; |
7863 | 7080 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7950 /* From a decoding perspective, ENUM is the same as INT32. */ | 7167 /* From a decoding perspective, ENUM is the same as INT32. */ |
7951 if (descriptor_type == UPB_DESCRIPTOR_TYPE_ENUM) | 7168 if (descriptor_type == UPB_DESCRIPTOR_TYPE_ENUM) |
7952 descriptor_type = UPB_DESCRIPTOR_TYPE_INT32; | 7169 descriptor_type = UPB_DESCRIPTOR_TYPE_INT32; |
7953 | 7170 |
7954 parse_type = (opcode)descriptor_type; | 7171 parse_type = (opcode)descriptor_type; |
7955 | 7172 |
7956 /* TODO(haberman): generate packed or non-packed first depending on "packed" | 7173 /* TODO(haberman): generate packed or non-packed first depending on "packed" |
7957 * setting in the fielddef. This will favor (in speed) whichever was | 7174 * setting in the fielddef. This will favor (in speed) whichever was |
7958 * specified. */ | 7175 * specified. */ |
7959 | 7176 |
7960 UPB_ASSERT((int)parse_type >= 0 && parse_type <= OP_MAX); | 7177 assert((int)parse_type >= 0 && parse_type <= OP_MAX); |
7961 sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); | 7178 sel = getsel(f, upb_handlers_getprimitivehandlertype(f)); |
7962 wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)]; | 7179 wire_type = upb_pb_native_wire_types[upb_fielddef_descriptortype(f)]; |
7963 if (upb_fielddef_isseq(f)) { | 7180 if (upb_fielddef_isseq(f)) { |
7964 putop(c, OP_CHECKDELIM, LABEL_ENDMSG); | 7181 putop(c, OP_CHECKDELIM, LABEL_ENDMSG); |
7965 putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH); | 7182 putchecktag(c, f, UPB_WIRE_TYPE_DELIMITED, LABEL_DISPATCH); |
7966 dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED); | 7183 dispatchtarget(c, method, f, UPB_WIRE_TYPE_DELIMITED); |
7967 putop(c, OP_PUSHLENDELIM); | 7184 putop(c, OP_PUSHLENDELIM); |
7968 putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Packed */ | 7185 putop(c, OP_STARTSEQ, getsel(f, UPB_HANDLER_STARTSEQ)); /* Packed */ |
7969 label(c, LABEL_LOOPSTART); | 7186 label(c, LABEL_LOOPSTART); |
7970 putop(c, parse_type, sel); | 7187 putop(c, parse_type, sel); |
(...skipping 21 matching lines...) Expand all Loading... |
7992 | 7209 |
7993 /* Adds bytecode for parsing the given message to the given decoderplan, | 7210 /* Adds bytecode for parsing the given message to the given decoderplan, |
7994 * while adding all dispatch targets to this message's dispatch table. */ | 7211 * while adding all dispatch targets to this message's dispatch table. */ |
7995 static void compile_method(compiler *c, upb_pbdecodermethod *method) { | 7212 static void compile_method(compiler *c, upb_pbdecodermethod *method) { |
7996 const upb_handlers *h; | 7213 const upb_handlers *h; |
7997 const upb_msgdef *md; | 7214 const upb_msgdef *md; |
7998 uint32_t* start_pc; | 7215 uint32_t* start_pc; |
7999 upb_msg_field_iter i; | 7216 upb_msg_field_iter i; |
8000 upb_value val; | 7217 upb_value val; |
8001 | 7218 |
8002 UPB_ASSERT(method); | 7219 assert(method); |
8003 | 7220 |
8004 /* Clear all entries in the dispatch table. */ | 7221 /* Clear all entries in the dispatch table. */ |
8005 upb_inttable_uninit(&method->dispatch); | 7222 upb_inttable_uninit(&method->dispatch); |
8006 upb_inttable_init(&method->dispatch, UPB_CTYPE_UINT64); | 7223 upb_inttable_init(&method->dispatch, UPB_CTYPE_UINT64); |
8007 | 7224 |
8008 h = upb_pbdecodermethod_desthandlers(method); | 7225 h = upb_pbdecodermethod_desthandlers(method); |
8009 md = upb_handlers_msgdef(h); | 7226 md = upb_handlers_msgdef(h); |
8010 | 7227 |
8011 method->code_base.ofs = pcofs(c); | 7228 method->code_base.ofs = pcofs(c); |
8012 putop(c, OP_SETDISPATCH, &method->dispatch); | 7229 putop(c, OP_SETDISPATCH, &method->dispatch); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8140 | 7357 |
8141 | 7358 |
8142 /* TODO(haberman): allow this to be constructed for an arbitrary set of dest | 7359 /* TODO(haberman): allow this to be constructed for an arbitrary set of dest |
8143 * handlers and other mgroups (but verify we have a transitive closure). */ | 7360 * handlers and other mgroups (but verify we have a transitive closure). */ |
8144 const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, | 7361 const mgroup *mgroup_new(const upb_handlers *dest, bool allowjit, bool lazy, |
8145 const void *owner) { | 7362 const void *owner) { |
8146 mgroup *g; | 7363 mgroup *g; |
8147 compiler *c; | 7364 compiler *c; |
8148 | 7365 |
8149 UPB_UNUSED(allowjit); | 7366 UPB_UNUSED(allowjit); |
8150 UPB_ASSERT(upb_handlers_isfrozen(dest)); | 7367 assert(upb_handlers_isfrozen(dest)); |
8151 | 7368 |
8152 g = newgroup(owner); | 7369 g = newgroup(owner); |
8153 c = newcompiler(g, lazy); | 7370 c = newcompiler(g, lazy); |
8154 find_methods(c, dest); | 7371 find_methods(c, dest); |
8155 | 7372 |
8156 /* We compile in two passes: | 7373 /* We compile in two passes: |
8157 * 1. all messages are assigned relative offsets from the beginning of the | 7374 * 1. all messages are assigned relative offsets from the beginning of the |
8158 * bytecode (saved in method->code_base). | 7375 * bytecode (saved in method->code_base). |
8159 * 2. forwards OP_CALL instructions can be correctly linked since message | 7376 * 2. forwards OP_CALL instructions can be correctly linked since message |
8160 * offsets have been previously assigned. | 7377 * offsets have been previously assigned. |
8161 * | 7378 * |
8162 * Could avoid the second pass by linking OP_CALL instructions somehow. */ | 7379 * Could avoid the second pass by linking OP_CALL instructions somehow. */ |
8163 compile_methods(c); | 7380 compile_methods(c); |
8164 compile_methods(c); | 7381 compile_methods(c); |
8165 g->bytecode_end = c->pc; | 7382 g->bytecode_end = c->pc; |
8166 freecompiler(c); | 7383 freecompiler(c); |
8167 | 7384 |
8168 #ifdef UPB_DUMP_BYTECODE | 7385 #ifdef UPB_DUMP_BYTECODE |
8169 { | 7386 { |
8170 FILE *f = fopen("/tmp/upb-bytecode", "w"); | 7387 FILE *f = fopen("/tmp/upb-bytecode", "wb"); |
8171 UPB_ASSERT(f); | 7388 assert(f); |
8172 dumpbc(g->bytecode, g->bytecode_end, stderr); | 7389 dumpbc(g->bytecode, g->bytecode_end, stderr); |
8173 dumpbc(g->bytecode, g->bytecode_end, f); | 7390 dumpbc(g->bytecode, g->bytecode_end, f); |
8174 fclose(f); | 7391 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); | |
8180 } | 7392 } |
8181 #endif | 7393 #endif |
8182 | 7394 |
8183 sethandlers(g, allowjit); | 7395 sethandlers(g, allowjit); |
8184 return g; | 7396 return g; |
8185 } | 7397 } |
8186 | 7398 |
8187 | 7399 |
8188 /* upb_pbcodecache ************************************************************/ | 7400 /* upb_pbcodecache ************************************************************/ |
8189 | 7401 |
(...skipping 27 matching lines...) Expand all Loading... |
8217 upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) { | 7429 upb_pbcodecache *c, const upb_pbdecodermethodopts *opts) { |
8218 upb_value v; | 7430 upb_value v; |
8219 bool ok; | 7431 bool ok; |
8220 | 7432 |
8221 /* Right now we build a new DecoderMethod every time. | 7433 /* Right now we build a new DecoderMethod every time. |
8222 * TODO(haberman): properly cache methods by their true key. */ | 7434 * TODO(haberman): properly cache methods by their true key. */ |
8223 const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c); | 7435 const mgroup *g = mgroup_new(opts->handlers, c->allow_jit_, opts->lazy, c); |
8224 upb_inttable_push(&c->groups, upb_value_constptr(g)); | 7436 upb_inttable_push(&c->groups, upb_value_constptr(g)); |
8225 | 7437 |
8226 ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v); | 7438 ok = upb_inttable_lookupptr(&g->methods, opts->handlers, &v); |
8227 UPB_ASSERT(ok); | 7439 UPB_ASSERT_VAR(ok, ok); |
8228 return upb_value_getptr(v); | 7440 return upb_value_getptr(v); |
8229 } | 7441 } |
8230 | 7442 |
8231 | 7443 |
8232 /* upb_pbdecodermethodopts ****************************************************/ | 7444 /* upb_pbdecodermethodopts ****************************************************/ |
8233 | 7445 |
8234 void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts, | 7446 void upb_pbdecodermethodopts_init(upb_pbdecodermethodopts *opts, |
8235 const upb_handlers *h) { | 7447 const upb_handlers *h) { |
8236 opts->handlers = h; | 7448 opts->handlers = h; |
8237 opts->lazy = false; | 7449 opts->lazy = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8269 const char *kPbDecoderSubmessageTooLong = | 7481 const char *kPbDecoderSubmessageTooLong = |
8270 "Submessage end extends past enclosing submessage."; | 7482 "Submessage end extends past enclosing submessage."; |
8271 | 7483 |
8272 /* Error messages shared within this file. */ | 7484 /* Error messages shared within this file. */ |
8273 static const char *kUnterminatedVarint = "Unterminated varint."; | 7485 static const char *kUnterminatedVarint = "Unterminated varint."; |
8274 | 7486 |
8275 /* upb_pbdecoder **************************************************************/ | 7487 /* upb_pbdecoder **************************************************************/ |
8276 | 7488 |
8277 static opcode halt = OP_HALT; | 7489 static opcode halt = OP_HALT; |
8278 | 7490 |
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 | |
8284 /* Whether an op consumes any of the input buffer. */ | 7491 /* Whether an op consumes any of the input buffer. */ |
8285 static bool consumes_input(opcode op) { | 7492 static bool consumes_input(opcode op) { |
8286 switch (op) { | 7493 switch (op) { |
8287 case OP_SETDISPATCH: | 7494 case OP_SETDISPATCH: |
8288 case OP_STARTMSG: | 7495 case OP_STARTMSG: |
8289 case OP_ENDMSG: | 7496 case OP_ENDMSG: |
8290 case OP_STARTSEQ: | 7497 case OP_STARTSEQ: |
8291 case OP_ENDSEQ: | 7498 case OP_ENDSEQ: |
8292 case OP_STARTSUBMSG: | 7499 case OP_STARTSUBMSG: |
8293 case OP_ENDSUBMSG: | 7500 case OP_ENDSUBMSG: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8350 | 7557 |
8351 | 7558 |
8352 /* Buffering ******************************************************************/ | 7559 /* Buffering ******************************************************************/ |
8353 | 7560 |
8354 /* We operate on one buffer at a time, which is either the user's buffer passed | 7561 /* We operate on one buffer at a time, which is either the user's buffer passed |
8355 * to our "decode" callback or some residual bytes from the previous buffer. */ | 7562 * to our "decode" callback or some residual bytes from the previous buffer. */ |
8356 | 7563 |
8357 /* How many bytes can be safely read from d->ptr without reading past end-of-buf | 7564 /* How many bytes can be safely read from d->ptr without reading past end-of-buf |
8358 * or past the current delimited end. */ | 7565 * or past the current delimited end. */ |
8359 static size_t curbufleft(const upb_pbdecoder *d) { | 7566 static size_t curbufleft(const upb_pbdecoder *d) { |
8360 UPB_ASSERT(d->data_end >= d->ptr); | 7567 assert(d->data_end >= d->ptr); |
8361 return d->data_end - d->ptr; | 7568 return d->data_end - d->ptr; |
8362 } | 7569 } |
8363 | 7570 |
8364 /* How many bytes are available before end-of-buffer. */ | 7571 /* How many bytes are available before end-of-buffer. */ |
8365 static size_t bufleft(const upb_pbdecoder *d) { | 7572 static size_t bufleft(const upb_pbdecoder *d) { |
8366 return d->end - d->ptr; | 7573 return d->end - d->ptr; |
8367 } | 7574 } |
8368 | 7575 |
8369 /* Overall stream offset of d->ptr. */ | 7576 /* Overall stream offset of d->ptr. */ |
8370 uint64_t offset(const upb_pbdecoder *d) { | 7577 uint64_t offset(const upb_pbdecoder *d) { |
8371 return d->bufstart_ofs + (d->ptr - d->buf); | 7578 return d->bufstart_ofs + (d->ptr - d->buf); |
8372 } | 7579 } |
8373 | 7580 |
8374 /* How many bytes are available before the end of this delimited region. */ | 7581 /* How many bytes are available before the end of this delimited region. */ |
8375 size_t delim_remaining(const upb_pbdecoder *d) { | 7582 size_t delim_remaining(const upb_pbdecoder *d) { |
8376 return d->top->end_ofs - offset(d); | 7583 return d->top->end_ofs - offset(d); |
8377 } | 7584 } |
8378 | 7585 |
8379 /* Advances d->ptr. */ | 7586 /* Advances d->ptr. */ |
8380 static void advance(upb_pbdecoder *d, size_t len) { | 7587 static void advance(upb_pbdecoder *d, size_t len) { |
8381 UPB_ASSERT(curbufleft(d) >= len); | 7588 assert(curbufleft(d) >= len); |
8382 d->ptr += len; | 7589 d->ptr += len; |
8383 } | 7590 } |
8384 | 7591 |
8385 static bool in_buf(const char *p, const char *buf, const char *end) { | 7592 static bool in_buf(const char *p, const char *buf, const char *end) { |
8386 return p >= buf && p <= end; | 7593 return p >= buf && p <= end; |
8387 } | 7594 } |
8388 | 7595 |
8389 static bool in_residual_buf(const upb_pbdecoder *d, const char *p) { | 7596 static bool in_residual_buf(const upb_pbdecoder *d, const char *p) { |
8390 return in_buf(p, d->residual, d->residual_end); | 7597 return in_buf(p, d->residual, d->residual_end); |
8391 } | 7598 } |
(...skipping 12 matching lines...) Expand all Loading... |
8404 } | 7611 } |
8405 | 7612 |
8406 static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) { | 7613 static void switchtobuf(upb_pbdecoder *d, const char *buf, const char *end) { |
8407 d->ptr = buf; | 7614 d->ptr = buf; |
8408 d->buf = buf; | 7615 d->buf = buf; |
8409 d->end = end; | 7616 d->end = end; |
8410 set_delim_end(d); | 7617 set_delim_end(d); |
8411 } | 7618 } |
8412 | 7619 |
8413 static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) { | 7620 static void advancetobuf(upb_pbdecoder *d, const char *buf, size_t len) { |
8414 UPB_ASSERT(curbufleft(d) == 0); | 7621 assert(curbufleft(d) == 0); |
8415 d->bufstart_ofs += (d->end - d->buf); | 7622 d->bufstart_ofs += (d->end - d->buf); |
8416 switchtobuf(d, buf, buf + len); | 7623 switchtobuf(d, buf, buf + len); |
8417 } | 7624 } |
8418 | 7625 |
8419 static void checkpoint(upb_pbdecoder *d) { | 7626 static void checkpoint(upb_pbdecoder *d) { |
8420 /* The assertion here is in the interests of efficiency, not correctness. | 7627 /* The assertion here is in the interests of efficiency, not correctness. |
8421 * We are trying to ensure that we don't checkpoint() more often than | 7628 * We are trying to ensure that we don't checkpoint() more often than |
8422 * necessary. */ | 7629 * necessary. */ |
8423 UPB_ASSERT(d->checkpoint != d->ptr); | 7630 assert(d->checkpoint != d->ptr); |
8424 d->checkpoint = d->ptr; | 7631 d->checkpoint = d->ptr; |
8425 } | 7632 } |
8426 | 7633 |
8427 /* Skips "bytes" bytes in the stream, which may be more than available. If we | 7634 /* Skips "bytes" bytes in the stream, which may be more than available. If we |
8428 * skip more bytes than are available, we return a long read count to the caller | 7635 * skip more bytes than are available, we return a long read count to the caller |
8429 * indicating how many bytes can be skipped over before passing actual data | 7636 * indicating how many bytes can be skipped over before passing actual data |
8430 * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they | 7637 * again. Skipped bytes can pass a NULL buffer and the decoder guarantees they |
8431 * won't actually be read. | 7638 * won't actually be read. |
8432 */ | 7639 */ |
8433 static int32_t skip(upb_pbdecoder *d, size_t bytes) { | 7640 static int32_t skip(upb_pbdecoder *d, size_t bytes) { |
8434 UPB_ASSERT(!in_residual_buf(d, d->ptr) || d->size_param == 0); | 7641 assert(!in_residual_buf(d, d->ptr) || d->size_param == 0); |
8435 UPB_ASSERT(d->skip == 0); | 7642 assert(d->skip == 0); |
8436 if (bytes > delim_remaining(d)) { | 7643 if (bytes > delim_remaining(d)) { |
8437 seterr(d, "Skipped value extended beyond enclosing submessage."); | 7644 seterr(d, "Skipped value extended beyond enclosing submessage."); |
8438 return upb_pbdecoder_suspend(d); | 7645 return upb_pbdecoder_suspend(d); |
8439 } else if (bufleft(d) >= bytes) { | 7646 } else if (bufleft(d) > bytes) { |
8440 /* Skipped data is all in current buffer, and more is still available. */ | 7647 /* Skipped data is all in current buffer, and more is still available. */ |
8441 advance(d, bytes); | 7648 advance(d, bytes); |
8442 d->skip = 0; | 7649 d->skip = 0; |
8443 return DECODE_OK; | 7650 return DECODE_OK; |
8444 } else { | 7651 } else { |
8445 /* Skipped data extends beyond currently available buffers. */ | 7652 /* Skipped data extends beyond currently available buffers. */ |
8446 d->pc = d->last; | 7653 d->pc = d->last; |
8447 d->skip = bytes - curbufleft(d); | 7654 d->skip = bytes - curbufleft(d); |
8448 d->bufstart_ofs += (d->end - d->buf); | 7655 d->bufstart_ofs += (d->end - d->buf); |
8449 d->residual_end = d->residual; | 7656 d->residual_end = d->residual; |
8450 switchtobuf(d, d->residual, d->residual_end); | 7657 switchtobuf(d, d->residual, d->residual_end); |
8451 return d->size_param + d->skip; | 7658 return d->size_param + d->skip; |
8452 } | 7659 } |
8453 } | 7660 } |
8454 | 7661 |
8455 | 7662 |
8456 /* Resumes the decoder from an initial state or from a previous suspend. */ | 7663 /* Resumes the decoder from an initial state or from a previous suspend. */ |
8457 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, | 7664 int32_t upb_pbdecoder_resume(upb_pbdecoder *d, void *p, const char *buf, |
8458 size_t size, const upb_bufhandle *handle) { | 7665 size_t size, const upb_bufhandle *handle) { |
8459 UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */ | 7666 UPB_UNUSED(p); /* Useless; just for the benefit of the JIT. */ |
8460 | 7667 |
8461 /* d->skip and d->residual_end could probably elegantly be represented | 7668 d->buf_param = buf; |
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. */ | |
8467 d->size_param = size; | 7669 d->size_param = size; |
8468 d->handle = handle; | 7670 d->handle = handle; |
8469 | 7671 |
8470 /* Have to handle this case specially (ie. not with skip()) because the user | 7672 if (d->residual_end > d->residual) { |
8471 * is allowed to pass a NULL buffer here, which won't allow us to safely | 7673 /* We have residual bytes from the last buffer. */ |
8472 * calculate a d->end or use our normal functions like curbufleft(). */ | 7674 assert(d->ptr == d->residual); |
8473 if (d->skip && d->skip >= size) { | 7675 } else { |
8474 d->skip -= size; | 7676 switchtobuf(d, buf, buf + 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. */ | |
8481 } | 7677 } |
8482 | 7678 |
8483 /* We need to pretend that this was the actual buffer param, since some of the | 7679 d->checkpoint = d->ptr; |
8484 * calculations assume that d->ptr/d->buf is relative to this. */ | 7680 |
8485 d->buf_param = buf; | 7681 if (d->skip) { |
| 7682 size_t skip_bytes = d->skip; |
| 7683 d->skip = 0; |
| 7684 CHECK_RETURN(skip(d, skip_bytes)); |
| 7685 d->checkpoint = d->ptr; |
| 7686 } |
8486 | 7687 |
8487 if (!buf) { | 7688 if (!buf) { |
8488 /* NULL buf is ok if its entire span is covered by the "skip" above, but | 7689 /* NULL buf is ok if its entire span is covered by the "skip" above, but |
8489 * by this point we know that "skip" doesn't cover the buffer. */ | 7690 * by this point we know that "skip" doesn't cover the buffer. */ |
8490 seterr(d, "Passed NULL buffer over non-skippable region."); | 7691 seterr(d, "Passed NULL buffer over non-skippable region."); |
8491 return upb_pbdecoder_suspend(d); | 7692 return upb_pbdecoder_suspend(d); |
8492 } | 7693 } |
8493 | 7694 |
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. */ | |
8512 if (d->top->groupnum < 0) { | 7695 if (d->top->groupnum < 0) { |
8513 CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0)); | 7696 CHECK_RETURN(upb_pbdecoder_skipunknown(d, -1, 0)); |
8514 checkpoint(d); | 7697 d->checkpoint = d->ptr; |
8515 } | 7698 } |
8516 | 7699 |
8517 return DECODE_OK; | 7700 return DECODE_OK; |
8518 } | 7701 } |
8519 | 7702 |
8520 /* Suspends the decoder at the last checkpoint, without saving any residual | 7703 /* Suspends the decoder at the last checkpoint, without saving any residual |
8521 * bytes. If there are any unconsumed bytes, returns a short byte count. */ | 7704 * bytes. If there are any unconsumed bytes, returns a short byte count. */ |
8522 size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { | 7705 size_t upb_pbdecoder_suspend(upb_pbdecoder *d) { |
8523 d->pc = d->last; | 7706 d->pc = d->last; |
8524 if (d->checkpoint == d->residual) { | 7707 if (d->checkpoint == d->residual) { |
8525 /* Checkpoint was in residual buf; no user bytes were consumed. */ | 7708 /* Checkpoint was in residual buf; no user bytes were consumed. */ |
8526 d->ptr = d->residual; | 7709 d->ptr = d->residual; |
8527 return 0; | 7710 return 0; |
8528 } else { | 7711 } else { |
8529 size_t ret = d->size_param - (d->end - d->checkpoint); | 7712 size_t consumed; |
8530 UPB_ASSERT(!in_residual_buf(d, d->checkpoint)); | 7713 assert(!in_residual_buf(d, d->checkpoint)); |
8531 UPB_ASSERT(d->buf == d->buf_param || d->buf == &dummy_char); | 7714 assert(d->buf == d->buf_param); |
8532 | 7715 |
8533 d->bufstart_ofs += (d->checkpoint - d->buf); | 7716 consumed = d->checkpoint - d->buf; |
| 7717 d->bufstart_ofs += consumed; |
8534 d->residual_end = d->residual; | 7718 d->residual_end = d->residual; |
8535 switchtobuf(d, d->residual, d->residual_end); | 7719 switchtobuf(d, d->residual, d->residual_end); |
8536 return ret; | 7720 return consumed; |
8537 } | 7721 } |
8538 } | 7722 } |
8539 | 7723 |
8540 /* Suspends the decoder at the last checkpoint, and saves any unconsumed | 7724 /* Suspends the decoder at the last checkpoint, and saves any unconsumed |
8541 * bytes in our residual buffer. This is necessary if we need more user | 7725 * bytes in our residual buffer. This is necessary if we need more user |
8542 * bytes to form a complete value, which might not be contiguous in the | 7726 * bytes to form a complete value, which might not be contiguous in the |
8543 * user's buffers. Always consumes all user bytes. */ | 7727 * user's buffers. Always consumes all user bytes. */ |
8544 static size_t suspend_save(upb_pbdecoder *d) { | 7728 static size_t suspend_save(upb_pbdecoder *d) { |
8545 /* We hit end-of-buffer before we could parse a full value. | 7729 /* We hit end-of-buffer before we could parse a full value. |
8546 * Save any unconsumed bytes (if any) to the residual buffer. */ | 7730 * Save any unconsumed bytes (if any) to the residual buffer. */ |
8547 d->pc = d->last; | 7731 d->pc = d->last; |
8548 | 7732 |
8549 if (d->checkpoint == d->residual) { | 7733 if (d->checkpoint == d->residual) { |
8550 /* Checkpoint was in residual buf; append user byte(s) to residual buf. */ | 7734 /* Checkpoint was in residual buf; append user byte(s) to residual buf. */ |
8551 UPB_ASSERT((d->residual_end - d->residual) + d->size_param <= | 7735 assert((d->residual_end - d->residual) + d->size_param <= |
8552 sizeof(d->residual)); | 7736 sizeof(d->residual)); |
8553 if (!in_residual_buf(d, d->ptr)) { | 7737 if (!in_residual_buf(d, d->ptr)) { |
8554 d->bufstart_ofs -= (d->residual_end - d->residual); | 7738 d->bufstart_ofs -= (d->residual_end - d->residual); |
8555 } | 7739 } |
8556 memcpy(d->residual_end, d->buf_param, d->size_param); | 7740 memcpy(d->residual_end, d->buf_param, d->size_param); |
8557 d->residual_end += d->size_param; | 7741 d->residual_end += d->size_param; |
8558 } else { | 7742 } else { |
8559 /* Checkpoint was in user buf; old residual bytes not needed. */ | 7743 /* Checkpoint was in user buf; old residual bytes not needed. */ |
8560 size_t save; | 7744 size_t save; |
8561 UPB_ASSERT(!in_residual_buf(d, d->checkpoint)); | 7745 assert(!in_residual_buf(d, d->checkpoint)); |
8562 | 7746 |
8563 d->ptr = d->checkpoint; | 7747 d->ptr = d->checkpoint; |
8564 save = curbufleft(d); | 7748 save = curbufleft(d); |
8565 UPB_ASSERT(save <= sizeof(d->residual)); | 7749 assert(save <= sizeof(d->residual)); |
8566 memcpy(d->residual, d->ptr, save); | 7750 memcpy(d->residual, d->ptr, save); |
8567 d->residual_end = d->residual + save; | 7751 d->residual_end = d->residual + save; |
8568 d->bufstart_ofs = offset(d); | 7752 d->bufstart_ofs = offset(d); |
8569 } | 7753 } |
8570 | 7754 |
8571 switchtobuf(d, d->residual, d->residual_end); | 7755 switchtobuf(d, d->residual, d->residual_end); |
8572 return d->size_param; | 7756 return d->size_param; |
8573 } | 7757 } |
8574 | 7758 |
8575 /* Copies the next "bytes" bytes into "buf" and advances the stream. | 7759 /* Copies the next "bytes" bytes into "buf" and advances the stream. |
8576 * Requires that this many bytes are available in the current buffer. */ | 7760 * Requires that this many bytes are available in the current buffer. */ |
8577 UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf, | 7761 UPB_FORCEINLINE static void consumebytes(upb_pbdecoder *d, void *buf, |
8578 size_t bytes) { | 7762 size_t bytes) { |
8579 UPB_ASSERT(bytes <= curbufleft(d)); | 7763 assert(bytes <= curbufleft(d)); |
8580 memcpy(buf, d->ptr, bytes); | 7764 memcpy(buf, d->ptr, bytes); |
8581 advance(d, bytes); | 7765 advance(d, bytes); |
8582 } | 7766 } |
8583 | 7767 |
8584 /* Slow path for getting the next "bytes" bytes, regardless of whether they are | 7768 /* Slow path for getting the next "bytes" bytes, regardless of whether they are |
8585 * available in the current buffer or not. Returns a status code as described | 7769 * available in the current buffer or not. Returns a status code as described |
8586 * in decoder.int.h. */ | 7770 * in decoder.int.h. */ |
8587 UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, | 7771 UPB_NOINLINE static int32_t getbytes_slow(upb_pbdecoder *d, void *buf, |
8588 size_t bytes) { | 7772 size_t bytes) { |
8589 const size_t avail = curbufleft(d); | 7773 const size_t avail = curbufleft(d); |
8590 consumebytes(d, buf, avail); | 7774 consumebytes(d, buf, avail); |
8591 bytes -= avail; | 7775 bytes -= avail; |
8592 UPB_ASSERT(bytes > 0); | 7776 assert(bytes > 0); |
8593 if (in_residual_buf(d, d->ptr)) { | 7777 if (in_residual_buf(d, d->ptr)) { |
8594 advancetobuf(d, d->buf_param, d->size_param); | 7778 advancetobuf(d, d->buf_param, d->size_param); |
8595 } | 7779 } |
8596 if (curbufleft(d) >= bytes) { | 7780 if (curbufleft(d) >= bytes) { |
8597 consumebytes(d, (char *)buf + avail, bytes); | 7781 consumebytes(d, (char *)buf + avail, bytes); |
8598 return DECODE_OK; | 7782 return DECODE_OK; |
8599 } else if (d->data_end == d->delim_end) { | 7783 } else if (d->data_end == d->delim_end) { |
8600 seterr(d, "Submessage ended in the middle of a value or group"); | 7784 seterr(d, "Submessage ended in the middle of a value or group"); |
8601 return upb_pbdecoder_suspend(d); | 7785 return upb_pbdecoder_suspend(d); |
8602 } else { | 7786 } else { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8644 /* Decoding of wire types *****************************************************/ | 7828 /* Decoding of wire types *****************************************************/ |
8645 | 7829 |
8646 /* Slow path for decoding a varint from the current buffer position. | 7830 /* Slow path for decoding a varint from the current buffer position. |
8647 * Returns a status code as described in decoder.int.h. */ | 7831 * Returns a status code as described in decoder.int.h. */ |
8648 UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, | 7832 UPB_NOINLINE int32_t upb_pbdecoder_decode_varint_slow(upb_pbdecoder *d, |
8649 uint64_t *u64) { | 7833 uint64_t *u64) { |
8650 uint8_t byte = 0x80; | 7834 uint8_t byte = 0x80; |
8651 int bitpos; | 7835 int bitpos; |
8652 *u64 = 0; | 7836 *u64 = 0; |
8653 for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { | 7837 for(bitpos = 0; bitpos < 70 && (byte & 0x80); bitpos += 7) { |
8654 CHECK_RETURN(getbytes(d, &byte, 1)); | 7838 int32_t ret = getbytes(d, &byte, 1); |
| 7839 if (ret >= 0) return ret; |
8655 *u64 |= (uint64_t)(byte & 0x7F) << bitpos; | 7840 *u64 |= (uint64_t)(byte & 0x7F) << bitpos; |
8656 } | 7841 } |
8657 if(bitpos == 70 && (byte & 0x80)) { | 7842 if(bitpos == 70 && (byte & 0x80)) { |
8658 seterr(d, kUnterminatedVarint); | 7843 seterr(d, kUnterminatedVarint); |
8659 return upb_pbdecoder_suspend(d); | 7844 return upb_pbdecoder_suspend(d); |
8660 } | 7845 } |
8661 return DECODE_OK; | 7846 return DECODE_OK; |
8662 } | 7847 } |
8663 | 7848 |
8664 /* Decodes a varint from the current buffer position. | 7849 /* Decodes a varint from the current buffer position. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8765 static void decoder_pop(upb_pbdecoder *d) { d->top--; } | 7950 static void decoder_pop(upb_pbdecoder *d) { d->top--; } |
8766 | 7951 |
8767 UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, | 7952 UPB_NOINLINE int32_t upb_pbdecoder_checktag_slow(upb_pbdecoder *d, |
8768 uint64_t expected) { | 7953 uint64_t expected) { |
8769 uint64_t data = 0; | 7954 uint64_t data = 0; |
8770 size_t bytes = upb_value_size(expected); | 7955 size_t bytes = upb_value_size(expected); |
8771 size_t read = peekbytes(d, &data, bytes); | 7956 size_t read = peekbytes(d, &data, bytes); |
8772 if (read == bytes && data == expected) { | 7957 if (read == bytes && data == expected) { |
8773 /* Advance past matched bytes. */ | 7958 /* Advance past matched bytes. */ |
8774 int32_t ok = getbytes(d, &data, read); | 7959 int32_t ok = getbytes(d, &data, read); |
8775 UPB_ASSERT(ok < 0); | 7960 UPB_ASSERT_VAR(ok, ok < 0); |
8776 return DECODE_OK; | 7961 return DECODE_OK; |
8777 } else if (read < bytes && memcmp(&data, &expected, read) == 0) { | 7962 } else if (read < bytes && memcmp(&data, &expected, read) == 0) { |
8778 return suspend_save(d); | 7963 return suspend_save(d); |
8779 } else { | 7964 } else { |
8780 return DECODE_MISMATCH; | 7965 return DECODE_MISMATCH; |
8781 } | 7966 } |
8782 } | 7967 } |
8783 | 7968 |
8784 int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, | 7969 int32_t upb_pbdecoder_skipunknown(upb_pbdecoder *d, int32_t fieldnum, |
8785 uint8_t wire_type) { | 7970 uint8_t wire_type) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8840 } | 8025 } |
8841 | 8026 |
8842 /* Unknown group -- continue looping over unknown fields. */ | 8027 /* Unknown group -- continue looping over unknown fields. */ |
8843 checkpoint(d); | 8028 checkpoint(d); |
8844 } | 8029 } |
8845 } | 8030 } |
8846 | 8031 |
8847 static void goto_endmsg(upb_pbdecoder *d) { | 8032 static void goto_endmsg(upb_pbdecoder *d) { |
8848 upb_value v; | 8033 upb_value v; |
8849 bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v); | 8034 bool found = upb_inttable_lookup32(d->top->dispatch, DISPATCH_ENDMSG, &v); |
8850 UPB_ASSERT(found); | 8035 UPB_ASSERT_VAR(found, found); |
8851 d->pc = d->top->base + upb_value_getuint64(v); | 8036 d->pc = d->top->base + upb_value_getuint64(v); |
8852 } | 8037 } |
8853 | 8038 |
8854 /* Parses a tag and jumps to the corresponding bytecode instruction for this | 8039 /* Parses a tag and jumps to the corresponding bytecode instruction for this |
8855 * field. | 8040 * field. |
8856 * | 8041 * |
8857 * If the tag is unknown (or the wire type doesn't match), parses the field as | 8042 * If the tag is unknown (or the wire type doesn't match), parses the field as |
8858 * unknown. If the tag is a valid ENDGROUP tag, jumps to the bytecode | 8043 * unknown. If the tag is a valid ENDGROUP tag, jumps to the bytecode |
8859 * instruction for the end of message. */ | 8044 * instruction for the end of message. */ |
8860 static int32_t dispatch(upb_pbdecoder *d) { | 8045 static int32_t dispatch(upb_pbdecoder *d) { |
(...skipping 13 matching lines...) Expand all Loading... |
8874 * check the wire type against two possibilities. */ | 8059 * check the wire type against two possibilities. */ |
8875 if (fieldnum != DISPATCH_ENDMSG && | 8060 if (fieldnum != DISPATCH_ENDMSG && |
8876 upb_inttable_lookup32(dispatch, fieldnum, &val)) { | 8061 upb_inttable_lookup32(dispatch, fieldnum, &val)) { |
8877 uint64_t v = upb_value_getuint64(val); | 8062 uint64_t v = upb_value_getuint64(val); |
8878 if (wire_type == (v & 0xff)) { | 8063 if (wire_type == (v & 0xff)) { |
8879 d->pc = d->top->base + (v >> 16); | 8064 d->pc = d->top->base + (v >> 16); |
8880 return DECODE_OK; | 8065 return DECODE_OK; |
8881 } else if (wire_type == ((v >> 8) & 0xff)) { | 8066 } else if (wire_type == ((v >> 8) & 0xff)) { |
8882 bool found = | 8067 bool found = |
8883 upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val); | 8068 upb_inttable_lookup(dispatch, fieldnum + UPB_MAX_FIELDNUMBER, &val); |
8884 UPB_ASSERT(found); | 8069 UPB_ASSERT_VAR(found, found); |
8885 d->pc = d->top->base + upb_value_getuint64(val); | 8070 d->pc = d->top->base + upb_value_getuint64(val); |
8886 return DECODE_OK; | 8071 return DECODE_OK; |
8887 } | 8072 } |
8888 } | 8073 } |
8889 | 8074 |
8890 /* We have some unknown fields (or ENDGROUP) to parse. The DISPATCH or TAG | 8075 /* We have some unknown fields (or ENDGROUP) to parse. The DISPATCH or TAG |
8891 * bytecode that triggered this is preceded by a CHECKDELIM bytecode which | 8076 * bytecode that triggered this is preceded by a CHECKDELIM bytecode which |
8892 * we need to back up to, so that when we're done skipping unknown data we | 8077 * we need to back up to, so that when we're done skipping unknown data we |
8893 * can re-check the delimited end. */ | 8078 * can re-check the delimited end. */ |
8894 d->last--; /* Necessary if we get suspended */ | 8079 d->last--; /* Necessary if we get suspended */ |
8895 d->pc = d->last; | 8080 d->pc = d->last; |
8896 UPB_ASSERT(getop(*d->last) == OP_CHECKDELIM); | 8081 assert(getop(*d->last) == OP_CHECKDELIM); |
8897 | 8082 |
8898 /* Unknown field or ENDGROUP. */ | 8083 /* Unknown field or ENDGROUP. */ |
8899 retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type); | 8084 retval = upb_pbdecoder_skipunknown(d, fieldnum, wire_type); |
8900 | 8085 |
8901 CHECK_RETURN(retval); | 8086 CHECK_RETURN(retval); |
8902 | 8087 |
8903 if (retval == DECODE_ENDGROUP) { | 8088 if (retval == DECODE_ENDGROUP) { |
8904 goto_endmsg(d); | 8089 goto_endmsg(d); |
8905 return DECODE_OK; | 8090 return DECODE_OK; |
8906 } | 8091 } |
8907 | 8092 |
8908 return DECODE_OK; | 8093 return DECODE_OK; |
8909 } | 8094 } |
8910 | 8095 |
8911 /* Callers know that the stack is more than one deep because the opcodes that | 8096 /* Callers know that the stack is more than one deep because the opcodes that |
8912 * call this only occur after PUSH operations. */ | 8097 * call this only occur after PUSH operations. */ |
8913 upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) { | 8098 upb_pbdecoder_frame *outer_frame(upb_pbdecoder *d) { |
8914 UPB_ASSERT(d->top != d->stack); | 8099 assert(d->top != d->stack); |
8915 return d->top - 1; | 8100 return d->top - 1; |
8916 } | 8101 } |
8917 | 8102 |
8918 | 8103 |
8919 /* The main decoding loop *****************************************************/ | 8104 /* The main decoding loop *****************************************************/ |
8920 | 8105 |
8921 /* The main decoder VM function. Uses traditional bytecode dispatch loop with a | 8106 /* The main decoder VM function. Uses traditional bytecode dispatch loop with a |
8922 * switch() statement. */ | 8107 * switch() statement. */ |
8923 size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, | 8108 size_t run_decoder_vm(upb_pbdecoder *d, const mgroup *group, |
8924 const upb_bufhandle* handle) { | 8109 const upb_bufhandle* handle) { |
(...skipping 11 matching lines...) Expand all Loading... |
8936 int32_t instruction; | 8121 int32_t instruction; |
8937 opcode op; | 8122 opcode op; |
8938 uint32_t arg; | 8123 uint32_t arg; |
8939 int32_t longofs; | 8124 int32_t longofs; |
8940 | 8125 |
8941 d->last = d->pc; | 8126 d->last = d->pc; |
8942 instruction = *d->pc++; | 8127 instruction = *d->pc++; |
8943 op = getop(instruction); | 8128 op = getop(instruction); |
8944 arg = instruction >> 8; | 8129 arg = instruction >> 8; |
8945 longofs = arg; | 8130 longofs = arg; |
8946 UPB_ASSERT(d->ptr != d->residual_end); | 8131 assert(d->ptr != d->residual_end); |
8947 UPB_UNUSED(group); | 8132 UPB_UNUSED(group); |
8948 #ifdef UPB_DUMP_BYTECODE | 8133 #ifdef UPB_DUMP_BYTECODE |
8949 fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d " | 8134 fprintf(stderr, "s_ofs=%d buf_ofs=%d data_rem=%d buf_rem=%d delim_rem=%d " |
8950 "%x %s (%d)\n", | 8135 "%x %s (%d)\n", |
8951 (int)offset(d), | 8136 (int)offset(d), |
8952 (int)(d->ptr - d->buf), | 8137 (int)(d->ptr - d->buf), |
8953 (int)(d->data_end - d->ptr), | 8138 (int)(d->data_end - d->ptr), |
8954 (int)(d->end - d->ptr), | 8139 (int)(d->end - d->ptr), |
8955 (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)), | 8140 (int)((d->top->end_ofs - d->bufstart_ofs) - (d->ptr - d->buf)), |
8956 (int)(d->pc - 1 - group->bytecode), | 8141 (int)(d->pc - 1 - group->bytecode), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9011 VMCASE(OP_STRING, | 8196 VMCASE(OP_STRING, |
9012 uint32_t len = curbufleft(d); | 8197 uint32_t len = curbufleft(d); |
9013 size_t n = upb_sink_putstring(&d->top->sink, arg, d->ptr, len, handle); | 8198 size_t n = upb_sink_putstring(&d->top->sink, arg, d->ptr, len, handle); |
9014 if (n > len) { | 8199 if (n > len) { |
9015 if (n > delim_remaining(d)) { | 8200 if (n > delim_remaining(d)) { |
9016 seterr(d, "Tried to skip past end of string."); | 8201 seterr(d, "Tried to skip past end of string."); |
9017 return upb_pbdecoder_suspend(d); | 8202 return upb_pbdecoder_suspend(d); |
9018 } else { | 8203 } else { |
9019 int32_t ret = skip(d, n); | 8204 int32_t ret = skip(d, n); |
9020 /* This shouldn't return DECODE_OK, because n > len. */ | 8205 /* This shouldn't return DECODE_OK, because n > len. */ |
9021 UPB_ASSERT(ret >= 0); | 8206 assert(ret >= 0); |
9022 return ret; | 8207 return ret; |
9023 } | 8208 } |
9024 } | 8209 } |
9025 advance(d, n); | 8210 advance(d, n); |
9026 if (n < len || d->delim_end == NULL) { | 8211 if (n < len || d->delim_end == NULL) { |
9027 /* We aren't finished with this string yet. */ | 8212 /* We aren't finished with this string yet. */ |
9028 d->pc--; /* Repeat OP_STRING. */ | 8213 d->pc--; /* Repeat OP_STRING. */ |
9029 if (n > 0) checkpoint(d); | 8214 if (n > 0) checkpoint(d); |
9030 return upb_pbdecoder_suspend(d); | 8215 return upb_pbdecoder_suspend(d); |
9031 } | 8216 } |
9032 ) | 8217 ) |
9033 VMCASE(OP_ENDSTR, | 8218 VMCASE(OP_ENDSTR, |
9034 CHECK_SUSPEND(upb_sink_endstr(&d->top->sink, arg)); | 8219 CHECK_SUSPEND(upb_sink_endstr(&d->top->sink, arg)); |
9035 ) | 8220 ) |
9036 VMCASE(OP_PUSHTAGDELIM, | 8221 VMCASE(OP_PUSHTAGDELIM, |
9037 CHECK_SUSPEND(pushtagdelim(d, arg)); | 8222 CHECK_SUSPEND(pushtagdelim(d, arg)); |
9038 ) | 8223 ) |
9039 VMCASE(OP_SETBIGGROUPNUM, | 8224 VMCASE(OP_SETBIGGROUPNUM, |
9040 d->top->groupnum = *d->pc++; | 8225 d->top->groupnum = *d->pc++; |
9041 ) | 8226 ) |
9042 VMCASE(OP_POP, | 8227 VMCASE(OP_POP, |
9043 UPB_ASSERT(d->top > d->stack); | 8228 assert(d->top > d->stack); |
9044 decoder_pop(d); | 8229 decoder_pop(d); |
9045 ) | 8230 ) |
9046 VMCASE(OP_PUSHLENDELIM, | 8231 VMCASE(OP_PUSHLENDELIM, |
9047 uint32_t len; | 8232 uint32_t len; |
9048 CHECK_RETURN(decode_v32(d, &len)); | 8233 CHECK_RETURN(decode_v32(d, &len)); |
9049 CHECK_SUSPEND(decoder_push(d, offset(d) + len)); | 8234 CHECK_SUSPEND(decoder_push(d, offset(d) + len)); |
9050 set_delim_end(d); | 8235 set_delim_end(d); |
9051 ) | 8236 ) |
9052 VMCASE(OP_SETDELIM, | 8237 VMCASE(OP_SETDELIM, |
9053 set_delim_end(d); | 8238 set_delim_end(d); |
9054 ) | 8239 ) |
9055 VMCASE(OP_CHECKDELIM, | 8240 VMCASE(OP_CHECKDELIM, |
9056 /* We are guaranteed of this assert because we never allow ourselves to | 8241 /* We are guaranteed of this assert because we never allow ourselves to |
9057 * consume bytes beyond data_end, which covers delim_end when non-NULL. | 8242 * consume bytes beyond data_end, which covers delim_end when non-NULL. |
9058 */ | 8243 */ |
9059 UPB_ASSERT(!(d->delim_end && d->ptr > d->delim_end)); | 8244 assert(!(d->delim_end && d->ptr > d->delim_end)); |
9060 if (d->ptr == d->delim_end) | 8245 if (d->ptr == d->delim_end) |
9061 d->pc += longofs; | 8246 d->pc += longofs; |
9062 ) | 8247 ) |
9063 VMCASE(OP_CALL, | 8248 VMCASE(OP_CALL, |
9064 d->callstack[d->call_len++] = d->pc; | 8249 d->callstack[d->call_len++] = d->pc; |
9065 d->pc += longofs; | 8250 d->pc += longofs; |
9066 ) | 8251 ) |
9067 VMCASE(OP_RET, | 8252 VMCASE(OP_RET, |
9068 UPB_ASSERT(d->call_len > 0); | 8253 assert(d->call_len > 0); |
9069 d->pc = d->callstack[--d->call_len]; | 8254 d->pc = d->callstack[--d->call_len]; |
9070 ) | 8255 ) |
9071 VMCASE(OP_BRANCH, | 8256 VMCASE(OP_BRANCH, |
9072 d->pc += longofs; | 8257 d->pc += longofs; |
9073 ) | 8258 ) |
9074 VMCASE(OP_TAG1, | 8259 VMCASE(OP_TAG1, |
9075 uint8_t expected; | 8260 uint8_t expected; |
9076 CHECK_SUSPEND(curbufleft(d) > 0); | 8261 CHECK_SUSPEND(curbufleft(d) > 0); |
9077 expected = (arg >> 8) & 0xff; | 8262 expected = (arg >> 8) & 0xff; |
9078 if (*d->ptr == expected) { | 8263 if (*d->ptr == expected) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9185 group->jit_code(closure, method->code_base.ptr, &dummy, 0, NULL); | 8370 group->jit_code(closure, method->code_base.ptr, &dummy, 0, NULL); |
9186 } else | 8371 } else |
9187 #endif | 8372 #endif |
9188 { | 8373 { |
9189 const uint32_t *p = d->pc; | 8374 const uint32_t *p = d->pc; |
9190 d->stack->end_ofs = end; | 8375 d->stack->end_ofs = end; |
9191 /* Check the previous bytecode, but guard against beginning. */ | 8376 /* Check the previous bytecode, but guard against beginning. */ |
9192 if (p != method->code_base.ptr) p--; | 8377 if (p != method->code_base.ptr) p--; |
9193 if (getop(*p) == OP_CHECKDELIM) { | 8378 if (getop(*p) == OP_CHECKDELIM) { |
9194 /* Rewind from OP_TAG* to OP_CHECKDELIM. */ | 8379 /* Rewind from OP_TAG* to OP_CHECKDELIM. */ |
9195 UPB_ASSERT(getop(*d->pc) == OP_TAG1 || | 8380 assert(getop(*d->pc) == OP_TAG1 || |
9196 getop(*d->pc) == OP_TAG2 || | 8381 getop(*d->pc) == OP_TAG2 || |
9197 getop(*d->pc) == OP_TAGN || | 8382 getop(*d->pc) == OP_TAGN || |
9198 getop(*d->pc) == OP_DISPATCH); | 8383 getop(*d->pc) == OP_DISPATCH); |
9199 d->pc = p; | 8384 d->pc = p; |
9200 } | 8385 } |
9201 upb_pbdecoder_decode(closure, handler_data, &dummy, 0, NULL); | 8386 upb_pbdecoder_decode(closure, handler_data, &dummy, 0, NULL); |
9202 } | 8387 } |
9203 | 8388 |
9204 if (d->call_len != 0) { | 8389 if (d->call_len != 0) { |
9205 seterr(d, "Unexpected EOF inside submessage or group"); | 8390 seterr(d, "Unexpected EOF inside submessage or group"); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9244 d->method_ = m; | 8429 d->method_ = m; |
9245 d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting)); | 8430 d->callstack = upb_env_malloc(e, callstacksize(d, default_max_nesting)); |
9246 d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting)); | 8431 d->stack = upb_env_malloc(e, stacksize(d, default_max_nesting)); |
9247 if (!d->stack || !d->callstack) { | 8432 if (!d->stack || !d->callstack) { |
9248 return NULL; | 8433 return NULL; |
9249 } | 8434 } |
9250 | 8435 |
9251 d->env = e; | 8436 d->env = e; |
9252 d->limit = d->stack + default_max_nesting - 1; | 8437 d->limit = d->stack + default_max_nesting - 1; |
9253 d->stack_size = default_max_nesting; | 8438 d->stack_size = default_max_nesting; |
9254 d->status = NULL; | |
9255 | 8439 |
9256 upb_pbdecoder_reset(d); | 8440 upb_pbdecoder_reset(d); |
9257 upb_bytessink_reset(&d->input_, &m->input_handler_, d); | 8441 upb_bytessink_reset(&d->input_, &m->input_handler_, d); |
9258 | 8442 |
9259 UPB_ASSERT(sink); | 8443 assert(sink); |
9260 if (d->method_->dest_handlers_) { | 8444 if (d->method_->dest_handlers_) { |
9261 if (sink->handlers != d->method_->dest_handlers_) | 8445 if (sink->handlers != d->method_->dest_handlers_) |
9262 return NULL; | 8446 return NULL; |
9263 } | 8447 } |
9264 upb_sink_reset(&d->top->sink, sink->handlers, sink->closure); | 8448 upb_sink_reset(&d->top->sink, sink->handlers, sink->closure); |
9265 | 8449 |
9266 /* If this fails, increase the value in decoder.h. */ | 8450 /* If this fails, increase the value in decoder.h. */ |
9267 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= | 8451 assert(upb_env_bytesallocated(e) - size_before <= UPB_PB_DECODER_SIZE); |
9268 UPB_PB_DECODER_SIZE); | |
9269 return d; | 8452 return d; |
9270 } | 8453 } |
9271 | 8454 |
9272 uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d) { | 8455 uint64_t upb_pbdecoder_bytesparsed(const upb_pbdecoder *d) { |
9273 return offset(d); | 8456 return offset(d); |
9274 } | 8457 } |
9275 | 8458 |
9276 const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d) { | 8459 const upb_pbdecodermethod *upb_pbdecoder_method(const upb_pbdecoder *d) { |
9277 return d->method_; | 8460 return d->method_; |
9278 } | 8461 } |
9279 | 8462 |
9280 upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d) { | 8463 upb_bytessink *upb_pbdecoder_input(upb_pbdecoder *d) { |
9281 return &d->input_; | 8464 return &d->input_; |
9282 } | 8465 } |
9283 | 8466 |
9284 size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) { | 8467 size_t upb_pbdecoder_maxnesting(const upb_pbdecoder *d) { |
9285 return d->stack_size; | 8468 return d->stack_size; |
9286 } | 8469 } |
9287 | 8470 |
9288 bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) { | 8471 bool upb_pbdecoder_setmaxnesting(upb_pbdecoder *d, size_t max) { |
9289 UPB_ASSERT(d->top >= d->stack); | 8472 assert(d->top >= d->stack); |
9290 | 8473 |
9291 if (max < (size_t)(d->top - d->stack)) { | 8474 if (max < (size_t)(d->top - d->stack)) { |
9292 /* Can't set a limit smaller than what we are currently at. */ | 8475 /* Can't set a limit smaller than what we are currently at. */ |
9293 return false; | 8476 return false; |
9294 } | 8477 } |
9295 | 8478 |
9296 if (max > d->stack_size) { | 8479 if (max > d->stack_size) { |
9297 /* Need to reallocate stack and callstack to accommodate. */ | 8480 /* Need to reallocate stack and callstack to accommodate. */ |
9298 size_t old_size = stacksize(d, d->stack_size); | 8481 size_t old_size = stacksize(d, d->stack_size); |
9299 size_t new_size = stacksize(d, max); | 8482 size_t new_size = stacksize(d, max); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9367 ** be able to do it without affecting users. | 8550 ** be able to do it without affecting users. |
9368 ** | 8551 ** |
9369 ** The strategy is to buffer the segments of data that do *not* depend on | 8552 ** The strategy is to buffer the segments of data that do *not* depend on |
9370 ** unknown lengths in one buffer, and keep a separate buffer of segment pointers | 8553 ** unknown lengths in one buffer, and keep a separate buffer of segment pointers |
9371 ** and lengths. When the top-level submessage ends, we can go beginning to end, | 8554 ** and lengths. When the top-level submessage ends, we can go beginning to end, |
9372 ** alternating the writing of lengths with memcpy() of the rest of the data. | 8555 ** alternating the writing of lengths with memcpy() of the rest of the data. |
9373 ** At the top level though, no buffering is required. | 8556 ** At the top level though, no buffering is required. |
9374 */ | 8557 */ |
9375 | 8558 |
9376 | 8559 |
| 8560 #include <stdlib.h> |
9377 | 8561 |
9378 /* The output buffer is divided into segments; a segment is a string of data | 8562 /* The output buffer is divided into segments; a segment is a string of data |
9379 * that is "ready to go" -- it does not need any varint lengths inserted into | 8563 * that is "ready to go" -- it does not need any varint lengths inserted into |
9380 * the middle. The seams between segments are where varints will be inserted | 8564 * the middle. The seams between segments are where varints will be inserted |
9381 * once they are known. | 8565 * once they are known. |
9382 * | 8566 * |
9383 * We also use the concept of a "run", which is a range of encoded bytes that | 8567 * We also use the concept of a "run", which is a range of encoded bytes that |
9384 * occur at a single submessage level. Every segment contains one or more runs. | 8568 * occur at a single submessage level. Every segment contains one or more runs. |
9385 * | 8569 * |
9386 * A segment can span messages. Consider: | 8570 * A segment can span messages. Consider: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9438 int depth; | 8622 int depth; |
9439 }; | 8623 }; |
9440 | 8624 |
9441 /* low-level buffering ********************************************************/ | 8625 /* low-level buffering ********************************************************/ |
9442 | 8626 |
9443 /* Low-level functions for interacting with the output buffer. */ | 8627 /* Low-level functions for interacting with the output buffer. */ |
9444 | 8628 |
9445 /* TODO(haberman): handle pushback */ | 8629 /* TODO(haberman): handle pushback */ |
9446 static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) { | 8630 static void putbuf(upb_pb_encoder *e, const char *buf, size_t len) { |
9447 size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL); | 8631 size_t n = upb_bytessink_putbuf(e->output_, e->subc, buf, len, NULL); |
9448 UPB_ASSERT(n == len); | 8632 UPB_ASSERT_VAR(n, n == len); |
9449 } | 8633 } |
9450 | 8634 |
9451 static upb_pb_encoder_segment *top(upb_pb_encoder *e) { | 8635 static upb_pb_encoder_segment *top(upb_pb_encoder *e) { |
9452 return &e->segbuf[*e->top]; | 8636 return &e->segbuf[*e->top]; |
9453 } | 8637 } |
9454 | 8638 |
9455 /* Call to ensure that at least "bytes" bytes are available for writing at | 8639 /* Call to ensure that at least "bytes" bytes are available for writing at |
9456 * e->ptr. Returns false if the bytes could not be allocated. */ | 8640 * e->ptr. Returns false if the bytes could not be allocated. */ |
9457 static bool reserve(upb_pb_encoder *e, size_t bytes) { | 8641 static bool reserve(upb_pb_encoder *e, size_t bytes) { |
9458 if ((size_t)(e->limit - e->ptr) < bytes) { | 8642 if ((size_t)(e->limit - e->ptr) < bytes) { |
(...skipping 19 matching lines...) Expand all Loading... |
9478 e->limit = new_buf + new_size; | 8662 e->limit = new_buf + new_size; |
9479 e->buf = new_buf; | 8663 e->buf = new_buf; |
9480 } | 8664 } |
9481 | 8665 |
9482 return true; | 8666 return true; |
9483 } | 8667 } |
9484 | 8668 |
9485 /* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have | 8669 /* Call when "bytes" bytes have been writte at e->ptr. The caller *must* have |
9486 * previously called reserve() with at least this many bytes. */ | 8670 * previously called reserve() with at least this many bytes. */ |
9487 static void encoder_advance(upb_pb_encoder *e, size_t bytes) { | 8671 static void encoder_advance(upb_pb_encoder *e, size_t bytes) { |
9488 UPB_ASSERT((size_t)(e->limit - e->ptr) >= bytes); | 8672 assert((size_t)(e->limit - e->ptr) >= bytes); |
9489 e->ptr += bytes; | 8673 e->ptr += bytes; |
9490 } | 8674 } |
9491 | 8675 |
9492 /* Call when all of the bytes for a handler have been written. Flushes the | 8676 /* Call when all of the bytes for a handler have been written. Flushes the |
9493 * bytes if possible and necessary, returning false if this failed. */ | 8677 * bytes if possible and necessary, returning false if this failed. */ |
9494 static bool commit(upb_pb_encoder *e) { | 8678 static bool commit(upb_pb_encoder *e) { |
9495 if (!e->top) { | 8679 if (!e->top) { |
9496 /* We aren't inside a delimited region. Flush our accumulated bytes to | 8680 /* We aren't inside a delimited region. Flush our accumulated bytes to |
9497 * the output. | 8681 * the output. |
9498 * | 8682 * |
(...skipping 14 matching lines...) Expand all Loading... |
9513 | 8697 |
9514 memcpy(e->ptr, data, len); | 8698 memcpy(e->ptr, data, len); |
9515 encoder_advance(e, len); | 8699 encoder_advance(e, len); |
9516 return true; | 8700 return true; |
9517 } | 8701 } |
9518 | 8702 |
9519 /* Finish the current run by adding the run totals to the segment and message | 8703 /* Finish the current run by adding the run totals to the segment and message |
9520 * length. */ | 8704 * length. */ |
9521 static void accumulate(upb_pb_encoder *e) { | 8705 static void accumulate(upb_pb_encoder *e) { |
9522 size_t run_len; | 8706 size_t run_len; |
9523 UPB_ASSERT(e->ptr >= e->runbegin); | 8707 assert(e->ptr >= e->runbegin); |
9524 run_len = e->ptr - e->runbegin; | 8708 run_len = e->ptr - e->runbegin; |
9525 e->segptr->seglen += run_len; | 8709 e->segptr->seglen += run_len; |
9526 top(e)->msglen += run_len; | 8710 top(e)->msglen += run_len; |
9527 e->runbegin = e->ptr; | 8711 e->runbegin = e->ptr; |
9528 } | 8712 } |
9529 | 8713 |
9530 /* Call to indicate the start of delimited region for which the full length is | 8714 /* Call to indicate the start of delimited region for which the full length is |
9531 * not yet known. All data will be buffered until the length is known. | 8715 * not yet known. All data will be buffered until the length is known. |
9532 * Delimited regions may be nested; their lengths will all be tracked properly.
*/ | 8716 * Delimited regions may be nested; their lengths will all be tracked properly.
*/ |
9533 static bool start_delim(upb_pb_encoder *e) { | 8717 static bool start_delim(upb_pb_encoder *e) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9611 typedef struct { | 8795 typedef struct { |
9612 uint8_t bytes; | 8796 uint8_t bytes; |
9613 char tag[7]; | 8797 char tag[7]; |
9614 } tag_t; | 8798 } tag_t; |
9615 | 8799 |
9616 /* Allocates a new tag for this field, and sets it in these handlerattr. */ | 8800 /* Allocates a new tag for this field, and sets it in these handlerattr. */ |
9617 static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt, | 8801 static void new_tag(upb_handlers *h, const upb_fielddef *f, upb_wiretype_t wt, |
9618 upb_handlerattr *attr) { | 8802 upb_handlerattr *attr) { |
9619 uint32_t n = upb_fielddef_number(f); | 8803 uint32_t n = upb_fielddef_number(f); |
9620 | 8804 |
9621 tag_t *tag = upb_gmalloc(sizeof(tag_t)); | 8805 tag_t *tag = malloc(sizeof(tag_t)); |
9622 tag->bytes = upb_vencode64((n << 3) | wt, tag->tag); | 8806 tag->bytes = upb_vencode64((n << 3) | wt, tag->tag); |
9623 | 8807 |
9624 upb_handlerattr_init(attr); | 8808 upb_handlerattr_init(attr); |
9625 upb_handlerattr_sethandlerdata(attr, tag); | 8809 upb_handlerattr_sethandlerdata(attr, tag); |
9626 upb_handlers_addcleanup(h, tag, upb_gfree); | 8810 upb_handlers_addcleanup(h, tag, free); |
9627 } | 8811 } |
9628 | 8812 |
9629 static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) { | 8813 static bool encode_tag(upb_pb_encoder *e, const tag_t *tag) { |
9630 return encode_bytes(e, tag->tag, tag->bytes); | 8814 return encode_bytes(e, tag->tag, tag->bytes); |
9631 } | 8815 } |
9632 | 8816 |
9633 | 8817 |
9634 /* encoding of wire types *****************************************************/ | 8818 /* encoding of wire types *****************************************************/ |
9635 | 8819 |
9636 static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) { | 8820 static bool encode_fixed64(upb_pb_encoder *e, uint64_t val) { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9868 | 9052 |
9869 upb_pb_encoder_reset(e); | 9053 upb_pb_encoder_reset(e); |
9870 upb_sink_reset(&e->input_, h, e); | 9054 upb_sink_reset(&e->input_, h, e); |
9871 | 9055 |
9872 e->env = env; | 9056 e->env = env; |
9873 e->output_ = output; | 9057 e->output_ = output; |
9874 e->subc = output->closure; | 9058 e->subc = output->closure; |
9875 e->ptr = e->buf; | 9059 e->ptr = e->buf; |
9876 | 9060 |
9877 /* If this fails, increase the value in encoder.h. */ | 9061 /* If this fails, increase the value in encoder.h. */ |
9878 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= | 9062 assert(upb_env_bytesallocated(env) - size_before <= UPB_PB_ENCODER_SIZE); |
9879 UPB_PB_ENCODER_SIZE); | |
9880 return e; | 9063 return e; |
9881 } | 9064 } |
9882 | 9065 |
9883 upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } | 9066 upb_sink *upb_pb_encoder_input(upb_pb_encoder *e) { return &e->input_; } |
9884 | 9067 |
9885 | 9068 |
| 9069 #include <stdio.h> |
| 9070 #include <stdlib.h> |
| 9071 #include <string.h> |
9886 | 9072 |
9887 upb_filedef **upb_loaddescriptor(const char *buf, size_t n, const void *owner, | 9073 upb_def **upb_load_defs_from_descriptor(const char *str, size_t len, int *n, |
9888 upb_status *status) { | 9074 void *owner, upb_status *status) { |
9889 /* Create handlers. */ | 9075 /* Create handlers. */ |
9890 const upb_pbdecodermethod *decoder_m; | 9076 const upb_pbdecodermethod *decoder_m; |
9891 const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h); | 9077 const upb_handlers *reader_h = upb_descreader_newhandlers(&reader_h); |
9892 upb_env env; | 9078 upb_env env; |
9893 upb_pbdecodermethodopts opts; | 9079 upb_pbdecodermethodopts opts; |
9894 upb_pbdecoder *decoder; | 9080 upb_pbdecoder *decoder; |
9895 upb_descreader *reader; | 9081 upb_descreader *reader; |
9896 bool ok; | 9082 bool ok; |
9897 size_t i; | 9083 upb_def **ret = NULL; |
9898 upb_filedef **ret = NULL; | 9084 upb_def **defs; |
9899 | 9085 |
9900 upb_pbdecodermethodopts_init(&opts, reader_h); | 9086 upb_pbdecodermethodopts_init(&opts, reader_h); |
9901 decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m); | 9087 decoder_m = upb_pbdecodermethod_new(&opts, &decoder_m); |
9902 | 9088 |
9903 upb_env_init(&env); | 9089 upb_env_init(&env); |
9904 upb_env_reporterrorsto(&env, status); | 9090 upb_env_reporterrorsto(&env, status); |
9905 | 9091 |
9906 reader = upb_descreader_create(&env, reader_h); | 9092 reader = upb_descreader_create(&env, reader_h); |
9907 decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader)); | 9093 decoder = upb_pbdecoder_create(&env, decoder_m, upb_descreader_input(reader)); |
9908 | 9094 |
9909 /* Push input data. */ | 9095 /* Push input data. */ |
9910 ok = upb_bufsrc_putbuf(buf, n, upb_pbdecoder_input(decoder)); | 9096 ok = upb_bufsrc_putbuf(str, len, upb_pbdecoder_input(decoder)); |
9911 | 9097 |
9912 if (!ok) { | 9098 if (!ok) goto cleanup; |
9913 goto cleanup; | 9099 defs = upb_descreader_getdefs(reader, owner, n); |
9914 } | 9100 ret = malloc(sizeof(upb_def*) * (*n)); |
9915 | 9101 memcpy(ret, defs, sizeof(upb_def*) * (*n)); |
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; | |
9928 | 9102 |
9929 cleanup: | 9103 cleanup: |
9930 upb_env_uninit(&env); | 9104 upb_env_uninit(&env); |
9931 upb_handlers_unref(reader_h, &reader_h); | 9105 upb_handlers_unref(reader_h, &reader_h); |
9932 upb_pbdecodermethod_unref(decoder_m, &decoder_m); | 9106 upb_pbdecodermethod_unref(decoder_m, &decoder_m); |
9933 return ret; | 9107 return ret; |
9934 } | 9108 } |
| 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 } |
9935 /* | 9154 /* |
9936 * upb::pb::TextPrinter | 9155 * upb::pb::TextPrinter |
9937 * | 9156 * |
9938 * OPT: This is not optimized at all. It uses printf() which parses the format | 9157 * OPT: This is not optimized at all. It uses printf() which parses the format |
9939 * string every time, and it allocates memory for every put. | 9158 * string every time, and it allocates memory for every put. |
9940 */ | 9159 */ |
9941 | 9160 |
9942 | 9161 |
9943 #include <ctype.h> | 9162 #include <ctype.h> |
9944 #include <float.h> | 9163 #include <float.h> |
9945 #include <inttypes.h> | 9164 #include <inttypes.h> |
9946 #include <stdarg.h> | 9165 #include <stdarg.h> |
9947 #include <stdio.h> | 9166 #include <stdio.h> |
| 9167 #include <stdlib.h> |
9948 #include <string.h> | 9168 #include <string.h> |
9949 | 9169 |
9950 | 9170 |
9951 struct upb_textprinter { | 9171 struct upb_textprinter { |
9952 upb_sink input_; | 9172 upb_sink input_; |
9953 upb_bytessink *output_; | 9173 upb_bytessink *output_; |
9954 int indent_depth_; | 9174 int indent_depth_; |
9955 bool single_line_; | 9175 bool single_line_; |
9956 void *subc; | 9176 void *subc; |
9957 }; | 9177 }; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10033 bool ok; | 9253 bool ok; |
10034 | 9254 |
10035 va_start(args, fmt); | 9255 va_start(args, fmt); |
10036 | 9256 |
10037 /* Run once to get the length of the string. */ | 9257 /* Run once to get the length of the string. */ |
10038 _upb_va_copy(args_copy, args); | 9258 _upb_va_copy(args_copy, args); |
10039 len = _upb_vsnprintf(NULL, 0, fmt, args_copy); | 9259 len = _upb_vsnprintf(NULL, 0, fmt, args_copy); |
10040 va_end(args_copy); | 9260 va_end(args_copy); |
10041 | 9261 |
10042 /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */ | 9262 /* + 1 for NULL terminator (vsprintf() requires it even if we don't). */ |
10043 str = upb_gmalloc(len + 1); | 9263 str = malloc(len + 1); |
10044 if (!str) return false; | 9264 if (!str) return false; |
10045 written = vsprintf(str, fmt, args); | 9265 written = vsprintf(str, fmt, args); |
10046 va_end(args); | 9266 va_end(args); |
10047 UPB_ASSERT(written == len); | 9267 UPB_ASSERT_VAR(written, written == len); |
10048 | 9268 |
10049 ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL); | 9269 ok = upb_bytessink_putbuf(p->output_, p->subc, str, len, NULL); |
10050 upb_gfree(str); | 9270 free(str); |
10051 return ok; | 9271 return ok; |
10052 } | 9272 } |
10053 | 9273 |
10054 | 9274 |
10055 /* handlers *******************************************************************/ | 9275 /* handlers *******************************************************************/ |
10056 | 9276 |
10057 static bool textprinter_startmsg(void *c, const void *hd) { | 9277 static bool textprinter_startmsg(void *c, const void *hd) { |
10058 upb_textprinter *p = c; | 9278 upb_textprinter *p = c; |
10059 UPB_UNUSED(hd); | 9279 UPB_UNUSED(hd); |
10060 if (p->indent_depth_ == 0) { | 9280 if (p->indent_depth_ == 0) { |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10409 ** out: | 9629 ** out: |
10410 ** | 9630 ** |
10411 ** - handling of unicode escape sequences (including high surrogate pairs). | 9631 ** - handling of unicode escape sequences (including high surrogate pairs). |
10412 ** - properly check and report errors for unknown fields, stack overflow, | 9632 ** - properly check and report errors for unknown fields, stack overflow, |
10413 ** improper array nesting (or lack of nesting). | 9633 ** improper array nesting (or lack of nesting). |
10414 ** - handling of base64 sequences with padding characters. | 9634 ** - handling of base64 sequences with padding characters. |
10415 ** - handling of push-back (non-success returns from sink functions). | 9635 ** - handling of push-back (non-success returns from sink functions). |
10416 ** - handling of keys/escape-sequences/etc that span input buffers. | 9636 ** - handling of keys/escape-sequences/etc that span input buffers. |
10417 */ | 9637 */ |
10418 | 9638 |
| 9639 #include <stdio.h> |
| 9640 #include <stdint.h> |
10419 #include <assert.h> | 9641 #include <assert.h> |
| 9642 #include <string.h> |
| 9643 #include <stdlib.h> |
10420 #include <errno.h> | 9644 #include <errno.h> |
10421 #include <stdint.h> | |
10422 #include <stdlib.h> | |
10423 #include <string.h> | |
10424 | 9645 |
10425 | 9646 |
10426 #define UPB_JSON_MAX_DEPTH 64 | 9647 #define UPB_JSON_MAX_DEPTH 64 |
10427 | 9648 |
10428 typedef struct { | 9649 typedef struct { |
10429 upb_sink sink; | 9650 upb_sink sink; |
10430 | 9651 |
10431 /* The current message in which we're parsing, and the field whose value we're | 9652 /* The current message in which we're parsing, and the field whose value we're |
10432 * expecting next. */ | 9653 * expecting next. */ |
10433 const upb_msgdef *m; | 9654 const upb_msgdef *m; |
10434 const upb_fielddef *f; | 9655 const upb_fielddef *f; |
10435 | 9656 |
10436 /* The table mapping json name to fielddef for this message. */ | |
10437 upb_strtable *name_table; | |
10438 | |
10439 /* We are in a repeated-field context, ready to emit mapentries as | 9657 /* We are in a repeated-field context, ready to emit mapentries as |
10440 * submessages. This flag alters the start-of-object (open-brace) behavior to | 9658 * submessages. This flag alters the start-of-object (open-brace) behavior to |
10441 * begin a sequence of mapentry messages rather than a single submessage. */ | 9659 * begin a sequence of mapentry messages rather than a single submessage. */ |
10442 bool is_map; | 9660 bool is_map; |
10443 | 9661 |
10444 /* We are in a map-entry message context. This flag is set when parsing the | 9662 /* We are in a map-entry message context. This flag is set when parsing the |
10445 * value field of a single map entry and indicates to all value-field parsers | 9663 * value field of a single map entry and indicates to all value-field parsers |
10446 * (subobjects, strings, numbers, and bools) that the map-entry submessage | 9664 * (subobjects, strings, numbers, and bools) that the map-entry submessage |
10447 * should end as soon as the value is parsed. */ | 9665 * should end as soon as the value is parsed. */ |
10448 bool is_mapentry; | 9666 bool is_mapentry; |
10449 | 9667 |
10450 /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent | 9668 /* If |is_map| or |is_mapentry| is true, |mapfield| refers to the parent |
10451 * message's map field that we're currently parsing. This differs from |f| | 9669 * message's map field that we're currently parsing. This differs from |f| |
10452 * because |f| is the field in the *current* message (i.e., the map-entry | 9670 * because |f| is the field in the *current* message (i.e., the map-entry |
10453 * message itself), not the parent's field that leads to this map. */ | 9671 * message itself), not the parent's field that leads to this map. */ |
10454 const upb_fielddef *mapfield; | 9672 const upb_fielddef *mapfield; |
10455 } upb_jsonparser_frame; | 9673 } upb_jsonparser_frame; |
10456 | 9674 |
10457 struct upb_json_parser { | 9675 struct upb_json_parser { |
10458 upb_env *env; | 9676 upb_env *env; |
10459 const upb_json_parsermethod *method; | 9677 upb_byteshandler input_handler_; |
10460 upb_bytessink input_; | 9678 upb_bytessink input_; |
10461 | 9679 |
10462 /* Stack to track the JSON scopes we are in. */ | 9680 /* Stack to track the JSON scopes we are in. */ |
10463 upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH]; | 9681 upb_jsonparser_frame stack[UPB_JSON_MAX_DEPTH]; |
10464 upb_jsonparser_frame *top; | 9682 upb_jsonparser_frame *top; |
10465 upb_jsonparser_frame *limit; | 9683 upb_jsonparser_frame *limit; |
10466 | 9684 |
10467 upb_status status; | 9685 upb_status status; |
10468 | 9686 |
10469 /* Ragel's internal parsing stack for the parsing state machine. */ | 9687 /* Ragel's internal parsing stack for the parsing state machine. */ |
(...skipping 14 matching lines...) Expand all Loading... |
10484 int multipart_state; | 9702 int multipart_state; |
10485 upb_selector_t string_selector; | 9703 upb_selector_t string_selector; |
10486 | 9704 |
10487 /* Input capture. See details in parser.rl. */ | 9705 /* Input capture. See details in parser.rl. */ |
10488 const char *capture; | 9706 const char *capture; |
10489 | 9707 |
10490 /* Intermediate result of parsing a unicode escape sequence. */ | 9708 /* Intermediate result of parsing a unicode escape sequence. */ |
10491 uint32_t digit; | 9709 uint32_t digit; |
10492 }; | 9710 }; |
10493 | 9711 |
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 | |
10507 #define PARSER_CHECK_RETURN(x) if (!(x)) return false | 9712 #define PARSER_CHECK_RETURN(x) if (!(x)) return false |
10508 | 9713 |
10509 /* Used to signal that a capture has been suspended. */ | 9714 /* Used to signal that a capture has been suspended. */ |
10510 static char suspend_capture; | 9715 static char suspend_capture; |
10511 | 9716 |
10512 static upb_selector_t getsel_for_handlertype(upb_json_parser *p, | 9717 static upb_selector_t getsel_for_handlertype(upb_json_parser *p, |
10513 upb_handlertype_t type) { | 9718 upb_handlertype_t type) { |
10514 upb_selector_t sel; | 9719 upb_selector_t sel; |
10515 bool ok = upb_handlers_getselector(p->top->f, type, &sel); | 9720 bool ok = upb_handlers_getselector(p->top->f, type, &sel); |
10516 UPB_ASSERT(ok); | 9721 UPB_ASSERT_VAR(ok, ok); |
10517 return sel; | 9722 return sel; |
10518 } | 9723 } |
10519 | 9724 |
10520 static upb_selector_t parser_getsel(upb_json_parser *p) { | 9725 static upb_selector_t parser_getsel(upb_json_parser *p) { |
10521 return getsel_for_handlertype( | 9726 return getsel_for_handlertype( |
10522 p, upb_handlers_getprimitivehandlertype(p->top->f)); | 9727 p, upb_handlers_getprimitivehandlertype(p->top->f)); |
10523 } | 9728 } |
10524 | 9729 |
10525 static bool check_stack(upb_json_parser *p) { | 9730 static bool check_stack(upb_json_parser *p) { |
10526 if ((p->top + 1) == p->limit) { | 9731 if ((p->top + 1) == p->limit) { |
10527 upb_status_seterrmsg(&p->status, "Nesting too deep"); | 9732 upb_status_seterrmsg(&p->status, "Nesting too deep"); |
10528 upb_env_reporterror(p->env, &p->status); | 9733 upb_env_reporterror(p->env, &p->status); |
10529 return false; | 9734 return false; |
10530 } | 9735 } |
10531 | 9736 |
10532 return true; | 9737 return true; |
10533 } | 9738 } |
10534 | 9739 |
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 | |
10542 /* There are GCC/Clang built-ins for overflow checking which we could start | 9740 /* There are GCC/Clang built-ins for overflow checking which we could start |
10543 * using if there was any performance benefit to it. */ | 9741 * using if there was any performance benefit to it. */ |
10544 | 9742 |
10545 static bool checked_add(size_t a, size_t b, size_t *c) { | 9743 static bool checked_add(size_t a, size_t b, size_t *c) { |
10546 if (SIZE_MAX - a < b) return false; | 9744 if (SIZE_MAX - a < b) return false; |
10547 *c = a + b; | 9745 *c = a + b; |
10548 return true; | 9746 return true; |
10549 } | 9747 } |
10550 | 9748 |
10551 static size_t saturating_multiply(size_t a, size_t b) { | 9749 static size_t saturating_multiply(size_t a, size_t b) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10651 char output; | 9849 char output; |
10652 | 9850 |
10653 /* Last group contains only two input bytes, one output byte. */ | 9851 /* Last group contains only two input bytes, one output byte. */ |
10654 if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') { | 9852 if (ptr[0] == '=' || ptr[1] == '=' || ptr[3] != '=') { |
10655 goto badpadding; | 9853 goto badpadding; |
10656 } | 9854 } |
10657 | 9855 |
10658 val = b64lookup(ptr[0]) << 18 | | 9856 val = b64lookup(ptr[0]) << 18 | |
10659 b64lookup(ptr[1]) << 12; | 9857 b64lookup(ptr[1]) << 12; |
10660 | 9858 |
10661 UPB_ASSERT(!(val & 0x80000000)); | 9859 assert(!(val & 0x80000000)); |
10662 output = val >> 16; | 9860 output = val >> 16; |
10663 upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL); | 9861 upb_sink_putstring(&p->top->sink, sel, &output, 1, NULL); |
10664 return true; | 9862 return true; |
10665 } else { | 9863 } else { |
10666 uint32_t val; | 9864 uint32_t val; |
10667 char output[2]; | 9865 char output[2]; |
10668 | 9866 |
10669 /* Last group contains only three input bytes, two output bytes. */ | 9867 /* Last group contains only three input bytes, two output bytes. */ |
10670 if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') { | 9868 if (ptr[0] == '=' || ptr[1] == '=' || ptr[2] == '=') { |
10671 goto badpadding; | 9869 goto badpadding; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10705 * contiguous string and avoid any actual copy. So we optimistically begin | 9903 * contiguous string and avoid any actual copy. So we optimistically begin |
10706 * this way. But there are a few cases where we must instead copy into a | 9904 * this way. But there are a few cases where we must instead copy into a |
10707 * separate buffer: | 9905 * separate buffer: |
10708 * | 9906 * |
10709 * 1. The string was not contiguous in the input (it spanned buffers). | 9907 * 1. The string was not contiguous in the input (it spanned buffers). |
10710 * | 9908 * |
10711 * 2. The string included escape sequences that need to be interpreted to get | 9909 * 2. The string included escape sequences that need to be interpreted to get |
10712 * the true value in a contiguous buffer. */ | 9910 * the true value in a contiguous buffer. */ |
10713 | 9911 |
10714 static void assert_accumulate_empty(upb_json_parser *p) { | 9912 static void assert_accumulate_empty(upb_json_parser *p) { |
10715 UPB_ASSERT(p->accumulated == NULL); | 9913 UPB_UNUSED(p); |
10716 UPB_ASSERT(p->accumulated_len == 0); | 9914 assert(p->accumulated == NULL); |
| 9915 assert(p->accumulated_len == 0); |
10717 } | 9916 } |
10718 | 9917 |
10719 static void accumulate_clear(upb_json_parser *p) { | 9918 static void accumulate_clear(upb_json_parser *p) { |
10720 p->accumulated = NULL; | 9919 p->accumulated = NULL; |
10721 p->accumulated_len = 0; | 9920 p->accumulated_len = 0; |
10722 } | 9921 } |
10723 | 9922 |
10724 /* Used internally by accumulate_append(). */ | 9923 /* Used internally by accumulate_append(). */ |
10725 static bool accumulate_realloc(upb_json_parser *p, size_t need) { | 9924 static bool accumulate_realloc(upb_json_parser *p, size_t need) { |
10726 void *mem; | 9925 void *mem; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10772 | 9971 |
10773 memcpy(p->accumulate_buf + p->accumulated_len, buf, len); | 9972 memcpy(p->accumulate_buf + p->accumulated_len, buf, len); |
10774 p->accumulated_len += len; | 9973 p->accumulated_len += len; |
10775 return true; | 9974 return true; |
10776 } | 9975 } |
10777 | 9976 |
10778 /* Returns a pointer to the data accumulated since the last accumulate_clear() | 9977 /* Returns a pointer to the data accumulated since the last accumulate_clear() |
10779 * call, and writes the length to *len. This with point either to the input | 9978 * call, and writes the length to *len. This with point either to the input |
10780 * buffer or a temporary accumulate buffer. */ | 9979 * buffer or a temporary accumulate buffer. */ |
10781 static const char *accumulate_getptr(upb_json_parser *p, size_t *len) { | 9980 static const char *accumulate_getptr(upb_json_parser *p, size_t *len) { |
10782 UPB_ASSERT(p->accumulated); | 9981 assert(p->accumulated); |
10783 *len = p->accumulated_len; | 9982 *len = p->accumulated_len; |
10784 return p->accumulated; | 9983 return p->accumulated; |
10785 } | 9984 } |
10786 | 9985 |
10787 | 9986 |
10788 /* Mult-part text data ********************************************************/ | 9987 /* Mult-part text data ********************************************************/ |
10789 | 9988 |
10790 /* When we have text data in the input, it can often come in multiple segments. | 9989 /* When we have text data in the input, it can often come in multiple segments. |
10791 * For example, there may be some raw string data followed by an escape | 9990 * For example, there may be some raw string data followed by an escape |
10792 * sequence. The two segments are processed with different logic. Also buffer | 9991 * sequence. The two segments are processed with different logic. Also buffer |
(...skipping 17 matching lines...) Expand all Loading... |
10810 | 10009 |
10811 /* We are processing multipart data by pushing each part directly to the | 10010 /* We are processing multipart data by pushing each part directly to the |
10812 * current string handlers. */ | 10011 * current string handlers. */ |
10813 MULTIPART_PUSHEAGERLY = 2 | 10012 MULTIPART_PUSHEAGERLY = 2 |
10814 }; | 10013 }; |
10815 | 10014 |
10816 /* Start a multi-part text value where we accumulate the data for processing at | 10015 /* Start a multi-part text value where we accumulate the data for processing at |
10817 * the end. */ | 10016 * the end. */ |
10818 static void multipart_startaccum(upb_json_parser *p) { | 10017 static void multipart_startaccum(upb_json_parser *p) { |
10819 assert_accumulate_empty(p); | 10018 assert_accumulate_empty(p); |
10820 UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE); | 10019 assert(p->multipart_state == MULTIPART_INACTIVE); |
10821 p->multipart_state = MULTIPART_ACCUMULATE; | 10020 p->multipart_state = MULTIPART_ACCUMULATE; |
10822 } | 10021 } |
10823 | 10022 |
10824 /* Start a multi-part text value where we immediately push text data to a string | 10023 /* Start a multi-part text value where we immediately push text data to a string |
10825 * value with the given selector. */ | 10024 * value with the given selector. */ |
10826 static void multipart_start(upb_json_parser *p, upb_selector_t sel) { | 10025 static void multipart_start(upb_json_parser *p, upb_selector_t sel) { |
10827 assert_accumulate_empty(p); | 10026 assert_accumulate_empty(p); |
10828 UPB_ASSERT(p->multipart_state == MULTIPART_INACTIVE); | 10027 assert(p->multipart_state == MULTIPART_INACTIVE); |
10829 p->multipart_state = MULTIPART_PUSHEAGERLY; | 10028 p->multipart_state = MULTIPART_PUSHEAGERLY; |
10830 p->string_selector = sel; | 10029 p->string_selector = sel; |
10831 } | 10030 } |
10832 | 10031 |
10833 static bool multipart_text(upb_json_parser *p, const char *buf, size_t len, | 10032 static bool multipart_text(upb_json_parser *p, const char *buf, size_t len, |
10834 bool can_alias) { | 10033 bool can_alias) { |
10835 switch (p->multipart_state) { | 10034 switch (p->multipart_state) { |
10836 case MULTIPART_INACTIVE: | 10035 case MULTIPART_INACTIVE: |
10837 upb_status_seterrmsg( | 10036 upb_status_seterrmsg( |
10838 &p->status, "Internal error: unexpected state MULTIPART_INACTIVE"); | 10037 &p->status, "Internal error: unexpected state MULTIPART_INACTIVE"); |
(...skipping 12 matching lines...) Expand all Loading... |
10851 break; | 10050 break; |
10852 } | 10051 } |
10853 } | 10052 } |
10854 | 10053 |
10855 return true; | 10054 return true; |
10856 } | 10055 } |
10857 | 10056 |
10858 /* Note: this invalidates the accumulate buffer! Call only after reading its | 10057 /* Note: this invalidates the accumulate buffer! Call only after reading its |
10859 * contents. */ | 10058 * contents. */ |
10860 static void multipart_end(upb_json_parser *p) { | 10059 static void multipart_end(upb_json_parser *p) { |
10861 UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE); | 10060 assert(p->multipart_state != MULTIPART_INACTIVE); |
10862 p->multipart_state = MULTIPART_INACTIVE; | 10061 p->multipart_state = MULTIPART_INACTIVE; |
10863 accumulate_clear(p); | 10062 accumulate_clear(p); |
10864 } | 10063 } |
10865 | 10064 |
10866 | 10065 |
10867 /* Input capture **************************************************************/ | 10066 /* Input capture **************************************************************/ |
10868 | 10067 |
10869 /* Functionality for capturing a region of the input as text. Gracefully | 10068 /* Functionality for capturing a region of the input as text. Gracefully |
10870 * handles the case where a buffer seam occurs in the middle of the captured | 10069 * handles the case where a buffer seam occurs in the middle of the captured |
10871 * region. */ | 10070 * region. */ |
10872 | 10071 |
10873 static void capture_begin(upb_json_parser *p, const char *ptr) { | 10072 static void capture_begin(upb_json_parser *p, const char *ptr) { |
10874 UPB_ASSERT(p->multipart_state != MULTIPART_INACTIVE); | 10073 assert(p->multipart_state != MULTIPART_INACTIVE); |
10875 UPB_ASSERT(p->capture == NULL); | 10074 assert(p->capture == NULL); |
10876 p->capture = ptr; | 10075 p->capture = ptr; |
10877 } | 10076 } |
10878 | 10077 |
10879 static bool capture_end(upb_json_parser *p, const char *ptr) { | 10078 static bool capture_end(upb_json_parser *p, const char *ptr) { |
10880 UPB_ASSERT(p->capture); | 10079 assert(p->capture); |
10881 if (multipart_text(p, p->capture, ptr - p->capture, true)) { | 10080 if (multipart_text(p, p->capture, ptr - p->capture, true)) { |
10882 p->capture = NULL; | 10081 p->capture = NULL; |
10883 return true; | 10082 return true; |
10884 } else { | 10083 } else { |
10885 return false; | 10084 return false; |
10886 } | 10085 } |
10887 } | 10086 } |
10888 | 10087 |
10889 /* This is called at the end of each input buffer (ie. when we have hit a | 10088 /* This is called at the end of each input buffer (ie. when we have hit a |
10890 * buffer seam). If we are in the middle of capturing the input, this | 10089 * buffer seam). If we are in the middle of capturing the input, this |
(...skipping 12 matching lines...) Expand all Loading... |
10903 p->capture = &suspend_capture; | 10102 p->capture = &suspend_capture; |
10904 } else { | 10103 } else { |
10905 /* Need to back up the pointer to the beginning of the capture, since | 10104 /* Need to back up the pointer to the beginning of the capture, since |
10906 * we were not able to actually preserve it. */ | 10105 * we were not able to actually preserve it. */ |
10907 *ptr = p->capture; | 10106 *ptr = p->capture; |
10908 } | 10107 } |
10909 } | 10108 } |
10910 | 10109 |
10911 static void capture_resume(upb_json_parser *p, const char *ptr) { | 10110 static void capture_resume(upb_json_parser *p, const char *ptr) { |
10912 if (p->capture) { | 10111 if (p->capture) { |
10913 UPB_ASSERT(p->capture == &suspend_capture); | 10112 assert(p->capture == &suspend_capture); |
10914 p->capture = ptr; | 10113 p->capture = ptr; |
10915 } | 10114 } |
10916 } | 10115 } |
10917 | 10116 |
10918 | 10117 |
10919 /* Callbacks from the parser **************************************************/ | 10118 /* Callbacks from the parser **************************************************/ |
10920 | 10119 |
10921 /* These are the functions called directly from the parser itself. | 10120 /* These are the functions called directly from the parser itself. |
10922 * We define these in the same order as their declarations in the parser. */ | 10121 * We define these in the same order as their declarations in the parser. */ |
10923 | 10122 |
10924 static char escape_char(char in) { | 10123 static char escape_char(char in) { |
10925 switch (in) { | 10124 switch (in) { |
10926 case 'r': return '\r'; | 10125 case 'r': return '\r'; |
10927 case 't': return '\t'; | 10126 case 't': return '\t'; |
10928 case 'n': return '\n'; | 10127 case 'n': return '\n'; |
10929 case 'f': return '\f'; | 10128 case 'f': return '\f'; |
10930 case 'b': return '\b'; | 10129 case 'b': return '\b'; |
10931 case '/': return '/'; | 10130 case '/': return '/'; |
10932 case '"': return '"'; | 10131 case '"': return '"'; |
10933 case '\\': return '\\'; | 10132 case '\\': return '\\'; |
10934 default: | 10133 default: |
10935 UPB_ASSERT(0); | 10134 assert(0); |
10936 return 'x'; | 10135 return 'x'; |
10937 } | 10136 } |
10938 } | 10137 } |
10939 | 10138 |
10940 static bool escape(upb_json_parser *p, const char *ptr) { | 10139 static bool escape(upb_json_parser *p, const char *ptr) { |
10941 char ch = escape_char(*ptr); | 10140 char ch = escape_char(*ptr); |
10942 return multipart_text(p, &ch, 1, false); | 10141 return multipart_text(p, &ch, 1, false); |
10943 } | 10142 } |
10944 | 10143 |
10945 static void start_hex(upb_json_parser *p) { | 10144 static void start_hex(upb_json_parser *p) { |
10946 p->digit = 0; | 10145 p->digit = 0; |
10947 } | 10146 } |
10948 | 10147 |
10949 static void hexdigit(upb_json_parser *p, const char *ptr) { | 10148 static void hexdigit(upb_json_parser *p, const char *ptr) { |
10950 char ch = *ptr; | 10149 char ch = *ptr; |
10951 | 10150 |
10952 p->digit <<= 4; | 10151 p->digit <<= 4; |
10953 | 10152 |
10954 if (ch >= '0' && ch <= '9') { | 10153 if (ch >= '0' && ch <= '9') { |
10955 p->digit += (ch - '0'); | 10154 p->digit += (ch - '0'); |
10956 } else if (ch >= 'a' && ch <= 'f') { | 10155 } else if (ch >= 'a' && ch <= 'f') { |
10957 p->digit += ((ch - 'a') + 10); | 10156 p->digit += ((ch - 'a') + 10); |
10958 } else { | 10157 } else { |
10959 UPB_ASSERT(ch >= 'A' && ch <= 'F'); | 10158 assert(ch >= 'A' && ch <= 'F'); |
10960 p->digit += ((ch - 'A') + 10); | 10159 p->digit += ((ch - 'A') + 10); |
10961 } | 10160 } |
10962 } | 10161 } |
10963 | 10162 |
10964 static bool end_hex(upb_json_parser *p) { | 10163 static bool end_hex(upb_json_parser *p) { |
10965 uint32_t codepoint = p->digit; | 10164 uint32_t codepoint = p->digit; |
10966 | 10165 |
10967 /* emit the codepoint as UTF-8. */ | 10166 /* emit the codepoint as UTF-8. */ |
10968 char utf8[3]; /* support \u0000 -- \uFFFF -- need only three bytes. */ | 10167 char utf8[3]; /* support \u0000 -- \uFFFF -- need only three bytes. */ |
10969 int length = 0; | 10168 int length = 0; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11080 } | 10279 } |
11081 case UPB_TYPE_FLOAT: { | 10280 case UPB_TYPE_FLOAT: { |
11082 float val = strtod(p->accumulated, &end); | 10281 float val = strtod(p->accumulated, &end); |
11083 if (errno == ERANGE || end != myend) | 10282 if (errno == ERANGE || end != myend) |
11084 goto err; | 10283 goto err; |
11085 else | 10284 else |
11086 upb_sink_putfloat(&p->top->sink, parser_getsel(p), val); | 10285 upb_sink_putfloat(&p->top->sink, parser_getsel(p), val); |
11087 break; | 10286 break; |
11088 } | 10287 } |
11089 default: | 10288 default: |
11090 UPB_ASSERT(false); | 10289 assert(false); |
11091 } | 10290 } |
11092 | 10291 |
11093 multipart_end(p); | 10292 multipart_end(p); |
11094 | 10293 |
11095 return true; | 10294 return true; |
11096 | 10295 |
11097 err: | 10296 err: |
11098 upb_status_seterrf(&p->status, "error parsing number: %s", buf); | 10297 upb_status_seterrf(&p->status, "error parsing number: %s", buf); |
11099 upb_env_reporterror(p->env, &p->status); | 10298 upb_env_reporterror(p->env, &p->status); |
11100 multipart_end(p); | 10299 multipart_end(p); |
11101 return false; | 10300 return false; |
11102 } | 10301 } |
11103 | 10302 |
11104 static bool parser_putbool(upb_json_parser *p, bool val) { | 10303 static bool parser_putbool(upb_json_parser *p, bool val) { |
11105 bool ok; | 10304 bool ok; |
11106 | 10305 |
11107 if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) { | 10306 if (upb_fielddef_type(p->top->f) != UPB_TYPE_BOOL) { |
11108 upb_status_seterrf(&p->status, | 10307 upb_status_seterrf(&p->status, |
11109 "Boolean value specified for non-bool field: %s", | 10308 "Boolean value specified for non-bool field: %s", |
11110 upb_fielddef_name(p->top->f)); | 10309 upb_fielddef_name(p->top->f)); |
11111 upb_env_reporterror(p->env, &p->status); | 10310 upb_env_reporterror(p->env, &p->status); |
11112 return false; | 10311 return false; |
11113 } | 10312 } |
11114 | 10313 |
11115 ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val); | 10314 ok = upb_sink_putbool(&p->top->sink, parser_getsel(p), val); |
11116 UPB_ASSERT(ok); | 10315 UPB_ASSERT_VAR(ok, ok); |
11117 | 10316 |
11118 return true; | 10317 return true; |
11119 } | 10318 } |
11120 | 10319 |
11121 static bool start_stringval(upb_json_parser *p) { | 10320 static bool start_stringval(upb_json_parser *p) { |
11122 UPB_ASSERT(p->top->f); | 10321 assert(p->top->f); |
11123 | 10322 |
11124 if (upb_fielddef_isstring(p->top->f)) { | 10323 if (upb_fielddef_isstring(p->top->f)) { |
11125 upb_jsonparser_frame *inner; | 10324 upb_jsonparser_frame *inner; |
11126 upb_selector_t sel; | 10325 upb_selector_t sel; |
11127 | 10326 |
11128 if (!check_stack(p)) return false; | 10327 if (!check_stack(p)) return false; |
11129 | 10328 |
11130 /* Start a new parser frame: parser frames correspond one-to-one with | 10329 /* Start a new parser frame: parser frames correspond one-to-one with |
11131 * handler frames, and string events occur in a sub-frame. */ | 10330 * handler frames, and string events occur in a sub-frame. */ |
11132 inner = p->top + 1; | 10331 inner = p->top + 1; |
11133 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); | 10332 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); |
11134 upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); | 10333 upb_sink_startstr(&p->top->sink, sel, 0, &inner->sink); |
11135 inner->m = p->top->m; | 10334 inner->m = p->top->m; |
11136 inner->f = p->top->f; | 10335 inner->f = p->top->f; |
11137 inner->name_table = NULL; | |
11138 inner->is_map = false; | 10336 inner->is_map = false; |
11139 inner->is_mapentry = false; | 10337 inner->is_mapentry = false; |
11140 p->top = inner; | 10338 p->top = inner; |
11141 | 10339 |
11142 if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { | 10340 if (upb_fielddef_type(p->top->f) == UPB_TYPE_STRING) { |
11143 /* For STRING fields we push data directly to the handlers as it is | 10341 /* For STRING fields we push data directly to the handlers as it is |
11144 * parsed. We don't do this yet for BYTES fields, because our base64 | 10342 * parsed. We don't do this yet for BYTES fields, because our base64 |
11145 * decoder is not streaming. | 10343 * decoder is not streaming. |
11146 * | 10344 * |
11147 * TODO(haberman): make base64 decoding streaming also. */ | 10345 * TODO(haberman): make base64 decoding streaming also. */ |
(...skipping 26 matching lines...) Expand all Loading... |
11174 switch (upb_fielddef_type(p->top->f)) { | 10372 switch (upb_fielddef_type(p->top->f)) { |
11175 case UPB_TYPE_BYTES: | 10373 case UPB_TYPE_BYTES: |
11176 if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), | 10374 if (!base64_push(p, getsel_for_handlertype(p, UPB_HANDLER_STRING), |
11177 p->accumulated, p->accumulated_len)) { | 10375 p->accumulated, p->accumulated_len)) { |
11178 return false; | 10376 return false; |
11179 } | 10377 } |
11180 /* Fall through. */ | 10378 /* Fall through. */ |
11181 | 10379 |
11182 case UPB_TYPE_STRING: { | 10380 case UPB_TYPE_STRING: { |
11183 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); | 10381 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); |
| 10382 upb_sink_endstr(&p->top->sink, sel); |
11184 p->top--; | 10383 p->top--; |
11185 upb_sink_endstr(&p->top->sink, sel); | |
11186 break; | 10384 break; |
11187 } | 10385 } |
11188 | 10386 |
11189 case UPB_TYPE_ENUM: { | 10387 case UPB_TYPE_ENUM: { |
11190 /* Resolve enum symbolic name to integer value. */ | 10388 /* Resolve enum symbolic name to integer value. */ |
11191 const upb_enumdef *enumdef = | 10389 const upb_enumdef *enumdef = |
11192 (const upb_enumdef*)upb_fielddef_subdef(p->top->f); | 10390 (const upb_enumdef*)upb_fielddef_subdef(p->top->f); |
11193 | 10391 |
11194 size_t len; | 10392 size_t len; |
11195 const char *buf = accumulate_getptr(p, &len); | 10393 const char *buf = accumulate_getptr(p, &len); |
11196 | 10394 |
11197 int32_t int_val = 0; | 10395 int32_t int_val = 0; |
11198 ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); | 10396 ok = upb_enumdef_ntoi(enumdef, buf, len, &int_val); |
11199 | 10397 |
11200 if (ok) { | 10398 if (ok) { |
11201 upb_selector_t sel = parser_getsel(p); | 10399 upb_selector_t sel = parser_getsel(p); |
11202 upb_sink_putint32(&p->top->sink, sel, int_val); | 10400 upb_sink_putint32(&p->top->sink, sel, int_val); |
11203 } else { | 10401 } else { |
11204 upb_status_seterrf(&p->status, "Enum value unknown: '%.*s'", len, buf); | 10402 upb_status_seterrf(&p->status, "Enum value unknown: '%.*s'", len, buf); |
11205 upb_env_reporterror(p->env, &p->status); | 10403 upb_env_reporterror(p->env, &p->status); |
11206 } | 10404 } |
11207 | 10405 |
11208 break; | 10406 break; |
11209 } | 10407 } |
11210 | 10408 |
11211 default: | 10409 default: |
11212 UPB_ASSERT(false); | 10410 assert(false); |
11213 upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); | 10411 upb_status_seterrmsg(&p->status, "Internal error in JSON decoder"); |
11214 upb_env_reporterror(p->env, &p->status); | 10412 upb_env_reporterror(p->env, &p->status); |
11215 ok = false; | 10413 ok = false; |
11216 break; | 10414 break; |
11217 } | 10415 } |
11218 | 10416 |
11219 multipart_end(p); | 10417 multipart_end(p); |
11220 | 10418 |
11221 return ok; | 10419 return ok; |
11222 } | 10420 } |
11223 | 10421 |
11224 static void start_member(upb_json_parser *p) { | 10422 static void start_member(upb_json_parser *p) { |
11225 UPB_ASSERT(!p->top->f); | 10423 assert(!p->top->f); |
11226 multipart_startaccum(p); | 10424 multipart_startaccum(p); |
11227 } | 10425 } |
11228 | 10426 |
11229 /* Helper: invoked during parse_mapentry() to emit the mapentry message's key | 10427 /* Helper: invoked during parse_mapentry() to emit the mapentry message's key |
11230 * field based on the current contents of the accumulate buffer. */ | 10428 * field based on the current contents of the accumulate buffer. */ |
11231 static bool parse_mapentry_key(upb_json_parser *p) { | 10429 static bool parse_mapentry_key(upb_json_parser *p) { |
11232 | 10430 |
11233 size_t len; | 10431 size_t len; |
11234 const char *buf = accumulate_getptr(p, &len); | 10432 const char *buf = accumulate_getptr(p, &len); |
11235 | 10433 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11273 multipart_end(p); | 10471 multipart_end(p); |
11274 break; | 10472 break; |
11275 case UPB_TYPE_STRING: | 10473 case UPB_TYPE_STRING: |
11276 case UPB_TYPE_BYTES: { | 10474 case UPB_TYPE_BYTES: { |
11277 upb_sink subsink; | 10475 upb_sink subsink; |
11278 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); | 10476 upb_selector_t sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSTR); |
11279 upb_sink_startstr(&p->top->sink, sel, len, &subsink); | 10477 upb_sink_startstr(&p->top->sink, sel, len, &subsink); |
11280 sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); | 10478 sel = getsel_for_handlertype(p, UPB_HANDLER_STRING); |
11281 upb_sink_putstring(&subsink, sel, buf, len, NULL); | 10479 upb_sink_putstring(&subsink, sel, buf, len, NULL); |
11282 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); | 10480 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSTR); |
11283 upb_sink_endstr(&p->top->sink, sel); | 10481 upb_sink_endstr(&subsink, sel); |
11284 multipart_end(p); | 10482 multipart_end(p); |
11285 break; | 10483 break; |
11286 } | 10484 } |
11287 default: | 10485 default: |
11288 upb_status_seterrmsg(&p->status, "Invalid field type for map key"); | 10486 upb_status_seterrmsg(&p->status, "Invalid field type for map key"); |
11289 upb_env_reporterror(p->env, &p->status); | 10487 upb_env_reporterror(p->env, &p->status); |
11290 return false; | 10488 return false; |
11291 } | 10489 } |
11292 | 10490 |
11293 return true; | 10491 return true; |
(...skipping 20 matching lines...) Expand all Loading... |
11314 if (!check_stack(p)) return false; | 10512 if (!check_stack(p)) return false; |
11315 | 10513 |
11316 mapfield = p->top->mapfield; | 10514 mapfield = p->top->mapfield; |
11317 mapentrymsg = upb_fielddef_msgsubdef(mapfield); | 10515 mapentrymsg = upb_fielddef_msgsubdef(mapfield); |
11318 | 10516 |
11319 inner = p->top + 1; | 10517 inner = p->top + 1; |
11320 p->top->f = mapfield; | 10518 p->top->f = mapfield; |
11321 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); | 10519 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); |
11322 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); | 10520 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); |
11323 inner->m = mapentrymsg; | 10521 inner->m = mapentrymsg; |
11324 inner->name_table = NULL; | |
11325 inner->mapfield = mapfield; | 10522 inner->mapfield = mapfield; |
11326 inner->is_map = false; | 10523 inner->is_map = false; |
11327 | 10524 |
11328 /* Don't set this to true *yet* -- we reuse parsing handlers below to push | 10525 /* Don't set this to true *yet* -- we reuse parsing handlers below to push |
11329 * the key field value to the sink, and these handlers will pop the frame | 10526 * the key field value to the sink, and these handlers will pop the frame |
11330 * if they see is_mapentry (when invoked by the parser state machine, they | 10527 * if they see is_mapentry (when invoked by the parser state machine, they |
11331 * would have just seen the map-entry value, not key). */ | 10528 * would have just seen the map-entry value, not key). */ |
11332 inner->is_mapentry = false; | 10529 inner->is_mapentry = false; |
11333 p->top = inner; | 10530 p->top = inner; |
11334 | 10531 |
11335 /* send STARTMSG in submsg frame. */ | 10532 /* send STARTMSG in submsg frame. */ |
11336 upb_sink_startmsg(&p->top->sink); | 10533 upb_sink_startmsg(&p->top->sink); |
11337 | 10534 |
11338 parse_mapentry_key(p); | 10535 parse_mapentry_key(p); |
11339 | 10536 |
11340 /* Set up the value field to receive the map-entry value. */ | 10537 /* Set up the value field to receive the map-entry value. */ |
11341 p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_VALUE); | 10538 p->top->f = upb_msgdef_itof(p->top->m, UPB_MAPENTRY_VALUE); |
11342 p->top->is_mapentry = true; /* set up to pop frame after value is parsed. */ | 10539 p->top->is_mapentry = true; /* set up to pop frame after value is parsed. */ |
11343 p->top->mapfield = mapfield; | 10540 p->top->mapfield = mapfield; |
11344 if (p->top->f == NULL) { | 10541 if (p->top->f == NULL) { |
11345 upb_status_seterrmsg(&p->status, "mapentry message has no value"); | 10542 upb_status_seterrmsg(&p->status, "mapentry message has no value"); |
11346 upb_env_reporterror(p->env, &p->status); | 10543 upb_env_reporterror(p->env, &p->status); |
11347 return false; | 10544 return false; |
11348 } | 10545 } |
11349 | 10546 |
11350 return true; | 10547 return true; |
11351 } | 10548 } |
11352 | 10549 |
11353 static bool end_membername(upb_json_parser *p) { | 10550 static bool end_membername(upb_json_parser *p) { |
11354 UPB_ASSERT(!p->top->f); | 10551 assert(!p->top->f); |
11355 | 10552 |
11356 if (p->top->is_map) { | 10553 if (p->top->is_map) { |
11357 return handle_mapentry(p); | 10554 return handle_mapentry(p); |
11358 } else { | 10555 } else { |
11359 size_t len; | 10556 size_t len; |
11360 const char *buf = accumulate_getptr(p, &len); | 10557 const char *buf = accumulate_getptr(p, &len); |
11361 upb_value v; | 10558 const upb_fielddef *f = upb_msgdef_ntof(p->top->m, buf, len); |
11362 | 10559 |
11363 if (upb_strtable_lookup2(p->top->name_table, buf, len, &v)) { | 10560 if (!f) { |
11364 p->top->f = upb_value_getconstptr(v); | |
11365 multipart_end(p); | |
11366 | |
11367 return true; | |
11368 } else { | |
11369 /* TODO(haberman): Ignore unknown fields if requested/configured to do | 10561 /* TODO(haberman): Ignore unknown fields if requested/configured to do |
11370 * so. */ | 10562 * so. */ |
11371 upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); | 10563 upb_status_seterrf(&p->status, "No such field: %.*s\n", (int)len, buf); |
11372 upb_env_reporterror(p->env, &p->status); | 10564 upb_env_reporterror(p->env, &p->status); |
11373 return false; | 10565 return false; |
11374 } | 10566 } |
| 10567 |
| 10568 p->top->f = f; |
| 10569 multipart_end(p); |
| 10570 |
| 10571 return true; |
11375 } | 10572 } |
11376 } | 10573 } |
11377 | 10574 |
11378 static void end_member(upb_json_parser *p) { | 10575 static void end_member(upb_json_parser *p) { |
11379 /* If we just parsed a map-entry value, end that frame too. */ | 10576 /* If we just parsed a map-entry value, end that frame too. */ |
11380 if (p->top->is_mapentry) { | 10577 if (p->top->is_mapentry) { |
11381 upb_status s = UPB_STATUS_INIT; | 10578 upb_status s = UPB_STATUS_INIT; |
11382 upb_selector_t sel; | 10579 upb_selector_t sel; |
11383 bool ok; | 10580 bool ok; |
11384 const upb_fielddef *mapfield; | 10581 const upb_fielddef *mapfield; |
11385 | 10582 |
11386 UPB_ASSERT(p->top > p->stack); | 10583 assert(p->top > p->stack); |
11387 /* send ENDMSG on submsg. */ | 10584 /* send ENDMSG on submsg. */ |
11388 upb_sink_endmsg(&p->top->sink, &s); | 10585 upb_sink_endmsg(&p->top->sink, &s); |
11389 mapfield = p->top->mapfield; | 10586 mapfield = p->top->mapfield; |
11390 | 10587 |
11391 /* send ENDSUBMSG in repeated-field-of-mapentries frame. */ | 10588 /* send ENDSUBMSG in repeated-field-of-mapentries frame. */ |
11392 p->top--; | 10589 p->top--; |
11393 ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); | 10590 ok = upb_handlers_getselector(mapfield, UPB_HANDLER_ENDSUBMSG, &sel); |
11394 UPB_ASSERT(ok); | 10591 UPB_ASSERT_VAR(ok, ok); |
11395 upb_sink_endsubmsg(&p->top->sink, sel); | 10592 upb_sink_endsubmsg(&p->top->sink, sel); |
11396 } | 10593 } |
11397 | 10594 |
11398 p->top->f = NULL; | 10595 p->top->f = NULL; |
11399 } | 10596 } |
11400 | 10597 |
11401 static bool start_subobject(upb_json_parser *p) { | 10598 static bool start_subobject(upb_json_parser *p) { |
11402 UPB_ASSERT(p->top->f); | 10599 assert(p->top->f); |
11403 | 10600 |
11404 if (upb_fielddef_ismap(p->top->f)) { | 10601 if (upb_fielddef_ismap(p->top->f)) { |
11405 upb_jsonparser_frame *inner; | 10602 upb_jsonparser_frame *inner; |
11406 upb_selector_t sel; | 10603 upb_selector_t sel; |
11407 | 10604 |
11408 /* Beginning of a map. Start a new parser frame in a repeated-field | 10605 /* Beginning of a map. Start a new parser frame in a repeated-field |
11409 * context. */ | 10606 * context. */ |
11410 if (!check_stack(p)) return false; | 10607 if (!check_stack(p)) return false; |
11411 | 10608 |
11412 inner = p->top + 1; | 10609 inner = p->top + 1; |
11413 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); | 10610 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); |
11414 upb_sink_startseq(&p->top->sink, sel, &inner->sink); | 10611 upb_sink_startseq(&p->top->sink, sel, &inner->sink); |
11415 inner->m = upb_fielddef_msgsubdef(p->top->f); | 10612 inner->m = upb_fielddef_msgsubdef(p->top->f); |
11416 inner->name_table = NULL; | |
11417 inner->mapfield = p->top->f; | 10613 inner->mapfield = p->top->f; |
11418 inner->f = NULL; | 10614 inner->f = NULL; |
11419 inner->is_map = true; | 10615 inner->is_map = true; |
11420 inner->is_mapentry = false; | 10616 inner->is_mapentry = false; |
11421 p->top = inner; | 10617 p->top = inner; |
11422 | 10618 |
11423 return true; | 10619 return true; |
11424 } else if (upb_fielddef_issubmsg(p->top->f)) { | 10620 } else if (upb_fielddef_issubmsg(p->top->f)) { |
11425 upb_jsonparser_frame *inner; | 10621 upb_jsonparser_frame *inner; |
11426 upb_selector_t sel; | 10622 upb_selector_t sel; |
11427 | 10623 |
11428 /* Beginning of a subobject. Start a new parser frame in the submsg | 10624 /* Beginning of a subobject. Start a new parser frame in the submsg |
11429 * context. */ | 10625 * context. */ |
11430 if (!check_stack(p)) return false; | 10626 if (!check_stack(p)) return false; |
11431 | 10627 |
11432 inner = p->top + 1; | 10628 inner = p->top + 1; |
11433 | 10629 |
11434 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); | 10630 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSUBMSG); |
11435 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); | 10631 upb_sink_startsubmsg(&p->top->sink, sel, &inner->sink); |
11436 inner->m = upb_fielddef_msgsubdef(p->top->f); | 10632 inner->m = upb_fielddef_msgsubdef(p->top->f); |
11437 set_name_table(p, inner); | |
11438 inner->f = NULL; | 10633 inner->f = NULL; |
11439 inner->is_map = false; | 10634 inner->is_map = false; |
11440 inner->is_mapentry = false; | 10635 inner->is_mapentry = false; |
11441 p->top = inner; | 10636 p->top = inner; |
11442 | 10637 |
11443 return true; | 10638 return true; |
11444 } else { | 10639 } else { |
11445 upb_status_seterrf(&p->status, | 10640 upb_status_seterrf(&p->status, |
11446 "Object specified for non-message/group field: %s", | 10641 "Object specified for non-message/group field: %s", |
11447 upb_fielddef_name(p->top->f)); | 10642 upb_fielddef_name(p->top->f)); |
(...skipping 13 matching lines...) Expand all Loading... |
11461 p->top--; | 10656 p->top--; |
11462 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); | 10657 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSUBMSG); |
11463 upb_sink_endsubmsg(&p->top->sink, sel); | 10658 upb_sink_endsubmsg(&p->top->sink, sel); |
11464 } | 10659 } |
11465 } | 10660 } |
11466 | 10661 |
11467 static bool start_array(upb_json_parser *p) { | 10662 static bool start_array(upb_json_parser *p) { |
11468 upb_jsonparser_frame *inner; | 10663 upb_jsonparser_frame *inner; |
11469 upb_selector_t sel; | 10664 upb_selector_t sel; |
11470 | 10665 |
11471 UPB_ASSERT(p->top->f); | 10666 assert(p->top->f); |
11472 | 10667 |
11473 if (!upb_fielddef_isseq(p->top->f)) { | 10668 if (!upb_fielddef_isseq(p->top->f)) { |
11474 upb_status_seterrf(&p->status, | 10669 upb_status_seterrf(&p->status, |
11475 "Array specified for non-repeated field: %s", | 10670 "Array specified for non-repeated field: %s", |
11476 upb_fielddef_name(p->top->f)); | 10671 upb_fielddef_name(p->top->f)); |
11477 upb_env_reporterror(p->env, &p->status); | 10672 upb_env_reporterror(p->env, &p->status); |
11478 return false; | 10673 return false; |
11479 } | 10674 } |
11480 | 10675 |
11481 if (!check_stack(p)) return false; | 10676 if (!check_stack(p)) return false; |
11482 | 10677 |
11483 inner = p->top + 1; | 10678 inner = p->top + 1; |
11484 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); | 10679 sel = getsel_for_handlertype(p, UPB_HANDLER_STARTSEQ); |
11485 upb_sink_startseq(&p->top->sink, sel, &inner->sink); | 10680 upb_sink_startseq(&p->top->sink, sel, &inner->sink); |
11486 inner->m = p->top->m; | 10681 inner->m = p->top->m; |
11487 inner->name_table = NULL; | |
11488 inner->f = p->top->f; | 10682 inner->f = p->top->f; |
11489 inner->is_map = false; | 10683 inner->is_map = false; |
11490 inner->is_mapentry = false; | 10684 inner->is_mapentry = false; |
11491 p->top = inner; | 10685 p->top = inner; |
11492 | 10686 |
11493 return true; | 10687 return true; |
11494 } | 10688 } |
11495 | 10689 |
11496 static void end_array(upb_json_parser *p) { | 10690 static void end_array(upb_json_parser *p) { |
11497 upb_selector_t sel; | 10691 upb_selector_t sel; |
11498 | 10692 |
11499 UPB_ASSERT(p->top > p->stack); | 10693 assert(p->top > p->stack); |
11500 | 10694 |
11501 p->top--; | 10695 p->top--; |
11502 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); | 10696 sel = getsel_for_handlertype(p, UPB_HANDLER_ENDSEQ); |
11503 upb_sink_endseq(&p->top->sink, sel); | 10697 upb_sink_endseq(&p->top->sink, sel); |
11504 } | 10698 } |
11505 | 10699 |
11506 static void start_object(upb_json_parser *p) { | 10700 static void start_object(upb_json_parser *p) { |
11507 if (!p->top->is_map) { | 10701 if (!p->top->is_map) { |
11508 upb_sink_startmsg(&p->top->sink); | 10702 upb_sink_startmsg(&p->top->sink); |
11509 } | 10703 } |
(...skipping 25 matching lines...) Expand all Loading... |
11535 * ">" -- transition into a machine | 10729 * ">" -- transition into a machine |
11536 * "%" -- transition out of a machine | 10730 * "%" -- transition out of a machine |
11537 * "@" -- transition into a final state of a machine. | 10731 * "@" -- transition into a final state of a machine. |
11538 * | 10732 * |
11539 * "@" transitions are tricky because a machine can transition into a final | 10733 * "@" transitions are tricky because a machine can transition into a final |
11540 * state repeatedly. But in some cases we know this can't happen, for example | 10734 * state repeatedly. But in some cases we know this can't happen, for example |
11541 * a string which is delimited by a final '"' can only transition into its | 10735 * a string which is delimited by a final '"' can only transition into its |
11542 * final state once, when the closing '"' is seen. */ | 10736 * final state once, when the closing '"' is seen. */ |
11543 | 10737 |
11544 | 10738 |
11545 #line 1244 "upb/json/parser.rl" | 10739 #line 1218 "upb/json/parser.rl" |
11546 | 10740 |
11547 | 10741 |
11548 | 10742 |
11549 #line 1156 "upb/json/parser.c" | 10743 #line 1130 "upb/json/parser.c" |
11550 static const char _json_actions[] = { | 10744 static const char _json_actions[] = { |
11551 0, 1, 0, 1, 2, 1, 3, 1, | 10745 0, 1, 0, 1, 2, 1, 3, 1, |
11552 5, 1, 6, 1, 7, 1, 8, 1, | 10746 5, 1, 6, 1, 7, 1, 8, 1, |
11553 10, 1, 12, 1, 13, 1, 14, 1, | 10747 10, 1, 12, 1, 13, 1, 14, 1, |
11554 15, 1, 16, 1, 17, 1, 21, 1, | 10748 15, 1, 16, 1, 17, 1, 21, 1, |
11555 25, 1, 27, 2, 3, 8, 2, 4, | 10749 25, 1, 27, 2, 3, 8, 2, 4, |
11556 5, 2, 6, 2, 2, 6, 8, 2, | 10750 5, 2, 6, 2, 2, 6, 8, 2, |
11557 11, 9, 2, 13, 15, 2, 14, 15, | 10751 11, 9, 2, 13, 15, 2, 14, 15, |
11558 2, 18, 1, 2, 19, 27, 2, 20, | 10752 2, 18, 1, 2, 19, 27, 2, 20, |
11559 9, 2, 22, 27, 2, 23, 27, 2, | 10753 9, 2, 22, 27, 2, 23, 27, 2, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11688 }; | 10882 }; |
11689 | 10883 |
11690 static const int json_start = 1; | 10884 static const int json_start = 1; |
11691 | 10885 |
11692 static const int json_en_number_machine = 10; | 10886 static const int json_en_number_machine = 10; |
11693 static const int json_en_string_machine = 19; | 10887 static const int json_en_string_machine = 19; |
11694 static const int json_en_value_machine = 27; | 10888 static const int json_en_value_machine = 27; |
11695 static const int json_en_main = 1; | 10889 static const int json_en_main = 1; |
11696 | 10890 |
11697 | 10891 |
11698 #line 1247 "upb/json/parser.rl" | 10892 #line 1221 "upb/json/parser.rl" |
11699 | 10893 |
11700 size_t parse(void *closure, const void *hd, const char *buf, size_t size, | 10894 size_t parse(void *closure, const void *hd, const char *buf, size_t size, |
11701 const upb_bufhandle *handle) { | 10895 const upb_bufhandle *handle) { |
11702 upb_json_parser *parser = closure; | 10896 upb_json_parser *parser = closure; |
11703 | 10897 |
11704 /* Variables used by Ragel's generated code. */ | 10898 /* Variables used by Ragel's generated code. */ |
11705 int cs = parser->current_state; | 10899 int cs = parser->current_state; |
11706 int *stack = parser->parser_stack; | 10900 int *stack = parser->parser_stack; |
11707 int top = parser->parser_top; | 10901 int top = parser->parser_top; |
11708 | 10902 |
11709 const char *p = buf; | 10903 const char *p = buf; |
11710 const char *pe = buf + size; | 10904 const char *pe = buf + size; |
11711 | 10905 |
11712 parser->handle = handle; | 10906 parser->handle = handle; |
11713 | 10907 |
11714 UPB_UNUSED(hd); | 10908 UPB_UNUSED(hd); |
11715 UPB_UNUSED(handle); | 10909 UPB_UNUSED(handle); |
11716 | 10910 |
11717 capture_resume(parser, buf); | 10911 capture_resume(parser, buf); |
11718 | 10912 |
11719 | 10913 |
11720 #line 1327 "upb/json/parser.c" | 10914 #line 1301 "upb/json/parser.c" |
11721 { | 10915 { |
11722 int _klen; | 10916 int _klen; |
11723 unsigned int _trans; | 10917 unsigned int _trans; |
11724 const char *_acts; | 10918 const char *_acts; |
11725 unsigned int _nacts; | 10919 unsigned int _nacts; |
11726 const char *_keys; | 10920 const char *_keys; |
11727 | 10921 |
11728 if ( p == pe ) | 10922 if ( p == pe ) |
11729 goto _test_eof; | 10923 goto _test_eof; |
11730 if ( cs == 0 ) | 10924 if ( cs == 0 ) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11785 if ( _json_trans_actions[_trans] == 0 ) | 10979 if ( _json_trans_actions[_trans] == 0 ) |
11786 goto _again; | 10980 goto _again; |
11787 | 10981 |
11788 _acts = _json_actions + _json_trans_actions[_trans]; | 10982 _acts = _json_actions + _json_trans_actions[_trans]; |
11789 _nacts = (unsigned int) *_acts++; | 10983 _nacts = (unsigned int) *_acts++; |
11790 while ( _nacts-- > 0 ) | 10984 while ( _nacts-- > 0 ) |
11791 { | 10985 { |
11792 switch ( *_acts++ ) | 10986 switch ( *_acts++ ) |
11793 { | 10987 { |
11794 case 0: | 10988 case 0: |
| 10989 #line 1133 "upb/json/parser.rl" |
| 10990 { p--; {cs = stack[--top]; goto _again;} } |
| 10991 break; |
| 10992 case 1: |
| 10993 #line 1134 "upb/json/parser.rl" |
| 10994 { p--; {stack[top++] = cs; cs = 10; goto _again;} } |
| 10995 break; |
| 10996 case 2: |
| 10997 #line 1138 "upb/json/parser.rl" |
| 10998 { start_text(parser, p); } |
| 10999 break; |
| 11000 case 3: |
| 11001 #line 1139 "upb/json/parser.rl" |
| 11002 { CHECK_RETURN_TOP(end_text(parser, p)); } |
| 11003 break; |
| 11004 case 4: |
| 11005 #line 1145 "upb/json/parser.rl" |
| 11006 { start_hex(parser); } |
| 11007 break; |
| 11008 case 5: |
| 11009 #line 1146 "upb/json/parser.rl" |
| 11010 { hexdigit(parser, p); } |
| 11011 break; |
| 11012 case 6: |
| 11013 #line 1147 "upb/json/parser.rl" |
| 11014 { CHECK_RETURN_TOP(end_hex(parser)); } |
| 11015 break; |
| 11016 case 7: |
| 11017 #line 1153 "upb/json/parser.rl" |
| 11018 { CHECK_RETURN_TOP(escape(parser, p)); } |
| 11019 break; |
| 11020 case 8: |
11795 #line 1159 "upb/json/parser.rl" | 11021 #line 1159 "upb/json/parser.rl" |
11796 { p--; {cs = stack[--top]; goto _again;} } | 11022 { p--; {cs = stack[--top]; goto _again;} } |
11797 break; | 11023 break; |
11798 case 1: | |
11799 #line 1160 "upb/json/parser.rl" | |
11800 { p--; {stack[top++] = cs; cs = 10; goto _again;} } | |
11801 break; | |
11802 case 2: | |
11803 #line 1164 "upb/json/parser.rl" | |
11804 { start_text(parser, p); } | |
11805 break; | |
11806 case 3: | |
11807 #line 1165 "upb/json/parser.rl" | |
11808 { CHECK_RETURN_TOP(end_text(parser, p)); } | |
11809 break; | |
11810 case 4: | |
11811 #line 1171 "upb/json/parser.rl" | |
11812 { start_hex(parser); } | |
11813 break; | |
11814 case 5: | |
11815 #line 1172 "upb/json/parser.rl" | |
11816 { hexdigit(parser, p); } | |
11817 break; | |
11818 case 6: | |
11819 #line 1173 "upb/json/parser.rl" | |
11820 { CHECK_RETURN_TOP(end_hex(parser)); } | |
11821 break; | |
11822 case 7: | |
11823 #line 1179 "upb/json/parser.rl" | |
11824 { CHECK_RETURN_TOP(escape(parser, p)); } | |
11825 break; | |
11826 case 8: | |
11827 #line 1185 "upb/json/parser.rl" | |
11828 { p--; {cs = stack[--top]; goto _again;} } | |
11829 break; | |
11830 case 9: | 11024 case 9: |
11831 #line 1188 "upb/json/parser.rl" | 11025 #line 1162 "upb/json/parser.rl" |
11832 { {stack[top++] = cs; cs = 19; goto _again;} } | 11026 { {stack[top++] = cs; cs = 19; goto _again;} } |
11833 break; | 11027 break; |
11834 case 10: | 11028 case 10: |
11835 #line 1190 "upb/json/parser.rl" | 11029 #line 1164 "upb/json/parser.rl" |
11836 { p--; {stack[top++] = cs; cs = 27; goto _again;} } | 11030 { p--; {stack[top++] = cs; cs = 27; goto _again;} } |
11837 break; | 11031 break; |
11838 case 11: | 11032 case 11: |
11839 #line 1195 "upb/json/parser.rl" | 11033 #line 1169 "upb/json/parser.rl" |
11840 { start_member(parser); } | 11034 { start_member(parser); } |
11841 break; | 11035 break; |
11842 case 12: | 11036 case 12: |
11843 #line 1196 "upb/json/parser.rl" | 11037 #line 1170 "upb/json/parser.rl" |
11844 { CHECK_RETURN_TOP(end_membername(parser)); } | 11038 { CHECK_RETURN_TOP(end_membername(parser)); } |
11845 break; | 11039 break; |
11846 case 13: | 11040 case 13: |
11847 #line 1199 "upb/json/parser.rl" | 11041 #line 1173 "upb/json/parser.rl" |
11848 { end_member(parser); } | 11042 { end_member(parser); } |
11849 break; | 11043 break; |
11850 case 14: | 11044 case 14: |
11851 #line 1205 "upb/json/parser.rl" | 11045 #line 1179 "upb/json/parser.rl" |
11852 { start_object(parser); } | 11046 { start_object(parser); } |
11853 break; | 11047 break; |
11854 case 15: | 11048 case 15: |
11855 #line 1208 "upb/json/parser.rl" | 11049 #line 1182 "upb/json/parser.rl" |
11856 { end_object(parser); } | 11050 { end_object(parser); } |
11857 break; | 11051 break; |
11858 case 16: | 11052 case 16: |
11859 #line 1214 "upb/json/parser.rl" | 11053 #line 1188 "upb/json/parser.rl" |
11860 { CHECK_RETURN_TOP(start_array(parser)); } | 11054 { CHECK_RETURN_TOP(start_array(parser)); } |
11861 break; | 11055 break; |
11862 case 17: | 11056 case 17: |
11863 #line 1218 "upb/json/parser.rl" | 11057 #line 1192 "upb/json/parser.rl" |
11864 { end_array(parser); } | 11058 { end_array(parser); } |
11865 break; | 11059 break; |
11866 case 18: | 11060 case 18: |
11867 #line 1223 "upb/json/parser.rl" | 11061 #line 1197 "upb/json/parser.rl" |
11868 { start_number(parser, p); } | 11062 { start_number(parser, p); } |
11869 break; | 11063 break; |
11870 case 19: | 11064 case 19: |
11871 #line 1224 "upb/json/parser.rl" | 11065 #line 1198 "upb/json/parser.rl" |
11872 { CHECK_RETURN_TOP(end_number(parser, p)); } | 11066 { CHECK_RETURN_TOP(end_number(parser, p)); } |
11873 break; | 11067 break; |
11874 case 20: | 11068 case 20: |
11875 #line 1226 "upb/json/parser.rl" | 11069 #line 1200 "upb/json/parser.rl" |
11876 { CHECK_RETURN_TOP(start_stringval(parser)); } | 11070 { CHECK_RETURN_TOP(start_stringval(parser)); } |
11877 break; | 11071 break; |
11878 case 21: | 11072 case 21: |
11879 #line 1227 "upb/json/parser.rl" | 11073 #line 1201 "upb/json/parser.rl" |
11880 { CHECK_RETURN_TOP(end_stringval(parser)); } | 11074 { CHECK_RETURN_TOP(end_stringval(parser)); } |
11881 break; | 11075 break; |
11882 case 22: | 11076 case 22: |
11883 #line 1229 "upb/json/parser.rl" | 11077 #line 1203 "upb/json/parser.rl" |
11884 { CHECK_RETURN_TOP(parser_putbool(parser, true)); } | 11078 { CHECK_RETURN_TOP(parser_putbool(parser, true)); } |
11885 break; | 11079 break; |
11886 case 23: | 11080 case 23: |
11887 #line 1231 "upb/json/parser.rl" | 11081 #line 1205 "upb/json/parser.rl" |
11888 { CHECK_RETURN_TOP(parser_putbool(parser, false)); } | 11082 { CHECK_RETURN_TOP(parser_putbool(parser, false)); } |
11889 break; | 11083 break; |
11890 case 24: | 11084 case 24: |
11891 #line 1233 "upb/json/parser.rl" | 11085 #line 1207 "upb/json/parser.rl" |
11892 { /* null value */ } | 11086 { /* null value */ } |
11893 break; | 11087 break; |
11894 case 25: | 11088 case 25: |
11895 #line 1235 "upb/json/parser.rl" | 11089 #line 1209 "upb/json/parser.rl" |
11896 { CHECK_RETURN_TOP(start_subobject(parser)); } | 11090 { CHECK_RETURN_TOP(start_subobject(parser)); } |
11897 break; | 11091 break; |
11898 case 26: | 11092 case 26: |
11899 #line 1236 "upb/json/parser.rl" | 11093 #line 1210 "upb/json/parser.rl" |
11900 { end_subobject(parser); } | 11094 { end_subobject(parser); } |
11901 break; | 11095 break; |
11902 case 27: | 11096 case 27: |
11903 #line 1241 "upb/json/parser.rl" | 11097 #line 1215 "upb/json/parser.rl" |
11904 { p--; {cs = stack[--top]; goto _again;} } | 11098 { p--; {cs = stack[--top]; goto _again;} } |
11905 break; | 11099 break; |
11906 #line 1513 "upb/json/parser.c" | 11100 #line 1487 "upb/json/parser.c" |
11907 } | 11101 } |
11908 } | 11102 } |
11909 | 11103 |
11910 _again: | 11104 _again: |
11911 if ( cs == 0 ) | 11105 if ( cs == 0 ) |
11912 goto _out; | 11106 goto _out; |
11913 if ( ++p != pe ) | 11107 if ( ++p != pe ) |
11914 goto _resume; | 11108 goto _resume; |
11915 _test_eof: {} | 11109 _test_eof: {} |
11916 _out: {} | 11110 _out: {} |
11917 } | 11111 } |
11918 | 11112 |
11919 #line 1268 "upb/json/parser.rl" | 11113 #line 1242 "upb/json/parser.rl" |
11920 | 11114 |
11921 if (p != pe) { | 11115 if (p != pe) { |
11922 upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p); | 11116 upb_status_seterrf(&parser->status, "Parse error at %s\n", p); |
11923 upb_env_reporterror(parser->env, &parser->status); | 11117 upb_env_reporterror(parser->env, &parser->status); |
11924 } else { | 11118 } else { |
11925 capture_suspend(parser, &p); | 11119 capture_suspend(parser, &p); |
11926 } | 11120 } |
11927 | 11121 |
11928 error: | 11122 error: |
11929 /* Save parsing state back to parser. */ | 11123 /* Save parsing state back to parser. */ |
11930 parser->current_state = cs; | 11124 parser->current_state = cs; |
11931 parser->parser_top = top; | 11125 parser->parser_top = top; |
11932 | 11126 |
(...skipping 17 matching lines...) Expand all Loading... |
11950 int cs; | 11144 int cs; |
11951 int top; | 11145 int top; |
11952 | 11146 |
11953 p->top = p->stack; | 11147 p->top = p->stack; |
11954 p->top->f = NULL; | 11148 p->top->f = NULL; |
11955 p->top->is_map = false; | 11149 p->top->is_map = false; |
11956 p->top->is_mapentry = false; | 11150 p->top->is_mapentry = false; |
11957 | 11151 |
11958 /* Emit Ragel initialization of the parser. */ | 11152 /* Emit Ragel initialization of the parser. */ |
11959 | 11153 |
11960 #line 1567 "upb/json/parser.c" | 11154 #line 1541 "upb/json/parser.c" |
11961 { | 11155 { |
11962 cs = json_start; | 11156 cs = json_start; |
11963 top = 0; | 11157 top = 0; |
11964 } | 11158 } |
11965 | 11159 |
11966 #line 1308 "upb/json/parser.rl" | 11160 #line 1282 "upb/json/parser.rl" |
11967 p->current_state = cs; | 11161 p->current_state = cs; |
11968 p->parser_top = top; | 11162 p->parser_top = top; |
11969 accumulate_clear(p); | 11163 accumulate_clear(p); |
11970 p->multipart_state = MULTIPART_INACTIVE; | 11164 p->multipart_state = MULTIPART_INACTIVE; |
11971 p->capture = NULL; | 11165 p->capture = NULL; |
11972 p->accumulated = NULL; | 11166 p->accumulated = NULL; |
11973 upb_status_clear(&p->status); | 11167 upb_status_clear(&p->status); |
11974 } | 11168 } |
11975 | 11169 |
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 } | |
12048 | 11170 |
12049 /* Public API *****************************************************************/ | 11171 /* Public API *****************************************************************/ |
12050 | 11172 |
12051 upb_json_parser *upb_json_parser_create(upb_env *env, | 11173 upb_json_parser *upb_json_parser_create(upb_env *env, upb_sink *output) { |
12052 const upb_json_parsermethod *method, | |
12053 upb_sink *output) { | |
12054 #ifndef NDEBUG | 11174 #ifndef NDEBUG |
12055 const size_t size_before = upb_env_bytesallocated(env); | 11175 const size_t size_before = upb_env_bytesallocated(env); |
12056 #endif | 11176 #endif |
12057 upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser)); | 11177 upb_json_parser *p = upb_env_malloc(env, sizeof(upb_json_parser)); |
12058 if (!p) return false; | 11178 if (!p) return false; |
12059 | 11179 |
12060 p->env = env; | 11180 p->env = env; |
12061 p->method = method; | |
12062 p->limit = p->stack + UPB_JSON_MAX_DEPTH; | 11181 p->limit = p->stack + UPB_JSON_MAX_DEPTH; |
12063 p->accumulate_buf = NULL; | 11182 p->accumulate_buf = NULL; |
12064 p->accumulate_buf_size = 0; | 11183 p->accumulate_buf_size = 0; |
12065 upb_bytessink_reset(&p->input_, &method->input_handler_, p); | 11184 upb_byteshandler_init(&p->input_handler_); |
| 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); |
12066 | 11188 |
12067 json_parser_reset(p); | 11189 json_parser_reset(p); |
12068 upb_sink_reset(&p->top->sink, output->handlers, output->closure); | 11190 upb_sink_reset(&p->top->sink, output->handlers, output->closure); |
12069 p->top->m = upb_handlers_msgdef(output->handlers); | 11191 p->top->m = upb_handlers_msgdef(output->handlers); |
12070 set_name_table(p, p->top); | |
12071 | 11192 |
12072 /* If this fails, uncomment and increase the value in parser.h. */ | 11193 /* If this fails, uncomment and increase the value in parser.h. */ |
12073 /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ | 11194 /* fprintf(stderr, "%zd\n", upb_env_bytesallocated(env) - size_before); */ |
12074 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(env) - size_before <= | 11195 assert(upb_env_bytesallocated(env) - size_before <= UPB_JSON_PARSER_SIZE); |
12075 UPB_JSON_PARSER_SIZE); | |
12076 return p; | 11196 return p; |
12077 } | 11197 } |
12078 | 11198 |
12079 upb_bytessink *upb_json_parser_input(upb_json_parser *p) { | 11199 upb_bytessink *upb_json_parser_input(upb_json_parser *p) { |
12080 return &p->input_; | 11200 return &p->input_; |
12081 } | 11201 } |
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 } | |
12108 /* | 11202 /* |
12109 ** This currently uses snprintf() to format primitives, and could be optimized | 11203 ** This currently uses snprintf() to format primitives, and could be optimized |
12110 ** further. | 11204 ** further. |
12111 */ | 11205 */ |
12112 | 11206 |
12113 | 11207 |
| 11208 #include <stdlib.h> |
| 11209 #include <stdio.h> |
12114 #include <string.h> | 11210 #include <string.h> |
12115 #include <stdint.h> | 11211 #include <stdint.h> |
12116 | 11212 |
12117 struct upb_json_printer { | 11213 struct upb_json_printer { |
12118 upb_sink input_; | 11214 upb_sink input_; |
12119 /* BytesSink closure. */ | 11215 /* BytesSink closure. */ |
12120 void *subc_; | 11216 void *subc_; |
12121 upb_bytessink *output_; | 11217 upb_bytessink *output_; |
12122 | 11218 |
12123 /* We track the depth so that we know when to emit startstr/endstr on the | 11219 /* We track the depth so that we know when to emit startstr/endstr on the |
12124 * output. */ | 11220 * output. */ |
12125 int depth_; | 11221 int depth_; |
12126 | 11222 |
12127 /* Have we emitted the first element? This state is necessary to emit commas | 11223 /* Have we emitted the first element? This state is necessary to emit commas |
12128 * without leaving a trailing comma in arrays/maps. We keep this state per | 11224 * without leaving a trailing comma in arrays/maps. We keep this state per |
12129 * frame depth. | 11225 * frame depth. |
12130 * | 11226 * |
12131 * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages. | 11227 * Why max_depth * 2? UPB_MAX_HANDLER_DEPTH counts depth as nested messages. |
12132 * We count frames (contexts in which we separate elements by commas) as both | 11228 * We count frames (contexts in which we separate elements by commas) as both |
12133 * repeated fields and messages (maps), and the worst case is a | 11229 * repeated fields and messages (maps), and the worst case is a |
12134 * message->repeated field->submessage->repeated field->... nesting. */ | 11230 * message->repeated field->submessage->repeated field->... nesting. */ |
12135 bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; | 11231 bool first_elem_[UPB_MAX_HANDLER_DEPTH * 2]; |
12136 }; | 11232 }; |
12137 | 11233 |
12138 /* StringPiece; a pointer plus a length. */ | 11234 /* StringPiece; a pointer plus a length. */ |
12139 typedef struct { | 11235 typedef struct { |
12140 char *ptr; | 11236 const char *ptr; |
12141 size_t len; | 11237 size_t len; |
12142 } strpc; | 11238 } strpc; |
12143 | 11239 |
12144 void freestrpc(void *ptr) { | 11240 strpc *newstrpc(upb_handlers *h, const upb_fielddef *f) { |
12145 strpc *pc = ptr; | 11241 strpc *ret = malloc(sizeof(*ret)); |
12146 upb_gfree(pc->ptr); | 11242 ret->ptr = upb_fielddef_name(f); |
12147 upb_gfree(pc); | 11243 ret->len = strlen(ret->ptr); |
12148 } | 11244 upb_handlers_addcleanup(h, ret, free); |
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); | |
12168 return ret; | 11245 return ret; |
12169 } | 11246 } |
12170 | 11247 |
12171 /* ------------ JSON string printing: values, maps, arrays ------------------ */ | 11248 /* ------------ JSON string printing: values, maps, arrays ------------------ */ |
12172 | 11249 |
12173 static void print_data( | 11250 static void print_data( |
12174 upb_json_printer *p, const char *buf, unsigned int len) { | 11251 upb_json_printer *p, const char *buf, unsigned int len) { |
12175 /* TODO: Will need to change if we support pushback from the sink. */ | 11252 /* TODO: Will need to change if we support pushback from the sink. */ |
12176 size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); | 11253 size_t n = upb_bytessink_putbuf(p->output_, p->subc_, buf, len, NULL); |
12177 UPB_ASSERT(n == len); | 11254 UPB_ASSERT_VAR(n, n == len); |
12178 } | 11255 } |
12179 | 11256 |
12180 static void print_comma(upb_json_printer *p) { | 11257 static void print_comma(upb_json_printer *p) { |
12181 if (!p->first_elem_[p->depth_]) { | 11258 if (!p->first_elem_[p->depth_]) { |
12182 print_data(p, ",", 1); | 11259 print_data(p, ",", 1); |
12183 } | 11260 } |
12184 p->first_elem_[p->depth_] = false; | 11261 p->first_elem_[p->depth_] = false; |
12185 } | 11262 } |
12186 | 11263 |
12187 /* Helpers that print properly formatted elements to the JSON output stream. */ | 11264 /* Helpers that print properly formatted elements to the JSON output stream. */ |
12188 | 11265 |
12189 /* Used for escaping control chars in strings. */ | 11266 /* Used for escaping control chars in strings. */ |
12190 static const char kControlCharLimit = 0x20; | 11267 static const char kControlCharLimit = 0x20; |
12191 | 11268 |
12192 UPB_INLINE bool is_json_escaped(char c) { | 11269 UPB_INLINE bool is_json_escaped(char c) { |
12193 /* See RFC 4627. */ | 11270 /* See RFC 4627. */ |
12194 unsigned char uc = (unsigned char)c; | 11271 unsigned char uc = (unsigned char)c; |
12195 return uc < kControlCharLimit || uc == '"' || uc == '\\'; | 11272 return uc < kControlCharLimit || uc == '"' || uc == '\\'; |
12196 } | 11273 } |
12197 | 11274 |
12198 UPB_INLINE const char* json_nice_escape(char c) { | 11275 UPB_INLINE char* json_nice_escape(char c) { |
12199 switch (c) { | 11276 switch (c) { |
12200 case '"': return "\\\""; | 11277 case '"': return "\\\""; |
12201 case '\\': return "\\\\"; | 11278 case '\\': return "\\\\"; |
12202 case '\b': return "\\b"; | 11279 case '\b': return "\\b"; |
12203 case '\f': return "\\f"; | 11280 case '\f': return "\\f"; |
12204 case '\n': return "\\n"; | 11281 case '\n': return "\\n"; |
12205 case '\r': return "\\r"; | 11282 case '\r': return "\\r"; |
12206 case '\t': return "\\t"; | 11283 case '\t': return "\\t"; |
12207 default: return NULL; | 11284 default: return NULL; |
12208 } | 11285 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12517 const unsigned char *from = (const unsigned char*)str; | 11594 const unsigned char *from = (const unsigned char*)str; |
12518 char *to = data; | 11595 char *to = data; |
12519 size_t remaining = len; | 11596 size_t remaining = len; |
12520 size_t bytes; | 11597 size_t bytes; |
12521 | 11598 |
12522 UPB_UNUSED(handler_data); | 11599 UPB_UNUSED(handler_data); |
12523 UPB_UNUSED(handle); | 11600 UPB_UNUSED(handle); |
12524 | 11601 |
12525 while (remaining > 2) { | 11602 while (remaining > 2) { |
12526 /* TODO(haberman): handle encoded lengths > sizeof(data) */ | 11603 /* TODO(haberman): handle encoded lengths > sizeof(data) */ |
12527 UPB_ASSERT((limit - to) >= 4); | 11604 UPB_ASSERT_VAR(limit, (limit - to) >= 4); |
12528 | 11605 |
12529 to[0] = base64[from[0] >> 2]; | 11606 to[0] = base64[from[0] >> 2]; |
12530 to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)]; | 11607 to[1] = base64[((from[0] & 0x3) << 4) | (from[1] >> 4)]; |
12531 to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)]; | 11608 to[2] = base64[((from[1] & 0xf) << 2) | (from[2] >> 6)]; |
12532 to[3] = base64[from[2] & 0x3f]; | 11609 to[3] = base64[from[2] & 0x3f]; |
12533 | 11610 |
12534 remaining -= 3; | 11611 remaining -= 3; |
12535 to += 4; | 11612 to += 4; |
12536 from += 3; | 11613 from += 3; |
12537 } | 11614 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12661 const char *str, size_t len, | 11738 const char *str, size_t len, |
12662 const upb_bufhandle *handle) { | 11739 const upb_bufhandle *handle) { |
12663 upb_json_printer *p = closure; | 11740 upb_json_printer *p = closure; |
12664 CHK(putbytes(closure, handler_data, str, len, handle)); | 11741 CHK(putbytes(closure, handler_data, str, len, handle)); |
12665 print_data(p, ":", 1); | 11742 print_data(p, ":", 1); |
12666 return len; | 11743 return len; |
12667 } | 11744 } |
12668 | 11745 |
12669 static void set_enum_hd(upb_handlers *h, | 11746 static void set_enum_hd(upb_handlers *h, |
12670 const upb_fielddef *f, | 11747 const upb_fielddef *f, |
12671 bool preserve_fieldnames, | |
12672 upb_handlerattr *attr) { | 11748 upb_handlerattr *attr) { |
12673 EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData)); | 11749 EnumHandlerData *hd = malloc(sizeof(EnumHandlerData)); |
12674 hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f); | 11750 hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f); |
12675 hd->keyname = newstrpc(h, f, preserve_fieldnames); | 11751 hd->keyname = newstrpc(h, f); |
12676 upb_handlers_addcleanup(h, hd, upb_gfree); | 11752 upb_handlers_addcleanup(h, hd, free); |
12677 upb_handlerattr_sethandlerdata(attr, hd); | 11753 upb_handlerattr_sethandlerdata(attr, hd); |
12678 } | 11754 } |
12679 | 11755 |
12680 /* Set up handlers for a mapentry submessage (i.e., an individual key/value pair | 11756 /* Set up handlers for a mapentry submessage (i.e., an individual key/value pair |
12681 * in a map). | 11757 * in a map). |
12682 * | 11758 * |
12683 * TODO: Handle missing key, missing value, out-of-order key/value, or repeated | 11759 * TODO: Handle missing key, missing value, out-of-order key/value, or repeated |
12684 * key or value cases properly. The right way to do this is to allocate a | 11760 * key or value cases properly. The right way to do this is to allocate a |
12685 * temporary structure at the start of a mapentry submessage, store key and | 11761 * temporary structure at the start of a mapentry submessage, store key and |
12686 * value data in it as key and value handlers are called, and then print the | 11762 * value data in it as key and value handlers are called, and then print the |
12687 * key/value pair once at the end of the submessage. If we don't do this, we | 11763 * key/value pair once at the end of the submessage. If we don't do this, we |
12688 * should at least detect the case and throw an error. However, so far all of | 11764 * should at least detect the case and throw an error. However, so far all of |
12689 * our sources that emit mapentry messages do so canonically (with one key | 11765 * our sources that emit mapentry messages do so canonically (with one key |
12690 * field, and then one value field), so this is not a pressing concern at the | 11766 * field, and then one value field), so this is not a pressing concern at the |
12691 * moment. */ | 11767 * moment. */ |
12692 void printer_sethandlers_mapentry(const void *closure, bool preserve_fieldnames, | 11768 void printer_sethandlers_mapentry(const void *closure, upb_handlers *h) { |
12693 upb_handlers *h) { | |
12694 const upb_msgdef *md = upb_handlers_msgdef(h); | 11769 const upb_msgdef *md = upb_handlers_msgdef(h); |
12695 | 11770 |
12696 /* A mapentry message is printed simply as '"key": value'. Rather than | 11771 /* A mapentry message is printed simply as '"key": value'. Rather than |
12697 * special-case key and value for every type below, we just handle both | 11772 * special-case key and value for every type below, we just handle both |
12698 * fields explicitly here. */ | 11773 * fields explicitly here. */ |
12699 const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY); | 11774 const upb_fielddef* key_field = upb_msgdef_itof(md, UPB_MAPENTRY_KEY); |
12700 const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE); | 11775 const upb_fielddef* value_field = upb_msgdef_itof(md, UPB_MAPENTRY_VALUE); |
12701 | 11776 |
12702 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; | 11777 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; |
12703 | 11778 |
(...skipping 17 matching lines...) Expand all Loading... |
12721 break; | 11796 break; |
12722 case UPB_TYPE_STRING: | 11797 case UPB_TYPE_STRING: |
12723 upb_handlers_setstartstr(h, key_field, mapkeyval_startstr, &empty_attr); | 11798 upb_handlers_setstartstr(h, key_field, mapkeyval_startstr, &empty_attr); |
12724 upb_handlers_setstring(h, key_field, mapkey_str, &empty_attr); | 11799 upb_handlers_setstring(h, key_field, mapkey_str, &empty_attr); |
12725 upb_handlers_setendstr(h, key_field, mapkey_endstr, &empty_attr); | 11800 upb_handlers_setendstr(h, key_field, mapkey_endstr, &empty_attr); |
12726 break; | 11801 break; |
12727 case UPB_TYPE_BYTES: | 11802 case UPB_TYPE_BYTES: |
12728 upb_handlers_setstring(h, key_field, mapkey_bytes, &empty_attr); | 11803 upb_handlers_setstring(h, key_field, mapkey_bytes, &empty_attr); |
12729 break; | 11804 break; |
12730 default: | 11805 default: |
12731 UPB_ASSERT(false); | 11806 assert(false); |
12732 break; | 11807 break; |
12733 } | 11808 } |
12734 | 11809 |
12735 switch (upb_fielddef_type(value_field)) { | 11810 switch (upb_fielddef_type(value_field)) { |
12736 case UPB_TYPE_INT32: | 11811 case UPB_TYPE_INT32: |
12737 upb_handlers_setint32(h, value_field, putint32_t, &empty_attr); | 11812 upb_handlers_setint32(h, value_field, putint32_t, &empty_attr); |
12738 break; | 11813 break; |
12739 case UPB_TYPE_INT64: | 11814 case UPB_TYPE_INT64: |
12740 upb_handlers_setint64(h, value_field, putint64_t, &empty_attr); | 11815 upb_handlers_setint64(h, value_field, putint64_t, &empty_attr); |
12741 break; | 11816 break; |
(...skipping 15 matching lines...) Expand all Loading... |
12757 case UPB_TYPE_STRING: | 11832 case UPB_TYPE_STRING: |
12758 upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr); | 11833 upb_handlers_setstartstr(h, value_field, mapkeyval_startstr, &empty_attr); |
12759 upb_handlers_setstring(h, value_field, putstr, &empty_attr); | 11834 upb_handlers_setstring(h, value_field, putstr, &empty_attr); |
12760 upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr); | 11835 upb_handlers_setendstr(h, value_field, mapvalue_endstr, &empty_attr); |
12761 break; | 11836 break; |
12762 case UPB_TYPE_BYTES: | 11837 case UPB_TYPE_BYTES: |
12763 upb_handlers_setstring(h, value_field, putbytes, &empty_attr); | 11838 upb_handlers_setstring(h, value_field, putbytes, &empty_attr); |
12764 break; | 11839 break; |
12765 case UPB_TYPE_ENUM: { | 11840 case UPB_TYPE_ENUM: { |
12766 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; | 11841 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; |
12767 set_enum_hd(h, value_field, preserve_fieldnames, &enum_attr); | 11842 set_enum_hd(h, value_field, &enum_attr); |
12768 upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr); | 11843 upb_handlers_setint32(h, value_field, mapvalue_enum, &enum_attr); |
12769 upb_handlerattr_uninit(&enum_attr); | 11844 upb_handlerattr_uninit(&enum_attr); |
12770 break; | 11845 break; |
12771 } | 11846 } |
12772 case UPB_TYPE_MESSAGE: | 11847 case UPB_TYPE_MESSAGE: |
12773 /* No handler necessary -- the submsg handlers will print the message | 11848 /* No handler necessary -- the submsg handlers will print the message |
12774 * as appropriate. */ | 11849 * as appropriate. */ |
12775 break; | 11850 break; |
12776 } | 11851 } |
12777 | 11852 |
12778 upb_handlerattr_uninit(&empty_attr); | 11853 upb_handlerattr_uninit(&empty_attr); |
12779 } | 11854 } |
12780 | 11855 |
12781 void printer_sethandlers(const void *closure, upb_handlers *h) { | 11856 void printer_sethandlers(const void *closure, upb_handlers *h) { |
12782 const upb_msgdef *md = upb_handlers_msgdef(h); | 11857 const upb_msgdef *md = upb_handlers_msgdef(h); |
12783 bool is_mapentry = upb_msgdef_mapentry(md); | 11858 bool is_mapentry = upb_msgdef_mapentry(md); |
12784 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; | 11859 upb_handlerattr empty_attr = UPB_HANDLERATTR_INITIALIZER; |
12785 upb_msg_field_iter i; | 11860 upb_msg_field_iter i; |
12786 const bool *preserve_fieldnames_ptr = closure; | 11861 |
12787 const bool preserve_fieldnames = *preserve_fieldnames_ptr; | 11862 UPB_UNUSED(closure); |
12788 | 11863 |
12789 if (is_mapentry) { | 11864 if (is_mapentry) { |
12790 /* mapentry messages are sufficiently different that we handle them | 11865 /* mapentry messages are sufficiently different that we handle them |
12791 * separately. */ | 11866 * separately. */ |
12792 printer_sethandlers_mapentry(closure, preserve_fieldnames, h); | 11867 printer_sethandlers_mapentry(closure, h); |
12793 return; | 11868 return; |
12794 } | 11869 } |
12795 | 11870 |
12796 upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); | 11871 upb_handlers_setstartmsg(h, printer_startmsg, &empty_attr); |
12797 upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); | 11872 upb_handlers_setendmsg(h, printer_endmsg, &empty_attr); |
12798 | 11873 |
12799 #define TYPE(type, name, ctype) \ | 11874 #define TYPE(type, name, ctype) \ |
12800 case type: \ | 11875 case type: \ |
12801 if (upb_fielddef_isseq(f)) { \ | 11876 if (upb_fielddef_isseq(f)) { \ |
12802 upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \ | 11877 upb_handlers_set##name(h, f, repeated_##ctype, &empty_attr); \ |
12803 } else { \ | 11878 } else { \ |
12804 upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \ | 11879 upb_handlers_set##name(h, f, scalar_##ctype, &name_attr); \ |
12805 } \ | 11880 } \ |
12806 break; | 11881 break; |
12807 | 11882 |
12808 upb_msg_field_begin(&i, md); | 11883 upb_msg_field_begin(&i, md); |
12809 for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { | 11884 for(; !upb_msg_field_done(&i); upb_msg_field_next(&i)) { |
12810 const upb_fielddef *f = upb_msg_iter_field(&i); | 11885 const upb_fielddef *f = upb_msg_iter_field(&i); |
12811 | 11886 |
12812 upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER; | 11887 upb_handlerattr name_attr = UPB_HANDLERATTR_INITIALIZER; |
12813 upb_handlerattr_sethandlerdata(&name_attr, | 11888 upb_handlerattr_sethandlerdata(&name_attr, newstrpc(h, f)); |
12814 newstrpc(h, f, preserve_fieldnames)); | |
12815 | 11889 |
12816 if (upb_fielddef_ismap(f)) { | 11890 if (upb_fielddef_ismap(f)) { |
12817 upb_handlers_setstartseq(h, f, startmap, &name_attr); | 11891 upb_handlers_setstartseq(h, f, startmap, &name_attr); |
12818 upb_handlers_setendseq(h, f, endmap, &name_attr); | 11892 upb_handlers_setendseq(h, f, endmap, &name_attr); |
12819 } else if (upb_fielddef_isseq(f)) { | 11893 } else if (upb_fielddef_isseq(f)) { |
12820 upb_handlers_setstartseq(h, f, startseq, &name_attr); | 11894 upb_handlers_setstartseq(h, f, startseq, &name_attr); |
12821 upb_handlers_setendseq(h, f, endseq, &empty_attr); | 11895 upb_handlers_setendseq(h, f, endseq, &empty_attr); |
12822 } | 11896 } |
12823 | 11897 |
12824 switch (upb_fielddef_type(f)) { | 11898 switch (upb_fielddef_type(f)) { |
12825 TYPE(UPB_TYPE_FLOAT, float, float); | 11899 TYPE(UPB_TYPE_FLOAT, float, float); |
12826 TYPE(UPB_TYPE_DOUBLE, double, double); | 11900 TYPE(UPB_TYPE_DOUBLE, double, double); |
12827 TYPE(UPB_TYPE_BOOL, bool, bool); | 11901 TYPE(UPB_TYPE_BOOL, bool, bool); |
12828 TYPE(UPB_TYPE_INT32, int32, int32_t); | 11902 TYPE(UPB_TYPE_INT32, int32, int32_t); |
12829 TYPE(UPB_TYPE_UINT32, uint32, uint32_t); | 11903 TYPE(UPB_TYPE_UINT32, uint32, uint32_t); |
12830 TYPE(UPB_TYPE_INT64, int64, int64_t); | 11904 TYPE(UPB_TYPE_INT64, int64, int64_t); |
12831 TYPE(UPB_TYPE_UINT64, uint64, uint64_t); | 11905 TYPE(UPB_TYPE_UINT64, uint64, uint64_t); |
12832 case UPB_TYPE_ENUM: { | 11906 case UPB_TYPE_ENUM: { |
12833 /* For now, we always emit symbolic names for enums. We may want an | 11907 /* For now, we always emit symbolic names for enums. We may want an |
12834 * option later to control this behavior, but we will wait for a real | 11908 * option later to control this behavior, but we will wait for a real |
12835 * need first. */ | 11909 * need first. */ |
12836 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; | 11910 upb_handlerattr enum_attr = UPB_HANDLERATTR_INITIALIZER; |
12837 set_enum_hd(h, f, preserve_fieldnames, &enum_attr); | 11911 set_enum_hd(h, f, &enum_attr); |
12838 | 11912 |
12839 if (upb_fielddef_isseq(f)) { | 11913 if (upb_fielddef_isseq(f)) { |
12840 upb_handlers_setint32(h, f, repeated_enum, &enum_attr); | 11914 upb_handlers_setint32(h, f, repeated_enum, &enum_attr); |
12841 } else { | 11915 } else { |
12842 upb_handlers_setint32(h, f, scalar_enum, &enum_attr); | 11916 upb_handlers_setint32(h, f, scalar_enum, &enum_attr); |
12843 } | 11917 } |
12844 | 11918 |
12845 upb_handlerattr_uninit(&enum_attr); | 11919 upb_handlerattr_uninit(&enum_attr); |
12846 break; | 11920 break; |
12847 } | 11921 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12895 #endif | 11969 #endif |
12896 | 11970 |
12897 upb_json_printer *p = upb_env_malloc(e, sizeof(upb_json_printer)); | 11971 upb_json_printer *p = upb_env_malloc(e, sizeof(upb_json_printer)); |
12898 if (!p) return NULL; | 11972 if (!p) return NULL; |
12899 | 11973 |
12900 p->output_ = output; | 11974 p->output_ = output; |
12901 json_printer_reset(p); | 11975 json_printer_reset(p); |
12902 upb_sink_reset(&p->input_, h, p); | 11976 upb_sink_reset(&p->input_, h, p); |
12903 | 11977 |
12904 /* If this fails, increase the value in printer.h. */ | 11978 /* If this fails, increase the value in printer.h. */ |
12905 UPB_ASSERT_DEBUGVAR(upb_env_bytesallocated(e) - size_before <= | 11979 assert(upb_env_bytesallocated(e) - size_before <= UPB_JSON_PRINTER_SIZE); |
12906 UPB_JSON_PRINTER_SIZE); | |
12907 return p; | 11980 return p; |
12908 } | 11981 } |
12909 | 11982 |
12910 upb_sink *upb_json_printer_input(upb_json_printer *p) { | 11983 upb_sink *upb_json_printer_input(upb_json_printer *p) { |
12911 return &p->input_; | 11984 return &p->input_; |
12912 } | 11985 } |
12913 | 11986 |
12914 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, | 11987 const upb_handlers *upb_json_printer_newhandlers(const upb_msgdef *md, |
12915 bool preserve_fieldnames, | |
12916 const void *owner) { | 11988 const void *owner) { |
12917 return upb_handlers_newfrozen( | 11989 return upb_handlers_newfrozen(md, owner, printer_sethandlers, NULL); |
12918 md, owner, printer_sethandlers, &preserve_fieldnames); | |
12919 } | 11990 } |
OLD | NEW |