Skip to content

Commit

Permalink
Bump upb version to fix ruby flakes
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 506798675
  • Loading branch information
mkruskal-google authored and copybara-github committed Feb 3, 2023
1 parent bb76301 commit ccbdaa7
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 42 deletions.
41 changes: 40 additions & 1 deletion php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5811,6 +5811,7 @@ upb_FindUnknownRet upb_MiniTable_FindUnknown(const upb_Message* msg,
return ret;
}

// Warning: See TODO(b/267655898)
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
Expand All @@ -5821,7 +5822,10 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
// Callers should check that message is not set first before calling
// PromotoUnknownToMessage.
UPB_ASSERT(mini_table->subs[field->submsg_index].submsg == sub_mini_table);
UPB_ASSERT(upb_Message_GetMessage(msg, field, NULL) == NULL);
bool is_oneof = _upb_MiniTableField_InOneOf(field);
if (!is_oneof || _upb_getoneofcase_field(msg, field) == field->number) {
UPB_ASSERT(upb_Message_GetMessage(msg, field, NULL) == NULL);
}
upb_UnknownToMessageRet ret;
ret.status = kUpb_UnknownToMessage_Ok;
do {
Expand Down Expand Up @@ -5849,6 +5853,9 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
}
} while (unknown.status == kUpb_FindUnknown_Ok);
if (message) {
if (is_oneof) {
*_upb_oneofcase_field(msg, field) = field->number;
}
upb_Message_SetMessage(msg, mini_table, field, message);
ret.message = message;
}
Expand Down Expand Up @@ -6170,6 +6177,38 @@ upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field) {
return field->descriptortype;
}

static bool upb_MiniTable_Is_Oneof(const upb_MiniTableField* f) {
return f->presence < 0;
}

const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m,
const upb_MiniTableField* f) {
if (UPB_UNLIKELY(!upb_MiniTable_Is_Oneof(f))) {
return NULL;
}
const upb_MiniTableField* ptr = &m->fields[0];
const upb_MiniTableField* end = &m->fields[m->field_count];
while (++ptr < end) {
if (ptr->presence == (*f).presence) {
return ptr;
}
}
return NULL;
}

bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
const upb_MiniTableField** f) {
const upb_MiniTableField* ptr = *f;
const upb_MiniTableField* end = &m->fields[m->field_count];
while (++ptr < end) {
if (ptr->presence == (*f)->presence) {
*f = ptr;
return true;
}
}
return false;
}


#include <inttypes.h>
#include <stdlib.h>
Expand Down
60 changes: 41 additions & 19 deletions php/ext/google/protobuf/php-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,26 @@ UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
return mini_table->subs[field->submsg_index].subenum;
}

// If this field is in a oneof, returns the first field in the oneof.
//
// Otherwise returns NULL.
//
// Usage:
// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f);
// do {
// ..
// } while (upb_MiniTable_NextOneofField(m, &field);
//
const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m,
const upb_MiniTableField* f);

