summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2014-08-18 21:11:10 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2014-08-18 21:11:10 +0300
commitbe0b9e047a007685aa10a268f9bf856e9a52ef58 (patch)
tree81ac0c52f93b5ece781c3c1a0c9821ffc5725ebc
parent62b4a8ecaac45ce62cc93e09261d60e6ceade1a9 (diff)
Rename poorly named identifier to avoid name conflicts.
Update issue 106 Status: FixedInGit
-rw-r--r--docs/migration.rst40
-rwxr-xr-xgenerator/nanopb_generator.py4
-rw-r--r--pb.h28
-rw-r--r--pb_common.h9
-rw-r--r--pb_decode.h6
-rw-r--r--pb_encode.h6
-rw-r--r--tests/splint/splint.rc1
7 files changed, 66 insertions, 28 deletions
diff --git a/docs/migration.rst b/docs/migration.rst
index 800bc1f9..5ac52b3e 100644
--- a/docs/migration.rst
+++ b/docs/migration.rst
@@ -44,7 +44,45 @@ The size of the type will be controlled by the *PB_FIELD_16BIT* and
**Required actions:** Regenerate all *.pb.h* files. In some cases casts to the
*pb_size_t* type may need to be added in the user code when accessing the
-*_count* fields.
+*_count* fields.
+
+**Error indications:** Incorrect data at runtime, crashes. But note that other
+changes in the same version already require regenerating the files and have
+better indications of errors, so this is only an issue for development
+versions.
+
+Renamed some macros and identifiers
+-----------------------------------
+**Rationale:** Some names in nanopb core were badly chosen and conflicted with
+ISO C99 reserved names or lacked a prefix. While they haven't caused trouble
+so far, it is reasonable to switch to non-conflicting names as these are rarely
+used from user code.
+
+**Changes:** The following identifier names have changed:
+
+ * Macros:
+
+ * STATIC_ASSERT(x) -> PB_STATIC_ASSERT(x)
+ * UNUSED(x) -> PB_UNUSED(x)
+
+ * Include guards:
+
+ * _PB_filename_ -> PB_filename_INCLUDED
+
+ * Structure forward declaration tags:
+
+ * _pb_field_t -> pb_field_s
+ * _pb_bytes_array_t -> pb_bytes_array_s
+ * _pb_callback_t -> pb_callback_s
+ * _pb_extension_type_t -> pb_extension_type_s
+ * _pb_extension_t -> pb_extension_s
+ * _pb_istream_t -> pb_istream_s
+ * _pb_ostream_t -> pb_ostream_s
+
+**Required actions:** Regenerate all *.pb.c* files. If you use any of the above
+identifiers in your application code, perform search-replace to the new name.
+
+**Error indications:** Compiler errors on lines with the macro/type names.
Nanopb-0.2.9 (2014-08-09)
=========================
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 80fb93ca..50108148 100755
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -768,8 +768,8 @@ def generate_header(dependencies, headername, enums, messages, extensions, optio
yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
symbol = make_identifier(headername)
- yield '#ifndef _PB_%s_\n' % symbol
- yield '#define _PB_%s_\n' % symbol
+ yield '#ifndef PB_%s_INCLUDED\n' % symbol
+ yield '#define PB_%s_INCLUDED\n' % symbol
try:
yield options.libformat % ('pb.h')
except TypeError:
diff --git a/pb.h b/pb.h
index 8ddf30ed..5edd6483 100644
--- a/pb.h
+++ b/pb.h
@@ -2,8 +2,8 @@
* stuff. For the high-level interface, see pb_encode.h and pb_decode.h.
*/
-#ifndef _PB_H_
-#define _PB_H_
+#ifndef PB_H_INCLUDED
+#define PB_H_INCLUDED
/*****************************************************************
* Nanopb compilation time options. You can change these here by *
@@ -213,8 +213,8 @@ typedef uint8_t pb_type_t;
* PB_FIELD_32BIT.
*/
PB_PACKED_STRUCT_START
-typedef struct _pb_field_t pb_field_t;
-struct _pb_field_t {
+typedef struct pb_field_s pb_field_t;
+struct pb_field_s {
pb_size_t tag;
pb_type_t type;
pb_size_t data_offset; /* Offset of field data, relative to previous field. */
@@ -251,11 +251,11 @@ PB_STATIC_ASSERT(sizeof(uint64_t) == 8, UINT64_T_WRONG_SIZE)
#define PB_BYTES_ARRAY_T(n) struct { pb_size_t size; uint8_t bytes[n]; }
#define PB_BYTES_ARRAY_T_ALLOCSIZE(n) ((size_t)n + offsetof(pb_bytes_array_t, bytes))
-struct _pb_bytes_array_t {
+struct pb_bytes_array_s {
pb_size_t size;
uint8_t bytes[1];
};
-typedef struct _pb_bytes_array_t pb_bytes_array_t;
+typedef struct pb_bytes_array_s pb_bytes_array_t;
/* This structure is used for giving the callback function.
* It is stored in the message structure and filled in by the method that
@@ -275,10 +275,10 @@ typedef struct _pb_bytes_array_t pb_bytes_array_t;
*
* The callback can be null if you want to skip a field.
*/
-typedef struct _pb_istream_t pb_istream_t;
-typedef struct _pb_ostream_t pb_ostream_t;
-typedef struct _pb_callback_t pb_callback_t;
-struct _pb_callback_t {
+typedef struct pb_istream_s pb_istream_t;
+typedef struct pb_ostream_s pb_ostream_t;
+typedef struct pb_callback_s pb_callback_t;
+struct pb_callback_s {
#ifdef PB_OLD_CALLBACK_STYLE
/* Deprecated since nanopb-0.2.1 */
union {
@@ -311,9 +311,9 @@ typedef enum {
* if you want to catch all unknown fields, you can also create a custom
* pb_extension_type_t with your own callback.
*/
-typedef struct _pb_extension_type_t pb_extension_type_t;
-typedef struct _pb_extension_t pb_extension_t;
-struct _pb_extension_type_t {
+typedef struct pb_extension_type_s pb_extension_type_t;
+typedef struct pb_extension_s pb_extension_t;
+struct pb_extension_type_s {
/* Called for each unknown field in the message.
* If you handle the field, read off all of its data and return true.
* If you do not handle the field, do not read anything and return true.
@@ -335,7 +335,7 @@ struct _pb_extension_type_t {
const void *arg;
};
-struct _pb_extension_t {
+struct pb_extension_s {
/* Type describing the extension field. Usually you'll initialize
* this to a pointer to the automatically generated structure. */
const pb_extension_type_t *type;
diff --git a/pb_common.h b/pb_common.h
index 01a37682..60b3d374 100644
--- a/pb_common.h
+++ b/pb_common.h
@@ -2,8 +2,8 @@
* These functions are rarely needed by applications directly.
*/
-#ifndef _PB_COMMON_H_
-#define _PB_COMMON_H_
+#ifndef PB_COMMON_H_INCLUDED
+#define PB_COMMON_H_INCLUDED
#include "pb.h"
@@ -12,14 +12,15 @@ extern "C" {
#endif
/* Iterator for pb_field_t list */
-typedef struct {
+struct pb_field_iter_s {
const pb_field_t *start; /* Start of the pb_field_t array */
const pb_field_t *pos; /* Current position of the iterator */
unsigned required_field_index; /* Zero-based index that counts only the required fields */
void *dest_struct; /* Pointer to start of the structure */
void *pData; /* Pointer to current field value */
void *pSize; /* Pointer to count/has field */
-} pb_field_iter_t;
+};
+typedef struct pb_field_iter_s pb_field_iter_t;
/* Initialize the field iterator structure to beginning.
* Returns false if the message type is empty. */
diff --git a/pb_decode.h b/pb_decode.h
index 8dc67408..3d433155 100644
--- a/pb_decode.h
+++ b/pb_decode.h
@@ -3,8 +3,8 @@
* field descriptions created by nanopb_generator.py.
*/
-#ifndef _PB_DECODE_H_
-#define _PB_DECODE_H_
+#ifndef PB_DECODE_H_INCLUDED
+#define PB_DECODE_H_INCLUDED
#include "pb.h"
@@ -25,7 +25,7 @@ extern "C" {
* is different than from the main stream. Don't use bytes_left to compute
* any pointers.
*/
-struct _pb_istream_t
+struct pb_istream_s
{
#ifdef PB_BUFFER_ONLY
/* Callback pointer is not used in buffer-only configuration.
diff --git a/pb_encode.h b/pb_encode.h
index f82bac8f..e992c8dc 100644
--- a/pb_encode.h
+++ b/pb_encode.h
@@ -3,8 +3,8 @@
* field descriptions created by nanopb_generator.py.
*/
-#ifndef _PB_ENCODE_H_
-#define _PB_ENCODE_H_
+#ifndef PB_ENCODE_H_INCLUDED
+#define PB_ENCODE_H_INCLUDED
#include "pb.h"
@@ -24,7 +24,7 @@ extern "C" {
* 4) Substreams will modify max_size and bytes_written. Don't use them
* to calculate any pointers.
*/
-struct _pb_ostream_t
+struct pb_ostream_s
{
#ifdef PB_BUFFER_ONLY
/* Callback pointer is not used in buffer-only configuration.
diff --git a/tests/splint/splint.rc b/tests/splint/splint.rc
index e2b26888..e47d3c21 100644
--- a/tests/splint/splint.rc
+++ b/tests/splint/splint.rc
@@ -2,7 +2,6 @@
+partial
+matchanyintegral
+strictlib
--isoreserved # to be fixed in 0.3
-nullassign
-predboolint
-predboolptr