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
45c23897
Commit
45c23897
authored
May 14, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug with dynamic unions.
parent
6e335427
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
5 deletions
+30
-5
dynamic-test.c++
c++/src/capnproto/dynamic-test.c++
+8
-0
schema.c++
c++/src/capnproto/schema.c++
+1
-1
test.capnp
c++/src/capnproto/test.capnp
+15
-0
CxxGenerator.hs
compiler/src/CxxGenerator.hs
+6
-4
No files found.
c++/src/capnproto/dynamic-test.c++
View file @
45c23897
...
...
@@ -733,6 +733,14 @@ TEST(DynamicApi, ConversionFailures) {
EXPECT_ANY_THROW
(
root
.
set
(
"boolField"
,
1
));
}
TEST
(
DynamicApi
,
LateUnion
)
{
MallocMessageBuilder
builder
;
auto
root
=
builder
.
initRoot
<
DynamicStruct
>
(
Schema
::
from
<
test
::
TestLateUnion
>
());
root
.
get
(
"theUnion"
).
as
<
DynamicUnion
>
().
set
(
"qux"
,
"hello"
);
EXPECT_EQ
(
"hello"
,
root
.
as
<
test
::
TestLateUnion
>
().
getTheUnion
().
getQux
());
}
}
// namespace
}
// namespace internal
}
// namespace capnproto
c++/src/capnproto/schema.c++
View file @
45c23897
...
...
@@ -150,7 +150,7 @@ Maybe<StructSchema::Member> StructSchema::Union::findMemberByName(Text::Reader n
StructSchema
::
Member
StructSchema
::
Union
::
getMemberByName
(
Text
::
Reader
name
)
const
{
Maybe
<
StructSchema
::
Member
>
member
=
findMemberByName
(
name
);
PRECOND
(
member
!=
nullptr
,
"
struct
has no such member"
,
name
);
PRECOND
(
member
!=
nullptr
,
"
union
has no such member"
,
name
);
return
*
member
;
}
...
...
c++/src/capnproto/test.capnp
View file @
45c23897
...
...
@@ -339,3 +339,18 @@ struct TestListDefaults {
textListList = [["foo", "bar"], ["baz"], ["qux", "corge"]],
structListList = [[(int32Field = 123), (int32Field = 456)], [(int32Field = 789)]]);
}
struct TestLateUnion {
# Test what happens if the unions are the first ordinals in the struct. At one point this was
# broken for the dynamic API.
foo @0 :Int32;
bar @1 :Text;
baz @2 :Int16;
theUnion @3 union {
qux @4 :Text;
corge @5 :List(Int32);
grault @6 :Float32;
}
}
compiler/src/CxxGenerator.hs
View file @
45c23897
...
...
@@ -287,8 +287,8 @@ memberTable (DescStruct desc) = let
$
List
.
sortBy
(
compare
`
on
`
ordinal
)
$
structMembers
desc
-- Fields of each union.
innerMembers
=
zipWith
indexedUnionMembers
[
1
..
]
$
List
.
sortBy
(
compare
`
on
`
unionNumber
)
$
structUnion
s
desc
innerMembers
=
catMaybes
$
zipWith
indexedUnionMembers
[
1
..
]
$
List
.
sortBy
(
compare
`
on
`
ordinal
)
$
structMember
s
desc
ordinal
(
DescField
f
)
=
fieldNumber
f
ordinal
(
DescUnion
u
)
=
unionNumber
u
...
...
@@ -298,8 +298,10 @@ memberTable (DescStruct desc) = let
memberName
(
DescUnion
u
)
=
Just
$
unionName
u
memberName
_
=
Nothing
indexedUnionMembers
i
u
=
zip
(
memberIndexes
i
)
$
mapMaybe
memberName
$
List
.
sortBy
(
compare
`
on
`
ordinal
)
$
unionMembers
u
indexedUnionMembers
i
(
DescUnion
u
)
=
Just
$
zip
(
memberIndexes
i
)
$
mapMaybe
memberName
$
List
.
sortBy
(
compare
`
on
`
ordinal
)
$
unionMembers
u
indexedUnionMembers
_
_
=
Nothing
in
concat
$
topMembers
:
innerMembers
...
...
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