Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with unknown message sizes being referred inside oneof enco…
…ded size calculation (#569) Nanopb generator attempts to calculate the maximum encoded size of messages when possible. If the message size is unbounded due to e.g. callbacks, the define for it will be skipped. However, for oneofs we need to calculate the maximum of all fields inside it, which is not easily done in C in compile time. The current method uses sizeof(union { .. }) to calculate the largest value. A recent change in 3ff6743 (#415, #494) moved the union to a separate line. This in turn caused compilation errors when the union was defined but one of the symbols it depends on (from another .proto file) was not defined. This commit fixes it by adding #if defined() guard around the definition.
- Loading branch information
1 parent
4b455da
commit ca01b33
Showing
4 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Regression test for #569: | ||
# Compilation error when dependent message size is not defined. | ||
|
||
Import("env") | ||
|
||
# For C compiler | ||
env.NanopbProto("a") | ||
env.NanopbProto("b") | ||
env.Object("a.pb.c") | ||
env.Object("b.pb.c") | ||
|
||
# For C++ compiler | ||
env.NanopbProtoCpp("a") | ||
env.NanopbProtoCpp("b") | ||
env.Object("a_cpp.o", "a.pb.cpp") | ||
env.Object("b_cpp.o", "b.pb.cpp") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
syntax = "proto3"; | ||
|
||
package a; | ||
|
||
message AUnknown { | ||
string data = 1; | ||
} | ||
|
||
message A { | ||
oneof data { | ||
AUnknown unknown = 1; | ||
int32 x = 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
syntax = "proto3"; | ||
|
||
import "a.proto"; | ||
|
||
package b; | ||
|
||
message B { | ||
oneof data { | ||
a.AUnknown unknown = 1; | ||
int32 x = 2; | ||
} | ||
} | ||
|
||
message B2 { | ||
oneof data { | ||
a.AUnknown unknown = 1; | ||
a.A unknown2 = 2; | ||
} | ||
} |