// Returns the next field in the oneof. If this is the last field in the
// oneof, returns NULL. The ordering of fields in the oneof is not
// guaranteed.
// REQUIRES: |iter| is and iterator.
bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
const upb_MiniTableField** f);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down Expand Up @@ -2942,6 +2962,8 @@ typedef struct {
//
// The unknown data is removed from message after field value is set
// using upb_Message_SetMessage.
//
// WARNING!: See b/267655898
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
Expand Down Expand Up @@ -3289,6 +3311,12 @@ extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init;
extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init;
extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init;

typedef enum {
google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
} google_protobuf_FieldDescriptorProto_Label;

typedef enum {
google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
Expand All @@ -3310,18 +3338,6 @@ typedef enum {
google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
} google_protobuf_FieldDescriptorProto_Type;

typedef enum {
google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
} google_protobuf_FieldDescriptorProto_Label;

typedef enum {
google_protobuf_FileOptions_SPEED = 1,
google_protobuf_FileOptions_CODE_SIZE = 2,
google_protobuf_FileOptions_LITE_RUNTIME = 3
} google_protobuf_FileOptions_OptimizeMode;

typedef enum {
google_protobuf_FieldOptions_STRING = 0,
google_protobuf_FieldOptions_CORD = 1,
Expand Down Expand Up @@ -3354,27 +3370,33 @@ typedef enum {
} google_protobuf_FieldOptions_OptionTargetType;

typedef enum {
google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
google_protobuf_MethodOptions_IDEMPOTENT = 2
} google_protobuf_MethodOptions_IdempotencyLevel;
google_protobuf_FileOptions_SPEED = 1,
google_protobuf_FileOptions_CODE_SIZE = 2,
google_protobuf_FileOptions_LITE_RUNTIME = 3
} google_protobuf_FileOptions_OptimizeMode;

typedef enum {
google_protobuf_GeneratedCodeInfo_Annotation_NONE = 0,
google_protobuf_GeneratedCodeInfo_Annotation_SET = 1,
google_protobuf_GeneratedCodeInfo_Annotation_ALIAS = 2
} google_protobuf_GeneratedCodeInfo_Annotation_Semantic;

typedef enum {
google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
google_protobuf_MethodOptions_IDEMPOTENT = 2
} google_protobuf_MethodOptions_IdempotencyLevel;


extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Type_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Label_enum_init;
extern const upb_MiniTableEnum google_protobuf_FileOptions_OptimizeMode_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Type_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_CType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_JSType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_OptionRetention_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_OptionTargetType_enum_init;
extern const upb_MiniTableEnum google_protobuf_MethodOptions_IdempotencyLevel_enum_init;
extern const upb_MiniTableEnum google_protobuf_FileOptions_OptimizeMode_enum_init;
extern const upb_MiniTableEnum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init;
extern const upb_MiniTableEnum google_protobuf_MethodOptions_IdempotencyLevel_enum_init;

/* google.protobuf.FileDescriptorSet */

Expand Down
4 changes: 2 additions & 2 deletions protobuf_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def protobuf_deps():
_github_archive(
name = "upb",
repo = "https://github.com/protocolbuffers/upb",
commit = "84a3fd2d2d943c8ff37f09feadb1dd3f60f954ee",
sha256 = "5c144471b9d92250e77710376251a6929e47b49eea50b8f380e759a9447fb60b",
commit = "662497f1d3dcced2bba1620cea9aae8b484bd3cd",
sha256 = "57c87ca4145d2cbc162a6c613b114b9325b577f4f6525bd78747a34b3d03627c",
patches = ["@com_google_protobuf//build_defs:upb.patch"],
)
41 changes: 40 additions & 1 deletion ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5448,6 +5448,7 @@ upb_FindUnknownRet upb_MiniTable_FindUnknown(const upb_Message* msg,
return ret;
}

// Warning: See TODO(b/267655898)
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
Expand All @@ -5458,7 +5459,10 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
// Callers should check that message is not set first before calling
// PromotoUnknownToMessage.
UPB_ASSERT(mini_table->subs[field->submsg_index].submsg == sub_mini_table);
UPB_ASSERT(upb_Message_GetMessage(msg, field, NULL) == NULL);
bool is_oneof = _upb_MiniTableField_InOneOf(field);
if (!is_oneof || _upb_getoneofcase_field(msg, field) == field->number) {
UPB_ASSERT(upb_Message_GetMessage(msg, field, NULL) == NULL);
}
upb_UnknownToMessageRet ret;
ret.status = kUpb_UnknownToMessage_Ok;
do {
Expand Down Expand Up @@ -5486,6 +5490,9 @@ upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
}
} while (unknown.status == kUpb_FindUnknown_Ok);
if (message) {
if (is_oneof) {
*_upb_oneofcase_field(msg, field) = field->number;
}
upb_Message_SetMessage(msg, mini_table, field, message);
ret.message = message;
}
Expand Down Expand Up @@ -5807,6 +5814,38 @@ upb_FieldType upb_MiniTableField_Type(const upb_MiniTableField* field) {
return field->descriptortype;
}

static bool upb_MiniTable_Is_Oneof(const upb_MiniTableField* f) {
return f->presence < 0;
}

const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m,
const upb_MiniTableField* f) {
if (UPB_UNLIKELY(!upb_MiniTable_Is_Oneof(f))) {
return NULL;
}
const upb_MiniTableField* ptr = &m->fields[0];
const upb_MiniTableField* end = &m->fields[m->field_count];
while (++ptr < end) {
if (ptr->presence == (*f).presence) {
return ptr;
}
}
return NULL;
}

bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
const upb_MiniTableField** f) {
const upb_MiniTableField* ptr = *f;
const upb_MiniTableField* end = &m->fields[m->field_count];
while (++ptr < end) {
if (ptr->presence == (*f)->presence) {
*f = ptr;
return true;
}
}
return false;
}


#include <inttypes.h>
#include <stdlib.h>
Expand Down
60 changes: 41 additions & 19 deletions ruby/ext/google/protobuf_c/ruby-upb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,26 @@ UPB_API_INLINE const upb_MiniTableEnum* upb_MiniTable_GetSubEnumTable(
return mini_table->subs[field->submsg_index].subenum;
}

