aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTilen Majerle <tilen.majerle@gmail.com>2023-11-05 16:16:49 +0100
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2024-02-27 09:36:08 +0200
commitf79aadbe35666bfe4dca585eb93419bd3d0a6d00 (patch)
treecfd7bc4910b7be873b95ffc3e47b07df8b996fe8
parent41319af88e569d4af31ea28a08fd2580a1f6655c (diff)
downloadnanopb-c-f79aadbe35666bfe4dca585eb93419bd3d0a6d00.tar.gz
Use pb_byte_t = uint8_t when UINT8_MAX is defined (#916)
Adapted from PR#916 by Petteri Aimonen.
-rw-r--r--docs/migration.md19
-rw-r--r--pb.h21
-rw-r--r--tests/regression/issue_485/uint8.expected4
3 files changed, 34 insertions, 10 deletions
diff --git a/docs/migration.md b/docs/migration.md
index 394b4fa..b00fffc 100644
--- a/docs/migration.md
+++ b/docs/migration.md
@@ -6,6 +6,25 @@ required modifications of user applications are explained. Also any
error indications are included, in order to make it easier to find this
document.
+Nanopb-0.4.9 (2024-xx-xx)
+-------------------------
+
+### Use uint8_t for pb_byte_t when UINT8_MAX is defined
+
+**Rationale:** Previously `pb_byte_t` was always defined as `uint8_least_t`.
+This could be annoying on some platforms without this define, or when some
+compiles might warn on conversion from `uint8_t`. However not all platforms
+support `uint8_t` sized access.
+
+**Changes:** The `stdint.h` header will define `UINT8_MAX` exactly if `uint8_t`
+is available. Use it to select which type to typedef.
+
+**Required actions:** Usually none. If any compiler warnings are generated,
+they can either be fixed or `PB_BYTE_T_OVERRIDE` can be defined to `uint_least8_t`
+to restore old behavior.
+
+**Error indications:** Implicit conversion from `uint_least8_t` to `uint8_t`.
+
Nanopb-0.4.8 (2023-11-11)
-------------------------
diff --git a/pb.h b/pb.h
index 8745ecc..e90c93a 100644
--- a/pb.h
+++ b/pb.h
@@ -215,12 +215,23 @@ PB_STATIC_ASSERT(1, STATIC_ASSERT_IS_NOT_WORKING)
#endif
#endif
+/* Data type for storing encoded data and other byte streams.
+ * This typedef exists to support platforms where uint8_t does not exist.
+ * You can regard it as equivalent on uint8_t on other platforms.
+ */
+#if defined(PB_BYTE_T_OVERRIDE)
+typedef PB_BYTE_T_OVERRIDE pb_byte_t;
+#elif defined(UINT8_MAX)
+typedef uint8_t pb_byte_t;
+#else
+typedef uint_least8_t pb_byte_t;
+#endif
+
/* List of possible field types. These are used in the autogenerated code.
* Least-significant 4 bits tell the scalar type
* Most-significant 4 bits specify repeated/required/packed etc.
*/
-
-typedef uint_least8_t pb_type_t;
+typedef pb_byte_t pb_type_t;
/**** Field data types ****/
@@ -301,12 +312,6 @@ typedef uint_least8_t pb_type_t;
#endif
#define PB_SIZE_MAX ((pb_size_t)-1)
-/* Data type for storing encoded data and other byte streams.
- * This typedef exists to support platforms where uint8_t does not exist.
- * You can regard it as equivalent on uint8_t on other platforms.
- */
-typedef uint_least8_t pb_byte_t;
-
/* Forward declaration of struct types */
typedef struct pb_istream_s pb_istream_t;
typedef struct pb_ostream_s pb_ostream_t;
diff --git a/tests/regression/issue_485/uint8.expected b/tests/regression/issue_485/uint8.expected
index 291ab81..c110c2d 100644
--- a/tests/regression/issue_485/uint8.expected
+++ b/tests/regression/issue_485/uint8.expected
@@ -1,3 +1,3 @@
-! ^\s*[^/* ].*uint8_t
-! ^\s*[^/* ].*int8_t
+! ^(?!.*\*)(?!.*typedef).*uint8_t.*
+! ^(?!.*\*)(?!.*typedef).*int8_t.*