diff --git a/upb/message/accessors.h b/upb/message/accessors.h index 7e6f8178de..12b81ce9a1 100644 --- a/upb/message/accessors.h +++ b/upb/message/accessors.h @@ -379,7 +379,8 @@ UPB_API_INLINE upb_Array* upb_Message_GetOrCreateMutableArray( _upb_MiniTableField_CheckIsArray(field); upb_Array* array = upb_Message_GetMutableArray(msg, field); if (!array) { - array = _upb_Array_New(arena, 4, _upb_MiniTableField_ElemSizeLg2(field)); + array = UPB_PRIVATE(_upb_Array_New)(arena, 4, + _upb_MiniTableField_ElemSizeLg2(field)); // Check again due to: https://godbolt.org/z/7WfaoKG1r _upb_MiniTableField_CheckIsArray(field); upb_MessageValue val; diff --git a/upb/message/array.c b/upb/message/array.c index 40264ea340..ba3f743010 100644 --- a/upb/message/array.c +++ b/upb/message/array.c @@ -19,7 +19,7 @@ #include "upb/port/def.inc" upb_Array* upb_Array_New(upb_Arena* a, upb_CType type) { - return _upb_Array_New(a, 4, upb_CType_SizeLg2(type)); + return UPB_PRIVATE(_upb_Array_New)(a, 4, upb_CType_SizeLg2(type)); } const void* upb_Array_DataPtr(const upb_Array* arr) { @@ -33,7 +33,7 @@ size_t upb_Array_Size(const upb_Array* arr) { return arr->size; } upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { upb_MessageValue ret; const char* data = _upb_array_constptr(arr); - const int lg2 = _upb_Array_ElemSizeLg2(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); UPB_ASSERT(i < arr->size); memcpy(&ret, data + (i << lg2), 1 << lg2); return ret; @@ -41,7 +41,7 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) { void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) { char* data = _upb_array_ptr(arr); - const int lg2 = _upb_Array_ElemSizeLg2(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); UPB_ASSERT(i < arr->size); memcpy(data + (i << lg2), &val, 1 << lg2); } @@ -57,7 +57,7 @@ bool upb_Array_Append(upb_Array* arr, upb_MessageValue val, upb_Arena* arena) { void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx, size_t count) { - const int lg2 = _upb_Array_ElemSizeLg2(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); char* data = _upb_array_ptr(arr); memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2); } @@ -94,20 +94,19 @@ bool upb_Array_Resize(upb_Array* arr, size_t size, upb_Arena* arena) { } const size_t newsize = arr->size; if (newsize > oldsize) { - const int lg2 = _upb_Array_ElemSizeLg2(arr); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr); char* data = _upb_array_ptr(arr); memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2); } return true; } -// EVERYTHING BELOW THIS LINE IS INTERNAL - DO NOT USE ///////////////////////// - -bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { - size_t new_capacity = UPB_MAX(arr->capacity, 4); - const int lg2 = _upb_Array_ElemSizeLg2(arr); - size_t old_bytes = arr->capacity << lg2; - void* ptr = _upb_array_ptr(arr); +bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity, + upb_Arena* arena) { + size_t new_capacity = UPB_MAX(array->UPB_PRIVATE(capacity), 4); + const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); + size_t old_bytes = array->UPB_PRIVATE(capacity) << lg2; + void* ptr = _upb_array_ptr(array); // Log2 ceiling of size. while (new_capacity < min_capacity) new_capacity *= 2; @@ -116,7 +115,7 @@ bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) { ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes); if (!ptr) return false; - _upb_Array_SetTaggedPtr(arr, ptr, lg2); - arr->capacity = new_capacity; + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(array, ptr, lg2); + array->UPB_PRIVATE(capacity) = new_capacity; return true; } diff --git a/upb/message/copy.c b/upb/message/copy.c index 62e8aa821d..52f8f67767 100644 --- a/upb/message/copy.c +++ b/upb/message/copy.c @@ -143,7 +143,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type, const upb_MiniTable* sub, upb_Arena* arena) { size_t size = array->size; upb_Array* cloned_array = - _upb_Array_New(arena, size, upb_CType_SizeLg2(value_type)); + UPB_PRIVATE(_upb_Array_New)(arena, size, upb_CType_SizeLg2(value_type)); if (!cloned_array) { return NULL; } diff --git a/upb/message/internal/array.h b/upb/message/internal/array.h index dc68a66baa..a99e2e44c8 100644 --- a/upb/message/internal/array.h +++ b/upb/message/internal/array.h @@ -35,81 +35,82 @@ struct upb_Array { // Bit #2 contains the frozen/immutable flag (currently unimplemented). uintptr_t data; - size_t size; // The number of elements in the array. - size_t capacity; // Allocated storage. Measured in elements. + size_t size; // The number of elements in the array. + size_t UPB_PRIVATE(capacity); // Allocated storage. Measured in elements. }; // LINT.ThenChange(GoogleInternalName1) -UPB_INLINE void _upb_Array_SetTaggedPtr(upb_Array* arr, void* data, - size_t lg2) { +UPB_INLINE void UPB_PRIVATE(_upb_Array_SetTaggedPtr)(upb_Array* array, + void* data, size_t lg2) { UPB_ASSERT(lg2 != 1); UPB_ASSERT(lg2 <= 4); const size_t bits = lg2 - (lg2 != 0); - arr->data = (uintptr_t)data | bits; + array->data = (uintptr_t)data | bits; } -UPB_INLINE size_t _upb_Array_ElemSizeLg2(const upb_Array* arr) { - const size_t bits = arr->data & _UPB_ARRAY_MASK_LG2; +UPB_INLINE size_t UPB_PRIVATE(_upb_Array_ElemSizeLg2)(const upb_Array* array) { + const size_t bits = array->data & _UPB_ARRAY_MASK_LG2; const size_t lg2 = bits + (bits != 0); return lg2; } -UPB_INLINE const void* _upb_array_constptr(const upb_Array* arr) { - _upb_Array_ElemSizeLg2(arr); // Check assertions. - return (void*)(arr->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); +UPB_INLINE const void* _upb_array_constptr(const upb_Array* array) { + UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array); // Check assertions. + return (void*)(array->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL); } -UPB_INLINE void* _upb_array_ptr(upb_Array* arr) { - return (void*)_upb_array_constptr(arr); +UPB_INLINE void* _upb_array_ptr(upb_Array* array) { + return (void*)_upb_array_constptr(array); } -UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, size_t init_capacity, - int elem_size_lg2) { +UPB_INLINE upb_Array* UPB_PRIVATE(_upb_Array_New)(upb_Arena* arena, + size_t init_capacity, + int elem_size_lg2) { UPB_ASSERT(elem_size_lg2 != 1); UPB_ASSERT(elem_size_lg2 <= 4); - const size_t arr_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); - const size_t bytes = arr_size + (init_capacity << elem_size_lg2); - upb_Array* arr = (upb_Array*)upb_Arena_Malloc(a, bytes); - if (!arr) return NULL; - _upb_Array_SetTaggedPtr(arr, UPB_PTR_AT(arr, arr_size, void), elem_size_lg2); - arr->size = 0; - arr->capacity = init_capacity; - return arr; + const size_t array_size = UPB_ALIGN_UP(sizeof(upb_Array), UPB_MALLOC_ALIGN); + const size_t bytes = array_size + (init_capacity << elem_size_lg2); + upb_Array* array = (upb_Array*)upb_Arena_Malloc(arena, bytes); + if (!array) return NULL; + UPB_PRIVATE(_upb_Array_SetTaggedPtr) + (array, UPB_PTR_AT(array, array_size, void), elem_size_lg2); + array->size = 0; + array->UPB_PRIVATE(capacity) = init_capacity; + return array; } // Resizes the capacity of the array to be at least min_size. -bool _upb_array_realloc(upb_Array* arr, size_t min_size, upb_Arena* arena); +bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_size, + upb_Arena* arena); -UPB_INLINE bool _upb_array_reserve(upb_Array* arr, size_t size, - upb_Arena* arena) { - if (arr->capacity < size) return _upb_array_realloc(arr, size, arena); +UPB_INLINE bool UPB_PRIVATE(_upb_Array_Reserve)(upb_Array* array, size_t size, + upb_Arena* arena) { + if (array->UPB_PRIVATE(capacity) < size) + return UPB_PRIVATE(_upb_Array_Realloc)(array, size, arena); return true; } // Resize without initializing new elements. -UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* arr, size_t size, +UPB_INLINE bool _upb_Array_ResizeUninitialized(upb_Array* array, size_t size, upb_Arena* arena) { - UPB_ASSERT(size <= arr->size || arena); // Allow NULL arena when shrinking. - if (!_upb_array_reserve(arr, size, arena)) return false; - arr->size = size; + UPB_ASSERT(size <= array->size || arena); // Allow NULL arena when shrinking. + if (!UPB_PRIVATE(_upb_Array_Reserve)(array, size, arena)) return false; + array->size = size; return true; } // This function is intended for situations where elem_size is compile-time // constant or a known expression of the form (1 << lg2), so that the expression // i*elem_size does not result in an actual multiplication. -UPB_INLINE void _upb_Array_Set(upb_Array* arr, size_t i, const void* data, - size_t elem_size) { - UPB_ASSERT(i < arr->size); - UPB_ASSERT(elem_size == 1U << _upb_Array_ElemSizeLg2(arr)); - char* arr_data = (char*)_upb_array_ptr(arr); +UPB_INLINE void UPB_PRIVATE(_upb_Array_Set)(upb_Array* array, size_t i, + const void* data, + size_t elem_size) { + UPB_ASSERT(i < array->size); + UPB_ASSERT(elem_size == 1U << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(array)); + char* arr_data = (char*)_upb_array_ptr(array); memcpy(arr_data + (i * elem_size), data, elem_size); } -UPB_INLINE void _upb_array_detach(const void* msg, size_t ofs) { - *UPB_PTR_AT(msg, ofs, upb_Array*) = NULL; -} - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/upb/reflection/stage0/google/protobuf/descriptor.upb.h b/upb/reflection/stage0/google/protobuf/descriptor.upb.h index 064a821d7d..b44602fb2e 100644 --- a/upb/reflection/stage0/google/protobuf/descriptor.upb.h +++ b/upb/reflection/stage0/google/protobuf/descriptor.upb.h @@ -328,7 +328,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescr } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -746,7 +746,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_dependency(google_protob if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_FileDescriptorProto_mutable_message_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { @@ -772,7 +772,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_FileDescripto } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_FileDescriptorProto_mutable_enum_type(google_protobuf_FileDescriptorProto* msg, size_t* size) { @@ -798,7 +798,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_FileDescr } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_ServiceDescriptorProto** google_protobuf_FileDescriptorProto_mutable_service(google_protobuf_FileDescriptorProto* msg, size_t* size) { @@ -824,7 +824,7 @@ UPB_INLINE struct google_protobuf_ServiceDescriptorProto* google_protobuf_FileDe } struct google_protobuf_ServiceDescriptorProto* sub = (struct google_protobuf_ServiceDescriptorProto*)_upb_Message_New(google__protobuf__ServiceDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_FileDescriptorProto_mutable_extension(google_protobuf_FileDescriptorProto* msg, size_t* size) { @@ -850,7 +850,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_FileDesc } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_options(google_protobuf_FileDescriptorProto *msg, google_protobuf_FileOptions* value) { @@ -898,7 +898,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_public_dependency(google if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_FileDescriptorProto_mutable_weak_dependency(google_protobuf_FileDescriptorProto* msg, size_t* size) { @@ -922,7 +922,7 @@ UPB_INLINE bool google_protobuf_FileDescriptorProto_add_weak_dependency(google_p if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_FileDescriptorProto *msg, upb_StringView value) { @@ -1323,7 +1323,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto** google_protobuf_DescriptorProto_mutable_nested_type(google_protobuf_DescriptorProto* msg, size_t* size) { @@ -1349,7 +1349,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto* google_protobuf_DescriptorPro } struct google_protobuf_DescriptorProto* sub = (struct google_protobuf_DescriptorProto*)_upb_Message_New(google__protobuf__DescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_EnumDescriptorProto** google_protobuf_DescriptorProto_mutable_enum_type(google_protobuf_DescriptorProto* msg, size_t* size) { @@ -1375,7 +1375,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto* google_protobuf_Descripto } struct google_protobuf_EnumDescriptorProto* sub = (struct google_protobuf_EnumDescriptorProto*)_upb_Message_New(google__protobuf__EnumDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange** google_protobuf_DescriptorProto_mutable_extension_range(google_protobuf_DescriptorProto* msg, size_t* size) { @@ -1401,7 +1401,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ExtensionRange* google_protobu } struct google_protobuf_DescriptorProto_ExtensionRange* sub = (struct google_protobuf_DescriptorProto_ExtensionRange*)_upb_Message_New(google__protobuf__DescriptorProto__ExtensionRange_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_FieldDescriptorProto** google_protobuf_DescriptorProto_mutable_extension(google_protobuf_DescriptorProto* msg, size_t* size) { @@ -1427,7 +1427,7 @@ UPB_INLINE struct google_protobuf_FieldDescriptorProto* google_protobuf_Descript } struct google_protobuf_FieldDescriptorProto* sub = (struct google_protobuf_FieldDescriptorProto*)_upb_Message_New(google__protobuf__FieldDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_DescriptorProto_set_options(google_protobuf_DescriptorProto *msg, google_protobuf_MessageOptions* value) { @@ -1465,7 +1465,7 @@ UPB_INLINE struct google_protobuf_OneofDescriptorProto* google_protobuf_Descript } struct google_protobuf_OneofDescriptorProto* sub = (struct google_protobuf_OneofDescriptorProto*)_upb_Message_New(google__protobuf__OneofDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE google_protobuf_DescriptorProto_ReservedRange** google_protobuf_DescriptorProto_mutable_reserved_range(google_protobuf_DescriptorProto* msg, size_t* size) { @@ -1491,7 +1491,7 @@ UPB_INLINE struct google_protobuf_DescriptorProto_ReservedRange* google_protobuf } struct google_protobuf_DescriptorProto_ReservedRange* sub = (struct google_protobuf_DescriptorProto_ReservedRange*)_upb_Message_New(google__protobuf__DescriptorProto__ReservedRange_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_DescriptorProto_mutable_reserved_name(google_protobuf_DescriptorProto* msg, size_t* size) { @@ -1515,7 +1515,7 @@ UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobu if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } @@ -1859,7 +1859,7 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions_Declaration* google_prot } struct google_protobuf_ExtensionRangeOptions_Declaration* sub = (struct google_protobuf_ExtensionRangeOptions_Declaration*)_upb_Message_New(google__protobuf__ExtensionRangeOptions__Declaration_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ExtensionRangeOptions_set_verification(google_protobuf_ExtensionRangeOptions *msg, int32_t value) { @@ -1901,7 +1901,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_Extension } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -2578,7 +2578,7 @@ UPB_INLINE struct google_protobuf_EnumValueDescriptorProto* google_protobuf_Enum } struct google_protobuf_EnumValueDescriptorProto* sub = (struct google_protobuf_EnumValueDescriptorProto*)_upb_Message_New(google__protobuf__EnumValueDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_EnumDescriptorProto_set_options(google_protobuf_EnumDescriptorProto *msg, google_protobuf_EnumOptions* value) { @@ -2616,7 +2616,7 @@ UPB_INLINE struct google_protobuf_EnumDescriptorProto_EnumReservedRange* google_ } struct google_protobuf_EnumDescriptorProto_EnumReservedRange* sub = (struct google_protobuf_EnumDescriptorProto_EnumReservedRange*)_upb_Message_New(google__protobuf__EnumDescriptorProto__EnumReservedRange_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE upb_StringView* google_protobuf_EnumDescriptorProto_mutable_reserved_name(google_protobuf_EnumDescriptorProto* msg, size_t* size) { @@ -2640,7 +2640,7 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_pro if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } @@ -2951,7 +2951,7 @@ UPB_INLINE struct google_protobuf_MethodDescriptorProto* google_protobuf_Service } struct google_protobuf_MethodDescriptorProto* sub = (struct google_protobuf_MethodDescriptorProto*)_upb_Message_New(google__protobuf__MethodDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_ServiceDescriptorProto_set_options(google_protobuf_ServiceDescriptorProto *msg, google_protobuf_ServiceOptions* value) { @@ -3629,7 +3629,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptio } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -3851,7 +3851,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOp } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -4209,7 +4209,7 @@ UPB_INLINE bool google_protobuf_FieldOptions_add_targets(google_protobuf_FieldOp if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE google_protobuf_FieldOptions_EditionDefault** google_protobuf_FieldOptions_mutable_edition_defaults(google_protobuf_FieldOptions* msg, size_t* size) { @@ -4235,7 +4235,7 @@ UPB_INLINE struct google_protobuf_FieldOptions_EditionDefault* google_protobuf_F } struct google_protobuf_FieldOptions_EditionDefault* sub = (struct google_protobuf_FieldOptions_EditionDefault*)_upb_Message_New(google__protobuf__FieldOptions__EditionDefault_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FieldOptions_set_features(google_protobuf_FieldOptions *msg, google_protobuf_FeatureSet* value) { @@ -4273,7 +4273,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOpti } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -4475,7 +4475,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOpti } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -4659,7 +4659,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptio } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -4824,7 +4824,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValue } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -4970,7 +4970,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOp } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -5135,7 +5135,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOpt } struct google_protobuf_UninterpretedOption* sub = (struct google_protobuf_UninterpretedOption*)_upb_Message_New(google__protobuf__UninterpretedOption_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -5325,7 +5325,7 @@ UPB_INLINE struct google_protobuf_UninterpretedOption_NamePart* google_protobuf_ } struct google_protobuf_UninterpretedOption_NamePart* sub = (struct google_protobuf_UninterpretedOption_NamePart*)_upb_Message_New(google__protobuf__UninterpretedOption__NamePart_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_UninterpretedOption_set_identifier_value(google_protobuf_UninterpretedOption *msg, upb_StringView value) { @@ -5705,7 +5705,7 @@ UPB_INLINE struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* g } struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault* sub = (struct google_protobuf_FeatureSetDefaults_FeatureSetEditionDefault*)_upb_Message_New(google__protobuf__FeatureSetDefaults__FeatureSetEditionDefault_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE void google_protobuf_FeatureSetDefaults_set_minimum_edition(google_protobuf_FeatureSetDefaults *msg, int32_t value) { @@ -5896,7 +5896,7 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_Sourc } struct google_protobuf_SourceCodeInfo_Location* sub = (struct google_protobuf_SourceCodeInfo_Location*)_upb_Message_New(google__protobuf__SourceCodeInfo__Location_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -6098,7 +6098,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_path(google_protobuf if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE int32_t* google_protobuf_SourceCodeInfo_Location_mutable_span(google_protobuf_SourceCodeInfo_Location* msg, size_t* size) { @@ -6122,7 +6122,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_span(google_protobuf if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_SourceCodeInfo_Location_set_leading_comments(google_protobuf_SourceCodeInfo_Location *msg, upb_StringView value) { @@ -6154,7 +6154,7 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_com if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } @@ -6254,7 +6254,7 @@ UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_ } struct google_protobuf_GeneratedCodeInfo_Annotation* sub = (struct google_protobuf_GeneratedCodeInfo_Annotation*)_upb_Message_New(google__protobuf__GeneratedCodeInfo__Annotation_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -6412,7 +6412,7 @@ UPB_INLINE bool google_protobuf_GeneratedCodeInfo_Annotation_add_path(google_pro if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_source_file(google_protobuf_GeneratedCodeInfo_Annotation *msg, upb_StringView value) { diff --git a/upb/wire/decode.c b/upb/wire/decode.c index f33ed06cc4..c2525ea6ac 100644 --- a/upb/wire/decode.c +++ b/upb/wire/decode.c @@ -112,8 +112,9 @@ static void _upb_Decoder_VerifyUtf8(upb_Decoder* d, const char* buf, int len) { } static bool _upb_Decoder_Reserve(upb_Decoder* d, upb_Array* arr, size_t elem) { - bool need_realloc = arr->capacity - arr->size < elem; - if (need_realloc && !_upb_array_realloc(arr, arr->size + elem, &d->arena)) { + bool need_realloc = arr->UPB_PRIVATE(capacity) - arr->size < elem; + if (need_realloc && + !UPB_PRIVATE(_upb_Array_Realloc)(arr, arr->size + elem, &d->arena)) { _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); } return need_realloc; @@ -477,7 +478,7 @@ upb_Array* _upb_Decoder_CreateArray(upb_Decoder* d, const upb_MiniTableField* field) { const upb_FieldType field_type = field->UPB_PRIVATE(descriptortype); const size_t lg2 = upb_FieldType_SizeLg2(field_type); - upb_Array* ret = _upb_Array_New(&d->arena, 4, lg2); + upb_Array* ret = UPB_PRIVATE(_upb_Array_New)(&d->arena, 4, lg2); if (!ret) _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); return ret; } diff --git a/upb/wire/decode_fast.c b/upb/wire/decode_fast.c index 0ce3feff78..5a412ef308 100644 --- a/upb/wire/decode_fast.c +++ b/upb/wire/decode_fast.c @@ -165,15 +165,15 @@ UPB_FORCEINLINE static void* fastdecode_resizearr(upb_Decoder* d, void* dst, fastdecode_arr* farr, int valbytes) { if (UPB_UNLIKELY(dst == farr->end)) { - size_t old_capacity = farr->arr->capacity; + size_t old_capacity = farr->arr->UPB_PRIVATE(capacity); size_t old_bytes = old_capacity * valbytes; size_t new_capacity = old_capacity * 2; size_t new_bytes = new_capacity * valbytes; char* old_ptr = _upb_array_ptr(farr->arr); char* new_ptr = upb_Arena_Realloc(&d->arena, old_ptr, old_bytes, new_bytes); uint8_t elem_size_lg2 = __builtin_ctz(valbytes); - _upb_Array_SetTaggedPtr(farr->arr, new_ptr, elem_size_lg2); - farr->arr->capacity = new_capacity; + UPB_PRIVATE(_upb_Array_SetTaggedPtr)(farr->arr, new_ptr, elem_size_lg2); + farr->arr->UPB_PRIVATE(capacity) = new_capacity; dst = (void*)(new_ptr + (old_capacity * valbytes)); farr->end = (void*)(new_ptr + (new_capacity * valbytes)); } @@ -255,13 +255,13 @@ static void* fastdecode_getfield(upb_Decoder* d, const char* ptr, *(uint32_t*)msg |= *hasbits; *hasbits = 0; if (UPB_LIKELY(!*arr_p)) { - farr->arr = _upb_Array_New(&d->arena, 8, elem_size_lg2); + farr->arr = UPB_PRIVATE(_upb_Array_New)(&d->arena, 8, elem_size_lg2); *arr_p = farr->arr; } else { farr->arr = *arr_p; } begin = _upb_array_ptr(farr->arr); - farr->end = begin + (farr->arr->capacity * valbytes); + farr->end = begin + (farr->arr->UPB_PRIVATE(capacity) * valbytes); *data = _upb_FastDecoder_LoadTag(ptr); return begin + (farr->arr->size * valbytes); } @@ -540,7 +540,8 @@ TAGBYTES(p) int elems = size / valbytes; \ \ if (UPB_LIKELY(!arr)) { \ - *arr_p = arr = _upb_Array_New(&d->arena, elems, elem_size_lg2); \ + *arr_p = arr = \ + UPB_PRIVATE(_upb_Array_New)(&d->arena, elems, elem_size_lg2); \ if (!arr) { \ _upb_FastDecoder_ErrorJmp(d, kUpb_DecodeStatus_Malformed); \ } \ diff --git a/upb_generator/protoc-gen-upb.cc b/upb_generator/protoc-gen-upb.cc index fa60e83603..f5c5056739 100644 --- a/upb_generator/protoc-gen-upb.cc +++ b/upb_generator/protoc-gen-upb.cc @@ -690,7 +690,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, } struct $0* sub = (struct $0*)_upb_Message_New($3, arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } )cc", @@ -706,7 +706,7 @@ void GenerateRepeatedSetters(upb::FieldDefPtr field, const DefPoolPair& pools, if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } )cc", diff --git a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h index 1c5e100f57..e706b9b7f9 100644 --- a/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h +++ b/upb_generator/stage0/google/protobuf/compiler/plugin.upb.h @@ -351,7 +351,7 @@ UPB_INLINE bool google_protobuf_compiler_CodeGeneratorRequest_add_file_to_genera if (!arr || !_upb_Array_ResizeUninitialized(arr, arr->size + 1, arena)) { return false; } - _upb_Array_Set(arr, arr->size - 1, &val, sizeof(val)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &val, sizeof(val)); return true; } UPB_INLINE void google_protobuf_compiler_CodeGeneratorRequest_set_parameter(google_protobuf_compiler_CodeGeneratorRequest *msg, upb_StringView value) { @@ -393,7 +393,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_ } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } UPB_INLINE struct google_protobuf_FileDescriptorProto** google_protobuf_compiler_CodeGeneratorRequest_mutable_source_file_descriptors(google_protobuf_compiler_CodeGeneratorRequest* msg, size_t* size) { @@ -419,7 +419,7 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_compiler_ } struct google_protobuf_FileDescriptorProto* sub = (struct google_protobuf_FileDescriptorProto*)_upb_Message_New(google__protobuf__FileDescriptorProto_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; } @@ -557,7 +557,7 @@ UPB_INLINE struct google_protobuf_compiler_CodeGeneratorResponse_File* google_pr } struct google_protobuf_compiler_CodeGeneratorResponse_File* sub = (struct google_protobuf_compiler_CodeGeneratorResponse_File*)_upb_Message_New(google__protobuf__compiler__CodeGeneratorResponse__File_msg_init(), arena); if (!arr || !sub) return NULL; - _upb_Array_Set(arr, arr->size - 1, &sub, sizeof(sub)); + UPB_PRIVATE(_upb_Array_Set)(arr, arr->size - 1, &sub, sizeof(sub)); return sub; }