summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-12 10:52:26 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2017-02-12 10:52:26 +0200
commit112fd594442aaf8003764b32390d60162a38131b (patch)
treebd531424e441794d9795d392d78d69e5090f769f
parent2467922d47a579d447406eddcecdb1127d33213b (diff)
parenta5d90990263b3171cc699315e69d0e09f6a420ad (diff)
Merge branch 'master' of github.com:nanopb/nanopb
-rw-r--r--CMakeLists.txt83
-rw-r--r--docs/migration.rst13
-rwxr-xr-xgenerator/protoc-gen-nanopb2
-rw-r--r--generator/protoc-gen-nanopb.bat2
-rw-r--r--pb_decode.c29
-rw-r--r--pb_decode.h2
6 files changed, 94 insertions, 37 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7889bf4a..f69386bf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,12 +6,16 @@ set(nanopb_VERSION_STRING nanopb-0.3.8-dev)
string(REPLACE "nanopb-" "" nanopb_VERSION ${nanopb_VERSION_STRING})
+option(nanopb_BUILD_RUNTIME "Build the headers and libraries needed at runtime" ON)
+option(nanopb_BUILD_GENERATOR "Build the protoc plugin for code generation" ON)
option(nanopb_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON)
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
+include(GNUInstallDirs)
+
if(MSVC AND nanopb_MSVC_STATIC_RUNTIME)
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
@@ -22,38 +26,65 @@ if(MSVC AND nanopb_MSVC_STATIC_RUNTIME)
endforeach(flag_var)
endif()
-add_library(libprotobuf-nanopb STATIC
- pb.h
- pb_common.h
- pb_common.c
- pb_encode.h
- pb_encode.c
- pb_decode.h
- pb_decode.c)
+if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
+ set(CMAKE_INSTALL_CMAKEDIR "lib/cmake/nanopb")
+endif()
-target_include_directories(libprotobuf-nanopb INTERFACE
- $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
-)
+if(nanopb_BUILD_GENERATOR)
+ set(generator_protos nanopb plugin)
-include(GNUInstallDirs)
+ find_package(PythonInterp 2.7 REQUIRED)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c
+ "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'))"
+ OUTPUT_VARIABLE PYTHON_INSTDIR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
-if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
- set(CMAKE_INSTALL_CMAKEDIR "lib/cmake/nanopb")
+ foreach(generator_proto IN LISTS generator_protos)
+ string(REGEX REPLACE "([^;]+)" "generator/proto/\\1.proto" generator_proto_file "${generator_proto}")
+ string(REGEX REPLACE "([^;]+)" "\\1_pb2.py" generator_proto_py_file "${generator_proto}")
+ add_custom_command(
+ OUTPUT ${generator_proto_py_file}
+ COMMAND protoc --python_out=${CMAKE_CURRENT_BINARY_DIR} -Igenerator/proto ${generator_proto_file}
+ DEPENDS ${generator_proto_file}
+ )
+ add_custom_target("generate_${generator_proto_py_file}" ALL DEPENDS ${generator_proto_py_file})
+ install(
+ FILES ${generator_proto_py_file}
+ DESTINATION ${PYTHON_INSTDIR}
+ )
+ endforeach()
endif()
-install(TARGETS libprotobuf-nanopb EXPORT nanopb-targets
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+if(nanopb_BUILD_RUNTIME)
+ add_library(protobuf-nanopb STATIC
+ pb.h
+ pb_common.h
+ pb_common.c
+ pb_encode.h
+ pb_encode.c
+ pb_decode.h
+ pb_decode.c)
+
+ target_include_directories(protobuf-nanopb INTERFACE
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
+ )
-install(EXPORT nanopb-targets
- DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
- NAMESPACE nanopb::)
+ configure_file(extra/nanopb-config-version.cmake.in
+ nanopb-config-version.cmake @ONLY)
-configure_file(extra/nanopb-config-version.cmake.in
- nanopb-config-version.cmake @ONLY)
+ install(TARGETS protobuf-nanopb EXPORT nanopb-targets
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(FILES extra/nanopb-config.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/nanopb-config-version.cmake
- DESTINATION ${CMAKE_INSTALL_CMAKEDIR})
+ install(EXPORT nanopb-targets
+ DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
+ NAMESPACE nanopb::)
-install(FILES pb.h pb_common.h pb_encode.h pb_decode.h
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+ install(FILES extra/nanopb-config.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/nanopb-config-version.cmake
+ DESTINATION ${CMAKE_INSTALL_CMAKEDIR})
+
+ install(FILES pb.h pb_common.h pb_encode.h pb_decode.h
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+endif()
diff --git a/docs/migration.rst b/docs/migration.rst
index cd5911f5..2d9ce38c 100644
--- a/docs/migration.rst
+++ b/docs/migration.rst
@@ -11,6 +11,19 @@ are included, in order to make it easier to find this document.
.. contents ::
+Nanopb-0.3.8 (2017-xx-xx)
+=========================
+Fully drain substreams before closing
+
+**Rationale:** If the substream functions were called directly and the caller
+did not completely empty the substring before closing it, the parent stream
+would be put into an incorrect state.
+
+**Changes:** *pb_close_string_substream* can now error and returns a boolean.
+
+**Required actions:** Add error checking onto any call to
+*pb_close_string_substream*.
+
Nanopb-0.3.5 (2016-02-13)
=========================
diff --git a/generator/protoc-gen-nanopb b/generator/protoc-gen-nanopb
index 358f97cf..471a620b 100755
--- a/generator/protoc-gen-nanopb
+++ b/generator/protoc-gen-nanopb
@@ -3,7 +3,7 @@
# This file is used to invoke nanopb_generator.py as a plugin
# to protoc on Linux and other *nix-style systems.
# Use it like this:
-# protoc --plugin=nanopb=..../protoc-gen-nanopb --nanopb_out=dir foo.proto
+# protoc --plugin=protoc-gen-nanopb=..../protoc-gen-nanopb --nanopb_out=dir foo.proto
#
# Note that if you use the binary package of nanopb, the protoc
# path is already set up properly and there is no need to give
diff --git a/generator/protoc-gen-nanopb.bat b/generator/protoc-gen-nanopb.bat
index 7624984e..e6cf187f 100644
--- a/generator/protoc-gen-nanopb.bat
+++ b/generator/protoc-gen-nanopb.bat
@@ -2,7 +2,7 @@
:: This file is used to invoke nanopb_generator.py as a plugin
:: to protoc on Windows.
:: Use it like this:
-:: protoc --plugin=nanopb=..../protoc-gen-nanopb.bat --nanopb_out=dir foo.proto
+:: protoc --plugin=protoc-gen-nanopb=..../protoc-gen-nanopb.bat --nanopb_out=dir foo.proto
::
:: Note that if you use the binary package of nanopb, the protoc
:: path is already set up properly and there is no need to give
diff --git a/pb_decode.c b/pb_decode.c
index 1fcc4e5a..92d0175d 100644
--- a/pb_decode.c
+++ b/pb_decode.c
@@ -333,13 +333,19 @@ bool checkreturn pb_make_string_substream(pb_istream_t *stream, pb_istream_t *su
return true;
}
-void pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream)
+bool checkreturn pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream)
{
+ if (substream->bytes_left) {
+ if (!pb_read(substream, NULL, substream->bytes_left))
+ return false;
+ }
+
stream->state = substream->state;
#ifndef PB_NO_ERRMSG
stream->errmsg = substream->errmsg;
#endif
+ return true;
}
/*************************
@@ -385,11 +391,12 @@ static bool checkreturn decode_static_field(pb_istream_t *stream, pb_wire_type_t
}
(*size)++;
}
- pb_close_string_substream(stream, &substream);
-
+
if (substream.bytes_left != 0)
PB_RETURN_ERROR(stream, "array overflow");
-
+ if (!pb_close_string_substream(stream, &substream))
+ return false;
+
return status;
}
else
@@ -569,7 +576,8 @@ static bool checkreturn decode_pointer_field(pb_istream_t *stream, pb_wire_type_
(*size)++;
}
- pb_close_string_substream(stream, &substream);
+ if (!pb_close_string_substream(stream, &substream))
+ return false;
return status;
}
@@ -623,7 +631,9 @@ static bool checkreturn decode_callback_field(pb_istream_t *stream, pb_wire_type
PB_RETURN_ERROR(stream, "callback failed");
} while (substream.bytes_left);
- pb_close_string_substream(stream, &substream);
+ if (!pb_close_string_substream(stream, &substream))
+ return false;
+
return true;
}
else
@@ -964,7 +974,9 @@ bool pb_decode_delimited(pb_istream_t *stream, const pb_field_t fields[], void *
return false;
status = pb_decode(&substream, fields, dest_struct);
- pb_close_string_substream(stream, &substream);
+
+ if (!pb_close_string_substream(stream, &substream))
+ return false;
return status;
}
@@ -1343,6 +1355,7 @@ static bool checkreturn pb_dec_submessage(pb_istream_t *stream, const pb_field_t
else
status = pb_decode_noinit(&substream, submsg_fields, dest);
- pb_close_string_substream(stream, &substream);
+ if (!pb_close_string_substream(stream, &substream))
+ return false;
return status;
}
diff --git a/pb_decode.h b/pb_decode.h
index e7eb209c..a426bdd7 100644
--- a/pb_decode.h
+++ b/pb_decode.h
@@ -144,7 +144,7 @@ bool pb_decode_fixed64(pb_istream_t *stream, void *dest);
/* Make a limited-length substream for reading a PB_WT_STRING field. */
bool pb_make_string_substream(pb_istream_t *stream, pb_istream_t *substream);
-void pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream);
+bool pb_close_string_substream(pb_istream_t *stream, pb_istream_t *substream);
#ifdef __cplusplus
} /* extern "C" */