Merge pull request #545 from haberman/disable-proto2-enum

Two Ruby changes to unblock the release
pull/13171/head
Joshua Haberman 3 years ago committed by GitHub
commit 237e3bf51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      bazel/amalgamate.py
  2. 7
      upb/def.c
  3. 8
      upb/port_def.inc
  4. 1
      upb/port_undef.inc
  5. 10
      upb/table.c
  6. 2
      upb/table_internal.h

@ -44,6 +44,9 @@ class Amalgamator:
self.output_c.write("/* Amalgamated source file */\n")
self.output_c.write('#include "%supb.h"\n' % (prefix))
if prefix == "ruby-":
self.output_h.write("// Ruby is still using proto3 enum semantics for proto2\n")
self.output_h.write("#define UPB_DISABLE_PROTO2_ENUM_CHECKING\n")
self.output_c.write(open("upb/port_def.inc").read())
self.output_h.write("/* Amalgamated source file */\n")

@ -1414,6 +1414,7 @@ static uint8_t map_descriptortype(const upb_FieldDef* f) {
return kUpb_FieldType_Bytes;
} else if (type == kUpb_FieldType_Enum &&
(f->sub.enumdef->file->syntax == kUpb_Syntax_Proto3 ||
UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 ||
// TODO(https://github.com/protocolbuffers/upb/issues/541):
// fix map enum values to check for unknown enum values and put
// them in the unknown field set.
@ -1584,11 +1585,11 @@ static void make_layout(symtab_addctx* ctx, const upb_MessageDef* m) {
fill_fieldlayout(field, f);
if (upb_FieldDef_IsSubMessage(f)) {
if (field->descriptortype == kUpb_FieldType_Message ||
field->descriptortype == kUpb_FieldType_Group) {
field->submsg_index = sublayout_count++;
subs[field->submsg_index].submsg = upb_FieldDef_MessageSubDef(f)->layout;
} else if (upb_FieldDef_CType(f) == kUpb_CType_Enum &&
f->sub.enumdef->file->syntax == kUpb_Syntax_Proto2) {
} else if (field->descriptortype == kUpb_FieldType_Enum) {
field->submsg_index = sublayout_count++;
subs[field->submsg_index].subenum = upb_FieldDef_EnumSubDef(f)->layout;
UPB_ASSERT(subs[field->submsg_index].subenum);

@ -251,3 +251,11 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
#define UPB_UNPOISON_MEMORY_REGION(addr, size) \
((void)(addr), (void)(size))
#endif
/* Disable proto2 arena behavior (TEMPORARY) **********************************/
#ifdef UPB_DISABLE_PROTO2_ENUM_CHECKING
#define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 1
#else
#define UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3 0
#endif

@ -59,3 +59,4 @@
#undef UPB_POISON_MEMORY_REGION
#undef UPB_UNPOISON_MEMORY_REGION
#undef UPB_ASAN
#undef UPB_TREAT_PROTO2_ENUMS_LIKE_PROTO3

@ -433,14 +433,14 @@ const uint64_t kWyhashSalt[5] = {
0x082EFA98EC4E6C89ULL, 0x452821E638D01377ULL,
};
static uint32_t table_hash(const char* p, size_t n) {
uint32_t _upb_Hash(const char* p, size_t n) {
return Wyhash(p, n, 0, kWyhashSalt);
}
static uint32_t strhash(upb_tabkey key) {
uint32_t len;
char* str = upb_tabstr(key, &len);
return table_hash(str, len);
return _upb_Hash(str, len);
}
static bool streql(upb_tabkey k1, lookupkey_t k2) {
@ -496,20 +496,20 @@ bool upb_strtable_insert(upb_strtable* t, const char* k, size_t len,
tabkey = strcopy(key, a);
if (tabkey == 0) return false;
hash = table_hash(key.str.str, key.str.len);
hash = _upb_Hash(key.str.str, key.str.len);
insert(&t->t, key, tabkey, v, hash, &strhash, &streql);
return true;
}
bool upb_strtable_lookup2(const upb_strtable* t, const char* key, size_t len,
upb_value* v) {
uint32_t hash = table_hash(key, len);
uint32_t hash = _upb_Hash(key, len);
return lookup(&t->t, strkey2(key, len), v, hash, &streql);
}
bool upb_strtable_remove2(upb_strtable* t, const char* key, size_t len,
upb_value* val) {
uint32_t hash = table_hash(key, len);
uint32_t hash = _upb_Hash(key, len);
upb_tabkey tabkey;
return rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql);
}

@ -374,6 +374,8 @@ void upb_inttable_iter_setdone(upb_inttable_iter* i);
bool upb_inttable_iter_isequal(const upb_inttable_iter* i1,
const upb_inttable_iter* i2);
uint32_t _upb_Hash(const char* p, size_t n);
#ifdef __cplusplus
} /* extern "C" */
#endif

Loading…
Cancel
Save