Skip to content

Commit ea77a1a

Browse files
Auto-generate files after cl/742287802
1 parent a2db0a3 commit ea77a1a

File tree

4 files changed

+194
-190
lines changed

4 files changed

+194
-190
lines changed

php/ext/google/protobuf/php-upb.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,12 +3786,14 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
37863786
return ret;
37873787
}
37883788

3789-
upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) {
3789+
upb_Message* upb_Array_GetMutable(upb_Array* arr, size_t i) {
37903790
UPB_ASSERT(i < upb_Array_Size(arr));
3791-
upb_MutableMessageValue ret;
3791+
size_t elem_size = sizeof(upb_Message*);
3792+
UPB_ASSERT(elem_size == (1 << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr)));
37923793
char* data = upb_Array_MutableDataPtr(arr);
3793-
const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
3794-
memcpy(&ret, data + (i << lg2), 1 << lg2);
3794+
upb_Message* ret;
3795+
memcpy(&ret, data + (i * elem_size), elem_size);
3796+
UPB_ASSERT(!upb_Message_IsFrozen(ret));
37953797
return ret;
37963798
}
37973799

php/ext/google/protobuf/php-upb.h

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,16 +1648,6 @@ UPB_API_INLINE size_t upb_Array_Size(const struct upb_Array* arr) {
16481648

16491649
#endif /* UPB_MESSAGE_INTERNAL_ARRAY_H_ */
16501650

1651-
// Users should include array.h or map.h instead.
1652-
// IWYU pragma: private, include "upb/message/array.h"
1653-
1654-
#ifndef UPB_MESSAGE_VALUE_H_
1655-
#define UPB_MESSAGE_VALUE_H_
1656-
1657-
#include <stdint.h>
1658-
#include <string.h>
1659-
1660-
16611651
#ifndef UPB_MESSAGE_INTERNAL_TYPES_H_
16621652
#define UPB_MESSAGE_INTERNAL_TYPES_H_
16631653

@@ -1708,6 +1698,16 @@ UPB_INLINE void UPB_PRIVATE(_upb_Message_SetInternal)(
17081698

17091699
#endif /* UPB_MESSAGE_INTERNAL_TYPES_H_ */
17101700

1701+
// Users should include array.h or map.h instead.
1702+
// IWYU pragma: private, include "upb/message/array.h"
1703+
1704+
#ifndef UPB_MESSAGE_VALUE_H_
1705+
#define UPB_MESSAGE_VALUE_H_
1706+
1707+
#include <stdint.h>
1708+
#include <string.h>
1709+
1710+
17111711
// Must be last.
17121712

17131713
#ifdef __cplusplus
@@ -1767,6 +1767,84 @@ UPB_API_INLINE upb_MutableMessageValue upb_MutableMessageValue_Zero(void) {
17671767

17681768
#endif /* UPB_MESSAGE_VALUE_H_ */
17691769

1770+
#ifndef UPB_MINI_TABLE_MESSAGE_H_
1771+
#define UPB_MINI_TABLE_MESSAGE_H_
1772+
1773+
1774+
#ifndef UPB_MINI_TABLE_ENUM_H_
1775+
#define UPB_MINI_TABLE_ENUM_H_
1776+
1777+
#include <stdint.h>
1778+
1779+
1780+
#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_
1781+
#define UPB_MINI_TABLE_INTERNAL_ENUM_H_
1782+
1783+
#include <stdint.h>
1784+
1785+
// Must be last.
1786+
1787+
struct upb_MiniTableEnum {
1788+
uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask.
1789+
uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield.
1790+
uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow.
1791+
};
1792+
1793+
#ifdef __cplusplus
1794+
extern "C" {
1795+
#endif
1796+
1797+
UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(
1798+
const struct upb_MiniTableEnum* e, uint32_t val) {
1799+
if (UPB_LIKELY(val < 64)) {
1800+
const uint64_t mask =
1801+
e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32);
1802+
const uint64_t bit = 1ULL << val;
1803+
return (mask & bit) != 0;
1804+
}
1805+
if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) {
1806+
const uint32_t mask = e->UPB_PRIVATE(data)[val / 32];
1807+
const uint32_t bit = 1U << (val % 32);
1808+
return (mask & bit) != 0;
1809+
}
1810+
1811+
// OPT: binary search long lists?
1812+
const uint32_t* start =
1813+
&e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32];
1814+
const uint32_t* limit = &e->UPB_PRIVATE(
1815+
data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)];
1816+
for (const uint32_t* p = start; p < limit; p++) {
1817+
if (*p == val) return true;
1818+
}
1819+
return false;
1820+
}
1821+
1822+
#ifdef __cplusplus
1823+
} /* extern "C" */
1824+
#endif
1825+
1826+
1827+
#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */
1828+
1829+
// Must be last
1830+
1831+
typedef struct upb_MiniTableEnum upb_MiniTableEnum;
1832+
1833+
#ifdef __cplusplus
1834+
extern "C" {
1835+
#endif
1836+
1837+
// Validates enum value against range defined by enum mini table.
1838+
UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e,
1839+
uint32_t val);
1840+
1841+
#ifdef __cplusplus
1842+
} /* extern "C" */
1843+
#endif
1844+
1845+
1846+
#endif /* UPB_MINI_TABLE_ENUM_H_ */
1847+
17701848
#ifndef UPB_MINI_TABLE_FIELD_H_
17711849
#define UPB_MINI_TABLE_FIELD_H_
17721850

@@ -2095,84 +2173,6 @@ upb_MiniTableField_Type(const upb_MiniTableField* f);
20952173

