Addressed PR comments.

pull/13171/head
Joshua Haberman 3 years ago
parent 39365f16a7
commit 2df18f0a3e
  1. 19
      BUILD
  2. 2
      upb/msg_internal.h
  3. 6
      upb/msg_test.cc
  4. 65
      upb/msg_test.proto

19
BUILD

@ -230,27 +230,10 @@ cc_test(
proto_library(
name = "msg_test_proto",
srcs = [
"upb/msg_test.proto",
"upb/max_required_test.proto",
],
srcs = ["upb/msg_test.proto"],
deps = ["@com_google_protobuf//:test_messages_proto3_proto"],
)
genrule(
name = "gen_max_required_test_proto",
outs = ["upb/max_required_test.proto"],
cmd = """
echo "syntax = \\\"proto2\\\";" >> $@
echo "package upb_test;" >> $@
echo "message TestMaxRequiredFields {" >> $@
for i in {1..63}; do
echo " required int32 required_int32_$$i = $$i;" >> $@
done
echo "}" >> $@
""",
)
upb_proto_reflection_library(
name = "msg_test_upb_proto_reflection",
deps = [":msg_test_proto"],

@ -207,7 +207,7 @@ typedef struct {
UPB_INLINE uint64_t upb_msglayout_requiredmask(const upb_msglayout *l) {
int n = l->required_count;
assert(0 < n && n <= 63);
return (((uint64_t)1 << n) - 1) << 1;
return ((1ULL << n) - 1) << 1;
}
/** upb_extreg ****************************************************************/

@ -31,8 +31,6 @@
#include "upb/def.hpp"
#include "upb/json_decode.h"
#include "upb/json_encode.h"
#include "upb/max_required_test.upb.h"
#include "upb/max_required_test.upbdefs.h"
#include "upb/msg_test.upb.h"
#include "upb/msg_test.upbdefs.h"
#include "upb/upb.hpp"
@ -378,7 +376,7 @@ TEST(MessageTest, MaxRequiredFields) {
upb::MessageDefPtr m(upb_test_TestMaxRequiredFields_getmsgdef(symtab.ptr()));
upb_msgval val;
val.int32_val = 1;
for (int i = 1; i <= 62; i++) {
for (int i = 1; i <= 61; i++) {
upb::FieldDefPtr f = m.FindFieldByNumber(i);
ASSERT_TRUE(f);
upb_msg_set(test_msg, f.ptr(), val, arena.ptr());
@ -390,7 +388,7 @@ TEST(MessageTest, MaxRequiredFields) {
ASSERT_TRUE(serialized == nullptr);
// Succeeds, all required fields are set.
upb::FieldDefPtr f = m.FindFieldByNumber(63);
upb::FieldDefPtr f = m.FindFieldByNumber(62);
ASSERT_TRUE(f);
upb_msg_set(test_msg, f.ptr(), val, arena.ptr());
serialized = upb_test_TestMaxRequiredFields_serialize_ex(

@ -93,3 +93,68 @@ message TestRequiredFields {
message SubMessageHasRequired {
optional TestRequiredFields optional_message = 1;
}
message TestMaxRequiredFields {
required int32 required_int32_1 = 1;
required int32 required_int32_2 = 2;
required int32 required_int32_3 = 3;
required int32 required_int32_4 = 4;
required int32 required_int32_5 = 5;
required int32 required_int32_6 = 6;
required int32 required_int32_7 = 7;
required int32 required_int32_8 = 8;
required int32 required_int32_9 = 9;
required int32 required_int32_10 = 10;
required int32 required_int32_11 = 11;
required int32 required_int32_12 = 12;
required int32 required_int32_13 = 13;
required int32 required_int32_14 = 14;
required int32 required_int32_15 = 15;
required int32 required_int32_16 = 16;
required int32 required_int32_17 = 17;
required int32 required_int32_18 = 18;
required int32 required_int32_19 = 19;
required int32 required_int32_20 = 20;
required int32 required_int32_21 = 21;
required int32 required_int32_22 = 22;
required int32 required_int32_23 = 23;
required int32 required_int32_24 = 24;
required int32 required_int32_25 = 25;
required int32 required_int32_26 = 26;
required int32 required_int32_27 = 27;
required int32 required_int32_28 = 28;
required int32 required_int32_29 = 29;
required int32 required_int32_30 = 30;
required int32 required_int32_31 = 31;
required int32 required_int32_32 = 32;
required int32 required_int32_33 = 33;
required int32 required_int32_34 = 34;
required int32 required_int32_35 = 35;
required int32 required_int32_36 = 36;
required int32 required_int32_37 = 37;
required int32 required_int32_38 = 38;
required int32 required_int32_39 = 39;
required int32 required_int32_40 = 40;
required int32 required_int32_41 = 41;
required int32 required_int32_42 = 42;
required int32 required_int32_43 = 43;
required int32 required_int32_44 = 44;
required int32 required_int32_45 = 45;
required int32 required_int32_46 = 46;
required int32 required_int32_47 = 47;
required int32 required_int32_48 = 48;
required int32 required_int32_49 = 49;
required int32 required_int32_50 = 50;
required int32 required_int32_51 = 51;
required int32 required_int32_52 = 52;
required int32 required_int32_53 = 53;
required int32 required_int32_54 = 54;
required int32 required_int32_55 = 55;
required int32 required_int32_56 = 56;
required int32 required_int32_57 = 57;
required int32 required_int32_58 = 58;
required int32 required_int32_59 = 59;
required int32 required_int32_60 = 60;
required int32 required_int32_61 = 61;
required int32 required_int32_62 = 62;
}

Loading…
Cancel
Save