Skip to content

Commit

Permalink
Auto-generate files after cl/592091162
Browse files Browse the repository at this point in the history
  • Loading branch information
protobuf-team-bot committed Dec 19, 2023
1 parent 121896d commit f284522
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 44 deletions.
48 changes: 30 additions & 18 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5934,10 +5934,19 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) {

// Must be last.

const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg,
size_t index) {
size_t count;
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);

UPB_ASSERT(index < count);
return &ext[index];
}

const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg,
uint32_t field_number) {
size_t count = 0;
const upb_Extension* ext = _upb_Message_Getexts(msg, &count);
size_t count;
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);

while (count--) {
if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext;
Expand Down Expand Up @@ -6231,7 +6240,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
}
// Clone extensions.
size_t ext_count;
const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count);
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count);
for (size_t i = 0; i < ext_count; ++i) {
const upb_Extension* msg_ext = &ext[i];
const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field);
Expand Down Expand Up @@ -6414,10 +6423,10 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity,

// Must be last.

const upb_Extension* _upb_Message_Getext(const upb_Message* msg,
const upb_MiniTableExtension* e) {
const struct upb_Extension* _upb_Message_Getext(
const upb_Message* msg, const upb_MiniTableExtension* e) {
size_t n;
const upb_Extension* ext = _upb_Message_Getexts(msg, &n);
const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n);

// For now we use linear search exclusively to find extensions.
// If this becomes an issue due to messages with lots of extensions,
Expand All @@ -6431,29 +6440,31 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg,
return NULL;
}

const upb_Extension* _upb_Message_Getexts(const upb_Message* msg,
size_t* count) {
const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
const upb_Message* msg, size_t* count) {
const upb_Message_Internal* in = upb_Message_Getinternal(msg);
if (in->internal) {
*count =
(in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension);
*count = (in->internal->size - in->internal->ext_begin) /
sizeof(struct upb_Extension);
return UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
} else {
*count = 0;
return NULL;
}
}

upb_Extension* _upb_Message_GetOrCreateExtension(
struct upb_Extension* _upb_Message_GetOrCreateExtension(
upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) {
upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e);
struct upb_Extension* ext =
(struct upb_Extension*)_upb_Message_Getext(msg, e);
if (ext) return ext;
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena))
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension),
arena))
return NULL;
upb_Message_Internal* in = upb_Message_Getinternal(msg);
in->internal->ext_begin -= sizeof(upb_Extension);
in->internal->ext_begin -= sizeof(struct upb_Extension);
ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
memset(ext, 0, sizeof(upb_Extension));
memset(ext, 0, sizeof(struct upb_Extension));
ext->ext = e;
return ext;
}
Expand Down Expand Up @@ -6819,7 +6830,7 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) {

size_t upb_Message_ExtensionCount(const upb_Message* msg) {
size_t count;
_upb_Message_Getexts(msg, &count);
UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
return count;
}

Expand Down Expand Up @@ -11437,7 +11448,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
if (ext_pool) {
// Return any extensions that are set.
size_t count;
const upb_Extension* ext = _upb_Message_Getexts(msg, &count);
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
if (i - n < count) {
ext += count - 1 - (i - n);
memcpy(out_val, &ext->data, sizeof(*out_val));
Expand Down Expand Up @@ -15587,7 +15598,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
* these in field number order relative to normal fields or even to each
* other. */
size_t ext_count;
const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count);
const upb_Extension* ext =
UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count);
if (ext_count) {
if (e->options & kUpb_EncodeOption_Deterministic) {
_upb_sortedmap sorted;
Expand Down
11 changes: 7 additions & 4 deletions php/ext/google/protobuf/php-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1775,11 +1775,11 @@ upb_Extension* _upb_Message_GetOrCreateExtension(

// Returns an array of extensions for this message.
// Note: the array is ordered in reverse relative to the order of creation.
const upb_Extension* _upb_Message_Getexts(const upb_Message* msg,
size_t* count);
const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg,
size_t* count);

// Returns an extension for the given field number, or NULL if no extension
// exists for this field number.
// Returns an extension for a message with a given mini table,
// or NULL if no extension exists with this mini table.
const upb_Extension* _upb_Message_Getext(const upb_Message* msg,
const upb_MiniTableExtension* ext);

Expand Down Expand Up @@ -12287,6 +12287,9 @@ UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr,
extern "C" {
#endif

const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg,
size_t index);

// Returns the extension with the given field number, or NULL on failure.
const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg,
uint32_t field_number);
Expand Down
48 changes: 30 additions & 18 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5448,10 +5448,19 @@ void upb_Arena_DecRefFor(upb_Arena* arena, const void* owner) {

// Must be last.

const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg,
size_t index) {
size_t count;
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);

UPB_ASSERT(index < count);
return &ext[index];
}

const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg,
uint32_t field_number) {
size_t count = 0;
const upb_Extension* ext = _upb_Message_Getexts(msg, &count);
size_t count;
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);

