Commit 2c9c5c83 authored by David Renshaw's avatar David Renshaw

Account for the possibility of adopting an empty struct.

parent 6f26adbe
......@@ -896,10 +896,15 @@ struct WireHelpers {
if (dstSegment == srcSegment) {
// Same segment, so create a direct pointer.
dst->setKindAndTarget(srcTag->kind(), srcPtr, dstSegment);
// We can just copy the upper 32 bits. (Use memcpy() to comply with aliasing rules.)
memcpy(&dst->upper32Bits, &srcTag->upper32Bits, sizeof(srcTag->upper32Bits));
if (srcTag->kind() == WirePointer::STRUCT && srcTag->structRef.wordSize() == 0) {
dst->setKindAndTargetForEmptyStruct();
} else {
dst->setKindAndTarget(srcTag->kind(), srcPtr, dstSegment);
// We can just copy the upper 32 bits. (Use memcpy() to comply with aliasing rules.)
memcpy(&dst->upper32Bits, &srcTag->upper32Bits, sizeof(srcTag->upper32Bits));
}
} else {
// Need to create a far pointer. Try to allocate it in the same segment as the source, so
// that it doesn't need to be a double-far.
......
......@@ -48,6 +48,16 @@ TEST(Orphans, Structs) {
checkTestMessage(root.asReader().getStructField());
}
TEST(Orphans, EmptyStruct) {
MallocMessageBuilder builder;
auto root = builder.initRoot<test::TestAnyPointer>();
auto anyPointer = root.getAnyPointerField();
EXPECT_TRUE(anyPointer.isNull());
auto orphan = builder.getOrphanage().newOrphan<test::TestEmptyStruct>();
anyPointer.adopt(kj::mv(orphan));
EXPECT_FALSE(anyPointer.isNull());
}
TEST(Orphans, Lists) {
MallocMessageBuilder builder;
auto root = builder.initRoot<TestAllTypes>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment