diff options
39 files changed, 106 insertions, 23 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 8c6f8e64..b81b847e 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,13 @@ -nanopb-0.3.3 (2015-04-xx) +nanopb-0.3.4 (2015-09-26) + Fix handling of unsigned 8- and 16-bit enums (issue 164) + Fix generator on systems where python = python3. (issue 155) + Fix compiler warning on GCC 5.x (issue 171) + Make the generator better handle imported .protos (issue 165) + Add packed_enum option to generator. + Add syntax= line to .proto files (issue 167) + Add PlatformIO registry manifest file. (pr 156) + +nanopb-0.3.3 (2015-04-10) Fix missing files in Linux binary package (issue 146) Fix generator bug when oneof is first field in a message. (issue 142) Fix generator error when long_names:false is combined with Oneofs. (issue 147) diff --git a/examples/cmake_simple/simple.c b/examples/cmake_simple/simple.c index 31272301..1f6b1373 100644 --- a/examples/cmake_simple/simple.c +++ b/examples/cmake_simple/simple.c @@ -15,8 +15,11 @@ int main() /* Allocate space on the stack to store the message data. * * Nanopb generates simple struct definitions for all the messages. - * - check out the contents of simple.pb.h! */ - SimpleMessage message; + * - check out the contents of simple.pb.h! + * It is a good idea to always initialize your structures + * so that you do not have garbage data from RAM in there. + */ + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that will write to our buffer. */ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); @@ -44,7 +47,7 @@ int main() { /* Allocate space for the decoded message. */ - SimpleMessage message; + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that reads from the buffer. */ pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); diff --git a/examples/cmake_simple/simple.proto b/examples/cmake_simple/simple.proto index 26e72f46..5c73a3b2 100644 --- a/examples/cmake_simple/simple.proto +++ b/examples/cmake_simple/simple.proto @@ -1,6 +1,8 @@ // A very simple protocol definition, consisting of only // one message. +syntax = "proto2"; + message SimpleMessage { required int32 lucky_number = 1; } diff --git a/examples/network_server/fileproto.proto b/examples/network_server/fileproto.proto index 3e70c492..5640b8d5 100644 --- a/examples/network_server/fileproto.proto +++ b/examples/network_server/fileproto.proto @@ -2,6 +2,8 @@ // // See also the nanopb-specific options in fileproto.options. +syntax = "proto2"; + message ListFilesRequest { optional string path = 1 [default = "/"]; } diff --git a/examples/simple/simple.c b/examples/simple/simple.c index 31272301..1f6b1373 100644 --- a/examples/simple/simple.c +++ b/examples/simple/simple.c @@ -15,8 +15,11 @@ int main() /* Allocate space on the stack to store the message data. * * Nanopb generates simple struct definitions for all the messages. - * - check out the contents of simple.pb.h! */ - SimpleMessage message; + * - check out the contents of simple.pb.h! + * It is a good idea to always initialize your structures + * so that you do not have garbage data from RAM in there. + */ + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that will write to our buffer. */ pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); @@ -44,7 +47,7 @@ int main() { /* Allocate space for the decoded message. */ - SimpleMessage message; + SimpleMessage message = SimpleMessage_init_zero; /* Create a stream that reads from the buffer. */ pb_istream_t stream = pb_istream_from_buffer(buffer, message_length); diff --git a/examples/simple/simple.proto b/examples/simple/simple.proto index 26e72f46..5c73a3b2 100644 --- a/examples/simple/simple.proto +++ b/examples/simple/simple.proto @@ -1,6 +1,8 @@ // A very simple protocol definition, consisting of only // one message. +syntax = "proto2"; + message SimpleMessage { required int32 lucky_number = 1; } diff --git a/examples/using_double_on_avr/doubleproto.proto b/examples/using_double_on_avr/doubleproto.proto index d8b7f2db..72d3f9c1 100644 --- a/examples/using_double_on_avr/doubleproto.proto +++ b/examples/using_double_on_avr/doubleproto.proto @@ -1,4 +1,6 @@ // A message containing doubles, as used by other applications. +syntax = "proto2"; + message DoubleMessage { required double field1 = 1; required double field2 = 2; diff --git a/examples/using_union_messages/unionproto.proto b/examples/using_union_messages/unionproto.proto index d7c9de2d..209df0d2 100644 --- a/examples/using_union_messages/unionproto.proto +++ b/examples/using_union_messages/unionproto.proto @@ -5,6 +5,8 @@ // but they are commonly implemented by filling out exactly one of // several optional fields. +syntax = "proto2"; + message MsgType1 { required int32 value = 1; diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 82b79270..7fe0db95 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals '''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.''' -nanopb_version = "nanopb-0.3.4-dev" +nanopb_version = "nanopb-0.3.5-dev" import sys import re @@ -50,7 +50,7 @@ /* Version of the nanopb library. Just in case you want to check it in * your own program. */ -#define NANOPB_VERSION nanopb-0.3.4-dev +#define NANOPB_VERSION nanopb-0.3.5-dev /* Include all the system headers needed by nanopb. You will need the * definitions of the following: diff --git a/pb_decode.c b/pb_decode.c index b21bfe37..5cdcbcfb 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -886,7 +886,8 @@ bool checkreturn pb_decode_noinit(pb_istream_t *stream, const pb_field_t fields[ if (PB_HTYPE(iter.pos->type) == PB_HTYPE_REQUIRED && iter.required_field_index < PB_MAX_REQUIRED_FIELDS) { - fields_seen[iter.required_field_index >> 3] |= (uint8_t)(1 << (iter.required_field_index & 7)); + uint8_t tmp = (uint8_t)(1 << (iter.required_field_index & 7)); + fields_seen[iter.required_field_index >> 3] |= tmp; } if (!decode_field(stream, wire_type, &iter)) diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto index 28eaf0be..3995c552 100644 --- a/tests/alltypes/alltypes.proto +++ b/tests/alltypes/alltypes.proto @@ -1,3 +1,6 @@ +syntax = "proto2"; +// package name placeholder + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/backwards_compatibility/alltypes_legacy.proto b/tests/backwards_compatibility/alltypes_legacy.proto index d7631eb6..f5bc35ce 100644 --- a/tests/backwards_compatibility/alltypes_legacy.proto +++ b/tests/backwards_compatibility/alltypes_legacy.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/callbacks/callbacks.proto b/tests/callbacks/callbacks.proto index ccd1edd8..96ac744d 100644 --- a/tests/callbacks/callbacks.proto +++ b/tests/callbacks/callbacks.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { optional string stringvalue = 1; repeated int32 int32value = 2; diff --git a/tests/common/person.proto b/tests/common/person.proto index dafcf934..becefdf3 100644 --- a/tests/common/person.proto +++ b/tests/common/person.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import "nanopb.proto"; message Person { diff --git a/tests/common/unittestproto.proto b/tests/common/unittestproto.proto index 0ecb1f0b..23b5b97f 100644 --- a/tests/common/unittestproto.proto +++ b/tests/common/unittestproto.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; message IntegerArray { diff --git a/tests/cyclic_messages/cyclic.proto b/tests/cyclic_messages/cyclic.proto index a9d158cb..8cab0b14 100644 --- a/tests/cyclic_messages/cyclic.proto +++ b/tests/cyclic_messages/cyclic.proto @@ -2,6 +2,8 @@ // These can only be handled in pointer/callback mode, // see associated .options files. +syntax = "proto2"; + message TreeNode { optional int32 leaf = 1; diff --git a/tests/enum_sizes/enumsizes.proto b/tests/enum_sizes/enumsizes.proto index f9ab0b7f..a85d4160 100644 --- a/tests/enum_sizes/enumsizes.proto +++ b/tests/enum_sizes/enumsizes.proto @@ -4,6 +4,8 @@ * a bit of a problem for the encoder/decoder (issue #164). */ +syntax = "proto2"; + import 'nanopb.proto'; option (nanopb_fileopt).long_names = false; diff --git a/tests/extensions/extensions.proto b/tests/extensions/extensions.proto index 79c01245..fcd5b43b 100644 --- a/tests/extensions/extensions.proto +++ b/tests/extensions/extensions.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'alltypes.proto'; extend AllTypes { diff --git a/tests/field_size_16/alltypes.proto b/tests/field_size_16/alltypes.proto index 039391fc..ba1ec383 100644 --- a/tests/field_size_16/alltypes.proto +++ b/tests/field_size_16/alltypes.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/field_size_32/alltypes.proto b/tests/field_size_32/alltypes.proto index 5749e0d4..02ee1a6a 100644 --- a/tests/field_size_32/alltypes.proto +++ b/tests/field_size_32/alltypes.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { required string substuff1 = 1 [default = "1"]; required int32 substuff2 = 2 [default = 2]; diff --git a/tests/fuzztest/SConscript b/tests/fuzztest/SConscript index 35b697f9..973148c2 100644 --- a/tests/fuzztest/SConscript +++ b/tests/fuzztest/SConscript @@ -2,16 +2,19 @@ Import("env", "malloc_env") +def set_pkgname(src, dst, pkgname): + data = open(str(src)).read() + placeholder = '// package name placeholder' + assert placeholder in data + data = data.replace(placeholder, 'package %s;' % pkgname) + open(str(dst), 'w').write(data) + # We want both pointer and static versions of the AllTypes message # Prefix them with package name. env.Command("alltypes_static.proto", "#alltypes/alltypes.proto", - lambda target, source, env: - open(str(target[0]), 'w').write("package alltypes_static;\n" - + open(str(source[0])).read())) + lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_static')) env.Command("alltypes_pointer.proto", "#alltypes/alltypes.proto", - lambda target, source, env: - open(str(target[0]), 'w').write("package alltypes_pointer;\n" - + open(str(source[0])).read())) + lambda target, source, env: set_pkgname(source[0], target[0], 'alltypes_pointer')) p1 = env.NanopbProto(["alltypes_pointer", "alltypes_pointer.options"]) p2 = env.NanopbProto(["alltypes_static", "alltypes_static.options"]) diff --git a/tests/intsizes/intsizes.proto b/tests/intsizes/intsizes.proto index 236bf183..91444d41 100644 --- a/tests/intsizes/intsizes.proto +++ b/tests/intsizes/intsizes.proto @@ -6,6 +6,8 @@ * otherwise. E.g. uint32 + IS_8 => uint8_t */ +syntax = "proto2"; + import 'nanopb.proto'; message IntSizes { diff --git a/tests/message_sizes/messages1.proto b/tests/message_sizes/messages1.proto index 48af55a3..b66fad71 100644 --- a/tests/message_sizes/messages1.proto +++ b/tests/message_sizes/messages1.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + enum MessageStatus { FAIL = 0; OK = 1; diff --git a/tests/message_sizes/messages2.proto b/tests/message_sizes/messages2.proto index 19fc11ef..67614080 100644 --- a/tests/message_sizes/messages2.proto +++ b/tests/message_sizes/messages2.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; import 'messages1.proto'; diff --git a/tests/missing_fields/missing_fields.proto b/tests/missing_fields/missing_fields.proto index cbb23ba1..cc5e550b 100644 --- a/tests/missing_fields/missing_fields.proto +++ b/tests/missing_fields/missing_fields.proto @@ -1,5 +1,7 @@ /* Test for one missing field among many */ +syntax = "proto2"; + message AllFields { required int32 field1 = 1; diff --git a/tests/multiple_files/multifile1.proto b/tests/multiple_files/multifile1.proto index d804b67d..18f2c672 100644 --- a/tests/multiple_files/multifile1.proto +++ b/tests/multiple_files/multifile1.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message SubMessage { optional string stringvalue = 1; repeated int32 int32value = 2; diff --git a/tests/multiple_files/multifile2.proto b/tests/multiple_files/multifile2.proto index 66cb8a0b..4af45fd9 100644 --- a/tests/multiple_files/multifile2.proto +++ b/tests/multiple_files/multifile2.proto @@ -1,5 +1,7 @@ // Test if including generated header file for this file + implicit include of // multifile2.pb.h still compiles. Used with test_compiles.c. +syntax = "proto2"; + import "multifile1.proto"; message Callback2Message { diff --git a/tests/no_messages/no_messages.proto b/tests/no_messages/no_messages.proto index 279216b0..45bb2e66 100644 --- a/tests/no_messages/no_messages.proto +++ b/tests/no_messages/no_messages.proto @@ -1,5 +1,7 @@ /* Test that a file without any messages works. */ +syntax = "proto2"; + enum Test { First = 1; } diff --git a/tests/oneof/oneof.proto b/tests/oneof/oneof.proto index 00f1ceca..b4fe56f2 100644 --- a/tests/oneof/oneof.proto +++ b/tests/oneof/oneof.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; message SubMessage diff --git a/tests/options/options.proto b/tests/options/options.proto index b7050418..aa722b52 100644 --- a/tests/options/options.proto +++ b/tests/options/options.proto @@ -2,6 +2,8 @@ * options.expected lists the patterns that are searched for in the output. */ +syntax = "proto2"; + import "nanopb.proto"; // File level options diff --git a/tests/package_name/SConscript b/tests/package_name/SConscript index 897bc99c..4afc5037 100644 --- a/tests/package_name/SConscript +++ b/tests/package_name/SConscript @@ -3,14 +3,16 @@ Import("env") -# Build a modified alltypes.proto -def modify_proto(target, source, env): - '''Add a "package test.package;" directive to the beginning of the .proto file.''' - data = open(str(source[0]), 'r').read() - open(str(target[0]), 'w').write("package test.package;\n\n" + data) - return 0 +def set_pkgname(src, dst, pkgname): + data = open(str(src)).read() + placeholder = '// package name placeholder' + assert placeholder in data + data = data.replace(placeholder, 'package %s;' % pkgname) + open(str(dst), 'w').write(data) -env.Command("alltypes.proto", "#alltypes/alltypes.proto", modify_proto) +# Build a modified alltypes.proto +env.Command("alltypes.proto", "#alltypes/alltypes.proto", + lambda target, source, env: set_pkgname(source[0], target[0], 'test.package')) env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE")) env.NanopbProto(["alltypes", "alltypes.options"]) diff --git a/tests/regression/issue_118/enumdef.proto b/tests/regression/issue_118/enumdef.proto index 830d2988..46845bc9 100644 --- a/tests/regression/issue_118/enumdef.proto +++ b/tests/regression/issue_118/enumdef.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; enum MyEnum { diff --git a/tests/regression/issue_118/enumuse.proto b/tests/regression/issue_118/enumuse.proto index d778fb8f..4afc4521 100644 --- a/tests/regression/issue_118/enumuse.proto +++ b/tests/regression/issue_118/enumuse.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'enumdef.proto'; message MyMessage { diff --git a/tests/regression/issue_125/extensionbug.proto b/tests/regression/issue_125/extensionbug.proto index c4ac6860..fd1e74f1 100644 --- a/tests/regression/issue_125/extensionbug.proto +++ b/tests/regression/issue_125/extensionbug.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message Message1 { optional uint32 fieldA = 1; diff --git a/tests/regression/issue_141/testproto.proto b/tests/regression/issue_141/testproto.proto index 21598b45..a445c68a 100644 --- a/tests/regression/issue_141/testproto.proto +++ b/tests/regression/issue_141/testproto.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + import 'nanopb.proto'; message SubMessage diff --git a/tests/regression/issue_145/comments.proto b/tests/regression/issue_145/comments.proto index 4e86b302..621779f5 100644 --- a/tests/regression/issue_145/comments.proto +++ b/tests/regression/issue_145/comments.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + message DummyMessage { required string foo = 1; required string bar = 2; diff --git a/tests/regression/issue_166/enums.proto b/tests/regression/issue_166/enums.proto index a0964ab4..36948044 100644 --- a/tests/regression/issue_166/enums.proto +++ b/tests/regression/issue_166/enums.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + enum SignedEnum { SE_MIN = -1; SE_MAX = 255; diff --git a/tests/special_characters/funny-proto+name has.characters.proto b/tests/special_characters/funny-proto+name has.characters.proto index e69de29b..26b2cb1b 100644 --- a/tests/special_characters/funny-proto+name has.characters.proto +++ b/tests/special_characters/funny-proto+name has.characters.proto @@ -0,0 +1 @@ +syntax="proto2"; |