Skip to content

Conversation

@Noltari
Copy link
Member

@Noltari Noltari commented Nov 10, 2025

Add proper types for BOOL and INT8 instead of mixing them.
This allows using blobmsg_add_u8 for uint8_t without converting values to
true or false.

Note: I didn't have time to test it yet.

CC @Alphix @systemcrash

@nbd168
Copy link
Member

nbd168 commented Nov 10, 2025

NACK. I'd prefer to just deprecate treating u8 as integer and deprecate using u16 in blobmsg entirely. That way we can avoid a lot of compatibility mess and JSON conversion issues. Due to padding, u8, u16 and u32 attributes have the same effective size anyway, so there isn't really a good reason to use them for integer values.

@systemcrash
Copy link

NACK. I'd prefer to just deprecate treating u8 as integer and deprecate using u16 in blobmsg entirely. That way we can avoid a lot of compatibility mess and JSON conversion issues. Due to padding, u8, u16 and u32 attributes have the same effective size anyway, so there isn't really a good reason to use them for integer values.

So u8 always becomes boolean, and anything numeric should use u32?

@nbd168
Copy link
Member

nbd168 commented Nov 10, 2025

Yes. Either u32 or u64 (if bigger values are required).

@systemcrash
Copy link

Ah. I see. Could you put a heads-up in the or a readme or somewhere appropriate for this, please?

systemcrash added a commit to systemcrash/odhcp6c that referenced this pull request Nov 10, 2025
ubus coerces u8 to boolean, and one workaround suitable is to amend u8
values (despite them being and containing only a u8 int) to u32 values. ubus
coerces u8 to booleans due to historical reasons. Any calls to e.g.

ubus call odhcp6c.eth1 get_state

(and subsequently downstream dependencies which use this invocation)

return booleans(!) where there shall be a number.

Amended calls to blobmsg_add_u8 into blobmsg_add_u32 to resolve this.
Amended calls to blobmsg_add_u16 into blobmsg_add_u32 also.

Apparently u8 and u16 get padded to u32 anyway.

See @nbd168 openwrt/libubox#25 (comment)
"
I'd prefer to just deprecate treating u8 as integer and deprecate using u16 in
blobmsg entirely. That way we can avoid a lot of compatibility mess and JSON
conversion issues. Due to padding, u8, u16 and u32 attributes have the same
effective size anyway, so there isn't really a good reason to use them for
integer values.
"

Signed-off-by: Paul Donald <[email protected]>
@systemcrash
Copy link

might need a transition shim since there are some downstream users of blobmsg_add_u16

@Noltari Noltari changed the title blobmsg: split BOOL and INT8 types blobmsg: remove INT8 and INT16 types Nov 10, 2025
@Noltari Noltari requested a review from Ansuel November 11, 2025 07:12
Noltari pushed a commit to systemcrash/odhcp6c that referenced this pull request Nov 11, 2025
ubus coerces u8 to boolean, and one workaround suitable is to amend u8
values (despite them being and containing only a u8 int) to u32 values. ubus
coerces u8 to booleans due to historical reasons. Any calls to e.g.

ubus call odhcp6c.eth1 get_state

(and subsequently downstream dependencies which use this invocation)

return booleans(!) where there shall be a number.

Amended calls to blobmsg_add_u8 into blobmsg_add_u32 to resolve this.
Amended calls to blobmsg_add_u16 into blobmsg_add_u32 also.

Apparently u8 and u16 get padded to u32 anyway.

See @nbd168 openwrt/libubox#25 (comment)
"
I'd prefer to just deprecate treating u8 as integer and deprecate using u16 in
blobmsg entirely. That way we can avoid a lot of compatibility mess and JSON
conversion issues. Due to padding, u8, u16 and u32 attributes have the same
effective size anyway, so there isn't really a good reason to use them for
integer values.
"

Signed-off-by: Paul Donald <[email protected]>
Link: openwrt#117
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Noltari added a commit to Noltari/libubox that referenced this pull request Nov 11, 2025
u8 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Noltari added a commit to Noltari/libubox that referenced this pull request Nov 11, 2025
u16 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Noltari added a commit to Noltari/libubox that referenced this pull request Nov 11, 2025
u8 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
@Noltari Noltari marked this pull request as ready for review November 11, 2025 15:41
Noltari added a commit to Noltari/libubox that referenced this pull request Nov 12, 2025
u16 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Noltari added a commit to Noltari/libubox that referenced this pull request Nov 12, 2025
u8 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
u16 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
u8 has the same effective size as u32 so we can remove it to avoid a lot
of compatibility mess and JSON conversion issues.

Link: openwrt#25
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
@nbd168
Copy link
Member

nbd168 commented Nov 12, 2025

I'd prefer to just deprecate int8/int16 support without actually removing it.

@Noltari Noltari marked this pull request as draft November 13, 2025 07:43
@Noltari
Copy link
Member Author

Noltari commented Nov 14, 2025

I'd prefer to just deprecate int8/int16 support without actually removing it.

@nbd168 deprecated in #28

I'll leave this PR as draft just in case someone wants to remove them in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants