Disallow initializing `Messages` (as well as `Maps` and `RepeatedFields`) with nil `Arena`.

Fixes a test flake.

PiperOrigin-RevId: 642334064
pull/17104/head
Protobuf Team Bot 10 months ago committed by Copybara-Service
parent 9f2893a554
commit e4970aac30
  1. 1
      ruby/ext/google/protobuf_c/map.c
  2. 5
      ruby/ext/google/protobuf_c/message.c
  3. 1
      ruby/ext/google/protobuf_c/repeated_field.c

@ -66,6 +66,7 @@ static VALUE Map_alloc(VALUE klass) {
VALUE Map_GetRubyWrapper(const upb_Map* map, upb_CType key_type,
TypeInfo value_type, VALUE arena) {
PBRUBY_ASSERT(map);
PBRUBY_ASSERT(arena != Qnil);
VALUE val = ObjectCache_Get(map);

@ -86,6 +86,7 @@ upb_Message* Message_GetMutable(VALUE msg_rb, const upb_MessageDef** m) {
}
void Message_InitPtr(VALUE self_, const upb_Message* msg, VALUE arena) {
PBRUBY_ASSERT(arena != Qnil);
Message* self = ruby_to_Message(self_);
self->msg = msg;
RB_OBJ_WRITE(self_, &self->arena, arena);
@ -299,14 +300,14 @@ VALUE Message_getfield_frozen(const upb_Message* msg, const upb_FieldDef* f,
const upb_FieldDef* val_f = map_field_value(f);
upb_CType key_type = upb_FieldDef_CType(key_f);
TypeInfo value_type_info = TypeInfo_get(val_f);
return Map_GetRubyWrapper(msgval.map_val, key_type, value_type_info, Qnil);
return Map_GetRubyWrapper(msgval.map_val, key_type, value_type_info, arena);
}
if (upb_FieldDef_IsRepeated(f)) {
if (msgval.array_val == NULL) {
return RepeatedField_EmptyFrozen(f);
}
return RepeatedField_GetRubyWrapper(msgval.array_val, TypeInfo_get(f),
Qnil);
arena);
}
VALUE ret;
if (upb_FieldDef_IsSubMessage(f)) {

@ -82,6 +82,7 @@ VALUE RepeatedField_EmptyFrozen(const upb_FieldDef* f) {
VALUE RepeatedField_GetRubyWrapper(const upb_Array* array, TypeInfo type_info,
VALUE arena) {
PBRUBY_ASSERT(array);
PBRUBY_ASSERT(arena != Qnil);
VALUE val = ObjectCache_Get(array);
if (val == Qnil) {

Loading…
Cancel
Save