Skip to content

Commit

Permalink
Set oneof case in array constructor (#6351)
Browse files Browse the repository at this point in the history
Forgot to set it previously.
  • Loading branch information
TeBoring committed Jul 8, 2019
1 parent f1ecf5c commit 864bd03
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions php/ext/google/protobuf/message.c
Expand Up @@ -469,11 +469,14 @@ void Message_construct(zval* msg, zval* array_wrapper) {
if (upb_fielddef_containingoneof(field)) {
void* memory = slot_memory(intern->descriptor->layout,
message_data(intern), field);
uint32_t* oneof_case = slot_oneof_case(intern->descriptor->layout,
message_data(intern), field);
int property_cache_index =
intern->descriptor->layout->fields[upb_fielddef_index(field)]
.cache_index;
cached = OBJ_PROP(Z_OBJ_P(msg), property_cache_index);
*(CACHED_VALUE**)(memory) = cached;
*oneof_case = upb_fielddef_number(field);
} else {
zend_property_info* property_info;
PHP_PROTO_FAKE_SCOPE_BEGIN(Z_OBJCE_P(msg));
Expand Down
2 changes: 2 additions & 0 deletions php/ext/google/protobuf/protobuf.h
Expand Up @@ -948,6 +948,8 @@ void layout_merge(MessageLayout* layout, MessageHeader* from,
const char* layout_get_oneof_case(MessageLayout* layout, const void* storage,
const upb_oneofdef* oneof TSRMLS_DC);
void free_layout(MessageLayout* layout);
uint32_t* slot_oneof_case(MessageLayout* layout, const void* storage,
const upb_fielddef* field);
void* slot_memory(MessageLayout* layout, const void* storage,
const upb_fielddef* field);

Expand Down
4 changes: 2 additions & 2 deletions php/ext/google/protobuf/storage.c
Expand Up @@ -572,8 +572,8 @@ static size_t align_up_to(size_t offset, size_t granularity) {
return (offset + granularity - 1) & ~(granularity - 1);
}

static uint32_t* slot_oneof_case(MessageLayout* layout, const void* storage,
const upb_fielddef* field) {
uint32_t* slot_oneof_case(MessageLayout* layout, const void* storage,
const upb_fielddef* field) {
return (uint32_t*)(((uint8_t*)storage) +
layout->fields[upb_fielddef_index(field)].case_offset);
}
Expand Down
2 changes: 2 additions & 0 deletions php/tests/generated_class_test.php
Expand Up @@ -1452,6 +1452,8 @@ public function testOneofMessageInArrayConstructor()
$m = new TestMessage([
'oneof_message' => new Sub(),
]);
$this->assertSame('oneof_message', $m->getMyOneof());
$this->assertNotNull($m->getOneofMessage());
}

public function testOneofStringInArrayConstructor()
Expand Down

0 comments on commit 864bd03

Please sign in to comment.