// If this field is in a oneof, returns the first field in the oneof.
//
// Otherwise returns NULL.
//
// Usage:
// const upb_MiniTableField* field = upb_MiniTable_GetOneof(m, f);
// do {
// ..
// } while (upb_MiniTable_NextOneofField(m, &field);
//
const upb_MiniTableField* upb_MiniTable_GetOneof(const upb_MiniTable* m,
const upb_MiniTableField* f);

// Returns the next field in the oneof. If this is the last field in the
// oneof, returns NULL. The ordering of fields in the oneof is not
// guaranteed.
// REQUIRES: |iter| is and iterator.
bool upb_MiniTable_NextOneofField(const upb_MiniTable* m,
const upb_MiniTableField** f);

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down Expand Up @@ -2944,6 +2964,8 @@ typedef struct {
//
// The unknown data is removed from message after field value is set
// using upb_Message_SetMessage.
//
// WARNING!: See b/267655898
upb_UnknownToMessageRet upb_MiniTable_PromoteUnknownToMessage(
upb_Message* msg, const upb_MiniTable* mini_table,
const upb_MiniTableField* field, const upb_MiniTable* sub_mini_table,
Expand Down Expand Up @@ -3291,6 +3313,12 @@ extern const upb_MiniTable google_protobuf_SourceCodeInfo_Location_msg_init;
extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_msg_init;
extern const upb_MiniTable google_protobuf_GeneratedCodeInfo_Annotation_msg_init;

typedef enum {
google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
} google_protobuf_FieldDescriptorProto_Label;

typedef enum {
google_protobuf_FieldDescriptorProto_TYPE_DOUBLE = 1,
google_protobuf_FieldDescriptorProto_TYPE_FLOAT = 2,
Expand All @@ -3312,18 +3340,6 @@ typedef enum {
google_protobuf_FieldDescriptorProto_TYPE_SINT64 = 18
} google_protobuf_FieldDescriptorProto_Type;

typedef enum {
google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
google_protobuf_FieldDescriptorProto_LABEL_REPEATED = 3
} google_protobuf_FieldDescriptorProto_Label;

typedef enum {
google_protobuf_FileOptions_SPEED = 1,
google_protobuf_FileOptions_CODE_SIZE = 2,
google_protobuf_FileOptions_LITE_RUNTIME = 3
} google_protobuf_FileOptions_OptimizeMode;

typedef enum {
google_protobuf_FieldOptions_STRING = 0,
google_protobuf_FieldOptions_CORD = 1,
Expand Down Expand Up @@ -3356,27 +3372,33 @@ typedef enum {
} google_protobuf_FieldOptions_OptionTargetType;

typedef enum {
google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
google_protobuf_MethodOptions_IDEMPOTENT = 2
} google_protobuf_MethodOptions_IdempotencyLevel;
google_protobuf_FileOptions_SPEED = 1,
google_protobuf_FileOptions_CODE_SIZE = 2,
google_protobuf_FileOptions_LITE_RUNTIME = 3
} google_protobuf_FileOptions_OptimizeMode;

typedef enum {
google_protobuf_GeneratedCodeInfo_Annotation_NONE = 0,
google_protobuf_GeneratedCodeInfo_Annotation_SET = 1,
google_protobuf_GeneratedCodeInfo_Annotation_ALIAS = 2
} google_protobuf_GeneratedCodeInfo_Annotation_Semantic;

typedef enum {
google_protobuf_MethodOptions_IDEMPOTENCY_UNKNOWN = 0,
google_protobuf_MethodOptions_NO_SIDE_EFFECTS = 1,
google_protobuf_MethodOptions_IDEMPOTENT = 2
} google_protobuf_MethodOptions_IdempotencyLevel;


extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Type_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Label_enum_init;
extern const upb_MiniTableEnum google_protobuf_FileOptions_OptimizeMode_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldDescriptorProto_Type_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_CType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_JSType_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_OptionRetention_enum_init;
extern const upb_MiniTableEnum google_protobuf_FieldOptions_OptionTargetType_enum_init;
extern const upb_MiniTableEnum google_protobuf_MethodOptions_IdempotencyLevel_enum_init;
extern const upb_MiniTableEnum google_protobuf_FileOptions_OptimizeMode_enum_init;
extern const upb_MiniTableEnum google_protobuf_GeneratedCodeInfo_Annotation_Semantic_enum_init;
extern const upb_MiniTableEnum google_protobuf_MethodOptions_IdempotencyLevel_enum_init;

/* google.protobuf.FileDescriptorSet */

Expand Down

0 comments on commit ccbdaa7

Please sign in to comment.