20962174
#endif /* UPB_MINI_TABLE_FIELD_H_ */
20972175

2098-
#ifndef UPB_MINI_TABLE_MESSAGE_H_
2099-
#define UPB_MINI_TABLE_MESSAGE_H_
2100-
2101-
2102-
#ifndef UPB_MINI_TABLE_ENUM_H_
2103-
#define UPB_MINI_TABLE_ENUM_H_
2104-
2105-
#include <stdint.h>
2106-
2107-
2108-
#ifndef UPB_MINI_TABLE_INTERNAL_ENUM_H_
2109-
#define UPB_MINI_TABLE_INTERNAL_ENUM_H_
2110-
2111-
#include <stdint.h>
2112-
2113-
// Must be last.
2114-
2115-
struct upb_MiniTableEnum {
2116-
uint32_t UPB_PRIVATE(mask_limit); // Highest that can be tested with mask.
2117-
uint32_t UPB_PRIVATE(value_count); // Number of values after the bitfield.
2118-
uint32_t UPB_PRIVATE(data)[]; // Bitmask + enumerated values follow.
2119-
};
2120-
2121-
#ifdef __cplusplus
2122-
extern "C" {
2123-
#endif
2124-
2125-
UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(
2126-
const struct upb_MiniTableEnum* e, uint32_t val) {
2127-
if (UPB_LIKELY(val < 64)) {
2128-
const uint64_t mask =
2129-
e->UPB_PRIVATE(data)[0] | ((uint64_t)e->UPB_PRIVATE(data)[1] << 32);
2130-
const uint64_t bit = 1ULL << val;
2131-
return (mask & bit) != 0;
2132-
}
2133-
if (UPB_LIKELY(val < e->UPB_PRIVATE(mask_limit))) {
2134-
const uint32_t mask = e->UPB_PRIVATE(data)[val / 32];
2135-
const uint32_t bit = 1U << (val % 32);
2136-
return (mask & bit) != 0;
2137-
}
2138-
2139-
// OPT: binary search long lists?
2140-
const uint32_t* start =
2141-
&e->UPB_PRIVATE(data)[e->UPB_PRIVATE(mask_limit) / 32];
2142-
const uint32_t* limit = &e->UPB_PRIVATE(
2143-
data)[e->UPB_PRIVATE(mask_limit) / 32 + e->UPB_PRIVATE(value_count)];
2144-
for (const uint32_t* p = start; p < limit; p++) {
2145-
if (*p == val) return true;
2146-
}
2147-
return false;
2148-
}
2149-
2150-
#ifdef __cplusplus
2151-
} /* extern "C" */
2152-
#endif
2153-
2154-
2155-
#endif /* UPB_MINI_TABLE_INTERNAL_ENUM_H_ */
2156-
2157-
// Must be last
2158-
2159-
typedef struct upb_MiniTableEnum upb_MiniTableEnum;
2160-
2161-
#ifdef __cplusplus
2162-
extern "C" {
2163-
#endif
2164-
2165-
// Validates enum value against range defined by enum mini table.
2166-
UPB_API_INLINE bool upb_MiniTableEnum_CheckValue(const upb_MiniTableEnum* e,
2167-
uint32_t val);
2168-
2169-
#ifdef __cplusplus
2170-
} /* extern "C" */
2171-
#endif
2172-
2173-
2174-
#endif /* UPB_MINI_TABLE_ENUM_H_ */
2175-
21762176
#ifndef UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
21772177
#define UPB_MINI_TABLE_INTERNAL_MESSAGE_H_
21782178

@@ -2512,9 +2512,9 @@ UPB_API_INLINE size_t upb_Array_Size(const upb_Array* arr);
25122512
// Returns the given element, which must be within the array's current size.
25132513
UPB_API upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i);
25142514

2515-
// Returns a mutating pointer to the given element, which must be within the
2516-
// array's current size.
2517-
UPB_API upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i);
2515+
// Returns a non-null mutating pointer to the given element. `arr` must be an
2516+
// array of a message type, and `i` must be within the array's current size.
2517+
UPB_API struct upb_Message* upb_Array_GetMutable(upb_Array* arr, size_t i);
25182518

25192519
// Sets the given element, which must be within the array's current size.
25202520
UPB_API void upb_Array_Set(upb_Array* arr, size_t i, upb_MessageValue val);

ruby/ext/google/protobuf_c/ruby-upb.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,12 +3786,14 @@ upb_MessageValue upb_Array_Get(const upb_Array* arr, size_t i) {
37863786
return ret;
37873787
}
37883788

3789-
upb_MutableMessageValue upb_Array_GetMutable(upb_Array* arr, size_t i) {
3789+
upb_Message* upb_Array_GetMutable(upb_Array* arr, size_t i) {
37903790
UPB_ASSERT(i < upb_Array_Size(arr));
3791-
upb_MutableMessageValue ret;
3791+
size_t elem_size = sizeof(upb_Message*);
3792+
UPB_ASSERT(elem_size == (1 << UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr)));
37923793
char* data = upb_Array_MutableDataPtr(arr);
3793-
const int lg2 = UPB_PRIVATE(_upb_Array_ElemSizeLg2)(arr);
3794-
memcpy(&ret, data + (i << lg2), 1 << lg2);
3794+
upb_Message* ret;
3795+
memcpy(&ret, data + (i * elem_size), elem_size);
3796+
UPB_ASSERT(!upb_Message_IsFrozen(ret));
37953797
return ret;
37963798
}
37973799

0 commit comments

Comments
 (0)