Auto-generate files after cl/583524301
diff --git a/php/ext/google/protobuf/php-upb.c b/php/ext/google/protobuf/php-upb.c
index 4f9b9e7..454fd69 100644
--- a/php/ext/google/protobuf/php-upb.c
+++ b/php/ext/google/protobuf/php-upb.c
@@ -6211,6 +6211,7 @@
}
+#include <stdint.h>
#include <string.h>
@@ -6231,7 +6232,7 @@
upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
upb_MessageValue ret;
const char* data = _upb_array_constptr(arr);
- int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
UPB_ASSERT(i < arr->size);
memcpy(&ret, data + (i << lg2), 1 << lg2);
return ret;
@@ -6239,7 +6240,7 @@
void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) {
char* data = _upb_array_ptr(arr);
- int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
UPB_ASSERT(i < arr->size);
memcpy(data + (i << lg2), &val, 1 << lg2);
}
@@ -6255,7 +6256,7 @@
void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
size_t count) {
- const int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
char* data = _upb_array_ptr(arr);
memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2);
}
@@ -6292,7 +6293,7 @@
}
const size_t newsize = arr->size;
if (newsize > oldsize) {
- const int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
char* data = _upb_array_ptr(arr);
memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2);
}
@@ -6303,19 +6304,18 @@
bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) {
size_t new_capacity = UPB_MAX(arr->capacity, 4);
- int elem_size_lg2 = arr->data & 7;
- size_t old_bytes = arr->capacity << elem_size_lg2;
- size_t new_bytes;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
+ size_t old_bytes = arr->capacity << lg2;
void* ptr = _upb_array_ptr(arr);
// Log2 ceiling of size.
while (new_capacity < min_capacity) new_capacity *= 2;
- new_bytes = new_capacity << elem_size_lg2;
+ const size_t new_bytes = new_capacity << lg2;
ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes);
if (!ptr) return false;
- arr->data = _upb_tag_arrptr(ptr, elem_size_lg2);
+ _upb_Array_SetTaggedPtr(arr, ptr, lg2);
arr->capacity = new_capacity;
return true;
}
@@ -14029,17 +14029,17 @@
static void* fastdecode_resizearr(upb_Decoder* d, void* dst,
fastdecode_arr* farr, int valbytes) {
if (UPB_UNLIKELY(dst == farr->end)) {
- size_t old_size = farr->arr->capacity;
- size_t old_bytes = old_size * valbytes;
- size_t new_size = old_size * 2;
- size_t new_bytes = new_size * valbytes;
+ size_t old_capacity = farr->arr->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);
- farr->arr->capacity = new_size;
- farr->arr->data = _upb_array_tagptr(new_ptr, elem_size_lg2);
- dst = (void*)(new_ptr + (old_size * valbytes));
- farr->end = (void*)(new_ptr + (new_size * valbytes));
+ _upb_Array_SetTaggedPtr(farr->arr, new_ptr, elem_size_lg2);
+ farr->arr->capacity = new_capacity;
+ dst = (void*)(new_ptr + (old_capacity * valbytes));
+ farr->end = (void*)(new_ptr + (new_capacity * valbytes));
}
return dst;
}
diff --git a/php/ext/google/protobuf/php-upb.h b/php/ext/google/protobuf/php-upb.h
index ba43d2f..f80121d 100644
--- a/php/ext/google/protobuf/php-upb.h
+++ b/php/ext/google/protobuf/php-upb.h
@@ -2572,6 +2572,10 @@
// Must be last.
+#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit.
+#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size.
+#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2)
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -2579,46 +2583,52 @@
// LINT.IfChange(struct_definition)
// Our internal representation for repeated fields.
struct upb_Array {
- uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */
- size_t size; /* The number of elements in the array. */
- size_t capacity; /* Allocated storage. Measured in elements. */
+ // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows:
+ // 0 maps to elem size 1
+ // 1 maps to elem size 4
+ // 2 maps to elem size 8
+ // 3 maps to elem size 16
+ //
+ // 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.
};
// LINT.ThenChange(GoogleInternalName1)
-UPB_INLINE size_t _upb_Array_ElementSizeLg2(const upb_Array* arr) {
- size_t ret = arr->data & 7;
- UPB_ASSERT(ret <= 4);
- return ret;
+UPB_INLINE void _upb_Array_SetTaggedPtr(upb_Array* arr, 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;
+}
+
+UPB_INLINE size_t _upb_Array_ElemSizeLg2(const upb_Array* arr) {
+ const size_t bits = arr->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_ElementSizeLg2(arr); // Check assertion.
- return (void*)(arr->data & ~(uintptr_t)7);
-}
-
-UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) {
- UPB_ASSERT(elem_size_lg2 <= 4);
- return (uintptr_t)ptr | elem_size_lg2;
+ _upb_Array_ElemSizeLg2(arr); // Check assertions.
+ return (void*)(arr->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL);
}
UPB_INLINE void* _upb_array_ptr(upb_Array* arr) {
return (void*)_upb_array_constptr(arr);
}
-UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) {
- UPB_ASSERT(elem_size_lg2 <= 4);
- UPB_ASSERT(((uintptr_t)ptr & 7) == 0);
- return (uintptr_t)ptr | (unsigned)elem_size_lg2;
-}
-
UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, 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;
- arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2);
+ _upb_Array_SetTaggedPtr(arr, UPB_PTR_AT(arr, arr_size, void), elem_size_lg2);
arr->size = 0;
arr->capacity = init_capacity;
return arr;
@@ -2648,7 +2658,7 @@
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_ElementSizeLg2(arr));
+ UPB_ASSERT(elem_size == 1U << _upb_Array_ElemSizeLg2(arr));
char* arr_data = (char*)_upb_array_ptr(arr);
memcpy(arr_data + (i * elem_size), data, elem_size);
}
@@ -2661,6 +2671,10 @@
} /* extern "C" */
#endif
+#undef _UPB_ARRAY_MASK_IMM
+#undef _UPB_ARRAY_MASK_LG2
+#undef _UPB_ARRAY_MASK_ALL
+
#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */
diff --git a/ruby/ext/google/protobuf_c/ruby-upb.c b/ruby/ext/google/protobuf_c/ruby-upb.c
index 13eaf31..7059996 100644
--- a/ruby/ext/google/protobuf_c/ruby-upb.c
+++ b/ruby/ext/google/protobuf_c/ruby-upb.c
@@ -5726,6 +5726,7 @@
}
+#include <stdint.h>
#include <string.h>
@@ -5746,7 +5747,7 @@
upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
upb_MessageValue ret;
const char* data = _upb_array_constptr(arr);
- int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
UPB_ASSERT(i < arr->size);
memcpy(&ret, data + (i << lg2), 1 << lg2);
return ret;
@@ -5754,7 +5755,7 @@
void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val) {
char* data = _upb_array_ptr(arr);
- int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
UPB_ASSERT(i < arr->size);
memcpy(data + (i << lg2), &val, 1 << lg2);
}
@@ -5770,7 +5771,7 @@
void upb_Array_Move(upb_Array* arr, size_t dst_idx, size_t src_idx,
size_t count) {
- const int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
char* data = _upb_array_ptr(arr);
memmove(&data[dst_idx << lg2], &data[src_idx << lg2], count << lg2);
}
@@ -5807,7 +5808,7 @@
}
const size_t newsize = arr->size;
if (newsize > oldsize) {
- const int lg2 = arr->data & 7;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
char* data = _upb_array_ptr(arr);
memset(data + (oldsize << lg2), 0, (newsize - oldsize) << lg2);
}
@@ -5818,19 +5819,18 @@
bool _upb_array_realloc(upb_Array* arr, size_t min_capacity, upb_Arena* arena) {
size_t new_capacity = UPB_MAX(arr->capacity, 4);
- int elem_size_lg2 = arr->data & 7;
- size_t old_bytes = arr->capacity << elem_size_lg2;
- size_t new_bytes;
+ const int lg2 = _upb_Array_ElemSizeLg2(arr);
+ size_t old_bytes = arr->capacity << lg2;
void* ptr = _upb_array_ptr(arr);
// Log2 ceiling of size.
while (new_capacity < min_capacity) new_capacity *= 2;
- new_bytes = new_capacity << elem_size_lg2;
+ const size_t new_bytes = new_capacity << lg2;
ptr = upb_Arena_Realloc(arena, ptr, old_bytes, new_bytes);
if (!ptr) return false;
- arr->data = _upb_tag_arrptr(ptr, elem_size_lg2);
+ _upb_Array_SetTaggedPtr(arr, ptr, lg2);
arr->capacity = new_capacity;
return true;
}
@@ -13544,17 +13544,17 @@
static void* fastdecode_resizearr(upb_Decoder* d, void* dst,
fastdecode_arr* farr, int valbytes) {
if (UPB_UNLIKELY(dst == farr->end)) {
- size_t old_size = farr->arr->capacity;
- size_t old_bytes = old_size * valbytes;
- size_t new_size = old_size * 2;
- size_t new_bytes = new_size * valbytes;
+ size_t old_capacity = farr->arr->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);
- farr->arr->capacity = new_size;
- farr->arr->data = _upb_array_tagptr(new_ptr, elem_size_lg2);
- dst = (void*)(new_ptr + (old_size * valbytes));
- farr->end = (void*)(new_ptr + (new_size * valbytes));
+ _upb_Array_SetTaggedPtr(farr->arr, new_ptr, elem_size_lg2);
+ farr->arr->capacity = new_capacity;
+ dst = (void*)(new_ptr + (old_capacity * valbytes));
+ farr->end = (void*)(new_ptr + (new_capacity * valbytes));
}
return dst;
}
diff --git a/ruby/ext/google/protobuf_c/ruby-upb.h b/ruby/ext/google/protobuf_c/ruby-upb.h
index 7958339..33e0e3c 100755
--- a/ruby/ext/google/protobuf_c/ruby-upb.h
+++ b/ruby/ext/google/protobuf_c/ruby-upb.h
@@ -2574,6 +2574,10 @@
// Must be last.
+#define _UPB_ARRAY_MASK_IMM 0x4 // Frozen/immutable bit.
+#define _UPB_ARRAY_MASK_LG2 0x3 // Encoded elem size.
+#define _UPB_ARRAY_MASK_ALL (_UPB_ARRAY_MASK_IMM | _UPB_ARRAY_MASK_LG2)
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -2581,46 +2585,52 @@
// LINT.IfChange(struct_definition)
// Our internal representation for repeated fields.
struct upb_Array {
- uintptr_t data; /* Tagged ptr: low 3 bits of ptr are lg2(elem size). */
- size_t size; /* The number of elements in the array. */
- size_t capacity; /* Allocated storage. Measured in elements. */
+ // This is a tagged pointer. Bits #0 and #1 encode the elem size as follows:
+ // 0 maps to elem size 1
+ // 1 maps to elem size 4
+ // 2 maps to elem size 8
+ // 3 maps to elem size 16
+ //
+ // 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.
};
// LINT.ThenChange(GoogleInternalName1)
-UPB_INLINE size_t _upb_Array_ElementSizeLg2(const upb_Array* arr) {
- size_t ret = arr->data & 7;
- UPB_ASSERT(ret <= 4);
- return ret;
+UPB_INLINE void _upb_Array_SetTaggedPtr(upb_Array* arr, 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;
+}
+
+UPB_INLINE size_t _upb_Array_ElemSizeLg2(const upb_Array* arr) {
+ const size_t bits = arr->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_ElementSizeLg2(arr); // Check assertion.
- return (void*)(arr->data & ~(uintptr_t)7);
-}
-
-UPB_INLINE uintptr_t _upb_array_tagptr(void* ptr, int elem_size_lg2) {
- UPB_ASSERT(elem_size_lg2 <= 4);
- return (uintptr_t)ptr | elem_size_lg2;
+ _upb_Array_ElemSizeLg2(arr); // Check assertions.
+ return (void*)(arr->data & ~(uintptr_t)_UPB_ARRAY_MASK_ALL);
}
UPB_INLINE void* _upb_array_ptr(upb_Array* arr) {
return (void*)_upb_array_constptr(arr);
}
-UPB_INLINE uintptr_t _upb_tag_arrptr(void* ptr, int elem_size_lg2) {
- UPB_ASSERT(elem_size_lg2 <= 4);
- UPB_ASSERT(((uintptr_t)ptr & 7) == 0);
- return (uintptr_t)ptr | (unsigned)elem_size_lg2;
-}
-
UPB_INLINE upb_Array* _upb_Array_New(upb_Arena* a, 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;
- arr->data = _upb_tag_arrptr(UPB_PTR_AT(arr, arr_size, void), elem_size_lg2);
+ _upb_Array_SetTaggedPtr(arr, UPB_PTR_AT(arr, arr_size, void), elem_size_lg2);
arr->size = 0;
arr->capacity = init_capacity;
return arr;
@@ -2650,7 +2660,7 @@
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_ElementSizeLg2(arr));
+ UPB_ASSERT(elem_size == 1U << _upb_Array_ElemSizeLg2(arr));
char* arr_data = (char*)_upb_array_ptr(arr);
memcpy(arr_data + (i * elem_size), data, elem_size);
}
@@ -2663,6 +2673,10 @@
} /* extern "C" */
#endif
+#undef _UPB_ARRAY_MASK_IMM
+#undef _UPB_ARRAY_MASK_LG2
+#undef _UPB_ARRAY_MASK_ALL
+
#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */