From 31385f71f488ca6d29a578eb57220c2d1bb3134a Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 26 Jan 2015 14:02:14 +0100 Subject: [PATCH] update nanopb to 0.2.9.2 --- firmware/protob/messages.pb.c | 2 +- firmware/protob/messages.pb.h | 2 +- firmware/protob/pb.h | 2 +- firmware/protob/pb_decode.c | 88 ++++++++++++++++++++++++----------- firmware/protob/storage.pb.c | 2 +- firmware/protob/storage.pb.h | 2 +- firmware/protob/types.pb.c | 2 +- firmware/protob/types.pb.h | 2 +- 8 files changed, 67 insertions(+), 35 deletions(-) diff --git a/firmware/protob/messages.pb.c b/firmware/protob/messages.pb.c index ac71a5b8d..d11890edf 100644 --- a/firmware/protob/messages.pb.c +++ b/firmware/protob/messages.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.2.9.1 */ +/* Generated by nanopb-0.2.9.2 */ #include "messages.pb.h" diff --git a/firmware/protob/messages.pb.h b/firmware/protob/messages.pb.h index aae1b549d..0c85401a8 100644 --- a/firmware/protob/messages.pb.h +++ b/firmware/protob/messages.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.2.9.1 */ +/* Generated by nanopb-0.2.9.2 */ #ifndef _PB_MESSAGES_PB_H_ #define _PB_MESSAGES_PB_H_ diff --git a/firmware/protob/pb.h b/firmware/protob/pb.h index 228ee55c1..70911e4db 100644 --- a/firmware/protob/pb.h +++ b/firmware/protob/pb.h @@ -46,7 +46,7 @@ /* Version of the nanopb library. Just in case you want to check it in * your own program. */ -#define NANOPB_VERSION nanopb-0.2.9.1 +#define NANOPB_VERSION nanopb-0.2.9.2 /* Include all the system headers needed by nanopb. You will need the * definitions of the following: diff --git a/firmware/protob/pb_decode.c b/firmware/protob/pb_decode.c index cebf59607..9edc8b3ab 100644 --- a/firmware/protob/pb_decode.c +++ b/firmware/protob/pb_decode.c @@ -42,6 +42,7 @@ static bool checkreturn pb_field_find(pb_field_iterator_t *iter, uint32_t tag); static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter); static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter); static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_type, pb_field_iterator_t *iter); +static void iter_from_extension(pb_field_iterator_t *iter, pb_extension_t *extension); static bool checkreturn default_extension_decoder(pb_istream_t *stream, pb_extension_t *extension, uint32_t tag, pb_wire_type_t wire_type); static bool checkreturn decode_extension(pb_istream_t *stream, uint32_t tag, pb_wire_type_t wire_type, pb_field_iterator_t *iter); static bool checkreturn find_extension_field(pb_field_iterator_t *iter); @@ -696,6 +697,19 @@ static bool checkreturn decode_field(pb_istream_t *stream, pb_wire_type_t wire_t } } +static void iter_from_extension(pb_field_iterator_t *iter, pb_extension_t *extension) +{ + const pb_field_t *field = (const pb_field_t*)extension->type->arg; + + iter->start = field; + iter->pos = field; + iter->field_index = 0; + iter->required_field_index = 0; + iter->dest_struct = extension->dest; + iter->pData = extension->dest; + iter->pSize = &extension->found; +} + /* Default handler for extension fields. Expects a pb_field_t structure * in extension->type->arg. */ static bool checkreturn default_extension_decoder(pb_istream_t *stream, @@ -707,14 +721,7 @@ static bool checkreturn default_extension_decoder(pb_istream_t *stream, if (field->tag != tag) return true; - iter.start = field; - iter.pos = field; - iter.field_index = 0; - iter.required_field_index = 0; - iter.dest_struct = extension->dest; - iter.pData = extension->dest; - iter.pSize = &extension->found; - + iter_from_extension(&iter, extension); return decode_field(stream, wire_type, &iter); } @@ -956,6 +963,47 @@ static void pb_release_single_field(const pb_field_iterator_t *iter) pb_type_t type; type = iter->pos->type; + /* Release anything contained inside an extension or submsg. + * This has to be done even if the submsg itself is statically + * allocated. */ + if (PB_LTYPE(type) == PB_LTYPE_EXTENSION) + { + /* Release fields from all extensions in the linked list */ + pb_extension_t *ext = *(pb_extension_t**)iter->pData; + while (ext != NULL) + { + pb_field_iterator_t ext_iter; + iter_from_extension(&ext_iter, ext); + pb_release_single_field(&ext_iter); + ext = ext->next; + } + } + else if (PB_LTYPE(type) == PB_LTYPE_SUBMESSAGE) + { + /* Release fields in submessage or submsg array */ + void *pItem = iter->pData; + pb_size_t count = 1; + + if (PB_ATYPE(type) == PB_ATYPE_POINTER) + { + pItem = *(void**)iter->pData; + } + + if (PB_HTYPE(type) == PB_HTYPE_REPEATED) + { + count = *(pb_size_t*)iter->pSize; + } + + if (pItem) + { + while (count--) + { + pb_release((const pb_field_t*)iter->pos->ptr, pItem); + pItem = (uint8_t*)pItem + iter->pos->data_size; + } + } + } + if (PB_ATYPE(type) == PB_ATYPE_POINTER) { if (PB_HTYPE(type) == PB_HTYPE_REPEATED && @@ -970,28 +1018,12 @@ static void pb_release_single_field(const pb_field_iterator_t *iter) pb_free(*pItem); *pItem++ = NULL; } - *(pb_size_t*)iter->pSize = 0; } - else if (PB_LTYPE(type) == PB_LTYPE_SUBMESSAGE) + + if (PB_HTYPE(type) == PB_HTYPE_REPEATED) { - /* Release fields in submessages */ - void *pItem = *(void**)iter->pData; - if (pItem) - { - pb_size_t count = 1; - - if (PB_HTYPE(type) == PB_HTYPE_REPEATED) - { - count = *(pb_size_t*)iter->pSize; - *(pb_size_t*)iter->pSize = 0; - } - - while (count--) - { - pb_release((const pb_field_t*)iter->pos->ptr, pItem); - pItem = (uint8_t*)pItem + iter->pos->data_size; - } - } + /* We are going to release the array, so set the size to 0 */ + *(pb_size_t*)iter->pSize = 0; } /* Release main item */ diff --git a/firmware/protob/storage.pb.c b/firmware/protob/storage.pb.c index ec96bd54f..34b40d3c8 100644 --- a/firmware/protob/storage.pb.c +++ b/firmware/protob/storage.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.2.9.1 */ +/* Generated by nanopb-0.2.9.2 */ #include "storage.pb.h" diff --git a/firmware/protob/storage.pb.h b/firmware/protob/storage.pb.h index f9df1390e..8251f4735 100644 --- a/firmware/protob/storage.pb.h +++ b/firmware/protob/storage.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.2.9.1 */ +/* Generated by nanopb-0.2.9.2 */ #ifndef _PB_STORAGE_PB_H_ #define _PB_STORAGE_PB_H_ diff --git a/firmware/protob/types.pb.c b/firmware/protob/types.pb.c index 6eb4cdf0a..343df0748 100644 --- a/firmware/protob/types.pb.c +++ b/firmware/protob/types.pb.c @@ -1,5 +1,5 @@ /* Automatically generated nanopb constant definitions */ -/* Generated by nanopb-0.2.9.1 */ +/* Generated by nanopb-0.2.9.2 */ #include "types.pb.h" diff --git a/firmware/protob/types.pb.h b/firmware/protob/types.pb.h index dd7b30bea..84234008a 100644 --- a/firmware/protob/types.pb.h +++ b/firmware/protob/types.pb.h @@ -1,5 +1,5 @@ /* Automatically generated nanopb header */ -/* Generated by nanopb-0.2.9.1 */ +/* Generated by nanopb-0.2.9.2 */ #ifndef _PB_TYPES_PB_H_ #define _PB_TYPES_PB_H_