[OpenWrt-Devel] [PATCH] libubox: use const *attr in getters

Peter Stadler peter.stadler at student.uibk.ac.at
Wed Jan 29 03:29:50 EST 2020


Change the signature of the following get-functions to accept
the `struct blob_attr *attr` as `const`:
  - blobmsg_get_u8
  - blobmsg_get_bool
  - blobmsg_get_u16
  - blobmsg_get_u32
  - blobmsg_get_u64
  - blobmsg_get_double
  - blobmsg_get_string
This allows to get the values instead of calling blobmsg_data.

Signed-off-by: Peter Stadler <peter.stadler at student.uibk.ac.at>
---
 blobmsg.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/blobmsg.h b/blobmsg.h
index be3c7ee..a76bc87 100644
--- a/blobmsg.h
+++ b/blobmsg.h
@@ -260,27 +260,27 @@ static inline int blobmsg_buf_init(struct blob_buf *buf)
 	return blob_buf_init(buf, BLOBMSG_TYPE_TABLE);
 }
 
-static inline uint8_t blobmsg_get_u8(struct blob_attr *attr)
+static inline uint8_t blobmsg_get_u8(const struct blob_attr *attr)
 {
 	return *(uint8_t *) blobmsg_data(attr);
 }
 
-static inline bool blobmsg_get_bool(struct blob_attr *attr)
+static inline bool blobmsg_get_bool(const struct blob_attr *attr)
 {
 	return *(uint8_t *) blobmsg_data(attr);
 }
 
-static inline uint16_t blobmsg_get_u16(struct blob_attr *attr)
+static inline uint16_t blobmsg_get_u16(const struct blob_attr *attr)
 {
 	return be16_to_cpu(*(uint16_t *) blobmsg_data(attr));
 }
 
-static inline uint32_t blobmsg_get_u32(struct blob_attr *attr)
+static inline uint32_t blobmsg_get_u32(const struct blob_attr *attr)
 {
 	return be32_to_cpu(*(uint32_t *) blobmsg_data(attr));
 }
 
-static inline uint64_t blobmsg_get_u64(struct blob_attr *attr)
+static inline uint64_t blobmsg_get_u64(const struct blob_attr *attr)
 {
 	uint32_t *ptr = (uint32_t *) blobmsg_data(attr);
 	uint64_t tmp = ((uint64_t) be32_to_cpu(ptr[0])) << 32;
@@ -288,7 +288,7 @@ static inline uint64_t blobmsg_get_u64(struct blob_attr *attr)
 	return tmp;
 }
 
-static inline double blobmsg_get_double(struct blob_attr *attr)
+static inline double blobmsg_get_double(const struct blob_attr *attr)
 {
 	union {
 		double d;
@@ -298,7 +298,7 @@ static inline double blobmsg_get_double(struct blob_attr *attr)
 	return v.d;
 }
 
-static inline char *blobmsg_get_string(struct blob_attr *attr)
+static inline char *blobmsg_get_string(const struct blob_attr *attr)
 {
 	if (!attr)
 		return NULL;
-- 
2.24.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list