Page MenuHomeFreeBSD

printf.9: Support more than 32 bits in %b
ClosedPublic

Authored by tuexen on Thu, Dec 18, 2:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Dec 19, 6:17 AM
Unknown Object (File)
Fri, Dec 19, 2:09 AM
Unknown Object (File)
Fri, Dec 19, 12:46 AM
Unknown Object (File)
Thu, Dec 18, 11:25 PM
Unknown Object (File)
Thu, Dec 18, 11:11 PM
Unknown Object (File)
Thu, Dec 18, 11:01 PM
Unknown Object (File)
Thu, Dec 18, 10:46 PM
Unknown Object (File)
Thu, Dec 18, 2:59 PM
Subscribers

Details

Summary

This will be usable after clang has been extended to accept length modifiers for %b when compiling kernel code. But we need FreeBSD to support it first...

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

share/man/man9/printf.9
182

Extra newline. (It would be better to remove it from the previous example.)

sys/kern/subr_prf.c
971

Can we not support a modifier, so %lb takes a long, %jb takes an intmax_t, etc., instead of having this ad-hoc encoding?

The example should follow style.9 as suggested by Mark.

tuexen added inline comments.
share/man/man9/printf.9
182

Fixed. The previous example has been fixed in a separate commit.

sys/kern/subr_prf.c
971

That is already supported by the code above. But you need to be able to specify bit positions from 1 to 128 now. The positions from 1 to 32 are encoded as characters from \01 to \40. So you need a way to encode the other positions. OpenBSD also uses the characters from \200 to \377 for it. If you have a different idea, I am happy to explore it.

Once this is in, I need to change clang such that it knows that you can use a length modifier (like l or j) in combination with %b. Right now it is warning that you can only use a 32-bit entity. But when you just ignore the warning, it works. Fixing clang is the next step when this change is in.

markj added inline comments.
sys/kern/subr_prf.c
663

IMO it would be better to keep this comment directly above kvprintf().

971

Ok, I see now: you need a range of 64 (why 128?) non-printable chars, and 0-31 doesn't work.

This revision is now accepted and ready to land.Fri, Dec 19, 2:33 PM
timo.voelker_fh-muenster.de added inline comments.
sys/kern/subr_prf.c
975

At least for me, parentheses would make it easier to read.

*(q++)
tuexen added inline comments.
sys/kern/subr_prf.c
663

Sure. Will do this.

971

In case we want to support printing flags from an 128 bit integer variable (uint128_t).

sys/kern/subr_prf.c
971

When does that ever happen?

uintmax_t is 64 bits wide, so that won't work anyway.

tuexen added inline comments.
sys/kern/subr_prf.c
975

*q++ is already is in other places in this file. So I keep it for consistency.

This revision was automatically updated to reflect the committed changes.
tuexen marked an inline comment as done.
sys/kern/subr_prf.c
971

I don't know. Would you prefer to limit the bit number range to 1, ..., 64? Using 1,..., 128 also results in having not invalid characters.

sys/kern/subr_prf.c
971

It's fine as it is, or at least it doesn't really matter. I just found the description confusing. I don't think we will ever use 128-bit flag variables.

tuexen added inline comments.
sys/kern/subr_prf.c
971

I see.