Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
00aed556
Commit
00aed556
authored
Dec 17, 2015
by
Kenton Varda
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #272 from dwrensha/transfer-empty-struct
Account for the possibility of adopting an empty struct.
parents
6f26adbe
2c9c5c83
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
layout.c++
c++/src/capnp/layout.c++
+8
-3
orphan-test.c++
c++/src/capnp/orphan-test.c++
+10
-0
No files found.
c++/src/capnp/layout.c++
View file @
00aed556
...
...
@@ -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.
...
...
c++/src/capnp/orphan-test.c++
View file @
00aed556
...
...
@@ -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
>
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment