|
|
|
@ -248,8 +248,23 @@ |
|
|
|
|
* expected behavior. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#if defined(__SANITIZE_ADDRESS__) |
|
|
|
|
/* Due to preprocessor limitations, the conditional logic for setting
|
|
|
|
|
* UPN_CLANG_ASAN below cannot be consolidated into a portable one-liner. |
|
|
|
|
* See https://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005fattribute.html.
|
|
|
|
|
*/ |
|
|
|
|
#if defined(__has_feature) |
|
|
|
|
#if __has_feature(address_sanitizer) |
|
|
|
|
#define UPB_CLANG_ASAN 1 |
|
|
|
|
#else |
|
|
|
|
#define UPB_CLANG_ASAN 0 |
|
|
|
|
#endif |
|
|
|
|
#else |
|
|
|
|
#define UPB_CLANG_ASAN 0 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(__SANITIZE_ADDRESS__) || UPB_CLANG_ASAN |
|
|
|
|
#define UPB_ASAN 1 |
|
|
|
|
#define UPB_ASAN_GUARD_SIZE 32 |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
@ -264,6 +279,7 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); |
|
|
|
|
__asan_unpoison_memory_region((addr), (size)) |
|
|
|
|
#else |
|
|
|
|
#define UPB_ASAN 0 |
|
|
|
|
#define UPB_ASAN_GUARD_SIZE 0 |
|
|
|
|
#define UPB_POISON_MEMORY_REGION(addr, size) \ |
|
|
|
|
((void)(addr), (void)(size)) |
|
|
|
|
#define UPB_UNPOISON_MEMORY_REGION(addr, size) \ |
|
|
|
@ -486,14 +502,22 @@ UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) { |
|
|
|
|
|
|
|
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_TYPEDEF_H_ |
|
|
|
|
#define UPB_MESSAGE_TYPEDEF_H_ |
|
|
|
|
|
|
|
|
|
// This typedef needs its own header to resolve a circular dependency between
|
|
|
|
|
// messages and mini tables.
|
|
|
|
|
typedef void upb_Message; |
|
|
|
|
|
|
|
|
|
#endif /* UPB_MESSAGE_TYPEDEF_H_ */ |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
typedef void upb_Message; |
|
|
|
|
|
|
|
|
|
// When a upb_Message* is stored in a message, array, or map, it is stored in a
|
|
|
|
|
// tagged form. If the tag bit is set, the referenced upb_Message is of type
|
|
|
|
|
// _kUpb_MiniTable_Empty (a sentinel message type with no fields) instead of
|
|
|
|
@ -625,8 +649,6 @@ UPB_INLINE bool upb_MiniTableEnum_CheckValue(const struct upb_MiniTableEnum* e, |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
// LINT.IfChange(mini_table_field_layout)
|
|
|
|
|
|
|
|
|
|
struct upb_MiniTableField { |
|
|
|
|
uint32_t number; |
|
|
|
|
uint16_t offset; |
|
|
|
@ -679,8 +701,6 @@ typedef enum { |
|
|
|
|
|
|
|
|
|
#define kUpb_FieldRep_Shift 6 |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/mini_table_field.ts:mini_table_field_layout)
|
|
|
|
|
|
|
|
|
|
UPB_INLINE upb_FieldRep |
|
|
|
|
_upb_MiniTableField_GetRep(const struct upb_MiniTableField* field) { |
|
|
|
|
return (upb_FieldRep)(field->mode >> kUpb_FieldRep_Shift); |
|
|
|
@ -732,8 +752,6 @@ UPB_INLINE bool upb_IsSubMessage(const struct upb_MiniTableField* field) { |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
typedef void upb_Message; |
|
|
|
|
|
|
|
|
|
struct upb_Decoder; |
|
|
|
|
typedef const char* _upb_FieldParser(struct upb_Decoder* d, const char* ptr, |
|
|
|
|
upb_Message* msg, intptr_t table, |
|
|
|
@ -755,8 +773,6 @@ typedef enum { |
|
|
|
|
kUpb_ExtMode_IsMapEntry = 4, |
|
|
|
|
} upb_ExtMode; |
|
|
|
|
|
|
|
|
|
// LINT.IfChange(mini_table_layout)
|
|
|
|
|
|
|
|
|
|
union upb_MiniTableSub; |
|
|
|
|
|
|
|
|
|
// upb_MiniTable represents the memory layout of a given upb_MessageDef.
|
|
|
|
@ -782,8 +798,6 @@ struct upb_MiniTable { |
|
|
|
|
_upb_FastTable_Entry fasttable[]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/mini_table.ts:presence_logic)
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
@ -1100,14 +1114,10 @@ UPB_INLINE void upb_gfree(void* ptr) { upb_free(&upb_alloc_global, ptr); } |
|
|
|
|
|
|
|
|
|
typedef struct upb_Arena upb_Arena; |
|
|
|
|
|
|
|
|
|
// LINT.IfChange(arena_head)
|
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
char *ptr, *end; |
|
|
|
|
} _upb_ArenaHead; |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/arena.ts:arena_head)
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
@ -1131,7 +1141,8 @@ UPB_INLINE size_t _upb_ArenaHas(upb_Arena* a) { |
|
|
|
|
|
|
|
|
|
UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { |
|
|
|
|
size = UPB_ALIGN_MALLOC(size); |
|
|
|
|
if (UPB_UNLIKELY(_upb_ArenaHas(a) < size)) { |
|
|
|
|
size_t span = size + UPB_ASAN_GUARD_SIZE; |
|
|
|
|
if (UPB_UNLIKELY(_upb_ArenaHas(a) < span)) { |
|
|
|
|
return _upb_Arena_SlowMalloc(a, size); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1142,18 +1153,7 @@ UPB_API_INLINE void* upb_Arena_Malloc(upb_Arena* a, size_t size) { |
|
|
|
|
UPB_ASSERT(UPB_ALIGN_MALLOC(size) == size); |
|
|
|
|
UPB_UNPOISON_MEMORY_REGION(ret, size); |
|
|
|
|
|
|
|
|
|
h->ptr += size; |
|
|
|
|
|
|
|
|
|
#if UPB_ASAN |
|
|
|
|
{ |
|
|
|
|
size_t guard_size = 32; |
|
|
|
|
if (_upb_ArenaHas(a) >= guard_size) { |
|
|
|
|
h->ptr += guard_size; |
|
|
|
|
} else { |
|
|
|
|
h->ptr = h->end; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
h->ptr += span; |
|
|
|
|
|
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
@ -1167,7 +1167,8 @@ UPB_API_INLINE void upb_Arena_ShrinkLast(upb_Arena* a, void* ptr, |
|
|
|
|
_upb_ArenaHead* h = (_upb_ArenaHead*)a; |
|
|
|
|
oldsize = UPB_ALIGN_MALLOC(oldsize); |
|
|
|
|
size = UPB_ALIGN_MALLOC(size); |
|
|
|
|
UPB_ASSERT((char*)ptr + oldsize == h->ptr); // Must be the last alloc.
|
|
|
|
|
// Must be the last alloc.
|
|
|
|
|
UPB_ASSERT((char*)ptr + oldsize == h->ptr - UPB_ASAN_GUARD_SIZE); |
|
|
|
|
UPB_ASSERT(size <= oldsize); |
|
|
|
|
h->ptr = (char*)ptr + size; |
|
|
|
|
} |
|
|
|
@ -1930,7 +1931,7 @@ UPB_INLINE int upb_Log2Ceiling(int x) { |
|
|
|
|
return 32 - __builtin_clz(x - 1); |
|
|
|
|
#else |
|
|
|
|
int lg2 = 0; |
|
|
|
|
while (1 << lg2 < x) lg2++; |
|
|
|
|
while ((1 << lg2) < x) lg2++; |
|
|
|
|
return lg2; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
@ -2099,7 +2100,15 @@ typedef struct { |
|
|
|
|
} upb_MapEntryData; |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
void* internal_data; |
|
|
|
|
// LINT.IfChange(internal_layout)
|
|
|
|
|
union { |
|
|
|
|
void* internal_data; |
|
|
|
|
|
|
|
|
|
// Force 8-byte alignment, since the data members may contain members that
|
|
|
|
|
// require 8-byte alignment.
|
|
|
|
|
double d; |
|
|
|
|
}; |
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal.h:internal_layout)
|
|
|
|
|
upb_MapEntryData data; |
|
|
|
|
} upb_MapEntry; |
|
|
|
|
|
|
|
|
@ -2267,10 +2276,22 @@ UPB_INLINE void _upb_msg_map_set_value(void* msg, const void* val, |
|
|
|
|
|
|
|
|
|
#endif /* UPB_COLLECTIONS_MAP_GENCODE_UTIL_H_ */ |
|
|
|
|
|
|
|
|
|
// This header is deprecated, use upb/mini_table/extension_registry.h instead
|
|
|
|
|
#ifndef UPB_MESSAGE_ACCESSORS_H_ |
|
|
|
|
#define UPB_MESSAGE_ACCESSORS_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
** Our memory representation for parsing tables and messages themselves. |
|
|
|
|
** Functions in this file are used by generated code and possibly reflection. |
|
|
|
|
** |
|
|
|
|
** The definitions in this file are internal to upb. |
|
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_INTERNAL_H_ |
|
|
|
|
#define UPB_MESSAGE_INTERNAL_H_ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_EXTENSION_REGISTRY_H_ |
|
|
|
|
#define UPB_EXTENSION_REGISTRY_H_ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ |
|
|
|
@ -2347,30 +2368,6 @@ UPB_API const upb_MiniTableExtension* upb_ExtensionRegistry_Lookup( |
|
|
|
|
|
|
|
|
|
#endif /* UPB_MINI_TABLE_EXTENSION_REGISTRY_H_ */ |
|
|
|
|
|
|
|
|
|
#endif /* UPB_EXTENSION_REGISTRY_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_ACCESSORS_H_ |
|
|
|
|
#define UPB_MESSAGE_ACCESSORS_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_ACCESSORS_INTERNAL_H_ |
|
|
|
|
#define UPB_MESSAGE_ACCESSORS_INTERNAL_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
** Our memory representation for parsing tables and messages themselves. |
|
|
|
|
** Functions in this file are used by generated code and possibly reflection. |
|
|
|
|
** |
|
|
|
|
** The definitions in this file are internal to upb. |
|
|
|
|
**/ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_INTERNAL_H_ |
|
|
|
|
#define UPB_MESSAGE_INTERNAL_H_ |
|
|
|
|
|
|
|
|
|
#include <stdlib.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
|
@ -2411,7 +2408,15 @@ typedef struct { |
|
|
|
|
} upb_Message_InternalData; |
|
|
|
|
|
|
|
|
|
typedef struct { |
|
|
|
|
upb_Message_InternalData* internal; |
|
|
|
|
// LINT.IfChange(internal_layout)
|
|
|
|
|
union { |
|
|
|
|
upb_Message_InternalData* internal; |
|
|
|
|
|
|
|
|
|
// Force 8-byte alignment, since the data members may contain members that
|
|
|
|
|
// require 8-byte alignment.
|
|
|
|
|
double d; |
|
|
|
|
}; |
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/upb/message/internal/map_entry.h:internal_layout)
|
|
|
|
|
/* Message data follows. */ |
|
|
|
|
} upb_Message_Internal; |
|
|
|
|
|
|
|
|
@ -2454,6 +2459,10 @@ bool _upb_Message_AddUnknown(upb_Message* msg, const char* data, size_t len, |
|
|
|
|
|
|
|
|
|
#endif /* UPB_MESSAGE_INTERNAL_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MESSAGE_INTERNAL_ACCESSORS_H_ |
|
|
|
|
#define UPB_MESSAGE_INTERNAL_ACCESSORS_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__) |
|
|
|
@ -2532,7 +2541,6 @@ UPB_INLINE uint32_t _upb_getoneofcase_field(const upb_Message* msg, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(GoogleInternalName2)
|
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/presence.ts:presence_logic)
|
|
|
|
|
|
|
|
|
|
UPB_INLINE bool _upb_MiniTableField_InOneOf(const upb_MiniTableField* field) { |
|
|
|
|
return field->presence < 0; |
|
|
|
@ -2557,8 +2565,6 @@ UPB_INLINE void _upb_Message_SetPresence(upb_Message* msg, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LINT.IfChange(message_raw_fields)
|
|
|
|
|
|
|
|
|
|
UPB_INLINE bool _upb_MiniTable_ValueIsNonZero(const void* default_val, |
|
|
|
|
const upb_MiniTableField* field) { |
|
|
|
|
char zero[16] = {0}; |
|
|
|
@ -2597,8 +2603,6 @@ UPB_INLINE void _upb_MiniTable_CopyFieldData(void* to, const void* from, |
|
|
|
|
UPB_UNREACHABLE(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LINT.ThenChange(//depot/google3/third_party/upb/js/impl/upb_bits/message.ts:message_raw_fields)
|
|
|
|
|
|
|
|
|
|
UPB_INLINE size_t |
|
|
|
|
_upb_MiniTable_ElementSizeLg2(const upb_MiniTableField* field) { |
|
|
|
|
const unsigned char table[] = { |
|
|
|
@ -2807,7 +2811,7 @@ UPB_INLINE upb_Map* _upb_Message_GetOrCreateMutableMap( |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // UPB_MESSAGE_ACCESSORS_INTERNAL_H_
|
|
|
|
|
#endif // UPB_MESSAGE_INTERNAL_ACCESSORS_H_
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
@ -3393,9 +3397,9 @@ upb_MiniTable* upb_MiniTable_BuildWithBuf(const char* data, size_t len, |
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
|
struct upb_MiniTableFile { |
|
|
|
|
const upb_MiniTable** msgs; |
|
|
|
|
const upb_MiniTableEnum** enums; |
|
|
|
|
const upb_MiniTableExtension** exts; |
|
|
|
|
const struct upb_MiniTable** msgs; |
|
|
|
|
const struct upb_MiniTableEnum** enums; |
|
|
|
|
const struct upb_MiniTableExtension** exts; |
|
|
|
|
int msg_count; |
|
|
|
|
int enum_count; |
|
|
|
|
int ext_count; |
|
|
|
@ -11527,8 +11531,8 @@ double _upb_NoLocaleStrtod(const char *str, char **endptr); |
|
|
|
|
|
|
|
|
|
#endif /* UPB_LEX_STRTOD_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MEM_ARENA_INTERNAL_H_ |
|
|
|
|
#define UPB_MEM_ARENA_INTERNAL_H_ |
|
|
|
|
#ifndef UPB_MEM_INTERNAL_ARENA_H_ |
|
|
|
|
#define UPB_MEM_INTERNAL_ARENA_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
@ -11610,7 +11614,7 @@ UPB_INLINE bool upb_Arena_HasInitialBlock(upb_Arena* arena) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_MEM_ARENA_INTERNAL_H_ */ |
|
|
|
|
#endif /* UPB_MEM_INTERNAL_ARENA_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_PORT_ATOMIC_H_ |
|
|
|
|
#define UPB_PORT_ATOMIC_H_ |
|
|
|
@ -11706,8 +11710,8 @@ extern "C" { |
|
|
|
|
#define UPB_WIRE_READER_H_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UPB_WIRE_SWAP_INTERNAL_H_ |
|
|
|
|
#define UPB_WIRE_SWAP_INTERNAL_H_ |
|
|
|
|
#ifndef UPB_WIRE_INTERNAL_SWAP_H_ |
|
|
|
|
#define UPB_WIRE_INTERNAL_SWAP_H_ |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
@ -11739,7 +11743,7 @@ UPB_INLINE uint64_t _upb_BigEndian_Swap64(uint64_t val) { |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_WIRE_SWAP_INTERNAL_H_ */ |
|
|
|
|
#endif /* UPB_WIRE_INTERNAL_SWAP_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_WIRE_TYPES_H_ |
|
|
|
|
#define UPB_WIRE_TYPES_H_ |
|
|
|
@ -12572,8 +12576,8 @@ upb_MethodDef* _upb_MethodDefs_New( |
|
|
|
|
|
|
|
|
|
#endif /* UPB_REFLECTION_METHOD_DEF_INTERNAL_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_WIRE_COMMON_INTERNAL_H_ |
|
|
|
|
#define UPB_WIRE_COMMON_INTERNAL_H_ |
|
|
|
|
#ifndef UPB_WIRE_INTERNAL_COMMON_H_ |
|
|
|
|
#define UPB_WIRE_INTERNAL_COMMON_H_ |
|
|
|
|
|
|
|
|
|
// Must be last.
|
|
|
|
|
|
|
|
|
@ -12592,15 +12596,15 @@ enum { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_WIRE_COMMON_INTERNAL_H_ */ |
|
|
|
|
#endif /* UPB_WIRE_INTERNAL_COMMON_H_ */ |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Internal implementation details of the decoder that are shared between |
|
|
|
|
* decode.c and decode_fast.c. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_WIRE_DECODE_INTERNAL_H_ |
|
|
|
|
#define UPB_WIRE_DECODE_INTERNAL_H_ |
|
|
|
|
#ifndef UPB_WIRE_INTERNAL_DECODE_H_ |
|
|
|
|
#define UPB_WIRE_INTERNAL_DECODE_H_ |
|
|
|
|
|
|
|
|
|
#include "utf8_range.h" |
|
|
|
|
|
|
|
|
@ -12723,7 +12727,7 @@ UPB_INLINE uint32_t _upb_FastDecoder_LoadTag(const char* ptr) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* UPB_WIRE_DECODE_INTERNAL_H_ */ |
|
|
|
|
#endif /* UPB_WIRE_INTERNAL_DECODE_H_ */ |
|
|
|
|
|
|
|
|
|
#ifndef UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ |
|
|
|
|
#define UPB_MINI_DESCRIPTOR_INTERNAL_BASE92_H_ |
|
|
|
@ -12919,6 +12923,8 @@ UPB_INLINE const char* upb_MdDecoder_DecodeBase92Varint( |
|
|
|
|
#undef UPB_POISON_MEMORY_REGION |
|
|
|
|
#undef UPB_UNPOISON_MEMORY_REGION |
|
|
|
|
#undef UPB_ASAN |
|
|
|
|
#undef UPB_ASAN_GUARD_SIZE |
|
|
|
|
#undef UPB_CLANG_ASAN |
|
|
|
|
#undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 |
|
|
|
|
#undef UPB_DEPRECATED |
|
|
|
|
#undef UPB_GNUC_MIN |
|
|
|
|