while (count--) {
if (upb_MiniTableExtension_Number(ext->ext) == field_number) return ext;
Expand Down Expand Up @@ -5745,7 +5754,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
}
// Clone extensions.
size_t ext_count;
const upb_Extension* ext = _upb_Message_Getexts(src, &ext_count);
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(src, &ext_count);
for (size_t i = 0; i < ext_count; ++i) {
const upb_Extension* msg_ext = &ext[i];
const upb_MiniTableField* field = &msg_ext->ext->UPB_PRIVATE(field);
Expand Down Expand Up @@ -5928,10 +5937,10 @@ bool UPB_PRIVATE(_upb_Array_Realloc)(upb_Array* array, size_t min_capacity,

// Must be last.

const upb_Extension* _upb_Message_Getext(const upb_Message* msg,
const upb_MiniTableExtension* e) {
const struct upb_Extension* _upb_Message_Getext(
const upb_Message* msg, const upb_MiniTableExtension* e) {
size_t n;
const upb_Extension* ext = _upb_Message_Getexts(msg, &n);
const struct upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &n);

// For now we use linear search exclusively to find extensions.
// If this becomes an issue due to messages with lots of extensions,
Expand All @@ -5945,29 +5954,31 @@ const upb_Extension* _upb_Message_Getext(const upb_Message* msg,
return NULL;
}

const upb_Extension* _upb_Message_Getexts(const upb_Message* msg,
size_t* count) {
const struct upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(
const upb_Message* msg, size_t* count) {
const upb_Message_Internal* in = upb_Message_Getinternal(msg);
if (in->internal) {
*count =
(in->internal->size - in->internal->ext_begin) / sizeof(upb_Extension);
*count = (in->internal->size - in->internal->ext_begin) /
sizeof(struct upb_Extension);
return UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
} else {
*count = 0;
return NULL;
}
}

upb_Extension* _upb_Message_GetOrCreateExtension(
struct upb_Extension* _upb_Message_GetOrCreateExtension(
upb_Message* msg, const upb_MiniTableExtension* e, upb_Arena* arena) {
upb_Extension* ext = (upb_Extension*)_upb_Message_Getext(msg, e);
struct upb_Extension* ext =
(struct upb_Extension*)_upb_Message_Getext(msg, e);
if (ext) return ext;
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(upb_Extension), arena))
if (!UPB_PRIVATE(_upb_Message_Realloc)(msg, sizeof(struct upb_Extension),
arena))
return NULL;
upb_Message_Internal* in = upb_Message_Getinternal(msg);
in->internal->ext_begin -= sizeof(upb_Extension);
in->internal->ext_begin -= sizeof(struct upb_Extension);
ext = UPB_PTR_AT(in->internal, in->internal->ext_begin, void);
memset(ext, 0, sizeof(upb_Extension));
memset(ext, 0, sizeof(struct upb_Extension));
ext->ext = e;
return ext;
}
Expand Down Expand Up @@ -6333,7 +6344,7 @@ void upb_Message_DeleteUnknown(upb_Message* msg, const char* data, size_t len) {

size_t upb_Message_ExtensionCount(const upb_Message* msg) {
size_t count;
_upb_Message_Getexts(msg, &count);
UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
return count;
}

Expand Down Expand Up @@ -10951,7 +10962,7 @@ bool upb_Message_Next(const upb_Message* msg, const upb_MessageDef* m,
if (ext_pool) {
// Return any extensions that are set.
size_t count;
const upb_Extension* ext = _upb_Message_Getexts(msg, &count);
const upb_Extension* ext = UPB_PRIVATE(_upb_Message_Getexts)(msg, &count);
if (i - n < count) {
ext += count - 1 - (i - n);
memcpy(out_val, &ext->data, sizeof(*out_val));
Expand Down Expand Up @@ -15101,7 +15112,8 @@ static void encode_message(upb_encstate* e, const upb_Message* msg,
* these in field number order relative to normal fields or even to each
* other. */
size_t ext_count;
const upb_Extension* ext = _upb_Message_Getexts(msg, &ext_count);
const upb_Extension* ext =
UPB_PRIVATE(_upb_Message_Getexts)(msg, &ext_count);
if (ext_count) {
if (e->options & kUpb_EncodeOption_Deterministic) {
_upb_sortedmap sorted;
Expand Down
11 changes: 7 additions & 4 deletions ruby/ext/google/protobuf_c/ruby-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1777,11 +1777,11 @@ upb_Extension* _upb_Message_GetOrCreateExtension(

// Returns an array of extensions for this message.
// Note: the array is ordered in reverse relative to the order of creation.
const upb_Extension* _upb_Message_Getexts(const upb_Message* msg,
size_t* count);
const upb_Extension* UPB_PRIVATE(_upb_Message_Getexts)(const upb_Message* msg,
size_t* count);

// Returns an extension for the given field number, or NULL if no extension
// exists for this field number.
// Returns an extension for a message with a given mini table,
// or NULL if no extension exists with this mini table.
const upb_Extension* _upb_Message_Getext(const upb_Message* msg,
const upb_MiniTableExtension* ext);

Expand Down Expand Up @@ -12059,6 +12059,9 @@ UPB_INLINE bool _upb_NonAtomic_CompareExchangeStrongP(void* addr,
extern "C" {
#endif

const upb_Extension* upb_Message_ExtensionByIndex(const upb_Message* msg,
size_t index);

// Returns the extension with the given field number, or NULL on failure.
const upb_Extension* upb_Message_FindExtensionByNumber(const upb_Message* msg,
uint32_t field_number);
Expand Down

0 comments on commit f284522

Please sign in to comment.