google-protobuf 4.31.1 → 4.32.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/google/protobuf_c/defs.c +304 -156
- data/ext/google/protobuf_c/extconf.rb +2 -8
- data/ext/google/protobuf_c/map.c +74 -37
- data/ext/google/protobuf_c/message.c +92 -56
- data/ext/google/protobuf_c/protobuf.c +1 -1
- data/ext/google/protobuf_c/protobuf.h +0 -2
- data/ext/google/protobuf_c/repeated_field.c +75 -38
- data/ext/google/protobuf_c/ruby-upb.c +13575 -14880
- data/ext/google/protobuf_c/ruby-upb.h +2051 -1805
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range.c +6 -6
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_neon.inc +1 -1
- data/ext/google/protobuf_c/third_party/utf8_range/utf8_range_sse.inc +1 -1
- data/lib/google/protobuf/api_pb.rb +1 -1
- data/lib/google/protobuf/descriptor_pb.rb +1 -1
- data/lib/google/tasks/ffi.rake +1 -1
- metadata +3 -4
- data/ext/google/protobuf_c/wrap_memcpy.c +0 -29
@@ -39,6 +39,33 @@
|
|
39
39
|
#define UPB_GNUC_MIN(x, y) 0
|
40
40
|
#endif
|
41
41
|
|
42
|
+
// Macros for checking for compiler attributes, defined here to avoid the
|
43
|
+
// problem described in
|
44
|
+
// https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html.
|
45
|
+
#ifdef __has_attribute
|
46
|
+
#define UPB_HAS_ATTRIBUTE(x) __has_attribute(x)
|
47
|
+
#else
|
48
|
+
#define UPB_HAS_ATTRIBUTE(x) 0
|
49
|
+
#endif
|
50
|
+
|
51
|
+
#ifdef __has_builtin
|
52
|
+
#define UPB_HAS_BUILTIN(x) __has_builtin(x)
|
53
|
+
#else
|
54
|
+
#define UPB_HAS_BUILTIN(x) 0
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#ifdef __has_extension
|
58
|
+
#define UPB_HAS_EXTENSION(x) __has_extension(x)
|
59
|
+
#else
|
60
|
+
#define UPB_HAS_EXTENSION(x) 0
|
61
|
+
#endif
|
62
|
+
|
63
|
+
#ifdef __has_feature
|
64
|
+
#define UPB_HAS_FEATURE(x) __has_feature(x)
|
65
|
+
#else
|
66
|
+
#define UPB_HAS_FEATURE(x) 0
|
67
|
+
#endif
|
68
|
+
|
42
69
|
#include <assert.h>
|
43
70
|
#include <setjmp.h>
|
44
71
|
#include <stdbool.h>
|
@@ -72,6 +99,8 @@ Error, UINTPTR_MAX is undefined
|
|
72
99
|
(((SIZE_MAX - offsetof(type, member[0])) / \
|
73
100
|
(offsetof(type, member[1]) - offsetof(type, member[0]))) < (size_t)count)
|
74
101
|
|
102
|
+
#define UPB_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
103
|
+
|
75
104
|
#define UPB_MAPTYPE_STRING 0
|
76
105
|
|
77
106
|
// UPB_EXPORT: always generate a public symbol.
|
@@ -111,12 +140,52 @@ Error, UINTPTR_MAX is undefined
|
|
111
140
|
#define UPBC_API
|
112
141
|
#endif
|
113
142
|
|
143
|
+
#if UPB_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
144
|
+
#define UPB_ASAN 1
|
145
|
+
#else
|
146
|
+
#define UPB_ASAN 0
|
147
|
+
#endif
|
148
|
+
|
149
|
+
#if UPB_HAS_FEATURE(hwaddress_sanitizer)
|
150
|
+
#define UPB_HWASAN 1
|
151
|
+
#define UPB_HWASAN_POISON_TAG 17
|
152
|
+
#define UPB_MALLOC_ALIGN 16
|
153
|
+
#else
|
154
|
+
#define UPB_HWASAN 0
|
114
155
|
#define UPB_MALLOC_ALIGN 8
|
156
|
+
#endif
|
157
|
+
|
158
|
+
#if UPB_HAS_FEATURE(thread_sanitizer) || defined(__SANITIZE_THREAD__)
|
159
|
+
#define UPB_TSAN 1
|
160
|
+
#else
|
161
|
+
#define UPB_TSAN 0
|
162
|
+
#endif
|
163
|
+
|
164
|
+
// An unfortunate concession to C++17 and MSVC, which don't support zero-sized
|
165
|
+
// structs.
|
166
|
+
#if UPB_ASAN || UPB_HWASAN || UPB_TSAN
|
167
|
+
#define UPB_XSAN_MEMBER upb_Xsan xsan;
|
168
|
+
#define UPB_XSAN(st) (&(st)->xsan)
|
169
|
+
#define UPB_XSAN_STRUCT_SIZE 1
|
170
|
+
#else
|
171
|
+
#define UPB_XSAN_MEMBER
|
172
|
+
#define UPB_XSAN(st) (NULL)
|
173
|
+
#define UPB_XSAN_STRUCT_SIZE 0
|
174
|
+
#endif
|
175
|
+
|
115
176
|
#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align))
|
116
177
|
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
|
117
178
|
#define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, UPB_MALLOC_ALIGN)
|
118
|
-
|
179
|
+
|
180
|
+
#if __STDC_VERSION__ >= 202311L || UPB_HAS_EXTENSION(cxx_alignof) || \
|
181
|
+
defined(__cplusplus)
|
182
|
+
#define UPB_ALIGN_OF(type) alignof(type)
|
183
|
+
#elif __STDC_VERSION__ >= 201112L || UPB_HAS_EXTENSION(c_alignof)
|
119
184
|
#define UPB_ALIGN_OF(type) _Alignof(type)
|
185
|
+
#elif UPB_GNUC_MIN(2, 95)
|
186
|
+
#define UPB_ALIGN_OF(type) __alignof__(type)
|
187
|
+
#elif defined(_MSC_VER)
|
188
|
+
#define UPB_ALIGN_OF(type) __alignof(type)
|
120
189
|
#else
|
121
190
|
#define UPB_ALIGN_OF(type) \
|
122
191
|
offsetof( \
|
@@ -136,6 +205,28 @@ Error, UINTPTR_MAX is undefined
|
|
136
205
|
#define UPB_ALIGN_AS(x) _Alignas(x)
|
137
206
|
#endif
|
138
207
|
|
208
|
+
#if __STDC_VERSION__ >= 202311L || UPB_HAS_EXTENSION(cxx_static_assert) || \
|
209
|
+
defined(__cplusplus)
|
210
|
+
#define UPB_STATIC_ASSERT(val, msg) static_assert((val), msg)
|
211
|
+
#elif __STDC_VERSION__ >= 201112L || UPB_HAS_EXTENSION(c_static_assert) || \
|
212
|
+
UPB_GNUC_MIN(4, 6)
|
213
|
+
#define UPB_STATIC_ASSERT(val, msg) _Static_assert((val), msg)
|
214
|
+
#else
|
215
|
+
// Unfortunately this hack doesn't work inside struct declarations, but it works
|
216
|
+
// everywhere else
|
217
|
+
#define UPB_STATIC_ASSERT_CONCAT_IMPL(s1, s2) s1##s2
|
218
|
+
#define UPB_STATIC_ASSERT_CONCAT(s1, s2) UPB_STATIC_ASSERT_CONCAT_IMPL(s1, s2)
|
219
|
+
#ifdef __COUNTER__
|
220
|
+
#define UPB_STATIC_ASSERT(condition, message) \
|
221
|
+
typedef char UPB_STATIC_ASSERT_CONCAT(static_assertion_failure_, \
|
222
|
+
__COUNTER__)[(condition) ? 1 : -1]
|
223
|
+
#else
|
224
|
+
#define UPB_STATIC_ASSERT(condition, message) \
|
225
|
+
typedef char UPB_STATIC_ASSERT_CONCAT(static_assertion_failure_, \
|
226
|
+
__LINE__)[(condition) ? 1 : -1]
|
227
|
+
#endif
|
228
|
+
#endif
|
229
|
+
|
139
230
|
// Hints to the compiler about likely/unlikely branches.
|
140
231
|
#if defined(__GNUC__) || defined(__clang__)
|
141
232
|
#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1)
|
@@ -145,16 +236,12 @@ Error, UINTPTR_MAX is undefined
|
|
145
236
|
#define UPB_UNLIKELY(x) (x)
|
146
237
|
#endif
|
147
238
|
|
148
|
-
#
|
149
|
-
#if __has_builtin(__builtin_expect_with_probability)
|
239
|
+
#if UPB_HAS_BUILTIN(__builtin_expect_with_probability)
|
150
240
|
#define UPB_UNPREDICTABLE(x) \
|
151
241
|
__builtin_expect_with_probability((bool)(x), 1, 0.5)
|
152
242
|
#else
|
153
243
|
#define UPB_UNPREDICTABLE(x) (x)
|
154
244
|
#endif
|
155
|
-
#else
|
156
|
-
#define UPB_UNPREDICTABLE(x) (x)
|
157
|
-
#endif
|
158
245
|
|
159
246
|
// Macros for function attributes on compilers that support them.
|
160
247
|
#if defined(__GNUC__) || defined(__clang__)
|
@@ -175,10 +262,16 @@ Error, UINTPTR_MAX is undefined
|
|
175
262
|
#define UPB_PRINTF(str, first_vararg)
|
176
263
|
#endif
|
177
264
|
|
265
|
+
#if defined(__clang__)
|
266
|
+
#define UPB_NODEREF __attribute__((noderef))
|
267
|
+
#else
|
268
|
+
#define UPB_NODEREF
|
269
|
+
#endif
|
270
|
+
|
178
271
|
#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
|
179
272
|
#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
|
180
273
|
|
181
|
-
#define UPB_UNUSED(var) (void)var
|
274
|
+
#define UPB_UNUSED(var) (void)(var)
|
182
275
|
|
183
276
|
// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true.
|
184
277
|
#ifdef NDEBUG
|
@@ -248,14 +341,10 @@ Error, UINTPTR_MAX is undefined
|
|
248
341
|
#define UPB_LONGJMP(buf, val) longjmp(buf, val)
|
249
342
|
#endif
|
250
343
|
|
251
|
-
#if ((__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__))
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
#define UPB_USE_C11_ATOMICS
|
256
|
-
#endif
|
257
|
-
#elif defined(__GNUC__)
|
258
|
-
// GCC supported atomics as an extension before it supported __has_extension
|
344
|
+
#if ((__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)) || \
|
345
|
+
UPB_HAS_EXTENSION(c_atomic) || \
|
346
|
+
defined(__GNUC__) // GCC supported atomics as an extension before it
|
347
|
+
// supported __has_extension
|
259
348
|
#define UPB_USE_C11_ATOMICS
|
260
349
|
#elif defined(_MSC_VER)
|
261
350
|
#define UPB_USE_MSC_ATOMICS
|
@@ -282,19 +371,17 @@ Error, UINTPTR_MAX is undefined
|
|
282
371
|
|
283
372
|
/* Configure whether fasttable is switched on or not. *************************/
|
284
373
|
|
285
|
-
#ifdef __has_attribute
|
286
|
-
#define UPB_HAS_ATTRIBUTE(x) __has_attribute(x)
|
287
|
-
#else
|
288
|
-
#define UPB_HAS_ATTRIBUTE(x) 0
|
289
|
-
#endif
|
290
|
-
|
291
374
|
#if UPB_HAS_ATTRIBUTE(musttail)
|
292
375
|
#define UPB_MUSTTAIL __attribute__((musttail))
|
293
376
|
#else
|
294
377
|
#define UPB_MUSTTAIL
|
295
378
|
#endif
|
296
379
|
|
297
|
-
#
|
380
|
+
#if UPB_HAS_ATTRIBUTE(preserve_none)
|
381
|
+
#define UPB_PRESERVE_NONE __attribute__((preserve_none))
|
382
|
+
#else
|
383
|
+
#define UPB_PRESERVE_NONE
|
384
|
+
#endif
|
298
385
|
|
299
386
|
/* This check is not fully robust: it does not require that we have "musttail"
|
300
387
|
* support available. We need tail calls to avoid consuming arbitrary amounts
|
@@ -345,84 +432,6 @@ Error, UINTPTR_MAX is undefined
|
|
345
432
|
|
346
433
|
#undef UPB_FASTTABLE_SUPPORTED
|
347
434
|
|
348
|
-
/* ASAN poisoning (for arena).
|
349
|
-
* If using UPB from an interpreted language like Ruby, a build of the
|
350
|
-
* interpreter compiled with ASAN enabled must be used in order to get sane and
|
351
|
-
* expected behavior.
|
352
|
-
*/
|
353
|
-
|
354
|
-
/* Due to preprocessor limitations, the conditional logic for setting
|
355
|
-
* UPB_CLANG_ASAN below cannot be consolidated into a portable one-liner.
|
356
|
-
* See https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html.
|
357
|
-
*/
|
358
|
-
#if defined(__has_feature)
|
359
|
-
#if __has_feature(address_sanitizer)
|
360
|
-
#define UPB_CLANG_ASAN 1
|
361
|
-
#else
|
362
|
-
#define UPB_CLANG_ASAN 0
|
363
|
-
#endif
|
364
|
-
#if __has_feature(thread_sanitizer)
|
365
|
-
#define UPB_CLANG_TSAN 1
|
366
|
-
#else
|
367
|
-
#define UPB_CLANG_TSAN 0
|
368
|
-
#endif
|
369
|
-
#else
|
370
|
-
#define UPB_CLANG_ASAN 0
|
371
|
-
#define UPB_CLANG_TSAN 0
|
372
|
-
#endif
|
373
|
-
|
374
|
-
#if defined(__SANITIZE_ADDRESS__) || UPB_CLANG_ASAN
|
375
|
-
#define UPB_ASAN 1
|
376
|
-
#define UPB_ASAN_GUARD_SIZE 32
|
377
|
-
#ifdef __cplusplus
|
378
|
-
extern "C" {
|
379
|
-
#endif
|
380
|
-
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
381
|
-
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
382
|
-
#ifdef __cplusplus
|
383
|
-
} /* extern "C" */
|
384
|
-
#endif
|
385
|
-
#define UPB_POISON_MEMORY_REGION(addr, size) \
|
386
|
-
__asan_poison_memory_region((addr), (size))
|
387
|
-
#define UPB_UNPOISON_MEMORY_REGION(addr, size) \
|
388
|
-
__asan_unpoison_memory_region((addr), (size))
|
389
|
-
#else
|
390
|
-
#define UPB_ASAN 0
|
391
|
-
#define UPB_ASAN_GUARD_SIZE 0
|
392
|
-
#define UPB_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
|
393
|
-
#define UPB_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size))
|
394
|
-
#endif
|
395
|
-
|
396
|
-
#if defined(__SANITIZE_THREAD__) || UPB_CLANG_TSAN
|
397
|
-
#define UPB_TSAN_PUBLISHED_MEMBER uintptr_t upb_tsan_safely_published;
|
398
|
-
#define UPB_TSAN_INIT_PUBLISHED(ptr) (ptr)->upb_tsan_safely_published = 0x5AFE
|
399
|
-
#define UPB_TSAN_CHECK_PUBLISHED(ptr) \
|
400
|
-
UPB_ASSERT((ptr)->upb_tsan_safely_published == 0x5AFE)
|
401
|
-
#define UPB_TSAN_PUBLISH 1
|
402
|
-
#define UPB_TSAN_CHECK_READ(member) \
|
403
|
-
__asm__ volatile("" ::"r"(*(char *)&(member)))
|
404
|
-
#define UPB_TSAN_CHECK_WRITE(member) \
|
405
|
-
do { \
|
406
|
-
char *write_upb_tsan_detect_race_ptr = (char *)&(member); \
|
407
|
-
char write_upb_tsan_detect_race = *write_upb_tsan_detect_race_ptr; \
|
408
|
-
__asm__ volatile("" : "+r"(write_upb_tsan_detect_race)); \
|
409
|
-
*write_upb_tsan_detect_race_ptr = write_upb_tsan_detect_race; \
|
410
|
-
} while (false)
|
411
|
-
#else
|
412
|
-
#define UPB_TSAN_PUBLISHED_MEMBER
|
413
|
-
#define UPB_TSAN_INIT_PUBLISHED(ptr)
|
414
|
-
#define UPB_TSAN_CHECK_PUBLISHED(ptr) \
|
415
|
-
do { \
|
416
|
-
} while (false && (ptr))
|
417
|
-
#define UPB_TSAN_PUBLISH 0
|
418
|
-
#define UPB_TSAN_CHECK_READ(member) \
|
419
|
-
do { \
|
420
|
-
} while (false && (member))
|
421
|
-
#define UPB_TSAN_CHECK_WRITE(member) \
|
422
|
-
do { \
|
423
|
-
} while (false && (member))
|
424
|
-
#endif
|
425
|
-
|
426
435
|
/* Disable proto2 arena behavior (TEMPORARY) **********************************/
|
427
436
|
|
428
437
|
#ifdef UPB_DISABLE_CLOSED_ENUM_CHECKING
|
@@ -556,49 +565,112 @@ Error, UINTPTR_MAX is undefined
|
|
556
565
|
|
557
566
|
#endif
|
558
567
|
|
559
|
-
#ifndef
|
560
|
-
#define
|
568
|
+
#ifndef UPB_GENERATED_CODE_SUPPORT_H_
|
569
|
+
#define UPB_GENERATED_CODE_SUPPORT_H_
|
561
570
|
|
562
|
-
|
571
|
+
// This is a bit awkward; we want to conditionally include the fast decoder,
|
572
|
+
// but we generally don't let macros like UPB_FASTTABLE leak into user code.
|
573
|
+
// We can't #include "decode_fast.h" inside the port/def.inc, because the
|
574
|
+
// inc files strictly prohibit recursive inclusion, and decode_fast.h includes
|
575
|
+
// port/def.inc. So instead we use this two-part dance to conditionally include
|
576
|
+
// decode_fast.h.
|
577
|
+
#if UPB_FASTTABLE
|
578
|
+
#define UPB_INCLUDE_FAST_DECODE
|
579
|
+
#endif
|
580
|
+
|
581
|
+
// IWYU pragma: begin_exports
|
582
|
+
|
583
|
+
#ifndef UPB_BASE_UPCAST_H_
|
584
|
+
#define UPB_BASE_UPCAST_H_
|
563
585
|
|
564
586
|
// Must be last.
|
565
587
|
|
566
|
-
|
588
|
+
// This macro provides a way to upcast message pointers in a way that is
|
589
|
+
// somewhat more bulletproof than blindly casting a pointer. Example:
|
590
|
+
//
|
591
|
+
// typedef struct {
|
592
|
+
// upb_Message UPB_PRIVATE(base);
|
593
|
+
// } pkg_FooMessage;
|
594
|
+
//
|
595
|
+
// void f(pkg_FooMessage* msg) {
|
596
|
+
// upb_Decode(UPB_UPCAST(msg), ...);
|
597
|
+
// }
|
598
|
+
|
599
|
+
#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only)
|
600
|
+
|
601
|
+
|
602
|
+
#endif /* UPB_BASE_UPCAST_H_ */
|
603
|
+
|
604
|
+
#ifndef UPB_MESSAGE_ACCESSORS_H_
|
605
|
+
#define UPB_MESSAGE_ACCESSORS_H_
|
606
|
+
|
607
|
+
#include <stdint.h>
|
608
|
+
|
609
|
+
#ifndef UPB_BASE_STRING_VIEW_H_
|
610
|
+
#define UPB_BASE_STRING_VIEW_H_
|
611
|
+
|
612
|
+
#include <string.h>
|
613
|
+
|
614
|
+
// Must be last.
|
615
|
+
|
616
|
+
#define UPB_STRINGVIEW_INIT(ptr, len) \
|
617
|
+
{ ptr, len }
|
618
|
+
|
619
|
+
#define UPB_STRINGVIEW_FORMAT "%.*s"
|
620
|
+
#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data
|
567
621
|
|
622
|
+
// LINT.IfChange(struct_definition)
|
568
623
|
typedef struct {
|
569
|
-
|
570
|
-
|
571
|
-
}
|
624
|
+
const char* data;
|
625
|
+
size_t size;
|
626
|
+
} upb_StringView;
|
572
627
|
|
573
628
|
#ifdef __cplusplus
|
574
629
|
extern "C" {
|
575
630
|
#endif
|
576
631
|
|
577
|
-
|
578
|
-
|
632
|
+
UPB_API_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
|
633
|
+
size_t size) {
|
634
|
+
upb_StringView ret;
|
635
|
+
ret.data = data;
|
636
|
+
ret.size = size;
|
637
|
+
return ret;
|
638
|
+
}
|
579
639
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...)
|
584
|
-
UPB_PRINTF(2, 3);
|
585
|
-
void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt,
|
586
|
-
va_list args) UPB_PRINTF(2, 0);
|
587
|
-
void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
|
588
|
-
va_list args) UPB_PRINTF(2, 0);
|
640
|
+
UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) {
|
641
|
+
return upb_StringView_FromDataAndSize(data, strlen(data));
|
642
|
+
}
|
589
643
|
|
590
|
-
|
591
|
-
|
592
|
-
|
644
|
+
UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) {
|
645
|
+
return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size));
|
646
|
+
}
|
593
647
|
|
648
|
+
// Compares StringViews following strcmp rules.
|
649
|
+
// Please note this comparison is neither unicode nor locale aware.
|
650
|
+
UPB_INLINE int upb_StringView_Compare(upb_StringView a, upb_StringView b) {
|
651
|
+
int result = memcmp(a.data, b.data, UPB_MIN(a.size, b.size));
|
652
|
+
if (result != 0) return result;
|
653
|
+
if (a.size < b.size) {
|
654
|
+
return -1;
|
655
|
+
} else if (a.size > b.size) {
|
656
|
+
return 1;
|
657
|
+
} else {
|
658
|
+
return 0;
|
659
|
+
}
|
660
|
+
}
|
594
661
|
|
595
|
-
|
662
|
+
// LINT.ThenChange(
|
663
|
+
// GoogleInternalName1,
|
664
|
+
// //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string,
|
665
|
+
// //depot/google3/third_party/upb/bits/typescript/string_view.ts
|
666
|
+
// )
|
596
667
|
|
597
|
-
#
|
598
|
-
|
668
|
+
#ifdef __cplusplus
|
669
|
+
} /* extern "C" */
|
670
|
+
#endif
|
599
671
|
|
600
|
-
#include <string.h>
|
601
672
|
|
673
|
+
#endif /* UPB_BASE_STRING_VIEW_H_ */
|
602
674
|
|
603
675
|
/* upb_Arena is a specific allocator implementation that uses arena allocation.
|
604
676
|
* The user provides an allocator that will be used to allocate the underlying
|
@@ -623,6 +695,8 @@ void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
|
|
623
695
|
#ifndef UPB_MEM_ALLOC_H_
|
624
696
|
#define UPB_MEM_ALLOC_H_
|
625
697
|
|
698
|
+
#include <stddef.h>
|
699
|
+
|
626
700
|
// Must be last.
|
627
701
|
|
628
702
|
#ifdef __cplusplus
|
@@ -634,9 +708,12 @@ typedef struct upb_alloc upb_alloc;
|
|
634
708
|
/* A combined `malloc()`/`free()` function.
|
635
709
|
* If `size` is 0 then the function acts like `free()`, otherwise it acts like
|
636
710
|
* `realloc()`. Only `oldsize` bytes from a previous allocation are
|
637
|
-
* preserved.
|
711
|
+
* preserved. If `actual_size` is not null and the allocator supports it, the
|
712
|
+
* actual size of the resulting allocation is stored in `actual_size`. If
|
713
|
+
* `actual_size` is not null, you must zero out the memory pointed to by
|
714
|
+
* `actual_size` before calling. */
|
638
715
|
typedef void* upb_alloc_func(upb_alloc* alloc, void* ptr, size_t oldsize,
|
639
|
-
size_t size);
|
716
|
+
size_t size, size_t* actual_size);
|
640
717
|
|
641
718
|
/* A upb_alloc is a possibly-stateful allocator object.
|
642
719
|
*
|
@@ -650,23 +727,37 @@ struct upb_alloc {
|
|
650
727
|
|
651
728
|
UPB_INLINE void* upb_malloc(upb_alloc* alloc, size_t size) {
|
652
729
|
UPB_ASSERT(alloc);
|
653
|
-
return alloc->func(alloc, NULL, 0, size);
|
730
|
+
return alloc->func(alloc, NULL, 0, size, NULL);
|
731
|
+
}
|
732
|
+
|
733
|
+
typedef struct {
|
734
|
+
void* p;
|
735
|
+
size_t n;
|
736
|
+
} upb_SizedPtr;
|
737
|
+
|
738
|
+
UPB_INLINE upb_SizedPtr upb_SizeReturningMalloc(upb_alloc* alloc, size_t size) {
|
739
|
+
UPB_ASSERT(alloc);
|
740
|
+
upb_SizedPtr result;
|
741
|
+
result.n = 0;
|
742
|
+
result.p = alloc->func(alloc, NULL, 0, size, &result.n);
|
743
|
+
result.n = result.p != NULL ? UPB_MAX(result.n, size) : 0;
|
744
|
+
return result;
|
654
745
|
}
|
655
746
|
|
656
747
|
UPB_INLINE void* upb_realloc(upb_alloc* alloc, void* ptr, size_t oldsize,
|
657
748
|
size_t size) {
|
658
749
|
UPB_ASSERT(alloc);
|
659
|
-
return alloc->func(alloc, ptr, oldsize, size);
|
750
|
+
return alloc->func(alloc, ptr, oldsize, size, NULL);
|
660
751
|
}
|
661
752
|
|
662
753
|
UPB_INLINE void upb_free(upb_alloc* alloc, void* ptr) {
|
663
754
|
UPB_ASSERT(alloc);
|
664
|
-
alloc->func(alloc, ptr, 0, 0);
|
755
|
+
alloc->func(alloc, ptr, 0, 0, NULL);
|
665
756
|
}
|
666
757
|
|
667
758
|
UPB_INLINE void upb_free_sized(upb_alloc* alloc, void* ptr, size_t size) {
|
668
759
|
UPB_ASSERT(alloc);
|
669
|
-
alloc->func(alloc, ptr, size, 0);
|
760
|
+
alloc->func(alloc, ptr, size, 0, NULL);
|
670
761
|
}
|
671
762
|
|
672
763
|
// The global allocator used by upb. Uses the standard malloc()/free().
|
@@ -702,6 +793,167 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); }
|
|
702
793
|
#include <stdint.h>
|
703
794
|
#include <string.h>
|
704
795
|
|
796
|
+
|
797
|
+
#ifndef UPB_PORT_SANITIZERS_H_
|
798
|
+
#define UPB_PORT_SANITIZERS_H_
|
799
|
+
|
800
|
+
#include <stddef.h>
|
801
|
+
#include <stdint.h>
|
802
|
+
#include <stdio.h>
|
803
|
+
|
804
|
+
// Must be last.
|
805
|
+
|
806
|
+
// Must be inside def.inc/undef.inc
|
807
|
+
#if UPB_HWASAN
|
808
|
+
#include <sanitizer/hwasan_interface.h>
|
809
|
+
#endif
|
810
|
+
|
811
|
+
#ifdef __cplusplus
|
812
|
+
extern "C" {
|
813
|
+
#endif
|
814
|
+
|
815
|
+
// UPB_ARENA_SIZE_HACK depends on this struct having size 1.
|
816
|
+
typedef struct {
|
817
|
+
uint8_t state;
|
818
|
+
} upb_Xsan;
|
819
|
+
|
820
|
+
UPB_INLINE uint8_t _upb_Xsan_NextTag(upb_Xsan *xsan) {
|
821
|
+
#if UPB_HWASAN
|
822
|
+
xsan->state++;
|
823
|
+
if (xsan->state <= UPB_HWASAN_POISON_TAG) {
|
824
|
+
xsan->state = UPB_HWASAN_POISON_TAG + 1;
|
825
|
+
}
|
826
|
+
return xsan->state;
|
827
|
+
#else
|
828
|
+
return 0;
|
829
|
+
#endif
|
830
|
+
}
|
831
|
+
|
832
|
+
enum {
|
833
|
+
#if UPB_ASAN
|
834
|
+
UPB_PRIVATE(kUpb_Asan_GuardSize) = 32,
|
835
|
+
#else
|
836
|
+
UPB_PRIVATE(kUpb_Asan_GuardSize) = 0,
|
837
|
+
#endif
|
838
|
+
};
|
839
|
+
|
840
|
+
UPB_INLINE uint8_t UPB_PRIVATE(_upb_Xsan_GetTag)(const void *addr) {
|
841
|
+
#if UPB_HWASAN
|
842
|
+
return __hwasan_get_tag_from_pointer(addr);
|
843
|
+
#else
|
844
|
+
return 0;
|
845
|
+
#endif
|
846
|
+
}
|
847
|
+
|
848
|
+
UPB_INLINE void UPB_PRIVATE(upb_Xsan_Init)(upb_Xsan *xsan) {
|
849
|
+
#if UPB_HWASAN || UPB_TSAN
|
850
|
+
xsan->state = 0;
|
851
|
+
#endif
|
852
|
+
}
|
853
|
+
|
854
|
+
// Marks the given region as poisoned, meaning that it is not accessible until
|
855
|
+
// it is unpoisoned.
|
856
|
+
UPB_INLINE void UPB_PRIVATE(upb_Xsan_PoisonRegion)(const void *addr,
|
857
|
+
size_t size) {
|
858
|
+
#if UPB_ASAN
|
859
|
+
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
860
|
+
__asan_poison_memory_region(addr, size);
|
861
|
+
#elif UPB_HWASAN
|
862
|
+
__hwasan_tag_memory(addr, UPB_HWASAN_POISON_TAG, UPB_ALIGN_MALLOC(size));
|
863
|
+
#endif
|
864
|
+
}
|
865
|
+
|
866
|
+
UPB_INLINE void *UPB_PRIVATE(_upb_Xsan_UnpoisonRegion)(void *addr, size_t size,
|
867
|
+
uint8_t tag) {
|
868
|
+
#if UPB_ASAN
|
869
|
+
UPB_UNUSED(tag);
|
870
|
+
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
871
|
+
__asan_unpoison_memory_region(addr, size);
|
872
|
+
return addr;
|
873
|
+
#elif UPB_HWASAN
|
874
|
+
__hwasan_tag_memory(addr, tag, UPB_ALIGN_MALLOC(size));
|
875
|
+
return __hwasan_tag_pointer(addr, tag);
|
876
|
+
#else
|
877
|
+
UPB_UNUSED(size);
|
878
|
+
UPB_UNUSED(tag);
|
879
|
+
|
880
|
+
// `addr` is the pointer that will be returned from arena alloc/realloc
|
881
|
+
// functions. In this code-path we know it must be non-NULL, but the compiler
|
882
|
+
// doesn't know this unless we add a UPB_ASSUME() annotation.
|
883
|
+
//
|
884
|
+
// This will let the optimizer optimize away NULL-checks if it can see that
|
885
|
+
// this path was taken.
|
886
|
+
UPB_ASSUME(addr);
|
887
|
+
return addr;
|
888
|
+
#endif
|
889
|
+
}
|
890
|
+
|
891
|
+
// Allows users to read and write to the given region, which will be considered
|
892
|
+
// distinct from other regions and may only be accessed through the returned
|
893
|
+
// pointer.
|
894
|
+
//
|
895
|
+
// `addr` must be aligned to the malloc alignment. Size may be unaligned,
|
896
|
+
// and with ASAN we can respect `size` precisely, but with HWASAN we must
|
897
|
+
// round `size` up to the next multiple of the malloc alignment, so the caller
|
898
|
+
// must guarantee that rounding up `size` will not cause overlap with other
|
899
|
+
// regions.
|
900
|
+
UPB_INLINE void *UPB_PRIVATE(upb_Xsan_NewUnpoisonedRegion)(upb_Xsan *xsan,
|
901
|
+
void *addr,
|
902
|
+
size_t size) {
|
903
|
+
return UPB_PRIVATE(_upb_Xsan_UnpoisonRegion)(addr, size,
|
904
|
+
_upb_Xsan_NextTag(xsan));
|
905
|
+
}
|
906
|
+
|
907
|
+
// Resizes the given region to a new size, *without* invalidating any existing
|
908
|
+
// pointers to the region.
|
909
|
+
//
|
910
|
+
// `tagged_addr` must be a pointer that was previously returned from
|
911
|
+
// `upb_Xsan_NewUnpoisonedRegion`. `old_size` must be the size that was
|
912
|
+
// originally passed to `upb_Xsan_NewUnpoisonedRegion`.
|
913
|
+
UPB_INLINE void *UPB_PRIVATE(upb_Xsan_ResizeUnpoisonedRegion)(void *tagged_addr,
|
914
|
+
size_t old_size,
|
915
|
+
size_t new_size) {
|
916
|
+
UPB_PRIVATE(upb_Xsan_PoisonRegion)(tagged_addr, old_size);
|
917
|
+
return UPB_PRIVATE(_upb_Xsan_UnpoisonRegion)(
|
918
|
+
tagged_addr, new_size, UPB_PRIVATE(_upb_Xsan_GetTag)(tagged_addr));
|
919
|
+
}
|
920
|
+
|
921
|
+
// Compares two pointers and returns true if they are equal. This returns the
|
922
|
+
// correct result even if one or both of the pointers are tagged.
|
923
|
+
UPB_INLINE bool UPB_PRIVATE(upb_Xsan_PtrEq)(const void *a, const void *b) {
|
924
|
+
#if UPB_HWASAN
|
925
|
+
return __hwasan_tag_pointer(a, 0) == __hwasan_tag_pointer(b, 0);
|
926
|
+
#else
|
927
|
+
return a == b;
|
928
|
+
#endif
|
929
|
+
}
|
930
|
+
|
931
|
+
// These annotations improve TSAN's ability to detect data races. By
|
932
|
+
// proactively accessing a non-atomic variable at the point where it is
|
933
|
+
// "logically" accessed, we can trigger TSAN diagnostics that might have
|
934
|
+
// otherwise been masked by subsequent atomic operations.
|
935
|
+
|
936
|
+
UPB_INLINE void UPB_PRIVATE(upb_Xsan_AccessReadOnly)(upb_Xsan *xsan) {
|
937
|
+
#if UPB_TSAN
|
938
|
+
// For performance we avoid using a volatile variable.
|
939
|
+
__asm__ volatile("" ::"r"(xsan->state));
|
940
|
+
#endif
|
941
|
+
}
|
942
|
+
|
943
|
+
UPB_INLINE void UPB_PRIVATE(upb_Xsan_AccessReadWrite)(upb_Xsan *xsan) {
|
944
|
+
#if UPB_TSAN
|
945
|
+
// For performance we avoid using a volatile variable.
|
946
|
+
__asm__ volatile("" : "+r"(xsan->state));
|
947
|
+
#endif
|
948
|
+
}
|
949
|
+
|
950
|
+
#ifdef __cplusplus
|
951
|
+
} /* extern "C" */
|
952
|
+
#endif
|
953
|
+
|
954
|
+
|
955
|
+
#endif // UPB_PORT_SANITIZERS_H_
|
956
|
+
|
705
957
|
// Must be last.
|
706
958
|
|
707
959
|
// This is QUITE an ugly hack, which specifies the number of pointers needed
|
@@ -709,13 +961,14 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); }
|
|
709
961
|
//
|
710
962
|
// We need this because the decoder inlines a upb_Arena for performance but
|
711
963
|
// the full struct is not visible outside of arena.c. Yes, I know, it's awful.
|
712
|
-
#define UPB_ARENA_SIZE_HACK (
|
964
|
+
#define UPB_ARENA_SIZE_HACK (10 + (UPB_XSAN_STRUCT_SIZE * 2))
|
713
965
|
|
714
966
|
// LINT.IfChange(upb_Arena)
|
715
967
|
|
716
968
|
struct upb_Arena {
|
717
969
|
char* UPB_ONLYBITS(ptr);
|
718
|
-
char* UPB_ONLYBITS(end);
|
970
|
+
const UPB_NODEREF char* UPB_ONLYBITS(end);
|
971
|
+
UPB_XSAN_MEMBER
|
719
972
|
};
|
720
973
|
|
721
974
|
// LINT.ThenChange(//depot/google3/third_party/upb/bits/typescript/arena.ts:upb_Arena)
|
@@ -733,102 +986,105 @@ UPB_INLINE size_t UPB_PRIVATE(_upb_ArenaHas)(const struct upb_Arena* a) {
|
|
733
986
|
return (size_t)(a->UPB_ONLYBITS(end) - a->UPB_ONLYBITS(ptr));
|
734
987
|
}
|
735
988
|
|
736
|
-
|
737
|
-
|
738
|
-
|
989
|
+
UPB_INLINE size_t UPB_PRIVATE(_upb_Arena_AllocSpan)(size_t size) {
|
990
|
+
return UPB_ALIGN_MALLOC(size) + UPB_PRIVATE(kUpb_Asan_GuardSize);
|
991
|
+
}
|
739
992
|
|
740
|
-
|
741
|
-
|
742
|
-
|
993
|
+
UPB_INLINE bool UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(
|
994
|
+
const struct upb_Arena* a, void* ptr, size_t size) {
|
995
|
+
return UPB_PRIVATE(upb_Xsan_PtrEq)(
|
996
|
+
(char*)ptr + UPB_PRIVATE(_upb_Arena_AllocSpan)(size),
|
997
|
+
a->UPB_ONLYBITS(ptr));
|
998
|
+
}
|
999
|
+
|
1000
|
+
UPB_INLINE bool UPB_PRIVATE(_upb_Arena_IsAligned)(const void* ptr) {
|
1001
|
+
return (uintptr_t)ptr % UPB_MALLOC_ALIGN == 0;
|
1002
|
+
}
|
1003
|
+
|
1004
|
+
UPB_API_INLINE void* upb_Arena_Malloc(struct upb_Arena* a, size_t size) {
|
1005
|
+
UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a));
|
1006
|
+
|
1007
|
+
size_t span = UPB_PRIVATE(_upb_Arena_AllocSpan)(size);
|
1008
|
+
|
1009
|
+
if (UPB_UNLIKELY(UPB_PRIVATE(_upb_ArenaHas)(a) < span)) {
|
1010
|
+
void* UPB_PRIVATE(_upb_Arena_SlowMalloc)(struct upb_Arena * a, size_t size);
|
743
1011
|
return UPB_PRIVATE(_upb_Arena_SlowMalloc)(a, span);
|
744
1012
|
}
|
745
1013
|
|
746
1014
|
// We have enough space to do a fast malloc.
|
747
1015
|
void* ret = a->UPB_ONLYBITS(ptr);
|
748
|
-
UPB_ASSERT(UPB_ALIGN_MALLOC((uintptr_t)ret) == (uintptr_t)ret);
|
749
|
-
UPB_ASSERT(UPB_ALIGN_MALLOC(size) == size);
|
750
|
-
UPB_UNPOISON_MEMORY_REGION(ret, size);
|
751
|
-
|
752
1016
|
a->UPB_ONLYBITS(ptr) += span;
|
1017
|
+
UPB_ASSERT(UPB_PRIVATE(_upb_Arena_IsAligned)(ret));
|
1018
|
+
UPB_ASSERT(UPB_PRIVATE(_upb_Arena_IsAligned)(a->UPB_ONLYBITS(ptr)));
|
753
1019
|
|
754
|
-
return ret;
|
1020
|
+
return UPB_PRIVATE(upb_Xsan_NewUnpoisonedRegion)(UPB_XSAN(a), ret, size);
|
755
1021
|
}
|
756
1022
|
|
757
1023
|
UPB_API_INLINE void upb_Arena_ShrinkLast(struct upb_Arena* a, void* ptr,
|
758
1024
|
size_t oldsize, size_t size) {
|
759
|
-
UPB_TSAN_CHECK_WRITE(a->UPB_ONLYBITS(ptr));
|
760
1025
|
UPB_ASSERT(ptr);
|
761
1026
|
UPB_ASSERT(size <= oldsize);
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
if ((char*)ptr + oldsize == arena_ptr) {
|
770
|
-
a->UPB_ONLYBITS(ptr) = (char*)ptr + size;
|
1027
|
+
|
1028
|
+
UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a));
|
1029
|
+
UPB_PRIVATE(upb_Xsan_ResizeUnpoisonedRegion)(ptr, oldsize, size);
|
1030
|
+
|
1031
|
+
if (UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(a, ptr, oldsize)) {
|
1032
|
+
// We can reclaim some memory.
|
1033
|
+
a->UPB_ONLYBITS(ptr) -= UPB_ALIGN_MALLOC(oldsize) - UPB_ALIGN_MALLOC(size);
|
771
1034
|
} else {
|
772
|
-
//
|
773
|
-
//
|
1035
|
+
// We can't reclaim any memory, but we need to verify that `ptr` really
|
1036
|
+
// does represent the most recent allocation.
|
774
1037
|
#ifndef NDEBUG
|
775
1038
|
bool _upb_Arena_WasLastAlloc(struct upb_Arena * a, void* ptr,
|
776
1039
|
size_t oldsize);
|
777
1040
|
UPB_ASSERT(_upb_Arena_WasLastAlloc(a, ptr, oldsize));
|
778
1041
|
#endif
|
779
1042
|
}
|
780
|
-
UPB_POISON_MEMORY_REGION((char*)ptr + (size - UPB_ASAN_GUARD_SIZE),
|
781
|
-
oldsize - size);
|
782
1043
|
}
|
783
1044
|
|
784
1045
|
UPB_API_INLINE bool upb_Arena_TryExtend(struct upb_Arena* a, void* ptr,
|
785
1046
|
size_t oldsize, size_t size) {
|
786
|
-
UPB_TSAN_CHECK_WRITE(a->UPB_ONLYBITS(ptr));
|
787
1047
|
UPB_ASSERT(ptr);
|
788
1048
|
UPB_ASSERT(size > oldsize);
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
size_t extend = size - oldsize;
|
795
|
-
if ((char*)ptr + oldsize == a->UPB_ONLYBITS(ptr) &&
|
1049
|
+
|
1050
|
+
UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a));
|
1051
|
+
size_t extend = UPB_ALIGN_MALLOC(size) - UPB_ALIGN_MALLOC(oldsize);
|
1052
|
+
|
1053
|
+
if (UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(a, ptr, oldsize) &&
|
796
1054
|
UPB_PRIVATE(_upb_ArenaHas)(a) >= extend) {
|
797
1055
|
a->UPB_ONLYBITS(ptr) += extend;
|
798
|
-
|
799
|
-
extend);
|
1056
|
+
UPB_PRIVATE(upb_Xsan_ResizeUnpoisonedRegion)(ptr, oldsize, size);
|
800
1057
|
return true;
|
801
1058
|
}
|
1059
|
+
|
802
1060
|
return false;
|
803
1061
|
}
|
804
1062
|
|
805
1063
|
UPB_API_INLINE void* upb_Arena_Realloc(struct upb_Arena* a, void* ptr,
|
806
1064
|
size_t oldsize, size_t size) {
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
1065
|
+
UPB_PRIVATE(upb_Xsan_AccessReadWrite)(UPB_XSAN(a));
|
1066
|
+
|
1067
|
+
void* ret;
|
1068
|
+
|
1069
|
+
if (ptr && (size <= oldsize || upb_Arena_TryExtend(a, ptr, oldsize, size))) {
|
1070
|
+
// We can extend or shrink in place.
|
1071
|
+
if (size <= oldsize &&
|
1072
|
+
UPB_PRIVATE(_upb_Arena_WasLastAllocFromCurrentBlock)(a, ptr, oldsize)) {
|
1073
|
+
upb_Arena_ShrinkLast(a, ptr, oldsize, size);
|
811
1074
|
}
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
} else {
|
819
|
-
UPB_POISON_MEMORY_REGION((char*)ptr + size, oldsize - size);
|
820
|
-
}
|
821
|
-
return ptr;
|
1075
|
+
ret = ptr;
|
1076
|
+
} else {
|
1077
|
+
// We need to copy into a new allocation.
|
1078
|
+
ret = upb_Arena_Malloc(a, size);
|
1079
|
+
if (ret && oldsize > 0) {
|
1080
|
+
memcpy(ret, ptr, UPB_MIN(oldsize, size));
|
822
1081
|
}
|
823
1082
|
}
|
824
|
-
void* ret = upb_Arena_Malloc(a, size);
|
825
|
-
|
826
|
-
if (ret && oldsize > 0) {
|
827
|
-
memcpy(ret, ptr, UPB_MIN(oldsize, size));
|
828
|
-
UPB_POISON_MEMORY_REGION(ptr, oldsize);
|
829
|
-
}
|
830
1083
|
|
831
|
-
|
1084
|
+
// We want to invalidate pointers to the old region if hwasan is enabled, so
|
1085
|
+
// we poison and unpoison even if ptr == ret.
|
1086
|
+
UPB_PRIVATE(upb_Xsan_PoisonRegion)(ptr, oldsize);
|
1087
|
+
return UPB_PRIVATE(upb_Xsan_NewUnpoisonedRegion)(UPB_XSAN(a), ret, size);
|
832
1088
|
}
|
833
1089
|
|
834
1090
|
#ifdef __cplusplus
|
@@ -945,572 +1201,392 @@ void upb_Arena_SetTraceHandler(void (*initArenaTraceHandler)(const upb_Arena*,
|
|
945
1201
|
|
946
1202
|
#endif /* UPB_MEM_ARENA_H_ */
|
947
1203
|
|
1204
|
+
#ifndef UPB_MESSAGE_ARRAY_H_
|
1205
|
+
#define UPB_MESSAGE_ARRAY_H_
|
1206
|
+
|
1207
|
+
#include <stddef.h>
|
1208
|
+
|
1209
|
+
|
1210
|
+
#ifndef UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
1211
|
+
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
1212
|
+
|
948
1213
|
// Must be last.
|
949
1214
|
|
1215
|
+
// The types a field can have. Note that this list is not identical to the
|
1216
|
+
// types defined in descriptor.proto, which gives INT32 and SINT32 separate
|
1217
|
+
// types (we distinguish the two with the "integer encoding" enum below).
|
1218
|
+
// This enum is an internal convenience only and has no meaning outside of upb.
|
1219
|
+
typedef enum {
|
1220
|
+
kUpb_CType_Bool = 1,
|
1221
|
+
kUpb_CType_Float = 2,
|
1222
|
+
kUpb_CType_Int32 = 3,
|
1223
|
+
kUpb_CType_UInt32 = 4,
|
1224
|
+
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
|
1225
|
+
kUpb_CType_Message = 6,
|
1226
|
+
kUpb_CType_Double = 7,
|
1227
|
+
kUpb_CType_Int64 = 8,
|
1228
|
+
kUpb_CType_UInt64 = 9,
|
1229
|
+
kUpb_CType_String = 10,
|
1230
|
+
kUpb_CType_Bytes = 11
|
1231
|
+
} upb_CType;
|
1232
|
+
|
1233
|
+
// The repeated-ness of each field; this matches descriptor.proto.
|
1234
|
+
typedef enum {
|
1235
|
+
kUpb_Label_Optional = 1,
|
1236
|
+
kUpb_Label_Required = 2,
|
1237
|
+
kUpb_Label_Repeated = 3
|
1238
|
+
} upb_Label;
|
1239
|
+
|
1240
|
+
// Descriptor types, as defined in descriptor.proto.
|
1241
|
+
typedef enum {
|
1242
|
+
kUpb_FieldType_Double = 1,
|
1243
|
+
kUpb_FieldType_Float = 2,
|
1244
|
+
kUpb_FieldType_Int64 = 3,
|
1245
|
+
kUpb_FieldType_UInt64 = 4,
|
1246
|
+
kUpb_FieldType_Int32 = 5,
|
1247
|
+
kUpb_FieldType_Fixed64 = 6,
|
1248
|
+
kUpb_FieldType_Fixed32 = 7,
|
1249
|
+
kUpb_FieldType_Bool = 8,
|
1250
|
+
kUpb_FieldType_String = 9,
|
1251
|
+
kUpb_FieldType_Group = 10,
|
1252
|
+
kUpb_FieldType_Message = 11,
|
1253
|
+
kUpb_FieldType_Bytes = 12,
|
1254
|
+
kUpb_FieldType_UInt32 = 13,
|
1255
|
+
kUpb_FieldType_Enum = 14,
|
1256
|
+
kUpb_FieldType_SFixed32 = 15,
|
1257
|
+
kUpb_FieldType_SFixed64 = 16,
|
1258
|
+
kUpb_FieldType_SInt32 = 17,
|
1259
|
+
kUpb_FieldType_SInt64 = 18,
|
1260
|
+
} upb_FieldType;
|
1261
|
+
|
1262
|
+
#define kUpb_FieldType_SizeOf 19
|
1263
|
+
|
950
1264
|
#ifdef __cplusplus
|
951
1265
|
extern "C" {
|
952
1266
|
#endif
|
953
1267
|
|
954
|
-
//
|
955
|
-
|
956
|
-
|
957
|
-
//
|
958
|
-
//
|
959
|
-
//
|
960
|
-
|
1268
|
+
// Convert from upb_FieldType to upb_CType
|
1269
|
+
UPB_INLINE upb_CType upb_FieldType_CType(upb_FieldType field_type) {
|
1270
|
+
static const upb_CType c_type[] = {
|
1271
|
+
kUpb_CType_Double, // kUpb_FieldType_Double
|
1272
|
+
kUpb_CType_Float, // kUpb_FieldType_Float
|
1273
|
+
kUpb_CType_Int64, // kUpb_FieldType_Int64
|
1274
|
+
kUpb_CType_UInt64, // kUpb_FieldType_UInt64
|
1275
|
+
kUpb_CType_Int32, // kUpb_FieldType_Int32
|
1276
|
+
kUpb_CType_UInt64, // kUpb_FieldType_Fixed64
|
1277
|
+
kUpb_CType_UInt32, // kUpb_FieldType_Fixed32
|
1278
|
+
kUpb_CType_Bool, // kUpb_FieldType_Bool
|
1279
|
+
kUpb_CType_String, // kUpb_FieldType_String
|
1280
|
+
kUpb_CType_Message, // kUpb_FieldType_Group
|
1281
|
+
kUpb_CType_Message, // kUpb_FieldType_Message
|
1282
|
+
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
|
1283
|
+
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
|
1284
|
+
kUpb_CType_Enum, // kUpb_FieldType_Enum
|
1285
|
+
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
|
1286
|
+
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
|
1287
|
+
kUpb_CType_Int32, // kUpb_FieldType_SInt32
|
1288
|
+
kUpb_CType_Int64, // kUpb_FieldType_SInt64
|
1289
|
+
};
|
961
1290
|
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
uintptr_t input_delta; // Diff between the original input pointer and patch
|
966
|
-
int limit; // Submessage limit relative to end
|
967
|
-
bool error; // To distinguish between EOF and error.
|
968
|
-
bool aliasing;
|
969
|
-
char patch[kUpb_EpsCopyInputStream_SlopBytes * 2];
|
970
|
-
} upb_EpsCopyInputStream;
|
1291
|
+
// -1 here because the enum is one-based but the table is zero-based.
|
1292
|
+
return c_type[field_type - 1];
|
1293
|
+
}
|
971
1294
|
|
972
|
-
|
973
|
-
//
|
974
|
-
|
975
|
-
|
976
|
-
|
1295
|
+
UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
|
1296
|
+
// clang-format off
|
1297
|
+
const unsigned kUnpackableTypes =
|
1298
|
+
(1 << kUpb_FieldType_String) |
|
1299
|
+
(1 << kUpb_FieldType_Bytes) |
|
1300
|
+
(1 << kUpb_FieldType_Message) |
|
1301
|
+
(1 << kUpb_FieldType_Group);
|
1302
|
+
// clang-format on
|
1303
|
+
return (1 << field_type) & ~kUnpackableTypes;
|
977
1304
|
}
|
978
1305
|
|
979
|
-
|
980
|
-
|
1306
|
+
#ifdef __cplusplus
|
1307
|
+
} /* extern "C" */
|
1308
|
+
#endif
|
981
1309
|
|
982
|
-
typedef const char* upb_EpsCopyInputStream_IsDoneFallbackFunc(
|
983
|
-
upb_EpsCopyInputStream* e, const char* ptr, int overrun);
|
984
1310
|
|
985
|
-
|
986
|
-
// [*ptr, size]. Updates `*ptr` as necessary to guarantee that at least
|
987
|
-
// kUpb_EpsCopyInputStream_SlopBytes are available to read.
|
988
|
-
UPB_INLINE void upb_EpsCopyInputStream_Init(upb_EpsCopyInputStream* e,
|
989
|
-
const char** ptr, size_t size,
|
990
|
-
bool enable_aliasing) {
|
991
|
-
if (size <= kUpb_EpsCopyInputStream_SlopBytes) {
|
992
|
-
memset(&e->patch, 0, 32);
|
993
|
-
if (size) memcpy(&e->patch, *ptr, size);
|
994
|
-
e->input_delta = (uintptr_t)*ptr - (uintptr_t)e->patch;
|
995
|
-
*ptr = e->patch;
|
996
|
-
e->end = *ptr + size;
|
997
|
-
e->limit = 0;
|
998
|
-
} else {
|
999
|
-
e->end = *ptr + size - kUpb_EpsCopyInputStream_SlopBytes;
|
1000
|
-
e->limit = kUpb_EpsCopyInputStream_SlopBytes;
|
1001
|
-
e->input_delta = 0;
|
1002
|
-
}
|
1003
|
-
e->aliasing = enable_aliasing;
|
1004
|
-
e->limit_ptr = e->end;
|
1005
|
-
e->error = false;
|
1006
|
-
}
|
1311
|
+
#endif /* UPB_BASE_DESCRIPTOR_CONSTANTS_H_ */
|
1007
1312
|
|
1008
|
-
|
1009
|
-
|
1010
|
-
kUpb_IsDoneStatus_Done,
|
1313
|
+
#ifndef UPB_MESSAGE_INTERNAL_ARRAY_H_
|
1314
|
+
#define UPB_MESSAGE_INTERNAL_ARRAY_H_
|
1011
1315
|
|
1012
|
-
|
1013
|
-
|
1316
|
+
#include <stdint.h>
|
1317
|
+
#include <string.h>
|
1014
1318
|
|
1015
|
-
// The current stream position is not at a limit, and the stream needs to
|
1016
|
-
// be flipped to a new buffer before more data can be read.
|
1017
|
-
kUpb_IsDoneStatus_NeedFallback,
|
1018
|
-
} upb_IsDoneStatus;
|
1019
1319
|
|
1020
|
-
//
|
1021
|
-
// function, it is simpler to call upb_EpsCopyInputStream_IsDone() if possible.
|
1022
|
-
UPB_INLINE upb_IsDoneStatus upb_EpsCopyInputStream_IsDoneStatus(
|
1023
|
-
upb_EpsCopyInputStream* e, const char* ptr, int* overrun) {
|
1024
|
-
*overrun = ptr - e->end;
|
1025
|
-
if (UPB_LIKELY(ptr < e->limit_ptr)) {
|
1026
|
-
return kUpb_IsDoneStatus_NotDone;
|
1027
|
-
} else if (UPB_LIKELY(*overrun == e->limit)) {
|
1028
|
-
return kUpb_IsDoneStatus_Done;
|
1029
|
-
} else {
|
1030
|
-
return kUpb_IsDoneStatus_NeedFallback;
|
1031
|
-
}
|
1032
|
-
}
|
1320
|
+
// Must be last.
|
1033
1321
|
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
// kUpb_EpsCopyInputStream_SlopBytes of data to be read in the current buffer.
|
1038
|
-
//
|
1039
|
-
// Postcondition: if the function returns false, there are at least
|
1040
|
-
// kUpb_EpsCopyInputStream_SlopBytes of data available to read at *ptr.
|
1041
|
-
UPB_INLINE bool upb_EpsCopyInputStream_IsDoneWithCallback(
|
1042
|
-
upb_EpsCopyInputStream* e, const char** ptr,
|
1043
|
-
upb_EpsCopyInputStream_IsDoneFallbackFunc* func) {
|
1044
|
-
int overrun;
|
1045
|
-
switch (upb_EpsCopyInputStream_IsDoneStatus(e, *ptr, &overrun)) {
|
1046
|
-
case kUpb_IsDoneStatus_Done:
|
1047
|
-
return true;
|
1048
|
-
case kUpb_IsDoneStatus_NotDone:
|
1049
|
-
return false;
|
1050
|
-
case kUpb_IsDoneStatus_NeedFallback:
|
1051
|
-
*ptr = func(e, *ptr, overrun);
|
1052
|
-
return *ptr == NULL;
|
1053
|
-
}
|
1054
|
-
UPB_UNREACHABLE();
|
1055
|
-
}
|
1322
|
+
#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit.
|
1323
|
+
#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size.
|
1324
|
+
#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2)
|
1056
1325
|
|
1057
|
-
|
1058
|
-
|
1326
|
+
#ifdef __cplusplus
|
1327
|
+
extern "C" {
|
1328
|
+
#endif
|
1059
1329
|
|
1060
|
-
//
|
1061
|
-
|
1062
|
-
//
|
1063
|
-
|
1064
|
-
//
|
1065
|
-
// to
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1330
|
+
// LINT.IfChange(upb_Array)
|
1331
|
+
|
1332
|
+
// Our internal representation for repeated fields.
|
1333
|
+
struct upb_Array {
|
1334
|
+
// This is a tagged pointer. Bits #0 and #1 encode the elem size as follows:
|
1335
|
+
// 0 maps to elem size 1
|
1336
|
+
// 1 maps to elem size 4
|
1337
|
+
// 2 maps to elem size 8
|
1338
|
+
// 3 maps to elem size 16
|
1339
|
+
//
|
1340
|
+
// Bit #2 contains the frozen/immutable flag.
|
1341
|
+
uintptr_t UPB_ONLYBITS(data);
|
1342
|
+
|
1343
|
+
size_t UPB_ONLYBITS(size); // The number of elements in the array.
|
1344
|
+
size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements.
|
1345
|
+
};
|
1346
|
+
|
1347
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Array_ShallowFreeze)(struct upb_Array* arr) {
|
1348
|
+
arr->UPB_ONLYBITS(data) |= _UPB_ARRAY_MASK_IMM;
|
1070
1349
|
}
|
1071
1350
|
|
1072
|
-
|
1073
|
-
|
1074
|
-
//
|
1075
|
-
// Note that this check does not respect any semantic limits on the stream,
|
1076
|
-
// either limits from PushLimit() or the overall stream end, so some of these
|
1077
|
-
// bytes may have unpredictable, nonsense values in them. The guarantee is only
|
1078
|
-
// that the bytes are valid to read from the perspective of the C language
|
1079
|
-
// (ie. you can read without triggering UBSAN or ASAN).
|
1080
|
-
UPB_INLINE size_t upb_EpsCopyInputStream_BytesAvailable(
|
1081
|
-
upb_EpsCopyInputStream* e, const char* ptr) {
|
1082
|
-
return (e->end - ptr) + kUpb_EpsCopyInputStream_SlopBytes;
|
1351
|
+
UPB_API_INLINE bool upb_Array_IsFrozen(const struct upb_Array* arr) {
|
1352
|
+
return (arr->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_IMM) != 0;
|
1083
1353
|
}
|
1084
1354
|
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
UPB_INLINE bool upb_EpsCopyInputStream_CheckSize(
|
1092
|
-
const upb_EpsCopyInputStream* e, const char* ptr, int size) {
|
1093
|
-
UPB_ASSERT(size >= 0);
|
1094
|
-
return ptr - e->end + size <= e->limit;
|
1355
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array,
|
1356
|
+
void* data, size_t lg2) {
|
1357
|
+
UPB_ASSERT(lg2 != 1);
|
1358
|
+
UPB_ASSERT(lg2 <= 4);
|
1359
|
+
const size_t bits = lg2 - (lg2 != 0);
|
1360
|
+
array->UPB_ONLYBITS(data) = (uintptr_t)data | bits;
|
1095
1361
|
}
|
1096
1362
|
|
1097
|
-
UPB_INLINE
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
// https://godbolt.org/z/35YGPz
|
1103
|
-
// In microbenchmarks this shows a small improvement.
|
1104
|
-
uintptr_t uptr = (uintptr_t)ptr;
|
1105
|
-
uintptr_t uend = (uintptr_t)e->limit_ptr;
|
1106
|
-
uintptr_t res = uptr + (size_t)size;
|
1107
|
-
if (!submessage) uend += kUpb_EpsCopyInputStream_SlopBytes;
|
1108
|
-
// NOTE: this check depends on having a linear address space. This is not
|
1109
|
-
// technically guaranteed by uintptr_t.
|
1110
|
-
bool ret = res >= uptr && res <= uend;
|
1111
|
-
if (size < 0) UPB_ASSERT(!ret);
|
1112
|
-
return ret;
|
1363
|
+
UPB_INLINE size_t
|
1364
|
+
UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) {
|
1365
|
+
const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2;
|
1366
|
+
const size_t lg2 = bits + (bits != 0);
|
1367
|
+
return lg2;
|
1113
1368
|
}
|
1114
1369
|
|
1115
|
-
|
1116
|
-
//
|
1117
|
-
|
1118
|
-
//
|
1119
|
-
// If the size is negative, this function will always return false. This
|
1120
|
-
// property can be useful in some cases.
|
1121
|
-
UPB_INLINE bool upb_EpsCopyInputStream_CheckDataSizeAvailable(
|
1122
|
-
upb_EpsCopyInputStream* e, const char* ptr, int size) {
|
1123
|
-
return _upb_EpsCopyInputStream_CheckSizeAvailable(e, ptr, size, false);
|
1370
|
+
UPB_API_INLINE const void* upb_Array_DataPtr(const struct upb_Array* array) {
|
1371
|
+
UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions.
|
1372
|
+
return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL);
|
1124
1373
|
}
|
1125
1374
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
// sub-message is available to be parsed in the current buffer.
|
1129
|
-
//
|
1130
|
-
// This implies that all fields from the sub-message can be parsed from the
|
1131
|
-
// current buffer while maintaining the invariant that we always have at least
|
1132
|
-
// kUpb_EpsCopyInputStream_SlopBytes of data available past the beginning of
|
1133
|
-
// any individual field start.
|
1134
|
-
//
|
1135
|
-
// If the size is negative, this function will always return false. This
|
1136
|
-
// property can be useful in some cases.
|
1137
|
-
UPB_INLINE bool upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(
|
1138
|
-
upb_EpsCopyInputStream* e, const char* ptr, int size) {
|
1139
|
-
return _upb_EpsCopyInputStream_CheckSizeAvailable(e, ptr, size, true);
|
1375
|
+
UPB_API_INLINE void* upb_Array_MutableDataPtr(struct upb_Array* array) {
|
1376
|
+
return (void*)upb_Array_DataPtr(array);
|
1140
1377
|
}
|
1141
1378
|
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1379
|
+
UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_NewMaybeAllowSlow)(
|
1380
|
+
upb_Arena* arena, size_t init_capacity, int elem_size_lg2,
|
1381
|
+
bool allow_slow) {
|
1382
|
+
UPB_ASSERT(elem_size_lg2 != 1);
|
1383
|
+
UPB_ASSERT(elem_size_lg2 <= 4);
|
1384
|
+
const size_t array_size =
|
1385
|
+
UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN);
|
1386
|
+
const size_t bytes = array_size + (init_capacity << elem_size_lg2);
|
1387
|
+
size_t span = UPB_PRIVATE(_upb_Arena_AllocSpan)(bytes);
|
1388
|
+
if (!allow_slow && UPB_PRIVATE(_upb_ArenaHas)(arena) < span) return NULL;
|
1389
|
+
struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes);
|
1390
|
+
if (!array) return NULL;
|
1391
|
+
UPB_PRIVATE(_upb_Array_SetTaggedPtr)
|
1392
|
+
(array, UPB_PTR_AT(array, array_size, void), elem_size_lg2);
|
1393
|
+
array->UPB_ONLYBITS(size) = 0;
|
1394
|
+
array->UPB_PRIVATE(capacity) = init_capacity;
|
1395
|
+
return array;
|
1147
1396
|
}
|
1148
1397
|
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
// When EpsCopyInputStream supports streaming, this will need to become a
|
1155
|
-
// runtime check.
|
1156
|
-
return e->aliasing &&
|
1157
|
-
upb_EpsCopyInputStream_CheckDataSizeAvailable(e, ptr, size);
|
1398
|
+
UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena,
|
1399
|
+
size_t init_capacity,
|
1400
|
+
int elem_size_lg2) {
|
1401
|
+
return UPB_PRIVATE(_upb_Array_NewMaybeAllowSlow)(arena, init_capacity,
|
1402
|
+
elem_size_lg2, true);
|
1158
1403
|
}
|
1159
1404
|
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
upb_EpsCopyInputStream* e, const char* ptr) {
|
1165
|
-
return (const char*)(((uintptr_t)ptr) + e->input_delta);
|
1405
|
+
UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_TryFastNew)(
|
1406
|
+
upb_Arena* arena, size_t init_capacity, int elem_size_lg2) {
|
1407
|
+
return UPB_PRIVATE(_upb_Array_NewMaybeAllowSlow)(arena, init_capacity,
|
1408
|
+
elem_size_lg2, false);
|
1166
1409
|
}
|
1167
1410
|
|
1168
|
-
//
|
1169
|
-
|
1170
|
-
|
1171
|
-
//
|
1172
|
-
// REQUIRES: Aliasing must be available for the given pointer. If the input is a
|
1173
|
-
// flat buffer and aliasing is enabled, then aliasing will always be available.
|
1174
|
-
UPB_INLINE const char* upb_EpsCopyInputStream_GetAliasedPtr(
|
1175
|
-
upb_EpsCopyInputStream* e, const char* ptr) {
|
1176
|
-
UPB_ASSUME(upb_EpsCopyInputStream_AliasingAvailable(e, ptr, 0));
|
1177
|
-
return upb_EpsCopyInputStream_GetInputPtr(e, ptr);
|
1178
|
-
}
|
1411
|
+
// Resizes the capacity of the array to be at least min_size.
|
1412
|
+
bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size,
|
1413
|
+
upb_Arena* arena);
|
1179
1414
|
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
const char* ret = *ptr + size;
|
1191
|
-
*ptr = upb_EpsCopyInputStream_GetAliasedPtr(e, *ptr);
|
1192
|
-
UPB_ASSUME(ret != NULL);
|
1193
|
-
return ret;
|
1415
|
+
UPB_FORCEINLINE
|
1416
|
+
bool UPB_PRIVATE(_upb_Array_TryFastRealloc)(struct upb_Array* array,
|
1417
|
+
size_t capacity, int elem_size_lg2,
|
1418
|
+
upb_Arena* arena) {
|
1419
|
+
size_t old_bytes = array->UPB_PRIVATE(capacity) << elem_size_lg2;
|
1420
|
+
size_t new_bytes = capacity << elem_size_lg2;
|
1421
|
+
UPB_ASSUME(new_bytes > old_bytes);
|
1422
|
+
if (!upb_Arena_TryExtend(arena, array, old_bytes, new_bytes)) return false;
|
1423
|
+
array->UPB_PRIVATE(capacity) = capacity;
|
1424
|
+
return true;
|
1194
1425
|
}
|
1195
1426
|
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
return
|
1427
|
+
UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
|
1428
|
+
upb_Arena* arena) {
|
1429
|
+
UPB_ASSERT(!upb_Array_IsFrozen(array));
|
1430
|
+
if (array->UPB_PRIVATE(capacity) < size)
|
1431
|
+
return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena);
|
1432
|
+
return true;
|
1202
1433
|
}
|
1203
1434
|
|
1204
|
-
//
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1435
|
+
// Resize without initializing new elements.
|
1436
|
+
UPB_INLINE bool UPB_PRIVATE(_upb_Array_ResizeUninitialized)(
|
1437
|
+
struct upb_Array* array, size_t size, upb_Arena* arena) {
|
1438
|
+
UPB_ASSERT(!upb_Array_IsFrozen(array));
|
1439
|
+
UPB_ASSERT(size <= array->UPB_ONLYBITS(size) ||
|
1440
|
+
arena); // Allow NULL arena when shrinking.
|
1441
|
+
if (!upb_Array_Reserve(array, size, arena)) return false;
|
1442
|
+
array->UPB_ONLYBITS(size) = size;
|
1443
|
+
return true;
|
1212
1444
|
}
|
1213
1445
|
|
1214
|
-
//
|
1215
|
-
//
|
1216
|
-
//
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
return upb_EpsCopyInputStream_ReadStringAliased(e, ptr, size);
|
1226
|
-
} else {
|
1227
|
-
// We need to allocate and copy.
|
1228
|
-
if (!upb_EpsCopyInputStream_CheckDataSizeAvailable(e, *ptr, size)) {
|
1229
|
-
return NULL;
|
1230
|
-
}
|
1231
|
-
UPB_ASSERT(arena);
|
1232
|
-
char* data = (char*)upb_Arena_Malloc(arena, size);
|
1233
|
-
if (!data) return NULL;
|
1234
|
-
const char* ret = upb_EpsCopyInputStream_Copy(e, *ptr, data, size);
|
1235
|
-
*ptr = data;
|
1236
|
-
return ret;
|
1237
|
-
}
|
1446
|
+
// This function is intended for situations where elem_size is compile-time
|
1447
|
+
// constant or a known expression of the form (1 << lg2), so that the expression
|
1448
|
+
// i*elem_size does not result in an actual multiplication.
|
1449
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i,
|
1450
|
+
const void* data,
|
1451
|
+
size_t elem_size) {
|
1452
|
+
UPB_ASSERT(!upb_Array_IsFrozen(array));
|
1453
|
+
UPB_ASSERT(i < array->UPB_ONLYBITS(size));
|
1454
|
+
UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array));
|
1455
|
+
char* arr_data = (char*)upb_Array_MutableDataPtr(array);
|
1456
|
+
memcpy(arr_data + (i * elem_size), data, elem_size);
|
1238
1457
|
}
|
1239
1458
|
|
1240
|
-
|
1241
|
-
|
1459
|
+
UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array* arr) {
|
1460
|
+
return arr->UPB_ONLYBITS(size);
|
1242
1461
|
}
|
1243
1462
|
|
1244
|
-
|
1245
|
-
|
1246
|
-
// upb_EpsCopyInputStream_IsDone() will return `true` when the stream position
|
1247
|
-
// reaches this limit.
|
1248
|
-
//
|
1249
|
-
// Returns a delta that the caller must store and supply to PopLimit() below.
|
1250
|
-
UPB_INLINE int upb_EpsCopyInputStream_PushLimit(upb_EpsCopyInputStream* e,
|
1251
|
-
const char* ptr, int size) {
|
1252
|
-
int limit = size + (int)(ptr - e->end);
|
1253
|
-
int delta = e->limit - limit;
|
1254
|
-
_upb_EpsCopyInputStream_CheckLimit(e);
|
1255
|
-
UPB_ASSERT(limit <= e->limit);
|
1256
|
-
e->limit = limit;
|
1257
|
-
e->limit_ptr = e->end + UPB_MIN(0, limit);
|
1258
|
-
_upb_EpsCopyInputStream_CheckLimit(e);
|
1259
|
-
return delta;
|
1463
|
+
UPB_API_INLINE size_t upb_Array_Capacity(const struct upb_Array* arr) {
|
1464
|
+
return arr->UPB_PRIVATE(capacity);
|
1260
1465
|
}
|
1261
1466
|
|
1262
|
-
//
|
1263
|
-
// once IsDone() returns true. The user must pass the delta that was returned
|
1264
|
-
// from PushLimit().
|
1265
|
-
UPB_INLINE void upb_EpsCopyInputStream_PopLimit(upb_EpsCopyInputStream* e,
|
1266
|
-
const char* ptr,
|
1267
|
-
int saved_delta) {
|
1268
|
-
UPB_ASSERT(ptr - e->end == e->limit);
|
1269
|
-
_upb_EpsCopyInputStream_CheckLimit(e);
|
1270
|
-
e->limit += saved_delta;
|
1271
|
-
e->limit_ptr = e->end + UPB_MIN(0, e->limit);
|
1272
|
-
_upb_EpsCopyInputStream_CheckLimit(e);
|
1273
|
-
}
|
1274
|
-
|
1275
|
-
UPB_INLINE const char* _upb_EpsCopyInputStream_IsDoneFallbackInline(
|
1276
|
-
upb_EpsCopyInputStream* e, const char* ptr, int overrun,
|
1277
|
-
upb_EpsCopyInputStream_BufferFlipCallback* callback) {
|
1278
|
-
if (overrun < e->limit) {
|
1279
|
-
// Need to copy remaining data into patch buffer.
|
1280
|
-
UPB_ASSERT(overrun < kUpb_EpsCopyInputStream_SlopBytes);
|
1281
|
-
const char* old_end = ptr;
|
1282
|
-
const char* new_start = &e->patch[0] + overrun;
|
1283
|
-
memset(e->patch + kUpb_EpsCopyInputStream_SlopBytes, 0,
|
1284
|
-
kUpb_EpsCopyInputStream_SlopBytes);
|
1285
|
-
memcpy(e->patch, e->end, kUpb_EpsCopyInputStream_SlopBytes);
|
1286
|
-
ptr = new_start;
|
1287
|
-
e->end = &e->patch[kUpb_EpsCopyInputStream_SlopBytes];
|
1288
|
-
e->limit -= kUpb_EpsCopyInputStream_SlopBytes;
|
1289
|
-
e->limit_ptr = e->end + e->limit;
|
1290
|
-
UPB_ASSERT(ptr < e->limit_ptr);
|
1291
|
-
e->input_delta = (uintptr_t)old_end - (uintptr_t)new_start;
|
1292
|
-
return callback(e, old_end, new_start);
|
1293
|
-
} else {
|
1294
|
-
UPB_ASSERT(overrun > e->limit);
|
1295
|
-
e->error = true;
|
1296
|
-
return callback(e, NULL, NULL);
|
1297
|
-
}
|
1298
|
-
}
|
1299
|
-
|
1300
|
-
typedef const char* upb_EpsCopyInputStream_ParseDelimitedFunc(
|
1301
|
-
upb_EpsCopyInputStream* e, const char* ptr, void* ctx);
|
1302
|
-
|
1303
|
-
// Tries to perform a fast-path handling of the given delimited message data.
|
1304
|
-
// If the sub-message beginning at `*ptr` and extending for `len` is short and
|
1305
|
-
// fits within this buffer, calls `func` with `ctx` as a parameter, where the
|
1306
|
-
// pushing and popping of limits is handled automatically and with lower cost
|
1307
|
-
// than the normal PushLimit()/PopLimit() sequence.
|
1308
|
-
UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast(
|
1309
|
-
upb_EpsCopyInputStream* e, const char** ptr, int len,
|
1310
|
-
upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) {
|
1311
|
-
if (!upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(e, *ptr, len)) {
|
1312
|
-
return false;
|
1313
|
-
}
|
1314
|
-
|
1315
|
-
// Fast case: Sub-message is <128 bytes and fits in the current buffer.
|
1316
|
-
// This means we can preserve limit/limit_ptr verbatim.
|
1317
|
-
const char* saved_limit_ptr = e->limit_ptr;
|
1318
|
-
int saved_limit = e->limit;
|
1319
|
-
e->limit_ptr = *ptr + len;
|
1320
|
-
e->limit = e->limit_ptr - e->end;
|
1321
|
-
UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit));
|
1322
|
-
*ptr = func(e, *ptr, ctx);
|
1323
|
-
e->limit_ptr = saved_limit_ptr;
|
1324
|
-
e->limit = saved_limit;
|
1325
|
-
UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit));
|
1326
|
-
return true;
|
1327
|
-
}
|
1467
|
+
// LINT.ThenChange(GoogleInternalName0)
|
1328
1468
|
|
1329
1469
|
#ifdef __cplusplus
|
1330
1470
|
} /* extern "C" */
|
1331
1471
|
#endif
|
1332
1472
|
|
1333
|
-
|
1334
|
-
#
|
1335
|
-
|
1336
|
-
#ifndef UPB_JSON_DECODE_H_
|
1337
|
-
#define UPB_JSON_DECODE_H_
|
1338
|
-
|
1339
|
-
#include <stddef.h>
|
1473
|
+
#undef _UPB_ARRAY_MASK_IMM
|
1474
|
+
#undef _UPB_ARRAY_MASK_LG2
|
1475
|
+
#undef _UPB_ARRAY_MASK_ALL
|
1340
1476
|
|
1341
1477
|
|
1342
|
-
|
1343
|
-
//
|
1344
|
-
// MiniTable-based accessors live in accessors.h.
|
1478
|
+
#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */
|
1345
1479
|
|
1346
|
-
#ifndef
|
1347
|
-
#define
|
1480
|
+
#ifndef UPB_MESSAGE_INTERNAL_TYPES_H_
|
1481
|
+
#define UPB_MESSAGE_INTERNAL_TYPES_H_
|
1348
1482
|
|
1349
|
-
#include <stddef.h>
|
1350
1483
|
#include <stdint.h>
|
1351
1484
|
|
1352
|
-
#ifndef UPB_BASE_STRING_VIEW_H_
|
1353
|
-
#define UPB_BASE_STRING_VIEW_H_
|
1354
|
-
|
1355
|
-
#include <string.h>
|
1356
|
-
|
1357
1485
|
// Must be last.
|
1358
1486
|
|
1359
|
-
#define
|
1360
|
-
{ ptr, len }
|
1361
|
-
|
1362
|
-
#define UPB_STRINGVIEW_FORMAT "%.*s"
|
1363
|
-
#define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data
|
1487
|
+
#define UPB_OPAQUE(x) x##_opaque
|
1364
1488
|
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
}
|
1489
|
+
struct upb_Message {
|
1490
|
+
union {
|
1491
|
+
uintptr_t UPB_OPAQUE(internal); // tagged pointer, low bit == frozen
|
1492
|
+
double d; // Forces same size for 32-bit/64-bit builds
|
1493
|
+
};
|
1494
|
+
};
|
1370
1495
|
|
1371
1496
|
#ifdef __cplusplus
|
1372
1497
|
extern "C" {
|
1373
1498
|
#endif
|
1374
1499
|
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
ret.data = data;
|
1379
|
-
ret.size = size;
|
1380
|
-
return ret;
|
1500
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Message_ShallowFreeze)(
|
1501
|
+
struct upb_Message* msg) {
|
1502
|
+
msg->UPB_OPAQUE(internal) |= 1ULL;
|
1381
1503
|
}
|
1382
1504
|
|
1383
|
-
|
1384
|
-
return
|
1505
|
+
UPB_API_INLINE bool upb_Message_IsFrozen(const struct upb_Message* msg) {
|
1506
|
+
return (msg->UPB_OPAQUE(internal) & 1ULL) != 0;
|
1385
1507
|
}
|
1386
1508
|
|
1387
|
-
UPB_INLINE
|
1388
|
-
|
1509
|
+
UPB_INLINE struct upb_Message_Internal* UPB_PRIVATE(_upb_Message_GetInternal)(
|
1510
|
+
const struct upb_Message* msg) {
|
1511
|
+
const uintptr_t tmp = msg->UPB_OPAQUE(internal) & ~1ULL;
|
1512
|
+
return (struct upb_Message_Internal*)tmp;
|
1389
1513
|
}
|
1390
1514
|
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
if (result == 0) {
|
1396
|
-
return a.size - b.size;
|
1397
|
-
}
|
1398
|
-
return result;
|
1515
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetInternal)(
|
1516
|
+
struct upb_Message* msg, struct upb_Message_Internal* internal) {
|
1517
|
+
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
1518
|
+
msg->UPB_OPAQUE(internal) = (uintptr_t)internal;
|
1399
1519
|
}
|
1400
1520
|
|
1401
|
-
// LINT.ThenChange(
|
1402
|
-
// GoogleInternalName1,
|
1403
|
-
// //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string,
|
1404
|
-
// //depot/google3/third_party/upb/bits/typescript/string_view.ts
|
1405
|
-
// )
|
1406
|
-
|
1407
1521
|
#ifdef __cplusplus
|
1408
1522
|
} /* extern "C" */
|
1409
1523
|
#endif
|
1410
1524
|
|
1411
|
-
|
1412
|
-
#endif /* UPB_BASE_STRING_VIEW_H_ */
|
1413
|
-
|
1414
|
-
#ifndef UPB_MESSAGE_ARRAY_H_
|
1415
|
-
#define UPB_MESSAGE_ARRAY_H_
|
1416
|
-
|
1417
|
-
#include <stddef.h>
|
1525
|
+
#undef UPB_OPAQUE
|
1418
1526
|
|
1419
1527
|
|
1420
|
-
#
|
1421
|
-
#define UPB_BASE_DESCRIPTOR_CONSTANTS_H_
|
1528
|
+
#endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */
|
1422
1529
|
|
1423
|
-
//
|
1530
|
+
// Users should include array.h or map.h instead.
|
1531
|
+
// IWYU pragma: private, include "upb/message/array.h"
|
1424
1532
|
|
1425
|
-
|
1426
|
-
|
1427
|
-
// types (we distinguish the two with the "integer encoding" enum below).
|
1428
|
-
// This enum is an internal convenience only and has no meaning outside of upb.
|
1429
|
-
typedef enum {
|
1430
|
-
kUpb_CType_Bool = 1,
|
1431
|
-
kUpb_CType_Float = 2,
|
1432
|
-
kUpb_CType_Int32 = 3,
|
1433
|
-
kUpb_CType_UInt32 = 4,
|
1434
|
-
kUpb_CType_Enum = 5, // Enum values are int32. TODO: rename
|
1435
|
-
kUpb_CType_Message = 6,
|
1436
|
-
kUpb_CType_Double = 7,
|
1437
|
-
kUpb_CType_Int64 = 8,
|
1438
|
-
kUpb_CType_UInt64 = 9,
|
1439
|
-
kUpb_CType_String = 10,
|
1440
|
-
kUpb_CType_Bytes = 11
|
1441
|
-
} upb_CType;
|
1533
|
+
#ifndef UPB_MESSAGE_VALUE_H_
|
1534
|
+
#define UPB_MESSAGE_VALUE_H_
|
1442
1535
|
|
1443
|
-
|
1444
|
-
|
1445
|
-
kUpb_Label_Optional = 1,
|
1446
|
-
kUpb_Label_Required = 2,
|
1447
|
-
kUpb_Label_Repeated = 3
|
1448
|
-
} upb_Label;
|
1536
|
+
#include <stdint.h>
|
1537
|
+
#include <string.h>
|
1449
1538
|
|
1450
|
-
// Descriptor types, as defined in descriptor.proto.
|
1451
|
-
typedef enum {
|
1452
|
-
kUpb_FieldType_Double = 1,
|
1453
|
-
kUpb_FieldType_Float = 2,
|
1454
|
-
kUpb_FieldType_Int64 = 3,
|
1455
|
-
kUpb_FieldType_UInt64 = 4,
|
1456
|
-
kUpb_FieldType_Int32 = 5,
|
1457
|
-
kUpb_FieldType_Fixed64 = 6,
|
1458
|
-
kUpb_FieldType_Fixed32 = 7,
|
1459
|
-
kUpb_FieldType_Bool = 8,
|
1460
|
-
kUpb_FieldType_String = 9,
|
1461
|
-
kUpb_FieldType_Group = 10,
|
1462
|
-
kUpb_FieldType_Message = 11,
|
1463
|
-
kUpb_FieldType_Bytes = 12,
|
1464
|
-
kUpb_FieldType_UInt32 = 13,
|
1465
|
-
kUpb_FieldType_Enum = 14,
|
1466
|
-
kUpb_FieldType_SFixed32 = 15,
|
1467
|
-
kUpb_FieldType_SFixed64 = 16,
|
1468
|
-
kUpb_FieldType_SInt32 = 17,
|
1469
|
-
kUpb_FieldType_SInt64 = 18,
|
1470
|
-
} upb_FieldType;
|
1471
1539
|
|
1472
|
-
|
1540
|
+
// Must be last.
|
1473
1541
|
|
1474
1542
|
#ifdef __cplusplus
|
1475
1543
|
extern "C" {
|
1476
1544
|
#endif
|
1477
1545
|
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
kUpb_CType_Message, // kUpb_FieldType_Group
|
1491
|
-
kUpb_CType_Message, // kUpb_FieldType_Message
|
1492
|
-
kUpb_CType_Bytes, // kUpb_FieldType_Bytes
|
1493
|
-
kUpb_CType_UInt32, // kUpb_FieldType_UInt32
|
1494
|
-
kUpb_CType_Enum, // kUpb_FieldType_Enum
|
1495
|
-
kUpb_CType_Int32, // kUpb_FieldType_SFixed32
|
1496
|
-
kUpb_CType_Int64, // kUpb_FieldType_SFixed64
|
1497
|
-
kUpb_CType_Int32, // kUpb_FieldType_SInt32
|
1498
|
-
kUpb_CType_Int64, // kUpb_FieldType_SInt64
|
1499
|
-
};
|
1546
|
+
typedef union {
|
1547
|
+
bool bool_val;
|
1548
|
+
float float_val;
|
1549
|
+
double double_val;
|
1550
|
+
int32_t int32_val;
|
1551
|
+
int64_t int64_val;
|
1552
|
+
uint32_t uint32_val;
|
1553
|
+
uint64_t uint64_val;
|
1554
|
+
const struct upb_Array* array_val;
|
1555
|
+
const struct upb_Map* map_val;
|
1556
|
+
const struct upb_Message* msg_val;
|
1557
|
+
upb_StringView str_val;
|
1500
1558
|
|
1501
|
-
//
|
1502
|
-
|
1559
|
+
// EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of
|
1560
|
+
// msg_val if unlinked sub-messages may possibly be in use. See the
|
1561
|
+
// documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more
|
1562
|
+
// information.
|
1563
|
+
uintptr_t tagged_msg_val; // upb_TaggedMessagePtr
|
1564
|
+
|
1565
|
+
// For an extension field, we are essentially treating ext->data (a
|
1566
|
+
// upb_MessageValue) as if it were a message with one field that lives at
|
1567
|
+
// offset 0. This works because upb_MessageValue is precisely one value that
|
1568
|
+
// can hold any type of data. Recall that an extension can be of any type
|
1569
|
+
// (scalar, repeated, or message). For a message extension, that will be a
|
1570
|
+
// single upb_Message* at offset 0 of the upb_MessageValue.
|
1571
|
+
struct upb_Message UPB_PRIVATE(ext_msg_val);
|
1572
|
+
} upb_MessageValue;
|
1573
|
+
|
1574
|
+
UPB_API_INLINE upb_MessageValue upb_MessageValue_Zero(void) {
|
1575
|
+
upb_MessageValue zero;
|
1576
|
+
memset(&zero, 0, sizeof(zero));
|
1577
|
+
return zero;
|
1503
1578
|
}
|
1504
1579
|
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1580
|
+
typedef union {
|
1581
|
+
struct upb_Array* array;
|
1582
|
+
struct upb_Map* map;
|
1583
|
+
struct upb_Message* msg;
|
1584
|
+
} upb_MutableMessageValue;
|
1585
|
+
|
1586
|
+
UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) {
|
1587
|
+
upb_MutableMessageValue zero;
|
1588
|
+
memset(&zero, 0, sizeof(zero));
|
1589
|
+
return zero;
|
1514
1590
|
}
|
1515
1591
|
|
1516
1592
|
#ifdef __cplusplus
|
@@ -1518,265 +1594,12 @@ UPB_INLINE bool upb_FieldType_IsPackable(upb_FieldType field_type) {
|
|
1518
1594
|
#endif
|
1519
1595
|
|
1520
1596
|
|
1521
|
-
#endif /*
|
1597
|
+
#endif /* UPB_MESSAGE_VALUE_H_ */
|
1522
1598
|
|
1523
|
-
#ifndef
|
1524
|
-
#define
|
1599
|
+
#ifndef UPB_MINI_TABLE_MESSAGE_H_
|
1600
|
+
#define UPB_MINI_TABLE_MESSAGE_H_
|
1525
1601
|
|
1526
1602
|
#include <stdint.h>
|
1527
|
-
#include <string.h>
|
1528
|
-
|
1529
|
-
|
1530
|
-
// Must be last.
|
1531
|
-
|
1532
|
-
#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit.
|
1533
|
-
#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size.
|
1534
|
-
#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2)
|
1535
|
-
|
1536
|
-
#ifdef __cplusplus
|
1537
|
-
extern "C" {
|
1538
|
-
#endif
|
1539
|
-
|
1540
|
-
// LINT.IfChange(upb_Array)
|
1541
|
-
|
1542
|
-
// Our internal representation for repeated fields.
|
1543
|
-
struct upb_Array {
|
1544
|
-
// This is a tagged pointer. Bits #0 and #1 encode the elem size as follows:
|
1545
|
-
// 0 maps to elem size 1
|
1546
|
-
// 1 maps to elem size 4
|
1547
|
-
// 2 maps to elem size 8
|
1548
|
-
// 3 maps to elem size 16
|
1549
|
-
//
|
1550
|
-
// Bit #2 contains the frozen/immutable flag.
|
1551
|
-
uintptr_t UPB_ONLYBITS(data);
|
1552
|
-
|
1553
|
-
size_t UPB_ONLYBITS(size); // The number of elements in the array.
|
1554
|
-
size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements.
|
1555
|
-
};
|
1556
|
-
|
1557
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Array_ShallowFreeze)(struct upb_Array* arr) {
|
1558
|
-
arr->UPB_ONLYBITS(data) |= _UPB_ARRAY_MASK_IMM;
|
1559
|
-
}
|
1560
|
-
|
1561
|
-
UPB_API_INLINE bool upb_Array_IsFrozen(const struct upb_Array* arr) {
|
1562
|
-
return (arr->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_IMM) != 0;
|
1563
|
-
}
|
1564
|
-
|
1565
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(struct upb_Array* array,
|
1566
|
-
void* data, size_t lg2) {
|
1567
|
-
UPB_ASSERT(lg2 != 1);
|
1568
|
-
UPB_ASSERT(lg2 <= 4);
|
1569
|
-
const size_t bits = lg2 - (lg2 != 0);
|
1570
|
-
array->UPB_ONLYBITS(data) = (uintptr_t)data | bits;
|
1571
|
-
}
|
1572
|
-
|
1573
|
-
UPB_INLINE size_t
|
1574
|
-
UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const struct upb_Array* array) {
|
1575
|
-
const size_t bits = array->UPB_ONLYBITS(data) & _UPB_ARRAY_MASK_LG2;
|
1576
|
-
const size_t lg2 = bits + (bits != 0);
|
1577
|
-
return lg2;
|
1578
|
-
}
|
1579
|
-
|
1580
|
-
UPB_API_INLINE const void* upb_Array_DataPtr(const struct upb_Array* array) {
|
1581
|
-
UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions.
|
1582
|
-
return (void*)(array->UPB_ONLYBITS(data) & ~(uintptr_t)_UPB_ARRAY_MASK_ALL);
|
1583
|
-
}
|
1584
|
-
|
1585
|
-
UPB_API_INLINE void* upb_Array_MutableDataPtr(struct upb_Array* array) {
|
1586
|
-
return (void*)upb_Array_DataPtr(array);
|
1587
|
-
}
|
1588
|
-
|
1589
|
-
UPB_INLINE struct upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena,
|
1590
|
-
size_t init_capacity,
|
1591
|
-
int elem_size_lg2) {
|
1592
|
-
UPB_ASSERT(elem_size_lg2 != 1);
|
1593
|
-
UPB_ASSERT(elem_size_lg2 <= 4);
|
1594
|
-
const size_t array_size =
|
1595
|
-
UPB_ALIGN_UP(sizeof(struct upb_Array), UPB_MALLOC_ALIGN);
|
1596
|
-
const size_t bytes = array_size + (init_capacity << elem_size_lg2);
|
1597
|
-
struct upb_Array* array = (struct upb_Array*)upb_Arena_Malloc(arena, bytes);
|
1598
|
-
if (!array) return NULL;
|
1599
|
-
UPB_PRIVATE(_upb_Array_SetTaggedPtr)
|
1600
|
-
(array, UPB_PTR_AT(array, array_size, void), elem_size_lg2);
|
1601
|
-
array->UPB_ONLYBITS(size) = 0;
|
1602
|
-
array->UPB_PRIVATE(capacity) = init_capacity;
|
1603
|
-
return array;
|
1604
|
-
}
|
1605
|
-
|
1606
|
-
// Resizes the capacity of the array to be at least min_size.
|
1607
|
-
bool UPB_PRIVATE(_upb_Array_Realloc)(struct upb_Array* array, size_t min_size,
|
1608
|
-
upb_Arena* arena);
|
1609
|
-
|
1610
|
-
UPB_API_INLINE bool upb_Array_Reserve(struct upb_Array* array, size_t size,
|
1611
|
-
upb_Arena* arena) {
|
1612
|
-
UPB_ASSERT(!upb_Array_IsFrozen(array));
|
1613
|
-
if (array->UPB_PRIVATE(capacity) < size)
|
1614
|
-
return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena);
|
1615
|
-
return true;
|
1616
|
-
}
|
1617
|
-
|
1618
|
-
// Resize without initializing new elements.
|
1619
|
-
UPB_INLINE bool UPB_PRIVATE(_upb_Array_ResizeUninitialized)(
|
1620
|
-
struct upb_Array* array, size_t size, upb_Arena* arena) {
|
1621
|
-
UPB_ASSERT(!upb_Array_IsFrozen(array));
|
1622
|
-
UPB_ASSERT(size <= array->UPB_ONLYBITS(size) ||
|
1623
|
-
arena); // Allow NULL arena when shrinking.
|
1624
|
-
if (!upb_Array_Reserve(array, size, arena)) return false;
|
1625
|
-
array->UPB_ONLYBITS(size) = size;
|
1626
|
-
return true;
|
1627
|
-
}
|
1628
|
-
|
1629
|
-
// This function is intended for situations where elem_size is compile-time
|
1630
|
-
// constant or a known expression of the form (1 << lg2), so that the expression
|
1631
|
-
// i*elem_size does not result in an actual multiplication.
|
1632
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(struct upb_Array* array, size_t i,
|
1633
|
-
const void* data,
|
1634
|
-
size_t elem_size) {
|
1635
|
-
UPB_ASSERT(!upb_Array_IsFrozen(array));
|
1636
|
-
UPB_ASSERT(i < array->UPB_ONLYBITS(size));
|
1637
|
-
UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array));
|
1638
|
-
char* arr_data = (char*)upb_Array_MutableDataPtr(array);
|
1639
|
-
memcpy(arr_data + (i * elem_size), data, elem_size);
|
1640
|
-
}
|
1641
|
-
|
1642
|
-
UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array* arr) {
|
1643
|
-
return arr->UPB_ONLYBITS(size);
|
1644
|
-
}
|
1645
|
-
|
1646
|
-
// LINT.ThenChange(GoogleInternalName0)
|
1647
|
-
|
1648
|
-
#ifdef __cplusplus
|
1649
|
-
} /* extern "C" */
|
1650
|
-
#endif
|
1651
|
-
|
1652
|
-
#undef _UPB_ARRAY_MASK_IMM
|
1653
|
-
#undef _UPB_ARRAY_MASK_LG2
|
1654
|
-
#undef _UPB_ARRAY_MASK_ALL
|
1655
|
-
|
1656
|
-
|
1657
|
-
#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */
|
1658
|
-
|
1659
|
-
#ifndef UPB_MESSAGE_INTERNAL_TYPES_H_
|
1660
|
-
#define UPB_MESSAGE_INTERNAL_TYPES_H_
|
1661
|
-
|
1662
|
-
#include <stdint.h>
|
1663
|
-
|
1664
|
-
// Must be last.
|
1665
|
-
|
1666
|
-
#define UPB_OPAQUE(x) x##_opaque
|
1667
|
-
|
1668
|
-
struct upb_Message {
|
1669
|
-
union {
|
1670
|
-
uintptr_t UPB_OPAQUE(internal); // tagged pointer, low bit == frozen
|
1671
|
-
double d; // Forces same size for 32-bit/64-bit builds
|
1672
|
-
};
|
1673
|
-
};
|
1674
|
-
|
1675
|
-
#ifdef __cplusplus
|
1676
|
-
extern "C" {
|
1677
|
-
#endif
|
1678
|
-
|
1679
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Message_ShallowFreeze)(
|
1680
|
-
struct upb_Message* msg) {
|
1681
|
-
msg->UPB_OPAQUE(internal) |= 1ULL;
|
1682
|
-
}
|
1683
|
-
|
1684
|
-
UPB_API_INLINE bool upb_Message_IsFrozen(const struct upb_Message* msg) {
|
1685
|
-
return (msg->UPB_OPAQUE(internal) & 1ULL) != 0;
|
1686
|
-
}
|
1687
|
-
|
1688
|
-
UPB_INLINE struct upb_Message_Internal* UPB_PRIVATE(_upb_Message_GetInternal)(
|
1689
|
-
const struct upb_Message* msg) {
|
1690
|
-
const uintptr_t tmp = msg->UPB_OPAQUE(internal) & ~1ULL;
|
1691
|
-
return (struct upb_Message_Internal*)tmp;
|
1692
|
-
}
|
1693
|
-
|
1694
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetInternal)(
|
1695
|
-
struct upb_Message* msg, struct upb_Message_Internal* internal) {
|
1696
|
-
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
1697
|
-
msg->UPB_OPAQUE(internal) = (uintptr_t)internal;
|
1698
|
-
}
|
1699
|
-
|
1700
|
-
#ifdef __cplusplus
|
1701
|
-
} /* extern "C" */
|
1702
|
-
#endif
|
1703
|
-
|
1704
|
-
#undef UPB_OPAQUE
|
1705
|
-
|
1706
|
-
|
1707
|
-
#endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */
|
1708
|
-
|
1709
|
-
// Users should include array.h or map.h instead.
|
1710
|
-
// IWYU pragma: private, include "upb/message/array.h"
|
1711
|
-
|
1712
|
-
#ifndef UPB_MESSAGE_VALUE_H_
|
1713
|
-
#define UPB_MESSAGE_VALUE_H_
|
1714
|
-
|
1715
|
-
#include <stdint.h>
|
1716
|
-
#include <string.h>
|
1717
|
-
|
1718
|
-
|
1719
|
-
// Must be last.
|
1720
|
-
|
1721
|
-
#ifdef __cplusplus
|
1722
|
-
extern "C" {
|
1723
|
-
#endif
|
1724
|
-
|
1725
|
-
typedef union {
|
1726
|
-
bool bool_val;
|
1727
|
-
float float_val;
|
1728
|
-
double double_val;
|
1729
|
-
int32_t int32_val;
|
1730
|
-
int64_t int64_val;
|
1731
|
-
uint32_t uint32_val;
|
1732
|
-
uint64_t uint64_val;
|
1733
|
-
const struct upb_Array* array_val;
|
1734
|
-
const struct upb_Map* map_val;
|
1735
|
-
const struct upb_Message* msg_val;
|
1736
|
-
upb_StringView str_val;
|
1737
|
-
|
1738
|
-
// EXPERIMENTAL: A tagged upb_Message*. Users must use this instead of
|
1739
|
-
// msg_val if unlinked sub-messages may possibly be in use. See the
|
1740
|
-
// documentation in kUpb_DecodeOption_ExperimentalAllowUnlinked for more
|
1741
|
-
// information.
|
1742
|
-
uintptr_t tagged_msg_val; // upb_TaggedMessagePtr
|
1743
|
-
|
1744
|
-
// For an extension field, we are essentially treating ext->data (a
|
1745
|
-
// upb_MessageValue) as if it were a message with one field that lives at
|
1746
|
-
// offset 0. This works because upb_MessageValue is precisely one value that
|
1747
|
-
// can hold any type of data. Recall that an extension can be of any type
|
1748
|
-
// (scalar, repeated, or message). For a message extension, that will be a
|
1749
|
-
// single upb_Message* at offset 0 of the upb_MessageValue.
|
1750
|
-
struct upb_Message UPB_PRIVATE(ext_msg_val);
|
1751
|
-
} upb_MessageValue;
|
1752
|
-
|
1753
|
-
UPB_API_INLINE upb_MessageValue upb_MessageValue_Zero(void) {
|
1754
|
-
upb_MessageValue zero;
|
1755
|
-
memset(&zero, 0, sizeof(zero));
|
1756
|
-
return zero;
|
1757
|
-
}
|
1758
|
-
|
1759
|
-
typedef union {
|
1760
|
-
struct upb_Array* array;
|
1761
|
-
struct upb_Map* map;
|
1762
|
-
struct upb_Message* msg;
|
1763
|
-
} upb_MutableMessageValue;
|
1764
|
-
|
1765
|
-
UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) {
|
1766
|
-
upb_MutableMessageValue zero;
|
1767
|
-
memset(&zero, 0, sizeof(zero));
|
1768
|
-
return zero;
|
1769
|
-
}
|
1770
|
-
|
1771
|
-
#ifdef __cplusplus
|
1772
|
-
} /* extern "C" */
|
1773
|
-
#endif
|
1774
|
-
|
1775
|
-
|
1776
|
-
#endif /* UPB_MESSAGE_VALUE_H_ */
|
1777
|
-
|
1778
|
-
#ifndef UPB_MINI_TABLE_MESSAGE_H_
|
1779
|
-
#define UPB_MINI_TABLE_MESSAGE_H_
|
1780
1603
|
|
1781
1604
|
|
1782
1605
|
#ifndef UPB_MINI_TABLE_ENUM_H_
|
@@ -2057,7 +1880,7 @@ UPB_INLINE char UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(
|
|
2057
1880
|
const struct upb_MiniTableField* f) {
|
2058
1881
|
UPB_ASSERT(UPB_PRIVATE(_upb_MiniTableField_HasHasbit)(f));
|
2059
1882
|
const uint16_t index = f->presence;
|
2060
|
-
return 1 << (index % 8);
|
1883
|
+
return (char)(1 << (index % 8));
|
2061
1884
|
}
|
2062
1885
|
|
2063
1886
|
UPB_INLINE uint16_t UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(
|
@@ -2242,9 +2065,11 @@ UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableSub_Message(
|
|
2242
2065
|
|
2243
2066
|
struct upb_Decoder;
|
2244
2067
|
struct upb_Message;
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2068
|
+
|
2069
|
+
typedef UPB_PRESERVE_NONE const char* _upb_FieldParser(
|
2070
|
+
struct upb_Decoder* d, const char* ptr, struct upb_Message* msg,
|
2071
|
+
intptr_t table, uint64_t hasbits, uint64_t data);
|
2072
|
+
|
2248
2073
|
typedef struct {
|
2249
2074
|
uint64_t field_data;
|
2250
2075
|
_upb_FieldParser* field_parser;
|
@@ -2262,8 +2087,12 @@ typedef enum {
|
|
2262
2087
|
kUpb_ExtMode_IsMapEntry = 4,
|
2263
2088
|
} upb_ExtMode;
|
2264
2089
|
|
2265
|
-
|
2266
|
-
|
2090
|
+
enum {
|
2091
|
+
kUpb_Message_Align = 8,
|
2092
|
+
};
|
2093
|
+
|
2094
|
+
// upb_MiniTable represents the memory layout of a given upb_MessageDef.
|
2095
|
+
// The members are public so generated code can initialize them,
|
2267
2096
|
// but users MUST NOT directly read or write any of its members.
|
2268
2097
|
|
2269
2098
|
// LINT.IfChange(minitable_struct_definition)
|
@@ -2271,8 +2100,8 @@ struct upb_MiniTable {
|
|
2271
2100
|
const upb_MiniTableSubInternal* UPB_PRIVATE(subs);
|
2272
2101
|
const struct upb_MiniTableField* UPB_ONLYBITS(fields);
|
2273
2102
|
|
2274
|
-
// Must be aligned to
|
2275
|
-
// unknown fields, extension dict, pointer to msglayout, etc.
|
2103
|
+
// Must be aligned to kUpb_Message_Align. Doesn't include internal members
|
2104
|
+
// like unknown fields, extension dict, pointer to msglayout, etc.
|
2276
2105
|
uint16_t UPB_PRIVATE(size);
|
2277
2106
|
|
2278
2107
|
uint16_t UPB_ONLYBITS(field_count);
|
@@ -2286,10 +2115,9 @@ struct upb_MiniTable {
|
|
2286
2115
|
const char* UPB_PRIVATE(full_name);
|
2287
2116
|
#endif
|
2288
2117
|
|
2289
|
-
#
|
2290
|
-
//
|
2291
|
-
//
|
2292
|
-
// of flexible array members is a GNU extension, not in C99 unfortunately.
|
2118
|
+
#if UPB_FASTTABLE || !defined(__cplusplus)
|
2119
|
+
// Flexible array member is not supported in C++, but it is an extension in
|
2120
|
+
// every compiler that supports UPB_FASTTABLE.
|
2293
2121
|
_upb_FastTable_Entry UPB_PRIVATE(fasttable)[];
|
2294
2122
|
#endif
|
2295
2123
|
};
|
@@ -2299,6 +2127,13 @@ struct upb_MiniTable {
|
|
2299
2127
|
extern "C" {
|
2300
2128
|
#endif
|
2301
2129
|
|
2130
|
+
UPB_INLINE void UPB_PRIVATE(upb_MiniTable_CheckInvariants)(
|
2131
|
+
const struct upb_MiniTable* mt) {
|
2132
|
+
UPB_STATIC_ASSERT(UPB_MALLOC_ALIGN >= kUpb_Message_Align, "Under aligned");
|
2133
|
+
UPB_STATIC_ASSERT(kUpb_Message_Align >= UPB_ALIGN_OF(void*), "Under aligned");
|
2134
|
+
UPB_ASSERT(mt->UPB_PRIVATE(size) % kUpb_Message_Align == 0);
|
2135
|
+
}
|
2136
|
+
|
2302
2137
|
UPB_INLINE const struct upb_MiniTable* UPB_PRIVATE(
|
2303
2138
|
_upb_MiniTable_StrongReference)(const struct upb_MiniTable* mt) {
|
2304
2139
|
#if defined(__GNUC__)
|
@@ -2320,6 +2155,54 @@ UPB_API_INLINE int upb_MiniTable_FieldCount(const struct upb_MiniTable* m) {
|
|
2320
2155
|
return m->UPB_ONLYBITS(field_count);
|
2321
2156
|
}
|
2322
2157
|
|
2158
|
+
UPB_API_INLINE bool upb_MiniTable_IsMessageSet(const struct upb_MiniTable* m) {
|
2159
|
+
return m->UPB_PRIVATE(ext) == kUpb_ExtMode_IsMessageSet;
|
2160
|
+
}
|
2161
|
+
|
2162
|
+
UPB_API_INLINE
|
2163
|
+
const struct upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
|
2164
|
+
const struct upb_MiniTable* m, uint32_t number) {
|
2165
|
+
const size_t i = ((size_t)number) - 1; // 0 wraps to SIZE_MAX
|
2166
|
+
|
2167
|
+
// Ideal case: index into dense fields
|
2168
|
+
if (i < m->UPB_PRIVATE(dense_below)) {
|
2169
|
+
UPB_ASSERT(m->UPB_ONLYBITS(fields)[i].UPB_ONLYBITS(number) == number);
|
2170
|
+
return &m->UPB_ONLYBITS(fields)[i];
|
2171
|
+
}
|
2172
|
+
|
2173
|
+
// Early exit if the field number is out of range.
|
2174
|
+
int32_t hi = m->UPB_ONLYBITS(field_count) - 1;
|
2175
|
+
if (hi < 0 || number > m->UPB_ONLYBITS(fields)[hi].UPB_ONLYBITS(number)) {
|
2176
|
+
return NULL;
|
2177
|
+
}
|
2178
|
+
|
2179
|
+
// Slow case: binary search
|
2180
|
+
uint32_t lo = m->UPB_PRIVATE(dense_below);
|
2181
|
+
const struct upb_MiniTableField* base = m->UPB_ONLYBITS(fields);
|
2182
|
+
while (hi >= (int32_t)lo) {
|
2183
|
+
uint32_t mid = (hi + lo) / 2;
|
2184
|
+
uint32_t num = base[mid].UPB_ONLYBITS(number);
|
2185
|
+
// These comparison operations allow, on ARM machines, to fuse all these
|
2186
|
+
// branches into one comparison followed by two CSELs to set the lo/hi
|
2187
|
+
// values, followed by a BNE to continue or terminate the loop. Since binary
|
2188
|
+
// search branches are generally unpredictable (50/50 in each direction),
|
2189
|
+
// this is a good deal. We use signed for the high, as this decrement may
|
2190
|
+
// underflow if mid is 0.
|
2191
|
+
int32_t hi_mid = mid - 1;
|
2192
|
+
uint32_t lo_mid = mid + 1;
|
2193
|
+
if (num == number) {
|
2194
|
+
return &base[mid];
|
2195
|
+
}
|
2196
|
+
if (UPB_UNPREDICTABLE(num < number)) {
|
2197
|
+
lo = lo_mid;
|
2198
|
+
} else {
|
2199
|
+
hi = hi_mid;
|
2200
|
+
}
|
2201
|
+
}
|
2202
|
+
|
2203
|
+
return NULL;
|
2204
|
+
}
|
2205
|
+
|
2323
2206
|
UPB_INLINE bool UPB_PRIVATE(_upb_MiniTable_IsEmpty)(
|
2324
2207
|
const struct upb_MiniTable* m) {
|
2325
2208
|
extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_Empty);
|
@@ -2431,7 +2314,7 @@ typedef struct upb_MiniTable upb_MiniTable;
|
|
2431
2314
|
extern "C" {
|
2432
2315
|
#endif
|
2433
2316
|
|
2434
|
-
|
2317
|
+
UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_FindFieldByNumber(
|
2435
2318
|
const upb_MiniTable* m, uint32_t number);
|
2436
2319
|
|
2437
2320
|
UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex(
|
@@ -2439,6 +2322,8 @@ UPB_API_INLINE const upb_MiniTableField* upb_MiniTable_GetFieldByIndex(
|
|
2439
2322
|
|
2440
2323
|
UPB_API_INLINE int upb_MiniTable_FieldCount(const upb_MiniTable* m);
|
2441
2324
|
|
2325
|
+
UPB_API_INLINE bool upb_MiniTable_IsMessageSet(const upb_MiniTable* m);
|
2326
|
+
|
2442
2327
|
// DEPRECATED: use upb_MiniTable_SubMessage() instead
|
2443
2328
|
// Returns the MiniTable for a message field, NULL if the field is unlinked.
|
2444
2329
|
UPB_API_INLINE const upb_MiniTable* upb_MiniTable_GetSubMessageTable(
|
@@ -2517,6 +2402,9 @@ UPB_API upb_Array* upb_Array_New(upb_Arena* a, upb_CType type);
|
|
2517
2402
|
// Returns the number of elements in the array.
|
2518
2403
|
UPB_API_INLINE size_t upb_Array_Size(const upb_Array* arr);
|
2519
2404
|
|
2405
|
+
// Returns the number of elements in the array.
|
2406
|
+
UPB_API_INLINE size_t upb_Array_Capacity(const upb_Array* arr);
|
2407
|
+
|
2520
2408
|
// Returns the given element, which must be within the array's current size.
|
2521
2409
|
UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i);
|
2522
2410
|
|
@@ -2577,6 +2465,52 @@ UPB_API_INLINE bool upb_Array_IsFrozen(const upb_Array* arr);
|
|
2577
2465
|
|
2578
2466
|
#endif /* UPB_MESSAGE_ARRAY_H_ */
|
2579
2467
|
|
2468
|
+
#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
|
2469
|
+
#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
|
2470
|
+
|
2471
|
+
#include <stddef.h>
|
2472
|
+
#include <stdint.h>
|
2473
|
+
#include <string.h>
|
2474
|
+
|
2475
|
+
|
2476
|
+
#ifndef UPB_BASE_INTERNAL_ENDIAN_H_
|
2477
|
+
#define UPB_BASE_INTERNAL_ENDIAN_H_
|
2478
|
+
|
2479
|
+
#include <stdint.h>
|
2480
|
+
|
2481
|
+
// Must be last.
|
2482
|
+
|
2483
|
+
#ifdef __cplusplus
|
2484
|
+
extern "C" {
|
2485
|
+
#endif
|
2486
|
+
|
2487
|
+
UPB_INLINE bool upb_IsLittleEndian(void) {
|
2488
|
+
const int x = 1;
|
2489
|
+
return *(char*)&x == 1;
|
2490
|
+
}
|
2491
|
+
|
2492
|
+
UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
|
2493
|
+
if (upb_IsLittleEndian()) return val;
|
2494
|
+
|
2495
|
+
return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
|
2496
|
+
((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
|
2497
|
+
}
|
2498
|
+
|
2499
|
+
UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
|
2500
|
+
if (upb_IsLittleEndian()) return val;
|
2501
|
+
|
2502
|
+
const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32;
|
2503
|
+
const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32));
|
2504
|
+
return hi | lo;
|
2505
|
+
}
|
2506
|
+
|
2507
|
+
#ifdef __cplusplus
|
2508
|
+
} /* extern "C" */
|
2509
|
+
#endif
|
2510
|
+
|
2511
|
+
|
2512
|
+
#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */
|
2513
|
+
|
2580
2514
|
#ifndef UPB_MESSAGE_INTERNAL_EXTENSION_H_
|
2581
2515
|
#define UPB_MESSAGE_INTERNAL_EXTENSION_H_
|
2582
2516
|
|
@@ -3234,6 +3168,11 @@ upb_MiniTableExtension_Number(const struct upb_MiniTableExtension* e) {
|
|
3234
3168
|
return e->UPB_PRIVATE(field).UPB_ONLYBITS(number);
|
3235
3169
|
}
|
3236
3170
|
|
3171
|
+
UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_Extendee(
|
3172
|
+
const struct upb_MiniTableExtension* e) {
|
3173
|
+
return e->UPB_PRIVATE(extendee);
|
3174
|
+
}
|
3175
|
+
|
3237
3176
|
UPB_API_INLINE const struct upb_MiniTable* upb_MiniTableExtension_GetSubMessage(
|
3238
3177
|
const struct upb_MiniTableExtension* e) {
|
3239
3178
|
if (upb_MiniTableExtension_CType(e) != kUpb_CType_Message) {
|
@@ -3296,6 +3235,9 @@ upb_MiniTableExtension_CType(const upb_MiniTableExtension* e);
|
|
3296
3235
|
UPB_API_INLINE uint32_t
|
3297
3236
|
upb_MiniTableExtension_Number(const upb_MiniTableExtension* e);
|
3298
3237
|
|
3238
|
+
UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_Extendee(
|
3239
|
+
const upb_MiniTableExtension* e);
|
3240
|
+
|
3299
3241
|
UPB_API_INLINE const upb_MiniTable* upb_MiniTableExtension_GetSubMessage(
|
3300
3242
|
const upb_MiniTableExtension* e);
|
3301
3243
|
|
@@ -3478,11 +3420,15 @@ UPB_API void upb_Message_SetNewMessageTraceHandler(
|
|
3478
3420
|
// Inline version upb_Message_New(), for internal use.
|
3479
3421
|
UPB_INLINE struct upb_Message* _upb_Message_New(const upb_MiniTable* m,
|
3480
3422
|
upb_Arena* a) {
|
3423
|
+
UPB_PRIVATE(upb_MiniTable_CheckInvariants)(m);
|
3481
3424
|
#ifdef UPB_TRACING_ENABLED
|
3482
3425
|
upb_Message_LogNewMessage(m, a);
|
3483
3426
|
#endif // UPB_TRACING_ENABLED
|
3484
3427
|
|
3485
|
-
const
|
3428
|
+
const size_t size = m->UPB_PRIVATE(size);
|
3429
|
+
// Message sizes are aligned up when constructing minitables; telling the
|
3430
|
+
// compiler this avoids redoing alignment on the malloc fast path
|
3431
|
+
UPB_ASSUME(size % kUpb_Message_Align == 0);
|
3486
3432
|
struct upb_Message* msg = (struct upb_Message*)upb_Arena_Malloc(a, size);
|
3487
3433
|
if (UPB_UNLIKELY(!msg)) return NULL;
|
3488
3434
|
memset(msg, 0, size);
|
@@ -3498,15 +3444,21 @@ UPB_NOINLINE bool UPB_PRIVATE(_upb_Message_AddUnknownSlowPath)(
|
|
3498
3444
|
|
3499
3445
|
// Adds unknown data (serialized protobuf data) to the given message. The data
|
3500
3446
|
// must represent one or more complete and well formed proto fields.
|
3501
|
-
//
|
3502
|
-
//
|
3447
|
+
//
|
3448
|
+
// If `alias_base` is NULL, the bytes from `data` will be copied into the
|
3449
|
+
// destination arena. Otherwise it must be a pointer to the beginning of the
|
3450
|
+
// buffer that `data` points into, which signals that the message must alias
|
3451
|
+
// the bytes instead of copying them. The value of `alias_base` is also used
|
3452
|
+
// to mark the boundary of the buffer, so that we do not inappropriately
|
3453
|
+
// coalesce two buffers that are separate objects but happen to be contiguous
|
3454
|
+
// in memory.
|
3503
3455
|
UPB_INLINE bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
|
3504
3456
|
const char* data,
|
3505
3457
|
size_t len,
|
3506
3458
|
upb_Arena* arena,
|
3507
|
-
|
3459
|
+
const char* alias_base) {
|
3508
3460
|
UPB_ASSERT(!upb_Message_IsFrozen(msg));
|
3509
|
-
if (
|
3461
|
+
if (alias_base) {
|
3510
3462
|
// Aliasing parse of a message with sequential unknown fields is a simple
|
3511
3463
|
// pointer bump, so inline it.
|
3512
3464
|
upb_Message_Internal* in = UPB_PRIVATE(_upb_Message_GetInternal)(msg);
|
@@ -3514,10 +3466,13 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
|
|
3514
3466
|
upb_TaggedAuxPtr ptr = in->aux_data[in->size - 1];
|
3515
3467
|
if (upb_TaggedAuxPtr_IsUnknown(ptr)) {
|
3516
3468
|
upb_StringView* existing = upb_TaggedAuxPtr_UnknownData(ptr);
|
3517
|
-
bool was_aliased = upb_TaggedAuxPtr_IsUnknownAliased(ptr);
|
3518
3469
|
// Fast path if the field we're adding is immediately after the last
|
3519
|
-
// added unknown field.
|
3520
|
-
|
3470
|
+
// added unknown field. However, we could be merging into an existing
|
3471
|
+
// message with an allocation that just happens to be positioned
|
3472
|
+
// immediately after the previous merged unknown field; this is
|
3473
|
+
// considered out-of-bounds and thus UB. Ensure it's in-bounds by
|
3474
|
+
// comparing with the original input pointer for our buffer.
|
3475
|
+
if (data != alias_base && existing->data + existing->size == data) {
|
3521
3476
|
existing->size += len;
|
3522
3477
|
return true;
|
3523
3478
|
}
|
@@ -3525,7 +3480,7 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
|
|
3525
3480
|
}
|
3526
3481
|
}
|
3527
3482
|
return UPB_PRIVATE(_upb_Message_AddUnknownSlowPath)(msg, data, len, arena,
|
3528
|
-
|
3483
|
+
alias_base != NULL);
|
3529
3484
|
}
|
3530
3485
|
|
3531
3486
|
// Adds unknown data (serialized protobuf data) to the given message.
|
@@ -3631,340 +3586,120 @@ UPB_INLINE bool UPB_PRIVATE(_upb_Message_NextExtensionReverse)(
|
|
3631
3586
|
|
3632
3587
|
#endif /* UPB_MESSAGE_INTERNAL_MESSAGE_H_ */
|
3633
3588
|
|
3634
|
-
|
3589
|
+
#ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
|
3590
|
+
#define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
|
3591
|
+
|
3592
|
+
#include <stdint.h>
|
3635
3593
|
|
3636
|
-
|
3594
|
+
|
3595
|
+
// Must be last.
|
3637
3596
|
|
3638
3597
|
#ifdef __cplusplus
|
3639
3598
|
extern "C" {
|
3640
3599
|
#endif
|
3641
3600
|
|
3642
|
-
//
|
3643
|
-
|
3644
|
-
|
3645
|
-
|
3646
|
-
|
3647
|
-
|
3648
|
-
//
|
3649
|
-
// uintptr_t iter = kUpb_Message_UnknownBegin;
|
3650
|
-
// upb_StringView data;
|
3651
|
-
// while (upb_Message_NextUnknown(msg, &data, &iter)) {
|
3652
|
-
// // Use data
|
3653
|
-
// }
|
3654
|
-
// Iterates in the order unknown fields were parsed.
|
3655
|
-
|
3656
|
-
#define kUpb_Message_UnknownBegin 0
|
3657
|
-
#define kUpb_Message_ExtensionBegin 0
|
3658
|
-
|
3659
|
-
UPB_INLINE bool upb_Message_NextUnknown(const upb_Message* msg,
|
3660
|
-
upb_StringView* data, uintptr_t* iter);
|
3601
|
+
// Internal-only because empty messages cannot be created by the user.
|
3602
|
+
UPB_INLINE uintptr_t
|
3603
|
+
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) {
|
3604
|
+
UPB_ASSERT(((uintptr_t)ptr & 1) == 0);
|
3605
|
+
return (uintptr_t)ptr | (empty ? 1 : 0);
|
3606
|
+
}
|
3661
3607
|
|
3662
|
-
|
3608
|
+
UPB_API_INLINE bool upb_TaggedMessagePtr_IsEmpty(uintptr_t ptr) {
|
3609
|
+
return ptr & 1;
|
3610
|
+
}
|
3663
3611
|
|
3664
|
-
|
3665
|
-
|
3666
|
-
|
3667
|
-
|
3668
|
-
// This must be done while iterating:
|
3669
|
-
//
|
3670
|
-
// uintptr_t iter = kUpb_Message_UnknownBegin;
|
3671
|
-
// upb_StringView data;
|
3672
|
-
// // Iterate chunks
|
3673
|
-
// while (upb_Message_NextUnknown(msg, &data, &iter)) {
|
3674
|
-
// // Iterate within a chunk, deleting ranges
|
3675
|
-
// while (ShouldDeleteSubSegment(&data)) {
|
3676
|
-
// // Data now points to the region to be deleted
|
3677
|
-
// switch (upb_Message_DeleteUnknown(msg, &data, &iter)) {
|
3678
|
-
// case kUpb_Message_DeleteUnknown_DeletedLast: return ok;
|
3679
|
-
// case kUpb_Message_DeleteUnknown_IterUpdated: break;
|
3680
|
-
// // If DeleteUnknown returned kUpb_Message_DeleteUnknown_IterUpdated,
|
3681
|
-
// // then data now points to the remaining unknown fields after the
|
3682
|
-
// // region that was just deleted.
|
3683
|
-
// case kUpb_Message_DeleteUnknown_AllocFail: return err;
|
3684
|
-
// }
|
3685
|
-
// }
|
3686
|
-
// }
|
3687
|
-
//
|
3688
|
-
// The range given in `data` must be contained inside the most recently
|
3689
|
-
// returned region.
|
3690
|
-
typedef enum upb_Message_DeleteUnknownStatus {
|
3691
|
-
kUpb_DeleteUnknown_DeletedLast,
|
3692
|
-
kUpb_DeleteUnknown_IterUpdated,
|
3693
|
-
kUpb_DeleteUnknown_AllocFail,
|
3694
|
-
} upb_Message_DeleteUnknownStatus;
|
3695
|
-
upb_Message_DeleteUnknownStatus upb_Message_DeleteUnknown(upb_Message* msg,
|
3696
|
-
upb_StringView* data,
|
3697
|
-
uintptr_t* iter,
|
3698
|
-
upb_Arena* arena);
|
3612
|
+
UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(
|
3613
|
+
uintptr_t ptr) {
|
3614
|
+
return (struct upb_Message*)(ptr & ~(uintptr_t)1);
|
3615
|
+
}
|
3699
3616
|
|
3700
|
-
|
3701
|
-
|
3617
|
+
UPB_API_INLINE struct upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
|
3618
|
+
uintptr_t ptr) {
|
3619
|
+
UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(ptr));
|
3620
|
+
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr);
|
3621
|
+
}
|
3702
3622
|
|
3703
|
-
|
3704
|
-
|
3705
|
-
|
3706
|
-
|
3707
|
-
|
3623
|
+
UPB_INLINE struct upb_Message* UPB_PRIVATE(
|
3624
|
+
_upb_TaggedMessagePtr_GetEmptyMessage)(uintptr_t ptr) {
|
3625
|
+
UPB_ASSERT(upb_TaggedMessagePtr_IsEmpty(ptr));
|
3626
|
+
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr);
|
3627
|
+
}
|
3708
3628
|
|
3709
|
-
|
3710
|
-
|
3711
|
-
|
3712
|
-
upb_MessageValue* out_v, uintptr_t* iter);
|
3629
|
+
#ifdef __cplusplus
|
3630
|
+
} /* extern "C" */
|
3631
|
+
#endif
|
3713
3632
|
|
3714
|
-
// Mark a message and all of its descendents as frozen/immutable.
|
3715
|
-
UPB_API void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m);
|
3716
3633
|
|
3717
|
-
|
3718
|
-
UPB_API_INLINE bool upb_Message_IsFrozen(const upb_Message* msg);
|
3634
|
+
#endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */
|
3719
3635
|
|
3720
|
-
|
3721
|
-
UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
|
3722
|
-
const upb_Arena* arena);
|
3636
|
+
// Must be last.
|
3723
3637
|
|
3724
|
-
|
3725
|
-
|
3726
|
-
|
3638
|
+
#if defined(__GNUC__) && !defined(__clang__)
|
3639
|
+
// GCC raises incorrect warnings in these functions. It thinks that we are
|
3640
|
+
// overrunning buffers, but we carefully write the functions in this file to
|
3641
|
+
// guarantee that this is impossible. GCC gets this wrong due it its failure
|
3642
|
+
// to perform constant propagation as we expect:
|
3643
|
+
// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108217
|
3644
|
+
// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108226
|
3645
|
+
//
|
3646
|
+
// Unfortunately this also indicates that GCC is not optimizing away the
|
3647
|
+
// switch() in cases where it should be, compromising the performance.
|
3648
|
+
#pragma GCC diagnostic push
|
3649
|
+
#pragma GCC diagnostic ignored "-Warray-bounds"
|
3650
|
+
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
3651
|
+
#if __GNUC__ >= 11
|
3652
|
+
#pragma GCC diagnostic ignored "-Wstringop-overread"
|
3653
|
+
#endif
|
3654
|
+
#endif
|
3727
3655
|
|
3728
3656
|
#ifdef __cplusplus
|
3729
|
-
|
3657
|
+
extern "C" {
|
3730
3658
|
#endif
|
3731
3659
|
|
3660
|
+
// LINT.IfChange(presence_logic)
|
3732
3661
|
|
3733
|
-
|
3662
|
+
// Hasbit access ///////////////////////////////////////////////////////////////
|
3734
3663
|
|
3735
|
-
|
3736
|
-
|
3664
|
+
UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)(
|
3665
|
+
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3666
|
+
const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
|
3667
|
+
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
|
3737
3668
|
|
3738
|
-
|
3669
|
+
return (*UPB_PTR_AT(msg, offset, const char) & mask) != 0;
|
3670
|
+
}
|
3739
3671
|
|
3740
|
-
|
3672
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)(
|
3673
|
+
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3674
|
+
const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
|
3675
|
+
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
|
3741
3676
|
|
3742
|
-
|
3743
|
-
|
3677
|
+
(*UPB_PTR_AT(msg, offset, char)) |= mask;
|
3678
|
+
}
|
3744
3679
|
|
3680
|
+
UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)(
|
3681
|
+
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3682
|
+
const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
|
3683
|
+
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
|
3745
3684
|
|
3746
|
-
|
3685
|
+
(*UPB_PTR_AT(msg, offset, char)) &= ~mask;
|
3686
|
+
}
|
3747
3687
|
|
3748
|
-
//
|
3688
|
+
// Oneof case access ///////////////////////////////////////////////////////////
|
3749
3689
|
|
3750
|
-
|
3751
|
-
|
3690
|
+
UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)(
|
3691
|
+
struct upb_Message* msg, const upb_MiniTableField* f) {
|
3692
|
+
return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f),
|
3693
|
+
uint32_t);
|
3694
|
+
}
|
3752
3695
|
|
3753
|
-
|
3754
|
-
|
3696
|
+
UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)(
|
3697
|
+
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3698
|
+
const uint32_t* ptr =
|
3699
|
+
UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f);
|
3755
3700
|
|
3756
|
-
|
3757
|
-
|
3758
|
-
#if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0
|
3759
|
-
// This header is checked in.
|
3760
|
-
#elif defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 1
|
3761
|
-
// This header is generated at build time by the bootstrapping process.
|
3762
|
-
#else
|
3763
|
-
// This is the normal header, generated by upb_c_proto_library().
|
3764
|
-
/* This file was generated by upb_generator from the input file:
|
3765
|
-
*
|
3766
|
-
* google/protobuf/descriptor.proto
|
3767
|
-
*
|
3768
|
-
* Do not edit -- your changes will be discarded when the file is
|
3769
|
-
* regenerated.
|
3770
|
-
* NO CHECKED-IN PROTOBUF GENCODE */
|
3771
|
-
|
3772
|
-
#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
|
3773
|
-
#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
|
3774
|
-
|
3775
|
-
|
3776
|
-
#ifndef UPB_GENERATED_CODE_SUPPORT_H_
|
3777
|
-
#define UPB_GENERATED_CODE_SUPPORT_H_
|
3778
|
-
|
3779
|
-
// IWYU pragma: begin_exports
|
3780
|
-
|
3781
|
-
#ifndef UPB_BASE_UPCAST_H_
|
3782
|
-
#define UPB_BASE_UPCAST_H_
|
3783
|
-
|
3784
|
-
// Must be last.
|
3785
|
-
|
3786
|
-
// This macro provides a way to upcast message pointers in a way that is
|
3787
|
-
// somewhat more bulletproof than blindly casting a pointer. Example:
|
3788
|
-
//
|
3789
|
-
// typedef struct {
|
3790
|
-
// upb_Message UPB_PRIVATE(base);
|
3791
|
-
// } pkg_FooMessage;
|
3792
|
-
//
|
3793
|
-
// void f(pkg_FooMessage* msg) {
|
3794
|
-
// upb_Decode(UPB_UPCAST(msg), ...);
|
3795
|
-
// }
|
3796
|
-
|
3797
|
-
#define UPB_UPCAST(x) (&(x)->base##_dont_copy_me__upb_internal_use_only)
|
3798
|
-
|
3799
|
-
|
3800
|
-
#endif /* UPB_BASE_UPCAST_H_ */
|
3801
|
-
|
3802
|
-
#ifndef UPB_MESSAGE_ACCESSORS_H_
|
3803
|
-
#define UPB_MESSAGE_ACCESSORS_H_
|
3804
|
-
|
3805
|
-
#include <stdint.h>
|
3806
|
-
|
3807
|
-
|
3808
|
-
#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_
|
3809
|
-
#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_
|
3810
|
-
|
3811
|
-
#include <stddef.h>
|
3812
|
-
#include <stdint.h>
|
3813
|
-
#include <string.h>
|
3814
|
-
|
3815
|
-
|
3816
|
-
#ifndef UPB_BASE_INTERNAL_ENDIAN_H_
|
3817
|
-
#define UPB_BASE_INTERNAL_ENDIAN_H_
|
3818
|
-
|
3819
|
-
#include <stdint.h>
|
3820
|
-
|
3821
|
-
// Must be last.
|
3822
|
-
|
3823
|
-
#ifdef __cplusplus
|
3824
|
-
extern "C" {
|
3825
|
-
#endif
|
3826
|
-
|
3827
|
-
UPB_INLINE bool upb_IsLittleEndian(void) {
|
3828
|
-
const int x = 1;
|
3829
|
-
return *(char*)&x == 1;
|
3830
|
-
}
|
3831
|
-
|
3832
|
-
UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
|
3833
|
-
if (upb_IsLittleEndian()) return val;
|
3834
|
-
|
3835
|
-
return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
|
3836
|
-
((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
|
3837
|
-
}
|
3838
|
-
|
3839
|
-
UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
|
3840
|
-
if (upb_IsLittleEndian()) return val;
|
3841
|
-
|
3842
|
-
const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32;
|
3843
|
-
const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32));
|
3844
|
-
return hi | lo;
|
3845
|
-
}
|
3846
|
-
|
3847
|
-
#ifdef __cplusplus
|
3848
|
-
} /* extern "C" */
|
3849
|
-
#endif
|
3850
|
-
|
3851
|
-
|
3852
|
-
#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */
|
3853
|
-
|
3854
|
-
#ifndef UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
|
3855
|
-
#define UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_
|
3856
|
-
|
3857
|
-
#include <stdint.h>
|
3858
|
-
|
3859
|
-
|
3860
|
-
// Must be last.
|
3861
|
-
|
3862
|
-
#ifdef __cplusplus
|
3863
|
-
extern "C" {
|
3864
|
-
#endif
|
3865
|
-
|
3866
|
-
// Internal-only because empty messages cannot be created by the user.
|
3867
|
-
UPB_INLINE uintptr_t
|
3868
|
-
UPB_PRIVATE(_upb_TaggedMessagePtr_Pack)(struct upb_Message* ptr, bool empty) {
|
3869
|
-
UPB_ASSERT(((uintptr_t)ptr & 1) == 0);
|
3870
|
-
return (uintptr_t)ptr | (empty ? 1 : 0);
|
3871
|
-
}
|
3872
|
-
|
3873
|
-
UPB_API_INLINE bool upb_TaggedMessagePtr_IsEmpty(uintptr_t ptr) {
|
3874
|
-
return ptr & 1;
|
3875
|
-
}
|
3876
|
-
|
3877
|
-
UPB_INLINE struct upb_Message* UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(
|
3878
|
-
uintptr_t ptr) {
|
3879
|
-
return (struct upb_Message*)(ptr & ~(uintptr_t)1);
|
3880
|
-
}
|
3881
|
-
|
3882
|
-
UPB_API_INLINE struct upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
|
3883
|
-
uintptr_t ptr) {
|
3884
|
-
UPB_ASSERT(!upb_TaggedMessagePtr_IsEmpty(ptr));
|
3885
|
-
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr);
|
3886
|
-
}
|
3887
|
-
|
3888
|
-
UPB_INLINE struct upb_Message* UPB_PRIVATE(
|
3889
|
-
_upb_TaggedMessagePtr_GetEmptyMessage)(uintptr_t ptr) {
|
3890
|
-
UPB_ASSERT(upb_TaggedMessagePtr_IsEmpty(ptr));
|
3891
|
-
return UPB_PRIVATE(_upb_TaggedMessagePtr_GetMessage)(ptr);
|
3892
|
-
}
|
3893
|
-
|
3894
|
-
#ifdef __cplusplus
|
3895
|
-
} /* extern "C" */
|
3896
|
-
#endif
|
3897
|
-
|
3898
|
-
|
3899
|
-
#endif /* UPB_MINI_TABLE_INTERNAL_TAGGED_PTR_H_ */
|
3900
|
-
|
3901
|
-
// Must be last.
|
3902
|
-
|
3903
|
-
#if defined(__GNUC__) && !defined(__clang__)
|
3904
|
-
// GCC raises incorrect warnings in these functions. It thinks that we are
|
3905
|
-
// overrunning buffers, but we carefully write the functions in this file to
|
3906
|
-
// guarantee that this is impossible. GCC gets this wrong due it its failure
|
3907
|
-
// to perform constant propagation as we expect:
|
3908
|
-
// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108217
|
3909
|
-
// - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108226
|
3910
|
-
//
|
3911
|
-
// Unfortunately this also indicates that GCC is not optimizing away the
|
3912
|
-
// switch() in cases where it should be, compromising the performance.
|
3913
|
-
#pragma GCC diagnostic push
|
3914
|
-
#pragma GCC diagnostic ignored "-Warray-bounds"
|
3915
|
-
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
3916
|
-
#if __GNUC__ >= 11
|
3917
|
-
#pragma GCC diagnostic ignored "-Wstringop-overread"
|
3918
|
-
#endif
|
3919
|
-
#endif
|
3920
|
-
|
3921
|
-
#ifdef __cplusplus
|
3922
|
-
extern "C" {
|
3923
|
-
#endif
|
3924
|
-
|
3925
|
-
// LINT.IfChange(presence_logic)
|
3926
|
-
|
3927
|
-
// Hasbit access ///////////////////////////////////////////////////////////////
|
3928
|
-
|
3929
|
-
UPB_INLINE bool UPB_PRIVATE(_upb_Message_GetHasbit)(
|
3930
|
-
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3931
|
-
const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
|
3932
|
-
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
|
3933
|
-
|
3934
|
-
return (*UPB_PTR_AT(msg, offset, const char) & mask) != 0;
|
3935
|
-
}
|
3936
|
-
|
3937
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetHasbit)(
|
3938
|
-
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3939
|
-
const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
|
3940
|
-
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
|
3941
|
-
|
3942
|
-
(*UPB_PTR_AT(msg, offset, char)) |= mask;
|
3943
|
-
}
|
3944
|
-
|
3945
|
-
UPB_INLINE void UPB_PRIVATE(_upb_Message_ClearHasbit)(
|
3946
|
-
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3947
|
-
const uint16_t offset = UPB_PRIVATE(_upb_MiniTableField_HasbitOffset)(f);
|
3948
|
-
const char mask = UPB_PRIVATE(_upb_MiniTableField_HasbitMask)(f);
|
3949
|
-
|
3950
|
-
(*UPB_PTR_AT(msg, offset, char)) &= ~mask;
|
3951
|
-
}
|
3952
|
-
|
3953
|
-
// Oneof case access ///////////////////////////////////////////////////////////
|
3954
|
-
|
3955
|
-
UPB_INLINE uint32_t* UPB_PRIVATE(_upb_Message_OneofCasePtr)(
|
3956
|
-
struct upb_Message* msg, const upb_MiniTableField* f) {
|
3957
|
-
return UPB_PTR_AT(msg, UPB_PRIVATE(_upb_MiniTableField_OneofOffset)(f),
|
3958
|
-
uint32_t);
|
3959
|
-
}
|
3960
|
-
|
3961
|
-
UPB_INLINE uint32_t UPB_PRIVATE(_upb_Message_GetOneofCase)(
|
3962
|
-
const struct upb_Message* msg, const upb_MiniTableField* f) {
|
3963
|
-
const uint32_t* ptr =
|
3964
|
-
UPB_PRIVATE(_upb_Message_OneofCasePtr)((struct upb_Message*)msg, f);
|
3965
|
-
|
3966
|
-
return *ptr;
|
3967
|
-
}
|
3701
|
+
return *ptr;
|
3702
|
+
}
|
3968
3703
|
|
3969
3704
|
UPB_INLINE void UPB_PRIVATE(_upb_Message_SetOneofCase)(
|
3970
3705
|
struct upb_Message* msg, const upb_MiniTableField* f) {
|
@@ -4556,6 +4291,16 @@ UPB_API_INLINE void upb_Message_SetClosedEnum(struct upb_Message* msg,
|
|
4556
4291
|
|
4557
4292
|
// Extension Setters ///////////////////////////////////////////////////////////
|
4558
4293
|
|
4294
|
+
UPB_API_INLINE bool upb_Message_SetExtensionMessage(
|
4295
|
+
struct upb_Message* msg, const upb_MiniTableExtension* e,
|
4296
|
+
struct upb_Message* value, upb_Arena* a) {
|
4297
|
+
UPB_ASSERT(value);
|
4298
|
+
UPB_ASSUME(upb_MiniTableExtension_CType(e) == kUpb_CType_Message);
|
4299
|
+
UPB_ASSUME(UPB_PRIVATE(_upb_MiniTableExtension_GetRep)(e) ==
|
4300
|
+
UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte));
|
4301
|
+
return upb_Message_SetExtension(msg, e, &value, a);
|
4302
|
+
}
|
4303
|
+
|
4559
4304
|
UPB_API_INLINE bool upb_Message_SetExtensionBool(
|
4560
4305
|
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
|
4561
4306
|
upb_Arena* a) {
|
@@ -5039,38 +4784,150 @@ UPB_API_INLINE bool upb_Map_IsFrozen(const upb_Map* map);
|
|
5039
4784
|
|
5040
4785
|
#endif /* UPB_MESSAGE_MAP_H_ */
|
5041
4786
|
|
5042
|
-
|
5043
|
-
|
4787
|
+
// Public APIs for message operations that do not depend on the schema.
|
4788
|
+
//
|
4789
|
+
// MiniTable-based accessors live in accessors.h.
|
4790
|
+
|
4791
|
+
#ifndef UPB_MESSAGE_MESSAGE_H_
|
4792
|
+
#define UPB_MESSAGE_MESSAGE_H_
|
5044
4793
|
|
4794
|
+
#include <stddef.h>
|
5045
4795
|
#include <stdint.h>
|
5046
4796
|
|
5047
4797
|
|
5048
4798
|
// Must be last.
|
5049
4799
|
|
5050
|
-
|
5051
|
-
// tagged form. If the tag bit is set, the referenced upb_Message is of type
|
5052
|
-
// _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of
|
5053
|
-
// that field's true message type. This forms the basis of what we call
|
5054
|
-
// "dynamic tree shaking."
|
5055
|
-
//
|
5056
|
-
// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for
|
5057
|
-
// more information.
|
5058
|
-
|
5059
|
-
typedef uintptr_t upb_TaggedMessagePtr;
|
4800
|
+
typedef struct upb_Message upb_Message;
|
5060
4801
|
|
5061
4802
|
#ifdef __cplusplus
|
5062
4803
|
extern "C" {
|
5063
4804
|
#endif
|
5064
4805
|
|
5065
|
-
//
|
5066
|
-
|
5067
|
-
// first promoted using the interfaces in message/promote.h.
|
5068
|
-
UPB_API_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr);
|
4806
|
+
// Creates a new message with the given mini_table on the given arena.
|
4807
|
+
UPB_API upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* arena);
|
5069
4808
|
|
5070
|
-
|
5071
|
-
|
4809
|
+
//
|
4810
|
+
// Unknown data may be stored non-contiguously. Each segment stores a block of
|
4811
|
+
// unknown fields. To iterate over segments:
|
4812
|
+
//
|
4813
|
+
// uintptr_t iter = kUpb_Message_UnknownBegin;
|
4814
|
+
// upb_StringView data;
|
4815
|
+
// while (upb_Message_NextUnknown(msg, &data, &iter)) {
|
4816
|
+
// // Use data
|
4817
|
+
// }
|
4818
|
+
// Iterates in the order unknown fields were parsed.
|
5072
4819
|
|
5073
|
-
#
|
4820
|
+
#define kUpb_Message_UnknownBegin 0
|
4821
|
+
#define kUpb_Message_ExtensionBegin 0
|
4822
|
+
|
4823
|
+
UPB_INLINE bool upb_Message_NextUnknown(const upb_Message* msg,
|
4824
|
+
upb_StringView* data, uintptr_t* iter);
|
4825
|
+
|
4826
|
+
UPB_INLINE bool upb_Message_HasUnknown(const upb_Message* msg);
|
4827
|
+
|
4828
|
+
// Removes a segment of unknown data from the message, advancing to the next
|
4829
|
+
// segment. Returns false if the removed segment was at the end of the last
|
4830
|
+
// chunk.
|
4831
|
+
//
|
4832
|
+
// This must be done while iterating:
|
4833
|
+
//
|
4834
|
+
// uintptr_t iter = kUpb_Message_UnknownBegin;
|
4835
|
+
// upb_StringView data;
|
4836
|
+
// // Iterate chunks
|
4837
|
+
// while (upb_Message_NextUnknown(msg, &data, &iter)) {
|
4838
|
+
// // Iterate within a chunk, deleting ranges
|
4839
|
+
// while (ShouldDeleteSubSegment(&data)) {
|
4840
|
+
// // Data now points to the region to be deleted
|
4841
|
+
// switch (upb_Message_DeleteUnknown(msg, &data, &iter)) {
|
4842
|
+
// case kUpb_Message_DeleteUnknown_DeletedLast: return ok;
|
4843
|
+
// case kUpb_Message_DeleteUnknown_IterUpdated: break;
|
4844
|
+
// // If DeleteUnknown returned kUpb_Message_DeleteUnknown_IterUpdated,
|
4845
|
+
// // then data now points to the remaining unknown fields after the
|
4846
|
+
// // region that was just deleted.
|
4847
|
+
// case kUpb_Message_DeleteUnknown_AllocFail: return err;
|
4848
|
+
// }
|
4849
|
+
// }
|
4850
|
+
// }
|
4851
|
+
//
|
4852
|
+
// The range given in `data` must be contained inside the most recently
|
4853
|
+
// returned region.
|
4854
|
+
typedef enum upb_Message_DeleteUnknownStatus {
|
4855
|
+
kUpb_DeleteUnknown_DeletedLast,
|
4856
|
+
kUpb_DeleteUnknown_IterUpdated,
|
4857
|
+
kUpb_DeleteUnknown_AllocFail,
|
4858
|
+
} upb_Message_DeleteUnknownStatus;
|
4859
|
+
upb_Message_DeleteUnknownStatus upb_Message_DeleteUnknown(upb_Message* msg,
|
4860
|
+
upb_StringView* data,
|
4861
|
+
uintptr_t* iter,
|
4862
|
+
upb_Arena* arena);
|
4863
|
+
|
4864
|
+
// Returns the number of extensions present in this message.
|
4865
|
+
size_t upb_Message_ExtensionCount(const upb_Message* msg);
|
4866
|
+
|
4867
|
+
// Iterates extensions in wire order
|
4868
|
+
UPB_INLINE bool upb_Message_NextExtension(const upb_Message* msg,
|
4869
|
+
const upb_MiniTableExtension** out_e,
|
4870
|
+
upb_MessageValue* out_v,
|
4871
|
+
uintptr_t* iter);
|
4872
|
+
|
4873
|
+
// Iterates extensions in reverse wire order
|
4874
|
+
UPB_INLINE bool UPB_PRIVATE(_upb_Message_NextExtensionReverse)(
|
4875
|
+
const struct upb_Message* msg, const upb_MiniTableExtension** out_e,
|
4876
|
+
upb_MessageValue* out_v, uintptr_t* iter);
|
4877
|
+
|
4878
|
+
// Mark a message and all of its descendents as frozen/immutable.
|
4879
|
+
UPB_API void upb_Message_Freeze(upb_Message* msg, const upb_MiniTable* m);
|
4880
|
+
|
4881
|
+
// Returns whether a message has been frozen.
|
4882
|
+
UPB_API_INLINE bool upb_Message_IsFrozen(const upb_Message* msg);
|
4883
|
+
|
4884
|
+
#ifdef UPB_TRACING_ENABLED
|
4885
|
+
UPB_API void upb_Message_LogNewMessage(const upb_MiniTable* m,
|
4886
|
+
const upb_Arena* arena);
|
4887
|
+
|
4888
|
+
UPB_API void upb_Message_SetNewMessageTraceHandler(
|
4889
|
+
void (*handler)(const upb_MiniTable* m, const upb_Arena* arena));
|
4890
|
+
#endif // UPB_TRACING_ENABLED
|
4891
|
+
|
4892
|
+
#ifdef __cplusplus
|
4893
|
+
} /* extern "C" */
|
4894
|
+
#endif
|
4895
|
+
|
4896
|
+
|
4897
|
+
#endif /* UPB_MESSAGE_MESSAGE_H_ */
|
4898
|
+
|
4899
|
+
#ifndef UPB_MINI_TABLE_TAGGED_PTR_H_
|
4900
|
+
#define UPB_MINI_TABLE_TAGGED_PTR_H_
|
4901
|
+
|
4902
|
+
#include <stdint.h>
|
4903
|
+
|
4904
|
+
|
4905
|
+
// Must be last.
|
4906
|
+
|
4907
|
+
// When a upb_Message* is stored in a message, array, or map, it is stored in a
|
4908
|
+
// tagged form. If the tag bit is set, the referenced upb_Message is of type
|
4909
|
+
// _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of
|
4910
|
+
// that field's true message type. This forms the basis of what we call
|
4911
|
+
// "dynamic tree shaking."
|
4912
|
+
//
|
4913
|
+
// See the documentation for kUpb_DecodeOption_ExperimentalAllowUnlinked for
|
4914
|
+
// more information.
|
4915
|
+
|
4916
|
+
typedef uintptr_t upb_TaggedMessagePtr;
|
4917
|
+
|
4918
|
+
#ifdef __cplusplus
|
4919
|
+
extern "C" {
|
4920
|
+
#endif
|
4921
|
+
|
4922
|
+
// Users who enable unlinked sub-messages must use this to test whether a
|
4923
|
+
// message is empty before accessing it. If a message is empty, it must be
|
4924
|
+
// first promoted using the interfaces in message/promote.h.
|
4925
|
+
UPB_API_INLINE bool upb_TaggedMessagePtr_IsEmpty(upb_TaggedMessagePtr ptr);
|
4926
|
+
|
4927
|
+
UPB_API_INLINE upb_Message* upb_TaggedMessagePtr_GetNonEmptyMessage(
|
4928
|
+
upb_TaggedMessagePtr ptr);
|
4929
|
+
|
4930
|
+
#ifdef __cplusplus
|
5074
4931
|
} /* extern "C" */
|
5075
4932
|
#endif
|
5076
4933
|
|
@@ -5269,6 +5126,10 @@ UPB_API_INLINE bool upb_Message_SetExtension(upb_Message* msg,
|
|
5269
5126
|
const upb_MiniTableExtension* e,
|
5270
5127
|
const void* value, upb_Arena* a);
|
5271
5128
|
|
5129
|
+
UPB_API_INLINE bool upb_Message_SetExtensionMessage(
|
5130
|
+
struct upb_Message* msg, const upb_MiniTableExtension* e,
|
5131
|
+
struct upb_Message* value, upb_Arena* a);
|
5132
|
+
|
5272
5133
|
UPB_API_INLINE bool upb_Message_SetExtensionBool(
|
5273
5134
|
struct upb_Message* msg, const upb_MiniTableExtension* e, bool value,
|
5274
5135
|
upb_Arena* a);
|
@@ -5381,6 +5242,46 @@ bool upb_Message_SetMapEntry(upb_Map* map, const upb_MiniTable* mini_table,
|
|
5381
5242
|
#ifndef UPB_MINI_TABLE_DECODE_H_
|
5382
5243
|
#define UPB_MINI_TABLE_DECODE_H_
|
5383
5244
|
|
5245
|
+
#include <stddef.h>
|
5246
|
+
|
5247
|
+
|
5248
|
+
#ifndef UPB_BASE_STATUS_H_
|
5249
|
+
#define UPB_BASE_STATUS_H_
|
5250
|
+
|
5251
|
+
#include <stdarg.h>
|
5252
|
+
|
5253
|
+
// Must be last.
|
5254
|
+
|
5255
|
+
#define _kUpb_Status_MaxMessage 511
|
5256
|
+
|
5257
|
+
typedef struct {
|
5258
|
+
bool ok;
|
5259
|
+
char msg[_kUpb_Status_MaxMessage]; // Error message; NULL-terminated.
|
5260
|
+
} upb_Status;
|
5261
|
+
|
5262
|
+
#ifdef __cplusplus
|
5263
|
+
extern "C" {
|
5264
|
+
#endif
|
5265
|
+
|
5266
|
+
UPB_API const char* upb_Status_ErrorMessage(const upb_Status* status);
|
5267
|
+
UPB_API bool upb_Status_IsOk(const upb_Status* status);
|
5268
|
+
|
5269
|
+
// These are no-op if |status| is NULL.
|
5270
|
+
UPB_API void upb_Status_Clear(upb_Status* status);
|
5271
|
+
void upb_Status_SetErrorMessage(upb_Status* status, const char* msg);
|
5272
|
+
void upb_Status_SetErrorFormat(upb_Status* status, const char* fmt, ...)
|
5273
|
+
UPB_PRINTF(2, 3);
|
5274
|
+
void upb_Status_VSetErrorFormat(upb_Status* status, const char* fmt,
|
5275
|
+
va_list args) UPB_PRINTF(2, 0);
|
5276
|
+
void upb_Status_VAppendErrorFormat(upb_Status* status, const char* fmt,
|
5277
|
+
va_list args) UPB_PRINTF(2, 0);
|
5278
|
+
|
5279
|
+
#ifdef __cplusplus
|
5280
|
+
} /* extern "C" */
|
5281
|
+
#endif
|
5282
|
+
|
5283
|
+
|
5284
|
+
#endif /* UPB_BASE_STATUS_H_ */
|
5384
5285
|
|
5385
5286
|
#ifndef UPB_MINI_TABLE_SUB_H_
|
5386
5287
|
#define UPB_MINI_TABLE_SUB_H_
|
@@ -5575,7 +5476,7 @@ UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_Build(
|
|
5575
5476
|
|
5576
5477
|
UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildMessage(
|
5577
5478
|
const char* data, size_t len, const upb_MiniTable* extendee,
|
5578
|
-
upb_MiniTable* submsg, upb_Arena* arena, upb_Status* status) {
|
5479
|
+
const upb_MiniTable* submsg, upb_Arena* arena, upb_Status* status) {
|
5579
5480
|
upb_MiniTableSub sub = upb_MiniTableSub_FromMessage(submsg);
|
5580
5481
|
return _upb_MiniTableExtension_Build(
|
5581
5482
|
data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status);
|
@@ -5583,7 +5484,7 @@ UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildMessage(
|
|
5583
5484
|
|
5584
5485
|
UPB_API_INLINE upb_MiniTableExtension* upb_MiniTableExtension_BuildEnum(
|
5585
5486
|
const char* data, size_t len, const upb_MiniTable* extendee,
|
5586
|
-
upb_MiniTableEnum* subenum, upb_Arena* arena, upb_Status* status) {
|
5487
|
+
const upb_MiniTableEnum* subenum, upb_Arena* arena, upb_Status* status) {
|
5587
5488
|
upb_MiniTableSub sub = upb_MiniTableSub_FromEnum(subenum);
|
5588
5489
|
return _upb_MiniTableExtension_Build(
|
5589
5490
|
data, len, extendee, sub, kUpb_MiniTablePlatform_Native, arena, status);
|
@@ -5661,6 +5562,7 @@ typedef enum {
|
|
5661
5562
|
kUpb_ExtensionRegistryStatus_Ok = 0,
|
5662
5563
|
kUpb_ExtensionRegistryStatus_DuplicateEntry = 1,
|
5663
5564
|
kUpb_ExtensionRegistryStatus_OutOfMemory = 2,
|
5565
|
+
kUpb_ExtensionRegistryStatus_InvalidExtension = 3,
|
5664
5566
|
} upb_ExtensionRegistryStatus;
|
5665
5567
|
|
5666
5568
|
// Creates a upb_ExtensionRegistry in the given arena.
|
@@ -5813,6 +5715,7 @@ UPB_API_INLINE int upb_MiniTableFile_MessageCount(const upb_MiniTableFile* f);
|
|
5813
5715
|
extern "C" {
|
5814
5716
|
#endif
|
5815
5717
|
|
5718
|
+
// LINT.IfChange
|
5816
5719
|
enum {
|
5817
5720
|
/* If set, strings and unknown fields will alias the input buffer instead of
|
5818
5721
|
* copying into the arena. */
|
@@ -5881,21 +5784,23 @@ enum {
|
|
5881
5784
|
* as non-UTF-8 proto3 string fields.
|
5882
5785
|
*/
|
5883
5786
|
kUpb_DecodeOption_AlwaysValidateUtf8 = 8,
|
5787
|
+
|
5788
|
+
/* EXPERIMENTAL:
|
5789
|
+
*
|
5790
|
+
* If set, the fasttable decoder will not be used. */
|
5791
|
+
kUpb_DecodeOption_DisableFastTable = 16,
|
5884
5792
|
};
|
5793
|
+
// LINT.ThenChange(//depot/google3/third_party/protobuf/rust/upb.rs:decode_status)
|
5885
5794
|
|
5886
5795
|
UPB_INLINE uint32_t upb_DecodeOptions_MaxDepth(uint16_t depth) {
|
5887
5796
|
return (uint32_t)depth << 16;
|
5888
5797
|
}
|
5889
5798
|
|
5890
|
-
UPB_INLINE uint16_t upb_DecodeOptions_GetMaxDepth(uint32_t options) {
|
5891
|
-
return options >> 16;
|
5892
|
-
}
|
5893
|
-
|
5894
5799
|
uint16_t upb_DecodeOptions_GetEffectiveMaxDepth(uint32_t options);
|
5895
5800
|
|
5896
5801
|
// Enforce an upper bound on recursion depth.
|
5897
5802
|
UPB_INLINE int upb_Decode_LimitDepth(uint32_t decode_options, uint32_t limit) {
|
5898
|
-
uint32_t max_depth =
|
5803
|
+
uint32_t max_depth = upb_DecodeOptions_GetEffectiveMaxDepth(decode_options);
|
5899
5804
|
if (max_depth > limit) max_depth = limit;
|
5900
5805
|
return upb_DecodeOptions_MaxDepth(max_depth) | (decode_options & 0xffff);
|
5901
5806
|
}
|
@@ -5933,6 +5838,12 @@ UPB_API upb_DecodeStatus upb_DecodeLengthPrefixed(
|
|
5933
5838
|
const upb_MiniTable* mt, const upb_ExtensionRegistry* extreg, int options,
|
5934
5839
|
upb_Arena* arena);
|
5935
5840
|
|
5841
|
+
// For testing: decode with tracing.
|
5842
|
+
UPB_API upb_DecodeStatus upb_DecodeWithTrace(
|
5843
|
+
const char* buf, size_t size, upb_Message* msg, const upb_MiniTable* mt,
|
5844
|
+
const upb_ExtensionRegistry* extreg, int options, upb_Arena* arena,
|
5845
|
+
char* trace_buf, size_t trace_size);
|
5846
|
+
|
5936
5847
|
// Utility function for wrapper languages to get an error string from a
|
5937
5848
|
// upb_DecodeStatus.
|
5938
5849
|
UPB_API const char* upb_DecodeStatus_String(upb_DecodeStatus status);
|
@@ -5989,15 +5900,11 @@ UPB_INLINE uint32_t upb_EncodeOptions_MaxDepth(uint16_t depth) {
|
|
5989
5900
|
return (uint32_t)depth << 16;
|
5990
5901
|
}
|
5991
5902
|
|
5992
|
-
UPB_INLINE uint16_t upb_EncodeOptions_GetMaxDepth(uint32_t options) {
|
5993
|
-
return options >> 16;
|
5994
|
-
}
|
5995
|
-
|
5996
5903
|
uint16_t upb_EncodeOptions_GetEffectiveMaxDepth(uint32_t options);
|
5997
5904
|
|
5998
5905
|
// Enforce an upper bound on recursion depth.
|
5999
5906
|
UPB_INLINE int upb_Encode_LimitDepth(uint32_t encode_options, uint32_t limit) {
|
6000
|
-
uint32_t max_depth =
|
5907
|
+
uint32_t max_depth = upb_EncodeOptions_GetEffectiveMaxDepth(encode_options);
|
6001
5908
|
if (max_depth > limit) max_depth = limit;
|
6002
5909
|
return upb_EncodeOptions_MaxDepth(max_depth) | (encode_options & 0xffff);
|
6003
5910
|
}
|
@@ -6021,153 +5928,13 @@ UPB_API const char* upb_EncodeStatus_String(upb_EncodeStatus status);
|
|
6021
5928
|
|
6022
5929
|
|
6023
5930
|
#endif /* UPB_WIRE_ENCODE_H_ */
|
6024
|
-
|
6025
|
-
// These are the specialized field parser functions for the fast parser.
|
6026
|
-
// Generated tables will refer to these by name.
|
6027
|
-
//
|
6028
|
-
// The function names are encoded with names like:
|
6029
|
-
//
|
6030
|
-
// // 123 4
|
6031
|
-
// upb_pss_1bt(); // Parse singular string, 1 byte tag.
|
6032
|
-
//
|
6033
|
-
// In position 1:
|
6034
|
-
// - 'p' for parse, most function use this
|
6035
|
-
// - 'c' for copy, for when we are copying strings instead of aliasing
|
6036
|
-
//
|
6037
|
-
// In position 2 (cardinality):
|
6038
|
-
// - 's' for singular, with or without hasbit
|
6039
|
-
// - 'o' for oneof
|
6040
|
-
// - 'r' for non-packed repeated
|
6041
|
-
// - 'p' for packed repeated
|
6042
|
-
//
|
6043
|
-
// In position 3 (type):
|
6044
|
-
// - 'b1' for bool
|
6045
|
-
// - 'v4' for 4-byte varint
|
6046
|
-
// - 'v8' for 8-byte varint
|
6047
|
-
// - 'z4' for zig-zag-encoded 4-byte varint
|
6048
|
-
// - 'z8' for zig-zag-encoded 8-byte varint
|
6049
|
-
// - 'f4' for 4-byte fixed
|
6050
|
-
// - 'f8' for 8-byte fixed
|
6051
|
-
// - 'm' for sub-message
|
6052
|
-
// - 's' for string (validate UTF-8)
|
6053
|
-
// - 'b' for bytes
|
6054
|
-
//
|
6055
|
-
// In position 4 (tag length):
|
6056
|
-
// - '1' for one-byte tags (field numbers 1-15)
|
6057
|
-
// - '2' for two-byte tags (field numbers 16-2048)
|
6058
|
-
|
6059
|
-
#ifndef UPB_WIRE_INTERNAL_DECODE_FAST_H_
|
6060
|
-
#define UPB_WIRE_INTERNAL_DECODE_FAST_H_
|
6061
|
-
|
6062
|
-
|
6063
|
-
// Must be last.
|
6064
|
-
|
6065
|
-
#if UPB_FASTTABLE
|
6066
|
-
|
6067
|
-
#ifdef __cplusplus
|
6068
|
-
extern "C" {
|
6069
|
-
#endif
|
6070
|
-
|
6071
|
-
struct upb_Decoder;
|
6072
|
-
|
6073
|
-
// The fallback, generic parsing function that can handle any field type.
|
6074
|
-
// This just uses the regular (non-fast) parser to parse a single field.
|
6075
|
-
const char* _upb_FastDecoder_DecodeGeneric(struct upb_Decoder* d,
|
6076
|
-
const char* ptr, upb_Message* msg,
|
6077
|
-
intptr_t table, uint64_t hasbits,
|
6078
|
-
uint64_t data);
|
6079
|
-
|
6080
|
-
#define UPB_PARSE_PARAMS \
|
6081
|
-
struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \
|
6082
|
-
uint64_t hasbits, uint64_t data
|
6083
|
-
|
6084
|
-
/* primitive fields ***********************************************************/
|
6085
|
-
|
6086
|
-
#define F(card, type, valbytes, tagbytes) \
|
6087
|
-
const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS);
|
6088
|
-
|
6089
|
-
#define TYPES(card, tagbytes) \
|
6090
|
-
F(card, b, 1, tagbytes) \
|
6091
|
-
F(card, v, 4, tagbytes) \
|
6092
|
-
F(card, v, 8, tagbytes) \
|
6093
|
-
F(card, z, 4, tagbytes) \
|
6094
|
-
F(card, z, 8, tagbytes) \
|
6095
|
-
F(card, f, 4, tagbytes) \
|
6096
|
-
F(card, f, 8, tagbytes)
|
6097
|
-
|
6098
|
-
#define TAGBYTES(card) \
|
6099
|
-
TYPES(card, 1) \
|
6100
|
-
TYPES(card, 2)
|
6101
|
-
|
6102
|
-
TAGBYTES(s)
|
6103
|
-
TAGBYTES(o)
|
6104
|
-
TAGBYTES(r)
|
6105
|
-
TAGBYTES(p)
|
6106
|
-
|
6107
|
-
#undef F
|
6108
|
-
#undef TYPES
|
6109
|
-
#undef TAGBYTES
|
6110
|
-
|
6111
|
-
/* string fields **************************************************************/
|
6112
|
-
|
6113
|
-
#define F(card, tagbytes, type) \
|
6114
|
-
const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \
|
6115
|
-
const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS);
|
6116
|
-
|
6117
|
-
#define UTF8(card, tagbytes) \
|
6118
|
-
F(card, tagbytes, s) \
|
6119
|
-
F(card, tagbytes, b)
|
6120
|
-
|
6121
|
-
#define TAGBYTES(card) \
|
6122
|
-
UTF8(card, 1) \
|
6123
|
-
UTF8(card, 2)
|
6124
|
-
|
6125
|
-
TAGBYTES(s)
|
6126
|
-
TAGBYTES(o)
|
6127
|
-
TAGBYTES(r)
|
6128
|
-
|
6129
|
-
#undef F
|
6130
|
-
#undef UTF8
|
6131
|
-
#undef TAGBYTES
|
6132
|
-
|
6133
|
-
/* sub-message fields *********************************************************/
|
6134
|
-
|
6135
|
-
#define F(card, tagbytes, size_ceil, ceil_arg) \
|
6136
|
-
const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS);
|
6137
|
-
|
6138
|
-
#define SIZES(card, tagbytes) \
|
6139
|
-
F(card, tagbytes, 64, 64) \
|
6140
|
-
F(card, tagbytes, 128, 128) \
|
6141
|
-
F(card, tagbytes, 192, 192) \
|
6142
|
-
F(card, tagbytes, 256, 256) \
|
6143
|
-
F(card, tagbytes, max, -1)
|
6144
|
-
|
6145
|
-
#define TAGBYTES(card) \
|
6146
|
-
SIZES(card, 1) \
|
6147
|
-
SIZES(card, 2)
|
6148
|
-
|
6149
|
-
TAGBYTES(s)
|
6150
|
-
TAGBYTES(o)
|
6151
|
-
TAGBYTES(r)
|
6152
|
-
|
6153
|
-
#undef F
|
6154
|
-
#undef SIZES
|
6155
|
-
#undef TAGBYTES
|
6156
|
-
|
6157
|
-
#undef UPB_PARSE_PARAMS
|
6158
|
-
|
6159
|
-
#ifdef __cplusplus
|
6160
|
-
} /* extern "C" */
|
5931
|
+
#ifdef UPB_INCLUDE_FAST_DECODE
|
6161
5932
|
#endif
|
6162
|
-
|
6163
|
-
#endif /* UPB_FASTTABLE */
|
6164
|
-
|
6165
|
-
|
6166
|
-
#endif /* UPB_WIRE_INTERNAL_DECODE_FAST_H_ */
|
6167
5933
|
// IWYU pragma: end_exports
|
6168
5934
|
|
6169
|
-
#
|
5935
|
+
#undef UPB_INCLUDE_FAST_DECODE
|
6170
5936
|
|
5937
|
+
#endif // UPB_GENERATED_CODE_SUPPORT_H_
|
6171
5938
|
/* This file was generated by upb_generator from the input file:
|
6172
5939
|
*
|
6173
5940
|
* google/protobuf/descriptor.proto
|
@@ -6284,6 +6051,8 @@ extern const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout;
|
|
6284
6051
|
|
6285
6052
|
#endif /* GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_MINITABLE_H_ */
|
6286
6053
|
|
6054
|
+
#ifndef UPB_BASE_INTERNAL_LOG2_H_
|
6055
|
+
#define UPB_BASE_INTERNAL_LOG2_H_
|
6287
6056
|
|
6288
6057
|
// Must be last.
|
6289
6058
|
|
@@ -6291,49 +6060,126 @@ extern const upb_MiniTableFile google_protobuf_descriptor_proto_upb_file_layout;
|
|
6291
6060
|
extern "C" {
|
6292
6061
|
#endif
|
6293
6062
|
|
6294
|
-
|
6295
|
-
|
6296
|
-
|
6297
|
-
|
6298
|
-
|
6299
|
-
|
6300
|
-
|
6301
|
-
|
6302
|
-
|
6303
|
-
|
6304
|
-
|
6305
|
-
|
6306
|
-
|
6307
|
-
|
6308
|
-
|
6309
|
-
|
6310
|
-
|
6311
|
-
|
6312
|
-
|
6313
|
-
|
6314
|
-
|
6315
|
-
|
6316
|
-
|
6317
|
-
|
6318
|
-
|
6319
|
-
|
6320
|
-
|
6321
|
-
|
6322
|
-
|
6323
|
-
|
6324
|
-
|
6325
|
-
|
6326
|
-
|
6327
|
-
|
6328
|
-
|
6329
|
-
|
6330
|
-
|
6331
|
-
|
6332
|
-
|
6333
|
-
|
6334
|
-
|
6335
|
-
|
6336
|
-
|
6063
|
+
UPB_INLINE int upb_Log2Ceiling(int x) {
|
6064
|
+
if (x <= 1) return 0;
|
6065
|
+
#ifdef __GNUC__
|
6066
|
+
return 32 - __builtin_clz(x - 1);
|
6067
|
+
#else
|
6068
|
+
int lg2 = 0;
|
6069
|
+
while ((1 << lg2) < x) lg2++;
|
6070
|
+
return lg2;
|
6071
|
+
#endif
|
6072
|
+
}
|
6073
|
+
|
6074
|
+
UPB_INLINE int upb_RoundUpToPowerOfTwo(int x) {
|
6075
|
+
return 1 << upb_Log2Ceiling(x);
|
6076
|
+
}
|
6077
|
+
|
6078
|
+
#ifdef __cplusplus
|
6079
|
+
} /* extern "C" */
|
6080
|
+
#endif
|
6081
|
+
|
6082
|
+
|
6083
|
+
#endif /* UPB_BASE_INTERNAL_LOG2_H_ */
|
6084
|
+
|
6085
|
+
#ifndef UPB_JSON_DECODE_H_
|
6086
|
+
#define UPB_JSON_DECODE_H_
|
6087
|
+
|
6088
|
+
#include <stddef.h>
|
6089
|
+
|
6090
|
+
|
6091
|
+
#ifndef UPB_REFLECTION_DEF_H_
|
6092
|
+
#define UPB_REFLECTION_DEF_H_
|
6093
|
+
|
6094
|
+
// IWYU pragma: begin_exports
|
6095
|
+
|
6096
|
+
// IWYU pragma: private, include "upb/reflection/def.h"
|
6097
|
+
|
6098
|
+
#ifndef UPB_REFLECTION_DEF_POOL_H_
|
6099
|
+
#define UPB_REFLECTION_DEF_POOL_H_
|
6100
|
+
|
6101
|
+
|
6102
|
+
// IWYU pragma: private, include "upb/reflection/def.h"
|
6103
|
+
|
6104
|
+
// Declarations common to all public def types.
|
6105
|
+
|
6106
|
+
#ifndef UPB_REFLECTION_COMMON_H_
|
6107
|
+
#define UPB_REFLECTION_COMMON_H_
|
6108
|
+
|
6109
|
+
#ifndef GOOGLE_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H__
|
6110
|
+
#define GOOGLE_UPB_UPB_REFLECTION_DESCRIPTOR_BOOTSTRAP_H__
|
6111
|
+
|
6112
|
+
// IWYU pragma: begin_exports
|
6113
|
+
|
6114
|
+
#if defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 0
|
6115
|
+
// This header is checked in.
|
6116
|
+
#elif defined(UPB_BOOTSTRAP_STAGE) && UPB_BOOTSTRAP_STAGE == 1
|
6117
|
+
// This header is generated at build time by the bootstrapping process.
|
6118
|
+
#else
|
6119
|
+
// This is the normal header, generated by upb_c_proto_library().
|
6120
|
+
/* This file was generated by upb_generator from the input file:
|
6121
|
+
*
|
6122
|
+
* google/protobuf/descriptor.proto
|
6123
|
+
*
|
6124
|
+
* Do not edit -- your changes will be discarded when the file is
|
6125
|
+
* regenerated.
|
6126
|
+
* NO CHECKED-IN PROTOBUF GENCODE */
|
6127
|
+
|
6128
|
+
#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
|
6129
|
+
#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H__UPB_H_
|
6130
|
+
|
6131
|
+
|
6132
|
+
|
6133
|
+
|
6134
|
+
// Must be last.
|
6135
|
+
|
6136
|
+
#ifdef __cplusplus
|
6137
|
+
extern "C" {
|
6138
|
+
#endif
|
6139
|
+
|
6140
|
+
typedef struct google_protobuf_FileDescriptorSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorSet;
|
6141
|
+
typedef struct google_protobuf_FileDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FileDescriptorProto;
|
6142
|
+
typedef struct google_protobuf_DescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto;
|
6143
|
+
typedef struct google_protobuf_DescriptorProto_ExtensionRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ExtensionRange;
|
6144
|
+
typedef struct google_protobuf_DescriptorProto_ReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_DescriptorProto_ReservedRange;
|
6145
|
+
typedef struct google_protobuf_ExtensionRangeOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions;
|
6146
|
+
typedef struct google_protobuf_ExtensionRangeOptions_Declaration { upb_Message UPB_PRIVATE(base); } google_protobuf_ExtensionRangeOptions_Declaration;
|
6147
|
+
typedef struct google_protobuf_FieldDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldDescriptorProto;
|
6148
|
+
typedef struct google_protobuf_OneofDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofDescriptorProto;
|
6149
|
+
typedef struct google_protobuf_EnumDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto;
|
6150
|
+
typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumDescriptorProto_EnumReservedRange;
|
6151
|
+
typedef struct google_protobuf_EnumValueDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueDescriptorProto;
|
6152
|
+
typedef struct google_protobuf_ServiceDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceDescriptorProto;
|
6153
|
+
typedef struct google_protobuf_MethodDescriptorProto { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodDescriptorProto;
|
6154
|
+
typedef struct google_protobuf_FileOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FileOptions;
|
6155
|
+
typedef struct google_protobuf_MessageOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MessageOptions;
|
6156
|
+
typedef struct google_protobuf_FieldOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions;
|
6157
|
+
typedef struct google_protobuf_FieldOptions_EditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions_EditionDefault;
|
6158
|
+
typedef struct google_protobuf_FieldOptions_FeatureSupport { upb_Message UPB_PRIVATE(base); } google_protobuf_FieldOptions_FeatureSupport;
|
6159
|
+
typedef struct google_protobuf_OneofOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_OneofOptions;
|
6160
|
+
typedef struct google_protobuf_EnumOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumOptions;
|
6161
|
+
typedef struct google_protobuf_EnumValueOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_EnumValueOptions;
|
6162
|
+
typedef struct google_protobuf_ServiceOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_ServiceOptions;
|
6163
|
+
typedef struct google_protobuf_MethodOptions { upb_Message UPB_PRIVATE(base); } google_protobuf_MethodOptions;
|
6164
|
+
typedef struct google_protobuf_UninterpretedOption { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption;
|
6165
|
+
typedef struct google_protobuf_UninterpretedOption_NamePart { upb_Message UPB_PRIVATE(base); } google_protobuf_UninterpretedOption_NamePart;
|
6166
|
+
typedef struct google_protobuf_FeatureSet { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSet;
|
6167
|
+
typedef struct google_protobuf_FeatureSet_VisibilityFeature { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSet_VisibilityFeature;
|
6168
|
+
typedef struct google_protobuf_FeatureSetDefaults { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults;
|
6169
|
+
typedef struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault { upb_Message UPB_PRIVATE(base); } google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault;
|
6170
|
+
typedef struct google_protobuf_SourceCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo;
|
6171
|
+
typedef struct google_protobuf_SourceCodeInfo_Location { upb_Message UPB_PRIVATE(base); } google_protobuf_SourceCodeInfo_Location;
|
6172
|
+
typedef struct google_protobuf_GeneratedCodeInfo { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo;
|
6173
|
+
typedef struct google_protobuf_GeneratedCodeInfo_Annotation { upb_Message UPB_PRIVATE(base); } google_protobuf_GeneratedCodeInfo_Annotation;
|
6174
|
+
|
6175
|
+
typedef enum {
|
6176
|
+
google_protobuf_EDITION_UNKNOWN = 0,
|
6177
|
+
google_protobuf_EDITION_1_TEST_ONLY = 1,
|
6178
|
+
google_protobuf_EDITION_2_TEST_ONLY = 2,
|
6179
|
+
google_protobuf_EDITION_LEGACY = 900,
|
6180
|
+
google_protobuf_EDITION_PROTO2 = 998,
|
6181
|
+
google_protobuf_EDITION_PROTO3 = 999,
|
6182
|
+
google_protobuf_EDITION_2023 = 1000,
|
6337
6183
|
google_protobuf_EDITION_2024 = 1001,
|
6338
6184
|
google_protobuf_EDITION_99997_TEST_ONLY = 99997,
|
6339
6185
|
google_protobuf_EDITION_99998_TEST_ONLY = 99998,
|
@@ -13670,6 +13516,7 @@ UPB_API bool upb_FieldDef_IsEnum(const upb_FieldDef* f);
|
|
13670
13516
|
bool upb_FieldDef_IsExtension(const upb_FieldDef* f);
|
13671
13517
|
UPB_API bool upb_FieldDef_IsMap(const upb_FieldDef* f);
|
13672
13518
|
bool upb_FieldDef_IsOptional(const upb_FieldDef* f);
|
13519
|
+
bool _upb_FieldDef_IsPackable(const upb_FieldDef* f);
|
13673
13520
|
UPB_API bool upb_FieldDef_IsPacked(const upb_FieldDef* f);
|
13674
13521
|
bool upb_FieldDef_IsPrimitive(const upb_FieldDef* f);
|
13675
13522
|
UPB_API bool upb_FieldDef_IsRepeated(const upb_FieldDef* f);
|
@@ -14301,6 +14148,24 @@ UPB_INLINE int _upb_vsnprintf(char* buf, size_t size, const char* fmt,
|
|
14301
14148
|
|
14302
14149
|
#endif // UPB_PORT_VSNPRINTF_COMPAT_H_
|
14303
14150
|
|
14151
|
+
#ifndef UPB_LEX_STRTOD_H_
|
14152
|
+
#define UPB_LEX_STRTOD_H_
|
14153
|
+
|
14154
|
+
// Must be last.
|
14155
|
+
|
14156
|
+
#ifdef __cplusplus
|
14157
|
+
extern "C" {
|
14158
|
+
#endif
|
14159
|
+
|
14160
|
+
double _upb_NoLocaleStrtod(const char *str, char **endptr);
|
14161
|
+
|
14162
|
+
#ifdef __cplusplus
|
14163
|
+
} /* extern "C" */
|
14164
|
+
#endif
|
14165
|
+
|
14166
|
+
|
14167
|
+
#endif /* UPB_LEX_STRTOD_H_ */
|
14168
|
+
|
14304
14169
|
#ifndef UPB_PORT_ATOMIC_H_
|
14305
14170
|
#define UPB_PORT_ATOMIC_H_
|
14306
14171
|
|
@@ -14652,37 +14517,6 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s, const upb_Message_Internal* in,
|
|
14652
14517
|
|
14653
14518
|
#endif /* UPB_MESSAGE_INTERNAL_MAP_SORTER_H_ */
|
14654
14519
|
|
14655
|
-
#ifndef UPB_BASE_INTERNAL_LOG2_H_
|
14656
|
-
#define UPB_BASE_INTERNAL_LOG2_H_
|
14657
|
-
|
14658
|
-
// Must be last.
|
14659
|
-
|
14660
|
-
#ifdef __cplusplus
|
14661
|
-
extern "C" {
|
14662
|
-
#endif
|
14663
|
-
|
14664
|
-
UPB_INLINE int upb_Log2Ceiling(int x) {
|
14665
|
-
if (x <= 1) return 0;
|
14666
|
-
#ifdef __GNUC__
|
14667
|
-
return 32 - __builtin_clz(x - 1);
|
14668
|
-
#else
|
14669
|
-
int lg2 = 0;
|
14670
|
-
while ((1 << lg2) < x) lg2++;
|
14671
|
-
return lg2;
|
14672
|
-
#endif
|
14673
|
-
}
|
14674
|
-
|
14675
|
-
UPB_INLINE int upb_RoundUpToPowerOfTwo(int x) {
|
14676
|
-
return 1 << upb_Log2Ceiling(x);
|
14677
|
-
}
|
14678
|
-
|
14679
|
-
#ifdef __cplusplus
|
14680
|
-
} /* extern "C" */
|
14681
|
-
#endif
|
14682
|
-
|
14683
|
-
|
14684
|
-
#endif /* UPB_BASE_INTERNAL_LOG2_H_ */
|
14685
|
-
|
14686
14520
|
#ifndef UPB_MESSAGE_COMPARE_H_
|
14687
14521
|
#define UPB_MESSAGE_COMPARE_H_
|
14688
14522
|
|
@@ -14773,43 +14607,450 @@ extern "C" {
|
|
14773
14607
|
// 2. We don't know about oneof/non-repeated fields, which should semantically
|
14774
14608
|
// discard every value except the last.
|
14775
14609
|
|
14776
|
-
typedef enum {
|
14777
|
-
kUpb_UnknownCompareResult_Equal = 0,
|
14778
|
-
kUpb_UnknownCompareResult_NotEqual = 1,
|
14779
|
-
kUpb_UnknownCompareResult_OutOfMemory = 2,
|
14780
|
-
kUpb_UnknownCompareResult_MaxDepthExceeded = 3,
|
14781
|
-
} upb_UnknownCompareResult;
|
14610
|
+
typedef enum {
|
14611
|
+
kUpb_UnknownCompareResult_Equal = 0,
|
14612
|
+
kUpb_UnknownCompareResult_NotEqual = 1,
|
14613
|
+
kUpb_UnknownCompareResult_OutOfMemory = 2,
|
14614
|
+
kUpb_UnknownCompareResult_MaxDepthExceeded = 3,
|
14615
|
+
} upb_UnknownCompareResult;
|
14616
|
+
|
14617
|
+
upb_UnknownCompareResult UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
|
14618
|
+
const upb_Message* msg1, const upb_Message* msg2, int max_depth);
|
14619
|
+
|
14620
|
+
#ifdef __cplusplus
|
14621
|
+
} /* extern "C" */
|
14622
|
+
#endif
|
14623
|
+
|
14624
|
+
|
14625
|
+
#endif /* UPB_MESSAGE_INTERNAL_COMPARE_UNKNOWN_H_ */
|
14626
|
+
|
14627
|
+
#ifndef GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__
|
14628
|
+
#define GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__
|
14629
|
+
|
14630
|
+
#include <stddef.h>
|
14631
|
+
#include <stdint.h>
|
14632
|
+
|
14633
|
+
|
14634
|
+
// Must be last.
|
14635
|
+
|
14636
|
+
#define kUpb_BaseField_Begin ((size_t)-1)
|
14637
|
+
bool UPB_PRIVATE(_upb_Message_NextBaseField)(const upb_Message* msg,
|
14638
|
+
const upb_MiniTable* m,
|
14639
|
+
const upb_MiniTableField** out_f,
|
14640
|
+
upb_MessageValue* out_v,
|
14641
|
+
uintptr_t* iter);
|
14642
|
+
|
14643
|
+
#endif // GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__
|
14644
|
+
|
14645
|
+
#ifndef UPB_WIRE_EPS_COPY_INPUT_STREAM_H_
|
14646
|
+
#define UPB_WIRE_EPS_COPY_INPUT_STREAM_H_
|
14647
|
+
|
14648
|
+
#include <stdint.h>
|
14649
|
+
#include <string.h>
|
14650
|
+
|
14651
|
+
|
14652
|
+
// Must be last.
|
14653
|
+
|
14654
|
+
#ifdef __cplusplus
|
14655
|
+
extern "C" {
|
14656
|
+
#endif
|
14657
|
+
|
14658
|
+
// The maximum number of bytes a single protobuf field can take up in the
|
14659
|
+
// wire format. We only want to do one bounds check per field, so the input
|
14660
|
+
// stream guarantees that after upb_EpsCopyInputStream_IsDone() is called,
|
14661
|
+
// the decoder can read this many bytes without performing another bounds
|
14662
|
+
// check. The stream will copy into a patch buffer as necessary to guarantee
|
14663
|
+
// this invariant.
|
14664
|
+
#define kUpb_EpsCopyInputStream_SlopBytes 16
|
14665
|
+
|
14666
|
+
typedef struct {
|
14667
|
+
const char* end; // Can read up to SlopBytes bytes beyond this.
|
14668
|
+
const char* limit_ptr; // For bounds checks, = end + UPB_MIN(limit, 0)
|
14669
|
+
uintptr_t input_delta; // Diff between the original input pointer and patch
|
14670
|
+
const char* buffer_start; // Pointer to the original input buffer
|
14671
|
+
int limit; // Submessage limit relative to end
|
14672
|
+
bool error; // To distinguish between EOF and error.
|
14673
|
+
bool aliasing;
|
14674
|
+
char patch[kUpb_EpsCopyInputStream_SlopBytes * 2];
|
14675
|
+
} upb_EpsCopyInputStream;
|
14676
|
+
|
14677
|
+
// Returns true if the stream is in the error state. A stream enters the error
|
14678
|
+
// state when the user reads past a limit (caught in IsDone()) or the
|
14679
|
+
// ZeroCopyInputStream returns an error.
|
14680
|
+
UPB_INLINE bool upb_EpsCopyInputStream_IsError(upb_EpsCopyInputStream* e) {
|
14681
|
+
return e->error;
|
14682
|
+
}
|
14683
|
+
|
14684
|
+
typedef const char* upb_EpsCopyInputStream_BufferFlipCallback(
|
14685
|
+
upb_EpsCopyInputStream* e, const char* old_end, const char* new_start);
|
14686
|
+
|
14687
|
+
typedef const char* upb_EpsCopyInputStream_IsDoneFallbackFunc(
|
14688
|
+
upb_EpsCopyInputStream* e, const char* ptr, int overrun);
|
14689
|
+
|
14690
|
+
// Initializes a upb_EpsCopyInputStream using the contents of the buffer
|
14691
|
+
// [*ptr, size]. Updates `*ptr` as necessary to guarantee that at least
|
14692
|
+
// kUpb_EpsCopyInputStream_SlopBytes are available to read.
|
14693
|
+
UPB_INLINE void upb_EpsCopyInputStream_Init(upb_EpsCopyInputStream* e,
|
14694
|
+
const char** ptr, size_t size,
|
14695
|
+
bool enable_aliasing) {
|
14696
|
+
e->buffer_start = *ptr;
|
14697
|
+
if (size <= kUpb_EpsCopyInputStream_SlopBytes) {
|
14698
|
+
memset(&e->patch, 0, 32);
|
14699
|
+
if (size) memcpy(&e->patch, *ptr, size);
|
14700
|
+
e->input_delta = (uintptr_t)*ptr - (uintptr_t)e->patch;
|
14701
|
+
*ptr = e->patch;
|
14702
|
+
e->end = *ptr + size;
|
14703
|
+
e->limit = 0;
|
14704
|
+
} else {
|
14705
|
+
e->end = *ptr + size - kUpb_EpsCopyInputStream_SlopBytes;
|
14706
|
+
e->limit = kUpb_EpsCopyInputStream_SlopBytes;
|
14707
|
+
e->input_delta = 0;
|
14708
|
+
}
|
14709
|
+
e->aliasing = enable_aliasing;
|
14710
|
+
e->limit_ptr = e->end;
|
14711
|
+
e->error = false;
|
14712
|
+
}
|
14713
|
+
|
14714
|
+
typedef enum {
|
14715
|
+
// The current stream position is at a limit.
|
14716
|
+
kUpb_IsDoneStatus_Done,
|
14717
|
+
|
14718
|
+
// The current stream position is not at a limit.
|
14719
|
+
kUpb_IsDoneStatus_NotDone,
|
14720
|
+
|
14721
|
+
// The current stream position is not at a limit, and the stream needs to
|
14722
|
+
// be flipped to a new buffer before more data can be read.
|
14723
|
+
kUpb_IsDoneStatus_NeedFallback,
|
14724
|
+
} upb_IsDoneStatus;
|
14725
|
+
|
14726
|
+
// Returns the status of the current stream position. This is a low-level
|
14727
|
+
// function, it is simpler to call upb_EpsCopyInputStream_IsDone() if possible.
|
14728
|
+
UPB_INLINE upb_IsDoneStatus upb_EpsCopyInputStream_IsDoneStatus(
|
14729
|
+
upb_EpsCopyInputStream* e, const char* ptr, int* overrun) {
|
14730
|
+
*overrun = ptr - e->end;
|
14731
|
+
if (UPB_LIKELY(ptr < e->limit_ptr)) {
|
14732
|
+
return kUpb_IsDoneStatus_NotDone;
|
14733
|
+
} else if (UPB_LIKELY(*overrun == e->limit)) {
|
14734
|
+
return kUpb_IsDoneStatus_Done;
|
14735
|
+
} else {
|
14736
|
+
return kUpb_IsDoneStatus_NeedFallback;
|
14737
|
+
}
|
14738
|
+
}
|
14739
|
+
|
14740
|
+
// Returns true if the stream has hit a limit, either the current delimited
|
14741
|
+
// limit or the overall end-of-stream. As a side effect, this function may flip
|
14742
|
+
// the pointer to a new buffer if there are less than
|
14743
|
+
// kUpb_EpsCopyInputStream_SlopBytes of data to be read in the current buffer.
|
14744
|
+
//
|
14745
|
+
// Postcondition: if the function returns false, there are at least
|
14746
|
+
// kUpb_EpsCopyInputStream_SlopBytes of data available to read at *ptr.
|
14747
|
+
UPB_INLINE bool upb_EpsCopyInputStream_IsDoneWithCallback(
|
14748
|
+
upb_EpsCopyInputStream* e, const char** ptr,
|
14749
|
+
upb_EpsCopyInputStream_IsDoneFallbackFunc* func) {
|
14750
|
+
int overrun;
|
14751
|
+
switch (upb_EpsCopyInputStream_IsDoneStatus(e, *ptr, &overrun)) {
|
14752
|
+
case kUpb_IsDoneStatus_Done:
|
14753
|
+
return true;
|
14754
|
+
case kUpb_IsDoneStatus_NotDone:
|
14755
|
+
return false;
|
14756
|
+
case kUpb_IsDoneStatus_NeedFallback:
|
14757
|
+
*ptr = func(e, *ptr, overrun);
|
14758
|
+
return *ptr == NULL;
|
14759
|
+
}
|
14760
|
+
UPB_UNREACHABLE();
|
14761
|
+
}
|
14762
|
+
|
14763
|
+
const char* _upb_EpsCopyInputStream_IsDoneFallbackNoCallback(
|
14764
|
+
upb_EpsCopyInputStream* e, const char* ptr, int overrun);
|
14765
|
+
|
14766
|
+
// A simpler version of IsDoneWithCallback() that does not support a buffer flip
|
14767
|
+
// callback. Useful in cases where we do not need to insert custom logic at
|
14768
|
+
// every buffer flip.
|
14769
|
+
//
|
14770
|
+
// If this returns true, the user must call upb_EpsCopyInputStream_IsError()
|
14771
|
+
// to distinguish between EOF and error.
|
14772
|
+
UPB_INLINE bool upb_EpsCopyInputStream_IsDone(upb_EpsCopyInputStream* e,
|
14773
|
+
const char** ptr) {
|
14774
|
+
return upb_EpsCopyInputStream_IsDoneWithCallback(
|
14775
|
+
e, ptr, _upb_EpsCopyInputStream_IsDoneFallbackNoCallback);
|
14776
|
+
}
|
14777
|
+
|
14778
|
+
// Returns the total number of bytes that are safe to read from the current
|
14779
|
+
// buffer without reading uninitialized or unallocated memory.
|
14780
|
+
//
|
14781
|
+
// Note that this check does not respect any semantic limits on the stream,
|
14782
|
+
// either limits from PushLimit() or the overall stream end, so some of these
|
14783
|
+
// bytes may have unpredictable, nonsense values in them. The guarantee is only
|
14784
|
+
// that the bytes are valid to read from the perspective of the C language
|
14785
|
+
// (ie. you can read without triggering UBSAN or ASAN).
|
14786
|
+
UPB_INLINE size_t upb_EpsCopyInputStream_BytesAvailable(
|
14787
|
+
upb_EpsCopyInputStream* e, const char* ptr) {
|
14788
|
+
return (e->end - ptr) + kUpb_EpsCopyInputStream_SlopBytes;
|
14789
|
+
}
|
14790
|
+
|
14791
|
+
// Returns true if the given delimited field size is valid (it does not extend
|
14792
|
+
// beyond any previously-pushed limits). `ptr` should point to the beginning
|
14793
|
+
// of the field data, after the delimited size.
|
14794
|
+
//
|
14795
|
+
// Note that this does *not* guarantee that all of the data for this field is in
|
14796
|
+
// the current buffer.
|
14797
|
+
UPB_INLINE bool upb_EpsCopyInputStream_CheckSize(
|
14798
|
+
const upb_EpsCopyInputStream* e, const char* ptr, int size) {
|
14799
|
+
UPB_ASSERT(size >= 0);
|
14800
|
+
return size <= e->limit - (ptr - e->end);
|
14801
|
+
}
|
14802
|
+
|
14803
|
+
UPB_INLINE bool _upb_EpsCopyInputStream_CheckSizeAvailable(
|
14804
|
+
upb_EpsCopyInputStream* e, const char* ptr, int size, bool submessage) {
|
14805
|
+
// This is one extra branch compared to the more normal:
|
14806
|
+
// return (size_t)(end - ptr) < size;
|
14807
|
+
// However it is one less computation if we are just about to use "ptr + len":
|
14808
|
+
// https://godbolt.org/z/35YGPz
|
14809
|
+
// In microbenchmarks this shows a small improvement.
|
14810
|
+
uintptr_t uptr = (uintptr_t)ptr;
|
14811
|
+
uintptr_t uend = (uintptr_t)e->limit_ptr;
|
14812
|
+
uintptr_t res = uptr + (size_t)size;
|
14813
|
+
if (!submessage) uend += kUpb_EpsCopyInputStream_SlopBytes;
|
14814
|
+
// NOTE: this check depends on having a linear address space. This is not
|
14815
|
+
// technically guaranteed by uintptr_t.
|
14816
|
+
bool ret = res >= uptr && res <= uend;
|
14817
|
+
if (size < 0) UPB_ASSERT(!ret);
|
14818
|
+
return ret;
|
14819
|
+
}
|
14820
|
+
|
14821
|
+
// Returns true if the given delimited field size is valid (it does not extend
|
14822
|
+
// beyond any previously-pushed limited) *and* all of the data for this field is
|
14823
|
+
// available to be read in the current buffer.
|
14824
|
+
//
|
14825
|
+
// If the size is negative, this function will always return false. This
|
14826
|
+
// property can be useful in some cases.
|
14827
|
+
UPB_INLINE bool upb_EpsCopyInputStream_CheckDataSizeAvailable(
|
14828
|
+
upb_EpsCopyInputStream* e, const char* ptr, int size) {
|
14829
|
+
return _upb_EpsCopyInputStream_CheckSizeAvailable(e, ptr, size, false);
|
14830
|
+
}
|
14831
|
+
|
14832
|
+
// Returns true if the given sub-message size is valid (it does not extend
|
14833
|
+
// beyond any previously-pushed limited) *and* all of the data for this
|
14834
|
+
// sub-message is available to be parsed in the current buffer.
|
14835
|
+
//
|
14836
|
+
// This implies that all fields from the sub-message can be parsed from the
|
14837
|
+
// current buffer while maintaining the invariant that we always have at least
|
14838
|
+
// kUpb_EpsCopyInputStream_SlopBytes of data available past the beginning of
|
14839
|
+
// any individual field start.
|
14840
|
+
//
|
14841
|
+
// If the size is negative, this function will always return false. This
|
14842
|
+
// property can be useful in some cases.
|
14843
|
+
UPB_INLINE bool upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(
|
14844
|
+
upb_EpsCopyInputStream* e, const char* ptr, int size) {
|
14845
|
+
return _upb_EpsCopyInputStream_CheckSizeAvailable(e, ptr, size, true);
|
14846
|
+
}
|
14847
|
+
|
14848
|
+
// Returns true if aliasing_enabled=true was passed to
|
14849
|
+
// upb_EpsCopyInputStream_Init() when this stream was initialized.
|
14850
|
+
UPB_INLINE bool upb_EpsCopyInputStream_AliasingEnabled(
|
14851
|
+
upb_EpsCopyInputStream* e) {
|
14852
|
+
return e->aliasing;
|
14853
|
+
}
|
14854
|
+
|
14855
|
+
// Returns true if aliasing_enabled=true was passed to
|
14856
|
+
// upb_EpsCopyInputStream_Init() when this stream was initialized *and* we can
|
14857
|
+
// alias into the region [ptr, size] in an input buffer.
|
14858
|
+
UPB_INLINE bool upb_EpsCopyInputStream_AliasingAvailable(
|
14859
|
+
upb_EpsCopyInputStream* e, const char* ptr, size_t size) {
|
14860
|
+
// When EpsCopyInputStream supports streaming, this will need to become a
|
14861
|
+
// runtime check.
|
14862
|
+
return e->aliasing &&
|
14863
|
+
upb_EpsCopyInputStream_CheckDataSizeAvailable(e, ptr, size);
|
14864
|
+
}
|
14865
|
+
|
14866
|
+
// Returns a pointer into an input buffer that corresponds to the parsing
|
14867
|
+
// pointer `ptr`. The returned pointer may be the same as `ptr`, but also may
|
14868
|
+
// be different if we are currently parsing out of the patch buffer.
|
14869
|
+
UPB_INLINE const char* upb_EpsCopyInputStream_GetInputPtr(
|
14870
|
+
upb_EpsCopyInputStream* e, const char* ptr) {
|
14871
|
+
// This somewhat silly looking add-and-subtract behavior provides provenance
|
14872
|
+
// from the original input buffer's pointer. After optimization it produces
|
14873
|
+
// the same assembly as just casting `(uintptr_t)ptr+input_delta`
|
14874
|
+
// https://godbolt.org/z/zosG88oPn
|
14875
|
+
size_t position =
|
14876
|
+
(uintptr_t)ptr + e->input_delta - (uintptr_t)e->buffer_start;
|
14877
|
+
return e->buffer_start + position;
|
14878
|
+
}
|
14879
|
+
|
14880
|
+
// Returns a pointer into an input buffer that corresponds to the parsing
|
14881
|
+
// pointer `ptr`. The returned pointer may be the same as `ptr`, but also may
|
14882
|
+
// be different if we are currently parsing out of the patch buffer.
|
14883
|
+
//
|
14884
|
+
// REQUIRES: Aliasing must be available for the given pointer. If the input is a
|
14885
|
+
// flat buffer and aliasing is enabled, then aliasing will always be available.
|
14886
|
+
UPB_INLINE const char* upb_EpsCopyInputStream_GetAliasedPtr(
|
14887
|
+
upb_EpsCopyInputStream* e, const char* ptr) {
|
14888
|
+
UPB_ASSUME(upb_EpsCopyInputStream_AliasingAvailable(e, ptr, 0));
|
14889
|
+
return upb_EpsCopyInputStream_GetInputPtr(e, ptr);
|
14890
|
+
}
|
14891
|
+
|
14892
|
+
// Reads string data from the input, aliasing into the input buffer instead of
|
14893
|
+
// copying. The parsing pointer is passed in `*ptr`, and will be updated if
|
14894
|
+
// necessary to point to the actual input buffer. Returns the new parsing
|
14895
|
+
// pointer, which will be advanced past the string data.
|
14896
|
+
//
|
14897
|
+
// REQUIRES: Aliasing must be available for this data region (test with
|
14898
|
+
// upb_EpsCopyInputStream_AliasingAvailable().
|
14899
|
+
UPB_INLINE const char* upb_EpsCopyInputStream_ReadStringAliased(
|
14900
|
+
upb_EpsCopyInputStream* e, const char** ptr, size_t size) {
|
14901
|
+
UPB_ASSUME(upb_EpsCopyInputStream_AliasingAvailable(e, *ptr, size));
|
14902
|
+
const char* ret = *ptr + size;
|
14903
|
+
*ptr = upb_EpsCopyInputStream_GetAliasedPtr(e, *ptr);
|
14904
|
+
UPB_ASSUME(ret != NULL);
|
14905
|
+
return ret;
|
14906
|
+
}
|
14907
|
+
|
14908
|
+
// Skips `size` bytes of data from the input and returns a pointer past the end.
|
14909
|
+
// Returns NULL on end of stream or error.
|
14910
|
+
UPB_INLINE const char* upb_EpsCopyInputStream_Skip(upb_EpsCopyInputStream* e,
|
14911
|
+
const char* ptr, int size) {
|
14912
|
+
if (!upb_EpsCopyInputStream_CheckDataSizeAvailable(e, ptr, size)) return NULL;
|
14913
|
+
return ptr + size;
|
14914
|
+
}
|
14915
|
+
|
14916
|
+
// Copies `size` bytes of data from the input `ptr` into the buffer `to`, and
|
14917
|
+
// returns a pointer past the end. Returns NULL on end of stream or error.
|
14918
|
+
UPB_INLINE const char* upb_EpsCopyInputStream_Copy(upb_EpsCopyInputStream* e,
|
14919
|
+
const char* ptr, void* to,
|
14920
|
+
int size) {
|
14921
|
+
if (!upb_EpsCopyInputStream_CheckDataSizeAvailable(e, ptr, size)) return NULL;
|
14922
|
+
memcpy(to, ptr, size);
|
14923
|
+
return ptr + size;
|
14924
|
+
}
|
14925
|
+
|
14926
|
+
// Reads string data from the stream and advances the pointer accordingly.
|
14927
|
+
// If aliasing was enabled when the stream was initialized, then the returned
|
14928
|
+
// pointer will point into the input buffer if possible, otherwise new data
|
14929
|
+
// will be allocated from arena and copied into. We may be forced to copy even
|
14930
|
+
// if aliasing was enabled if the input data spans input buffers.
|
14931
|
+
//
|
14932
|
+
// Returns NULL if memory allocation failed, or we reached a premature EOF.
|
14933
|
+
UPB_INLINE const char* upb_EpsCopyInputStream_ReadString(
|
14934
|
+
upb_EpsCopyInputStream* e, const char** ptr, size_t size,
|
14935
|
+
upb_Arena* arena) {
|
14936
|
+
if (upb_EpsCopyInputStream_AliasingAvailable(e, *ptr, size)) {
|
14937
|
+
return upb_EpsCopyInputStream_ReadStringAliased(e, ptr, size);
|
14938
|
+
} else {
|
14939
|
+
// We need to allocate and copy.
|
14940
|
+
if (!upb_EpsCopyInputStream_CheckDataSizeAvailable(e, *ptr, size)) {
|
14941
|
+
return NULL;
|
14942
|
+
}
|
14943
|
+
UPB_ASSERT(arena);
|
14944
|
+
char* data = (char*)upb_Arena_Malloc(arena, size);
|
14945
|
+
if (!data) return NULL;
|
14946
|
+
const char* ret = upb_EpsCopyInputStream_Copy(e, *ptr, data, size);
|
14947
|
+
*ptr = data;
|
14948
|
+
return ret;
|
14949
|
+
}
|
14950
|
+
}
|
14951
|
+
|
14952
|
+
UPB_INLINE void _upb_EpsCopyInputStream_CheckLimit(upb_EpsCopyInputStream* e) {
|
14953
|
+
UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit));
|
14954
|
+
}
|
14955
|
+
|
14956
|
+
// Pushes a limit onto the stack of limits for the current stream. The limit
|
14957
|
+
// will extend for `size` bytes beyond the position in `ptr`. Future calls to
|
14958
|
+
// upb_EpsCopyInputStream_IsDone() will return `true` when the stream position
|
14959
|
+
// reaches this limit.
|
14960
|
+
//
|
14961
|
+
// Returns a delta that the caller must store and supply to PopLimit() below.
|
14962
|
+
UPB_INLINE int upb_EpsCopyInputStream_PushLimit(upb_EpsCopyInputStream* e,
|
14963
|
+
const char* ptr, int size) {
|
14964
|
+
int limit = size + (int)(ptr - e->end);
|
14965
|
+
int delta = e->limit - limit;
|
14966
|
+
_upb_EpsCopyInputStream_CheckLimit(e);
|
14967
|
+
UPB_ASSERT(limit <= e->limit);
|
14968
|
+
e->limit = limit;
|
14969
|
+
e->limit_ptr = e->end + UPB_MIN(0, limit);
|
14970
|
+
_upb_EpsCopyInputStream_CheckLimit(e);
|
14971
|
+
return delta;
|
14972
|
+
}
|
14973
|
+
|
14974
|
+
// Pops the last limit that was pushed on this stream. This may only be called
|
14975
|
+
// once IsDone() returns true. The user must pass the delta that was returned
|
14976
|
+
// from PushLimit().
|
14977
|
+
UPB_INLINE void upb_EpsCopyInputStream_PopLimit(upb_EpsCopyInputStream* e,
|
14978
|
+
const char* ptr,
|
14979
|
+
int saved_delta) {
|
14980
|
+
UPB_ASSERT(ptr - e->end == e->limit);
|
14981
|
+
_upb_EpsCopyInputStream_CheckLimit(e);
|
14982
|
+
e->limit += saved_delta;
|
14983
|
+
e->limit_ptr = e->end + UPB_MIN(0, e->limit);
|
14984
|
+
_upb_EpsCopyInputStream_CheckLimit(e);
|
14985
|
+
}
|
14986
|
+
|
14987
|
+
UPB_INLINE const char* _upb_EpsCopyInputStream_IsDoneFallbackInline(
|
14988
|
+
upb_EpsCopyInputStream* e, const char* ptr, int overrun,
|
14989
|
+
upb_EpsCopyInputStream_BufferFlipCallback* callback) {
|
14990
|
+
if (overrun < e->limit) {
|
14991
|
+
// Need to copy remaining data into patch buffer.
|
14992
|
+
UPB_ASSERT(overrun < kUpb_EpsCopyInputStream_SlopBytes);
|
14993
|
+
const char* old_end = ptr;
|
14994
|
+
const char* new_start = &e->patch[0] + overrun;
|
14995
|
+
memset(e->patch + kUpb_EpsCopyInputStream_SlopBytes, 0,
|
14996
|
+
kUpb_EpsCopyInputStream_SlopBytes);
|
14997
|
+
memcpy(e->patch, e->end, kUpb_EpsCopyInputStream_SlopBytes);
|
14998
|
+
ptr = new_start;
|
14999
|
+
e->end = &e->patch[kUpb_EpsCopyInputStream_SlopBytes];
|
15000
|
+
e->limit -= kUpb_EpsCopyInputStream_SlopBytes;
|
15001
|
+
e->limit_ptr = e->end + e->limit;
|
15002
|
+
UPB_ASSERT(ptr < e->limit_ptr);
|
15003
|
+
e->input_delta = (uintptr_t)old_end - (uintptr_t)new_start;
|
15004
|
+
return callback(e, old_end, new_start);
|
15005
|
+
} else {
|
15006
|
+
UPB_ASSERT(overrun > e->limit);
|
15007
|
+
e->error = true;
|
15008
|
+
return callback(e, NULL, NULL);
|
15009
|
+
}
|
15010
|
+
}
|
15011
|
+
|
15012
|
+
typedef const char* upb_EpsCopyInputStream_ParseDelimitedFunc(
|
15013
|
+
upb_EpsCopyInputStream* e, const char* ptr, void* ctx);
|
14782
15014
|
|
14783
|
-
|
14784
|
-
|
15015
|
+
// Tries to perform a fast-path handling of the given delimited message data.
|
15016
|
+
// If the sub-message beginning at `*ptr` and extending for `len` is short and
|
15017
|
+
// fits within this buffer, calls `func` with `ctx` as a parameter, where the
|
15018
|
+
// pushing and popping of limits is handled automatically and with lower cost
|
15019
|
+
// than the normal PushLimit()/PopLimit() sequence.
|
15020
|
+
UPB_FORCEINLINE bool upb_EpsCopyInputStream_TryParseDelimitedFast(
|
15021
|
+
upb_EpsCopyInputStream* e, const char** ptr, int len,
|
15022
|
+
upb_EpsCopyInputStream_ParseDelimitedFunc* func, void* ctx) {
|
15023
|
+
if (!upb_EpsCopyInputStream_CheckSubMessageSizeAvailable(e, *ptr, len)) {
|
15024
|
+
return false;
|
15025
|
+
}
|
15026
|
+
|
15027
|
+
// Fast case: Sub-message is <128 bytes and fits in the current buffer.
|
15028
|
+
// This means we can preserve limit/limit_ptr verbatim.
|
15029
|
+
const char* saved_limit_ptr = e->limit_ptr;
|
15030
|
+
int saved_limit = e->limit;
|
15031
|
+
e->limit_ptr = *ptr + len;
|
15032
|
+
e->limit = e->limit_ptr - e->end;
|
15033
|
+
UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit));
|
15034
|
+
*ptr = func(e, *ptr, ctx);
|
15035
|
+
e->limit_ptr = saved_limit_ptr;
|
15036
|
+
e->limit = saved_limit;
|
15037
|
+
UPB_ASSERT(e->limit_ptr == e->end + UPB_MIN(0, e->limit));
|
15038
|
+
return true;
|
15039
|
+
}
|
14785
15040
|
|
14786
15041
|
#ifdef __cplusplus
|
14787
15042
|
} /* extern "C" */
|
14788
15043
|
#endif
|
14789
15044
|
|
14790
15045
|
|
14791
|
-
#endif
|
15046
|
+
#endif // UPB_WIRE_EPS_COPY_INPUT_STREAM_H_
|
14792
15047
|
|
14793
|
-
#ifndef
|
14794
|
-
#define
|
15048
|
+
#ifndef UPB_WIRE_READER_H_
|
15049
|
+
#define UPB_WIRE_READER_H_
|
14795
15050
|
|
14796
15051
|
#include <stddef.h>
|
14797
15052
|
#include <stdint.h>
|
14798
|
-
|
14799
|
-
|
14800
|
-
// Must be last.
|
14801
|
-
|
14802
|
-
#define kUpb_BaseField_Begin ((size_t)-1)
|
14803
|
-
bool UPB_PRIVATE(_upb_Message_NextBaseField)(const upb_Message* msg,
|
14804
|
-
const upb_MiniTable* m,
|
14805
|
-
const upb_MiniTableField** out_f,
|
14806
|
-
upb_MessageValue* out_v,
|
14807
|
-
uintptr_t* iter);
|
14808
|
-
|
14809
|
-
#endif // GOOGLE_UPB_UPB_MESSAGE_INTERNAL_ITERATOR_H__
|
14810
|
-
|
14811
|
-
#ifndef UPB_WIRE_READER_H_
|
14812
|
-
#define UPB_WIRE_READER_H_
|
15053
|
+
#include <string.h>
|
14813
15054
|
|
14814
15055
|
|
14815
15056
|
#ifndef UPB_WIRE_INTERNAL_READER_H_
|
@@ -15000,7 +15241,9 @@ UPB_INLINE const char* _upb_WireReader_SkipValue(
|
|
15000
15241
|
case kUpb_WireType_Delimited: {
|
15001
15242
|
int size;
|
15002
15243
|
ptr = upb_WireReader_ReadSize(ptr, &size);
|
15003
|
-
if (!ptr)
|
15244
|
+
if (!ptr || !upb_EpsCopyInputStream_CheckSize(stream, ptr, size)) {
|
15245
|
+
return NULL;
|
15246
|
+
}
|
15004
15247
|
ptr += size;
|
15005
15248
|
return ptr;
|
15006
15249
|
}
|
@@ -15166,307 +15409,124 @@ UPB_INLINE const char* _upb_Base92_DecodeVarint(const char* ptr,
|
|
15166
15409
|
typedef struct {
|
15167
15410
|
const char* end;
|
15168
15411
|
upb_Status* status;
|
15169
|
-
jmp_buf err;
|
15170
|
-
} upb_MdDecoder;
|
15171
|
-
|
15172
|
-
UPB_PRINTF(2, 3)
|
15173
|
-
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder* d,
|
15174
|
-
const char* fmt, ...) {
|
15175
|
-
if (d->status) {
|
15176
|
-
va_list argp;
|
15177
|
-
upb_Status_SetErrorMessage(d->status, "Error building mini table: ");
|
15178
|
-
va_start(argp, fmt);
|
15179
|
-
upb_Status_VAppendErrorFormat(d->status, fmt, argp);
|
15180
|
-
va_end(argp);
|
15181
|
-
}
|
15182
|
-
UPB_LONGJMP(d->err, 1);
|
15183
|
-
}
|
15184
|
-
|
15185
|
-
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder* d,
|
15186
|
-
const void* ptr) {
|
15187
|
-
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory");
|
15188
|
-
}
|
15189
|
-
|
15190
|
-
UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint(
|
15191
|
-
upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max,
|
15192
|
-
uint32_t* out_val) {
|
15193
|
-
ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val);
|
15194
|
-
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint");
|
15195
|
-
return ptr;
|
15196
|
-
}
|
15197
|
-
|
15198
|
-
|
15199
|
-
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
|
15200
|
-
|
15201
|
-
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
|
15202
|
-
#define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
|
15203
|
-
|
15204
|
-
|
15205
|
-
// Must be last.
|
15206
|
-
|
15207
|
-
typedef enum {
|
15208
|
-
kUpb_EncodedType_Double = 0,
|
15209
|
-
kUpb_EncodedType_Float = 1,
|
15210
|
-
kUpb_EncodedType_Fixed32 = 2,
|
15211
|
-
kUpb_EncodedType_Fixed64 = 3,
|
15212
|
-
kUpb_EncodedType_SFixed32 = 4,
|
15213
|
-
kUpb_EncodedType_SFixed64 = 5,
|
15214
|
-
kUpb_EncodedType_Int32 = 6,
|
15215
|
-
kUpb_EncodedType_UInt32 = 7,
|
15216
|
-
kUpb_EncodedType_SInt32 = 8,
|
15217
|
-
kUpb_EncodedType_Int64 = 9,
|
15218
|
-
kUpb_EncodedType_UInt64 = 10,
|
15219
|
-
kUpb_EncodedType_SInt64 = 11,
|
15220
|
-
kUpb_EncodedType_OpenEnum = 12,
|
15221
|
-
kUpb_EncodedType_Bool = 13,
|
15222
|
-
kUpb_EncodedType_Bytes = 14,
|
15223
|
-
kUpb_EncodedType_String = 15,
|
15224
|
-
kUpb_EncodedType_Group = 16,
|
15225
|
-
kUpb_EncodedType_Message = 17,
|
15226
|
-
kUpb_EncodedType_ClosedEnum = 18,
|
15227
|
-
|
15228
|
-
kUpb_EncodedType_RepeatedBase = 20,
|
15229
|
-
} upb_EncodedType;
|
15230
|
-
|
15231
|
-
typedef enum {
|
15232
|
-
kUpb_EncodedFieldModifier_FlipPacked = 1 << 0,
|
15233
|
-
kUpb_EncodedFieldModifier_IsRequired = 1 << 1,
|
15234
|
-
kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2,
|
15235
|
-
kUpb_EncodedFieldModifier_FlipValidateUtf8 = 1 << 3,
|
15236
|
-
} upb_EncodedFieldModifier;
|
15237
|
-
|
15238
|
-
enum {
|
15239
|
-
kUpb_EncodedValue_MinField = ' ',
|
15240
|
-
kUpb_EncodedValue_MaxField = 'I',
|
15241
|
-
kUpb_EncodedValue_MinModifier = 'L',
|
15242
|
-
kUpb_EncodedValue_MaxModifier = '[',
|
15243
|
-
kUpb_EncodedValue_End = '^',
|
15244
|
-
kUpb_EncodedValue_MinSkip = '_',
|
15245
|
-
kUpb_EncodedValue_MaxSkip = '~',
|
15246
|
-
kUpb_EncodedValue_OneofSeparator = '~',
|
15247
|
-
kUpb_EncodedValue_FieldSeparator = '|',
|
15248
|
-
kUpb_EncodedValue_MinOneofField = ' ',
|
15249
|
-
kUpb_EncodedValue_MaxOneofField = 'b',
|
15250
|
-
kUpb_EncodedValue_MaxEnumMask = 'A',
|
15251
|
-
};
|
15252
|
-
|
15253
|
-
enum {
|
15254
|
-
kUpb_EncodedVersion_EnumV1 = '!',
|
15255
|
-
kUpb_EncodedVersion_ExtensionV1 = '#',
|
15256
|
-
kUpb_EncodedVersion_MapV1 = '%',
|
15257
|
-
kUpb_EncodedVersion_MessageV1 = '$',
|
15258
|
-
kUpb_EncodedVersion_MessageSetV1 = '&',
|
15259
|
-
};
|
15260
|
-
|
15261
|
-
|
15262
|
-
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
|
15263
|
-
|
15264
|
-
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
15265
|
-
#define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
15266
|
-
|
15267
|
-
// Must be last.
|
15268
|
-
|
15269
|
-
typedef enum {
|
15270
|
-
kUpb_FieldModifier_IsRepeated = 1 << 0,
|
15271
|
-
kUpb_FieldModifier_IsPacked = 1 << 1,
|
15272
|
-
kUpb_FieldModifier_IsClosedEnum = 1 << 2,
|
15273
|
-
kUpb_FieldModifier_IsProto3Singular = 1 << 3,
|
15274
|
-
kUpb_FieldModifier_IsRequired = 1 << 4,
|
15275
|
-
kUpb_FieldModifier_ValidateUtf8 = 1 << 5,
|
15276
|
-
} kUpb_FieldModifier;
|
15277
|
-
|
15278
|
-
// These modifiers are also used on the wire.
|
15279
|
-
typedef enum {
|
15280
|
-
kUpb_MessageModifier_ValidateUtf8 = 1 << 0,
|
15281
|
-
kUpb_MessageModifier_DefaultIsPacked = 1 << 1,
|
15282
|
-
kUpb_MessageModifier_IsExtendable = 1 << 2,
|
15283
|
-
} kUpb_MessageModifier;
|
15284
|
-
|
15285
|
-
|
15286
|
-
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
15287
|
-
|
15288
|
-
#ifndef UPB_MINI_TABLE_COMPAT_H_
|
15289
|
-
#define UPB_MINI_TABLE_COMPAT_H_
|
15290
|
-
|
15291
|
-
|
15292
|
-
// Must be last.
|
15293
|
-
|
15294
|
-
// upb does not support mixing minitables from different sources but these
|
15295
|
-
// functions are still used by some existing users so for now we make them
|
15296
|
-
// available here. This may or may not change in the future so do not add
|
15297
|
-
// them to new code.
|
15298
|
-
|
15299
|
-
#ifdef __cplusplus
|
15300
|
-
extern "C" {
|
15301
|
-
#endif
|
15302
|
-
|
15303
|
-
// Checks if memory layout of src is compatible with dst.
|
15304
|
-
bool upb_MiniTable_Compatible(const upb_MiniTable* src,
|
15305
|
-
const upb_MiniTable* dst);
|
15306
|
-
|
15307
|
-
typedef enum {
|
15308
|
-
kUpb_MiniTableEquals_NotEqual,
|
15309
|
-
kUpb_MiniTableEquals_Equal,
|
15310
|
-
kUpb_MiniTableEquals_OutOfMemory,
|
15311
|
-
} upb_MiniTableEquals_Status;
|
15312
|
-
|
15313
|
-
// Checks equality of mini tables originating from different language runtimes.
|
15314
|
-
upb_MiniTableEquals_Status upb_MiniTable_Equals(const upb_MiniTable* src,
|
15315
|
-
const upb_MiniTable* dst);
|
15316
|
-
|
15317
|
-
#ifdef __cplusplus
|
15318
|
-
} /* extern "C" */
|
15319
|
-
#endif
|
15320
|
-
|
15321
|
-
|
15322
|
-
#endif /* UPB_MINI_TABLE_COMPAT_H_ */
|
15323
|
-
|
15324
|
-
#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_
|
15325
|
-
#define UPB_WIRE_INTERNAL_CONSTANTS_H_
|
15326
|
-
|
15327
|
-
#define kUpb_WireFormat_DefaultDepthLimit 100
|
15328
|
-
|
15329
|
-
// MessageSet wire format is:
|
15330
|
-
// message MessageSet {
|
15331
|
-
// repeated group Item = 1 {
|
15332
|
-
// required int32 type_id = 2;
|
15333
|
-
// required bytes message = 3;
|
15334
|
-
// }
|
15335
|
-
// }
|
15336
|
-
|
15337
|
-
enum {
|
15338
|
-
kUpb_MsgSet_Item = 1,
|
15339
|
-
kUpb_MsgSet_TypeId = 2,
|
15340
|
-
kUpb_MsgSet_Message = 3,
|
15341
|
-
};
|
15342
|
-
|
15343
|
-
#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */
|
15344
|
-
|
15345
|
-
/*
|
15346
|
-
* Internal implementation details of the decoder that are shared between
|
15347
|
-
* decode.c and decode_fast.c.
|
15348
|
-
*/
|
15349
|
-
|
15350
|
-
#ifndef UPB_WIRE_INTERNAL_DECODER_H_
|
15351
|
-
#define UPB_WIRE_INTERNAL_DECODER_H_
|
15352
|
-
|
15353
|
-
#include <stddef.h>
|
15354
|
-
|
15355
|
-
#include "utf8_range.h"
|
15356
|
-
|
15357
|
-
// Must be last.
|
15358
|
-
|
15359
|
-
#define DECODE_NOGROUP (uint32_t)-1
|
15360
|
-
|
15361
|
-
typedef struct upb_Decoder {
|
15362
|
-
upb_EpsCopyInputStream input;
|
15363
|
-
const upb_ExtensionRegistry* extreg;
|
15364
|
-
upb_Message* original_msg; // Pointer to preserve data to
|
15365
|
-
int depth; // Tracks recursion depth to bound stack usage.
|
15366
|
-
uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP.
|
15367
|
-
uint16_t options;
|
15368
|
-
bool missing_required;
|
15369
|
-
union {
|
15370
|
-
upb_Arena arena;
|
15371
|
-
void* foo[UPB_ARENA_SIZE_HACK];
|
15372
|
-
};
|
15373
|
-
upb_DecodeStatus status;
|
15374
|
-
jmp_buf err;
|
15375
|
-
|
15376
|
-
#ifndef NDEBUG
|
15377
|
-
const char* debug_tagstart;
|
15378
|
-
const char* debug_valstart;
|
15379
|
-
#endif
|
15380
|
-
} upb_Decoder;
|
15412
|
+
jmp_buf err;
|
15413
|
+
} upb_MdDecoder;
|
15381
15414
|
|
15382
|
-
|
15383
|
-
|
15384
|
-
*
|
15385
|
-
|
15386
|
-
|
15387
|
-
|
15388
|
-
|
15389
|
-
|
15415
|
+
UPB_PRINTF(2, 3)
|
15416
|
+
UPB_NORETURN UPB_INLINE void upb_MdDecoder_ErrorJmp(upb_MdDecoder* d,
|
15417
|
+
const char* fmt, ...) {
|
15418
|
+
if (d->status) {
|
15419
|
+
va_list argp;
|
15420
|
+
upb_Status_SetErrorMessage(d->status, "Error building mini table: ");
|
15421
|
+
va_start(argp, fmt);
|
15422
|
+
upb_Status_VAppendErrorFormat(d->status, fmt, argp);
|
15423
|
+
va_end(argp);
|
15424
|
+
}
|
15425
|
+
UPB_LONGJMP(d->err, 1);
|
15426
|
+
}
|
15390
15427
|
|
15391
|
-
|
15428
|
+
UPB_INLINE void upb_MdDecoder_CheckOutOfMemory(upb_MdDecoder* d,
|
15429
|
+
const void* ptr) {
|
15430
|
+
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Out of memory");
|
15431
|
+
}
|
15392
15432
|
|
15393
|
-
UPB_INLINE
|
15394
|
-
|
15395
|
-
|
15433
|
+
UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint(
|
15434
|
+
upb_MdDecoder* d, const char* ptr, char first_ch, uint8_t min, uint8_t max,
|
15435
|
+
uint32_t* out_val) {
|
15436
|
+
ptr = _upb_Base92_DecodeVarint(ptr, d->end, first_ch, min, max, out_val);
|
15437
|
+
if (!ptr) upb_MdDecoder_ErrorJmp(d, "Overlong varint");
|
15438
|
+
return ptr;
|
15396
15439
|
}
|
15397
15440
|
|
15398
|
-
const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
|
15399
|
-
const upb_Message* msg,
|
15400
|
-
const upb_MiniTable* m);
|
15401
15441
|
|
15402
|
-
|
15403
|
-
* left 8 and right 8 without loss of information. */
|
15404
|
-
UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) {
|
15405
|
-
return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask);
|
15406
|
-
}
|
15442
|
+
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_DECODER_H_
|
15407
15443
|
|
15408
|
-
|
15409
|
-
|
15410
|
-
}
|
15444
|
+
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
|
15445
|
+
#define UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
|
15411
15446
|
|
15412
|
-
const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e,
|
15413
|
-
const char* ptr, int overrun);
|
15414
15447
|
|
15415
|
-
|
15416
|
-
return upb_EpsCopyInputStream_IsDoneWithCallback(
|
15417
|
-
&d->input, ptr, &_upb_Decoder_IsDoneFallback);
|
15418
|
-
}
|
15448
|
+
// Must be last.
|
15419
15449
|
|
15420
|
-
|
15421
|
-
|
15422
|
-
|
15423
|
-
|
15424
|
-
|
15425
|
-
|
15450
|
+
typedef enum {
|
15451
|
+
kUpb_EncodedType_Double = 0,
|
15452
|
+
kUpb_EncodedType_Float = 1,
|
15453
|
+
kUpb_EncodedType_Fixed32 = 2,
|
15454
|
+
kUpb_EncodedType_Fixed64 = 3,
|
15455
|
+
kUpb_EncodedType_SFixed32 = 4,
|
15456
|
+
kUpb_EncodedType_SFixed64 = 5,
|
15457
|
+
kUpb_EncodedType_Int32 = 6,
|
15458
|
+
kUpb_EncodedType_UInt32 = 7,
|
15459
|
+
kUpb_EncodedType_SInt32 = 8,
|
15460
|
+
kUpb_EncodedType_Int64 = 9,
|
15461
|
+
kUpb_EncodedType_UInt64 = 10,
|
15462
|
+
kUpb_EncodedType_SInt64 = 11,
|
15463
|
+
kUpb_EncodedType_OpenEnum = 12,
|
15464
|
+
kUpb_EncodedType_Bool = 13,
|
15465
|
+
kUpb_EncodedType_Bytes = 14,
|
15466
|
+
kUpb_EncodedType_String = 15,
|
15467
|
+
kUpb_EncodedType_Group = 16,
|
15468
|
+
kUpb_EncodedType_Message = 17,
|
15469
|
+
kUpb_EncodedType_ClosedEnum = 18,
|
15426
15470
|
|
15427
|
-
|
15428
|
-
|
15429
|
-
const char* _upb_FastDecoder_TagDispatch(upb_Decoder* d, const char* ptr,
|
15430
|
-
upb_Message* msg, intptr_t table,
|
15431
|
-
uint64_t hasbits, uint64_t tag) {
|
15432
|
-
const upb_MiniTable* table_p = decode_totablep(table);
|
15433
|
-
uint8_t mask = table;
|
15434
|
-
uint64_t data;
|
15435
|
-
size_t idx = tag & mask;
|
15436
|
-
UPB_ASSUME((idx & 7) == 0);
|
15437
|
-
idx >>= 3;
|
15438
|
-
data = table_p->UPB_PRIVATE(fasttable)[idx].field_data ^ tag;
|
15439
|
-
UPB_MUSTTAIL return table_p->UPB_PRIVATE(fasttable)[idx].field_parser(
|
15440
|
-
d, ptr, msg, table, hasbits, data);
|
15441
|
-
}
|
15442
|
-
#endif
|
15471
|
+
kUpb_EncodedType_RepeatedBase = 20,
|
15472
|
+
} upb_EncodedType;
|
15443
15473
|
|
15444
|
-
|
15445
|
-
|
15446
|
-
|
15447
|
-
|
15448
|
-
|
15474
|
+
typedef enum {
|
15475
|
+
kUpb_EncodedFieldModifier_FlipPacked = 1 << 0,
|
15476
|
+
kUpb_EncodedFieldModifier_IsRequired = 1 << 1,
|
15477
|
+
kUpb_EncodedFieldModifier_IsProto3Singular = 1 << 2,
|
15478
|
+
kUpb_EncodedFieldModifier_FlipValidateUtf8 = 1 << 3,
|
15479
|
+
} upb_EncodedFieldModifier;
|
15449
15480
|
|
15481
|
+
enum {
|
15482
|
+
kUpb_EncodedValue_MinField = ' ',
|
15483
|
+
kUpb_EncodedValue_MaxField = 'I',
|
15484
|
+
kUpb_EncodedValue_MinModifier = 'L',
|
15485
|
+
kUpb_EncodedValue_MaxModifier = '[',
|
15486
|
+
kUpb_EncodedValue_End = '^',
|
15487
|
+
kUpb_EncodedValue_MinSkip = '_',
|
15488
|
+
kUpb_EncodedValue_MaxSkip = '~',
|
15489
|
+
kUpb_EncodedValue_OneofSeparator = '~',
|
15490
|
+
kUpb_EncodedValue_FieldSeparator = '|',
|
15491
|
+
kUpb_EncodedValue_MinOneofField = ' ',
|
15492
|
+
kUpb_EncodedValue_MaxOneofField = 'b',
|
15493
|
+
kUpb_EncodedValue_MaxEnumMask = 'A',
|
15494
|
+
};
|
15450
15495
|
|
15451
|
-
|
15496
|
+
enum {
|
15497
|
+
kUpb_EncodedVersion_EnumV1 = '!',
|
15498
|
+
kUpb_EncodedVersion_ExtensionV1 = '#',
|
15499
|
+
kUpb_EncodedVersion_MapV1 = '%',
|
15500
|
+
kUpb_EncodedVersion_MessageV1 = '$',
|
15501
|
+
kUpb_EncodedVersion_MessageSetV1 = '&',
|
15502
|
+
};
|
15452
15503
|
|
15453
|
-
#ifndef UPB_LEX_STRTOD_H_
|
15454
|
-
#define UPB_LEX_STRTOD_H_
|
15455
15504
|
|
15456
|
-
//
|
15505
|
+
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_WIRE_CONSTANTS_H_
|
15457
15506
|
|
15458
|
-
#
|
15459
|
-
|
15460
|
-
#endif
|
15507
|
+
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
15508
|
+
#define UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
15461
15509
|
|
15462
|
-
|
15510
|
+
// Must be last.
|
15463
15511
|
|
15464
|
-
|
15465
|
-
|
15466
|
-
|
15512
|
+
typedef enum {
|
15513
|
+
kUpb_FieldModifier_IsRepeated = 1 << 0,
|
15514
|
+
kUpb_FieldModifier_IsPacked = 1 << 1,
|
15515
|
+
kUpb_FieldModifier_IsClosedEnum = 1 << 2,
|
15516
|
+
kUpb_FieldModifier_IsProto3Singular = 1 << 3,
|
15517
|
+
kUpb_FieldModifier_IsRequired = 1 << 4,
|
15518
|
+
kUpb_FieldModifier_ValidateUtf8 = 1 << 5,
|
15519
|
+
} kUpb_FieldModifier;
|
15520
|
+
|
15521
|
+
// These modifiers are also used on the wire.
|
15522
|
+
typedef enum {
|
15523
|
+
kUpb_MessageModifier_ValidateUtf8 = 1 << 0,
|
15524
|
+
kUpb_MessageModifier_DefaultIsPacked = 1 << 1,
|
15525
|
+
kUpb_MessageModifier_IsExtendable = 1 << 2,
|
15526
|
+
} kUpb_MessageModifier;
|
15467
15527
|
|
15468
15528
|
|
15469
|
-
#endif
|
15529
|
+
#endif // UPB_MINI_DESCRIPTOR_INTERNAL_MODIFIERS_H_
|
15470
15530
|
|
15471
15531
|
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
|
15472
15532
|
#define UPB_MINI_DESCRIPTOR_INTERNAL_ENCODE_H_
|
@@ -16244,6 +16304,188 @@ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
|
|
16244
16304
|
|
16245
16305
|
#endif /* UPB_UTIL_DEF_TO_PROTO_H_ */
|
16246
16306
|
|
16307
|
+
#ifndef UPB_WIRE_INTERNAL_CONSTANTS_H_
|
16308
|
+
#define UPB_WIRE_INTERNAL_CONSTANTS_H_
|
16309
|
+
|
16310
|
+
#define kUpb_WireFormat_DefaultDepthLimit 100
|
16311
|
+
|
16312
|
+
// MessageSet wire format is:
|
16313
|
+
// message MessageSet {
|
16314
|
+
// repeated group Item = 1 {
|
16315
|
+
// required int32 type_id = 2;
|
16316
|
+
// required bytes message = 3;
|
16317
|
+
// }
|
16318
|
+
// }
|
16319
|
+
|
16320
|
+
enum {
|
16321
|
+
kUpb_MsgSet_Item = 1,
|
16322
|
+
kUpb_MsgSet_TypeId = 2,
|
16323
|
+
kUpb_MsgSet_Message = 3,
|
16324
|
+
};
|
16325
|
+
|
16326
|
+
#endif /* UPB_WIRE_INTERNAL_CONSTANTS_H_ */
|
16327
|
+
|
16328
|
+
/*
|
16329
|
+
* Internal implementation details of the decoder that are shared between
|
16330
|
+
* decode.c and decode_fast.c.
|
16331
|
+
*/
|
16332
|
+
|
16333
|
+
#ifndef UPB_WIRE_INTERNAL_DECODER_H_
|
16334
|
+
#define UPB_WIRE_INTERNAL_DECODER_H_
|
16335
|
+
|
16336
|
+
#include <setjmp.h>
|
16337
|
+
#include <stddef.h>
|
16338
|
+
#include <stdint.h>
|
16339
|
+
#include <string.h>
|
16340
|
+
|
16341
|
+
#include "utf8_range.h"
|
16342
|
+
|
16343
|
+
// Must be last.
|
16344
|
+
|
16345
|
+
#define DECODE_NOGROUP (uint32_t)-1
|
16346
|
+
|
16347
|
+
typedef struct upb_Decoder {
|
16348
|
+
upb_EpsCopyInputStream input;
|
16349
|
+
const upb_ExtensionRegistry* extreg;
|
16350
|
+
upb_Message* original_msg; // Pointer to preserve data to
|
16351
|
+
int depth; // Tracks recursion depth to bound stack usage.
|
16352
|
+
uint32_t end_group; // field number of END_GROUP tag, else DECODE_NOGROUP.
|
16353
|
+
uint16_t options;
|
16354
|
+
bool missing_required;
|
16355
|
+
bool message_is_done;
|
16356
|
+
union {
|
16357
|
+
upb_Arena arena;
|
16358
|
+
void* foo[UPB_ARENA_SIZE_HACK];
|
16359
|
+
};
|
16360
|
+
upb_DecodeStatus status;
|
16361
|
+
jmp_buf err;
|
16362
|
+
|
16363
|
+
#ifndef NDEBUG
|
16364
|
+
const char* debug_tagstart;
|
16365
|
+
const char* debug_valstart;
|
16366
|
+
char* trace_ptr;
|
16367
|
+
char* trace_end;
|
16368
|
+
#endif
|
16369
|
+
} upb_Decoder;
|
16370
|
+
|
16371
|
+
UPB_INLINE const char* upb_Decoder_Init(upb_Decoder* d, const char* buf,
|
16372
|
+
size_t size,
|
16373
|
+
const upb_ExtensionRegistry* extreg,
|
16374
|
+
int options, upb_Arena* arena,
|
16375
|
+
char* trace_buf, size_t trace_size) {
|
16376
|
+
upb_EpsCopyInputStream_Init(&d->input, &buf, size,
|
16377
|
+
options & kUpb_DecodeOption_AliasString);
|
16378
|
+
|
16379
|
+
d->extreg = extreg;
|
16380
|
+
d->depth = upb_DecodeOptions_GetEffectiveMaxDepth(options);
|
16381
|
+
d->end_group = DECODE_NOGROUP;
|
16382
|
+
d->options = (uint16_t)options;
|
16383
|
+
d->missing_required = false;
|
16384
|
+
d->status = kUpb_DecodeStatus_Ok;
|
16385
|
+
d->message_is_done = false;
|
16386
|
+
#ifndef NDEBUG
|
16387
|
+
d->trace_ptr = trace_buf;
|
16388
|
+
d->trace_end = UPB_PTRADD(trace_buf, trace_size);
|
16389
|
+
#endif
|
16390
|
+
if (trace_buf) *trace_buf = 0; // Null-terminate.
|
16391
|
+
|
16392
|
+
// Violating the encapsulation of the arena for performance reasons.
|
16393
|
+
// This is a temporary arena that we swap into and swap out of when we are
|
16394
|
+
// done. The temporary arena only needs to be able to handle allocation,
|
16395
|
+
// not fuse or free, so it does not need many of the members to be initialized
|
16396
|
+
// (particularly parent_or_count).
|
16397
|
+
UPB_PRIVATE(_upb_Arena_SwapIn)(&d->arena, arena);
|
16398
|
+
return buf;
|
16399
|
+
}
|
16400
|
+
|
16401
|
+
UPB_INLINE upb_DecodeStatus upb_Decoder_Destroy(upb_Decoder* d,
|
16402
|
+
upb_Arena* arena) {
|
16403
|
+
UPB_PRIVATE(_upb_Arena_SwapOut)(arena, &d->arena);
|
16404
|
+
return d->status;
|
16405
|
+
}
|
16406
|
+
|
16407
|
+
// Trace events are used to trace the progress of the decoder.
|
16408
|
+
// Events:
|
16409
|
+
// 'D' Fast dispatch
|
16410
|
+
// 'F' Field successfully parsed fast.
|
16411
|
+
// '<' Fallback to MiniTable parser.
|
16412
|
+
// 'M' Field successfully parsed with MiniTable.
|
16413
|
+
// 'X' Truncated -- trace buffer is full, further events were discarded.
|
16414
|
+
UPB_INLINE void _upb_Decoder_Trace(upb_Decoder* d, char event) {
|
16415
|
+
#ifndef NDEBUG
|
16416
|
+
if (d->trace_ptr == NULL) return;
|
16417
|
+
if (d->trace_ptr == d->trace_end - 1) {
|
16418
|
+
d->trace_ptr[-1] = 'X'; // Truncated.
|
16419
|
+
return;
|
16420
|
+
}
|
16421
|
+
d->trace_ptr[0] = event;
|
16422
|
+
d->trace_ptr[1] = '\0';
|
16423
|
+
d->trace_ptr++;
|
16424
|
+
#endif
|
16425
|
+
};
|
16426
|
+
|
16427
|
+
UPB_INLINE
|
16428
|
+
bool _upb_Decoder_VerifyUtf8Inline(const char* ptr, int len) {
|
16429
|
+
return utf8_range_IsValid(ptr, len);
|
16430
|
+
}
|
16431
|
+
|
16432
|
+
const char* _upb_Decoder_CheckRequired(upb_Decoder* d, const char* ptr,
|
16433
|
+
const upb_Message* msg,
|
16434
|
+
const upb_MiniTable* m);
|
16435
|
+
|
16436
|
+
/* x86-64 pointers always have the high 16 bits matching. So we can shift
|
16437
|
+
* left 8 and right 8 without loss of information. */
|
16438
|
+
UPB_INLINE intptr_t decode_totable(const upb_MiniTable* tablep) {
|
16439
|
+
return ((intptr_t)tablep << 8) | tablep->UPB_PRIVATE(table_mask);
|
16440
|
+
}
|
16441
|
+
|
16442
|
+
UPB_INLINE const upb_MiniTable* decode_totablep(intptr_t table) {
|
16443
|
+
return (const upb_MiniTable*)(table >> 8);
|
16444
|
+
}
|
16445
|
+
|
16446
|
+
const char* _upb_Decoder_IsDoneFallback(upb_EpsCopyInputStream* e,
|
16447
|
+
const char* ptr, int overrun);
|
16448
|
+
|
16449
|
+
const char* _upb_Decoder_DecodeMessage(upb_Decoder* d, const char* ptr,
|
16450
|
+
upb_Message* msg,
|
16451
|
+
const upb_MiniTable* layout);
|
16452
|
+
|
16453
|
+
UPB_INLINE bool _upb_Decoder_IsDone(upb_Decoder* d, const char** ptr) {
|
16454
|
+
return upb_EpsCopyInputStream_IsDoneWithCallback(
|
16455
|
+
&d->input, ptr, &_upb_Decoder_IsDoneFallback);
|
16456
|
+
}
|
16457
|
+
|
16458
|
+
UPB_NORETURN void* _upb_Decoder_ErrorJmp(upb_Decoder* d,
|
16459
|
+
upb_DecodeStatus status);
|
16460
|
+
|
16461
|
+
UPB_INLINE const char* _upb_Decoder_BufferFlipCallback(
|
16462
|
+
upb_EpsCopyInputStream* e, const char* old_end, const char* new_start) {
|
16463
|
+
upb_Decoder* d = (upb_Decoder*)e;
|
16464
|
+
if (!old_end) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed);
|
16465
|
+
return new_start;
|
16466
|
+
}
|
16467
|
+
|
16468
|
+
|
16469
|
+
#endif /* UPB_WIRE_INTERNAL_DECODER_H_ */
|
16470
|
+
#ifndef GOOGLE_UPB_UPB_WIRE_WRITER_H__
|
16471
|
+
#define GOOGLE_UPB_UPB_WIRE_WRITER_H__
|
16472
|
+
|
16473
|
+
#include <stdint.h>
|
16474
|
+
|
16475
|
+
// Must be last.
|
16476
|
+
|
16477
|
+
UPB_FORCEINLINE uint32_t
|
16478
|
+
UPB_PRIVATE(upb_WireWriter_VarintUnusedSizeFromLeadingZeros64)(uint64_t clz) {
|
16479
|
+
// Calculate how many bytes of the possible 10 bytes we will *not* encode,
|
16480
|
+
// because they are part of a zero prefix. For the number 300, it would use 2
|
16481
|
+
// bytes encoded, so the number of bytes to skip would be 8. Adding 7 to the
|
16482
|
+
// clz input ensures that we're rounding up.
|
16483
|
+
return (((uint32_t)clz + 7) * 9) >> 6;
|
16484
|
+
}
|
16485
|
+
|
16486
|
+
|
16487
|
+
#endif // GOOGLE_UPB_UPB_WIRE_WRITER_H__
|
16488
|
+
|
16247
16489
|
// This should #undef all macros #defined in def.inc
|
16248
16490
|
|
16249
16491
|
#undef UPB_SIZE
|
@@ -16262,7 +16504,9 @@ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
|
|
16262
16504
|
#undef UPB_ALIGN_MALLOC
|
16263
16505
|
#undef UPB_ALIGN_OF
|
16264
16506
|
#undef UPB_ALIGN_AS
|
16265
|
-
#undef
|
16507
|
+
#undef UPB_STATIC_ASSERT
|
16508
|
+
#undef UPB_STATIC_ASSERT_CONCAT
|
16509
|
+
#undef UPB_STATIC_ASSERT_CONCAT_IMPL
|
16266
16510
|
#undef UPB_LIKELY
|
16267
16511
|
#undef UPB_UNLIKELY
|
16268
16512
|
#undef UPB_UNPREDICTABLE
|
@@ -16270,6 +16514,7 @@ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
|
|
16270
16514
|
#undef UPB_NOINLINE
|
16271
16515
|
#undef UPB_NORETURN
|
16272
16516
|
#undef UPB_PRINTF
|
16517
|
+
#undef UPB_NODEREF
|
16273
16518
|
#undef UPB_MAX
|
16274
16519
|
#undef UPB_MIN
|
16275
16520
|
#undef UPB_UNUSED
|
@@ -16281,6 +16526,7 @@ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
|
|
16281
16526
|
#undef UPB_LONGJMP
|
16282
16527
|
#undef UPB_PTRADD
|
16283
16528
|
#undef UPB_MUSTTAIL
|
16529
|
+
#undef UPB_PRESERVE_NONE
|
16284
16530
|
#undef UPB_FASTTABLE_SUPPORTED
|
16285
16531
|
#undef UPB_FASTTABLE_MASK
|
16286
16532
|
#undef UPB_FASTTABLE
|
@@ -16288,14 +16534,10 @@ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
|
|
16288
16534
|
#undef UPB_POISON_MEMORY_REGION
|
16289
16535
|
#undef UPB_UNPOISON_MEMORY_REGION
|
16290
16536
|
#undef UPB_ASAN
|
16291
|
-
#undef
|
16292
|
-
#undef
|
16293
|
-
#undef
|
16294
|
-
#undef
|
16295
|
-
#undef UPB_TSAN_CHECK_PUBLISHED
|
16296
|
-
#undef UPB_TSAN_PUBLISH
|
16297
|
-
#undef UPB_TSAN_CHECK_READ
|
16298
|
-
#undef UPB_TSAN_CHECK_WRITE
|
16537
|
+
#undef UPB_HWASAN
|
16538
|
+
#undef UPB_HWASAN_POISON_TAG
|
16539
|
+
#undef UPB_MALLOC_ALIGN
|
16540
|
+
#undef UPB_TSAN
|
16299
16541
|
#undef UPB_TREAT_CLOSED_ENUMS_LIKE_OPEN
|
16300
16542
|
#undef UPB_DEPRECATED
|
16301
16543
|
#undef UPB_GNUC_MIN
|
@@ -16313,3 +16555,7 @@ google_protobuf_ServiceDescriptorProto* upb_ServiceDef_ToProto(
|
|
16313
16555
|
#undef UPB_LINKARR_START
|
16314
16556
|
#undef UPB_LINKARR_STOP
|
16315
16557
|
#undef UPB_FUTURE_BREAKING_CHANGES
|
16558
|
+
#undef UPB_HAS_ATTRIBUTE
|
16559
|
+
#undef UPB_HAS_BUILTIN
|
16560
|
+
#undef UPB_HAS_EXTENSION
|
16561
|
+
#undef UPB_HAS_FEATURE
|