Rename poorly named identifier to avoid name conflicts.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Mon, 18 Aug 2014 18:11:10 +0000 (21:11 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Mon, 18 Aug 2014 18:11:10 +0000 (21:11 +0300)
Update issue 106
Status: FixedInGit

docs/migration.rst
generator/nanopb_generator.py
pb.h
pb_common.h
pb_decode.h
pb_encode.h
tests/splint/splint.rc

index 800bc1f..5ac52b3 100644 (file)
@@ -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)
 =========================
index 80fb93c..5010814 100755 (executable)
@@ -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 8ddf30e..5edd648 100644 (file)
--- 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;
index 01a3768..60b3d37 100644 (file)
@@ -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. */
index 8dc6740..3d43315 100644 (file)
@@ -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.
index f82bac8..e992c8d 100644 (file)
@@ -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.
index e2b2688..e47d3c2 100644 (file)
@@ -2,7 +2,6 @@
 +partial
 +matchanyintegral
 +strictlib
--isoreserved           # to be fixed in 0.3
 -nullassign
 -predboolint
 -predboolptr