Page MenuHomeFreeBSD

bitstring: Support large bit strings.
ClosedPublic

Authored by des on Nov 21 2023, 10:58 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 26, 12:29 AM
Unknown Object (File)
Fri, Oct 18, 8:17 PM
Unknown Object (File)
Fri, Oct 18, 8:17 PM
Unknown Object (File)
Fri, Oct 18, 8:17 PM
Unknown Object (File)
Fri, Oct 18, 7:40 PM
Unknown Object (File)
Sep 25 2024, 5:30 PM
Unknown Object (File)
Sep 19 2024, 3:05 PM
Unknown Object (File)
Sep 16 2024, 11:34 PM

Details

Summary

Replace int with either size_t or ssize_t (depending on context) in
order to support bit strings up to SSIZE_MAX bits in length. Since
some of the arguments that need to change type are pointers, we must
resort to light preprocessor trickery to avoid breaking existing code.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 54545
Build 51434: arc lint + arc unit

Event Timeline

des requested review of this revision.Nov 21 2023, 10:58 AM
arichardson added inline comments.
sys/sys/bitstring.h
79

Can't we include cdefs.h and use the align_up macro from there?

des marked an inline comment as done.Nov 21 2023, 5:04 PM
des added inline comments.
sys/sys/bitstring.h
79

No. I rewrote this precisely to get away from __align_up(), which contrary to what the documentation says appears to coerce its arguments to int.

des marked an inline comment as done.Nov 21 2023, 5:04 PM
kevans added a subscriber: kevans.

I'm not seeing anything obviously wrong.

This revision is now accepted and ready to land.Nov 22 2023, 6:08 PM
This revision was automatically updated to reflect the committed changes.
dougm added inline comments.
sys/sys/bitstring.h
90–91

When do you see this returned value being too large for an int?

98

When do you see this parameter having a value too big for an int?

104

When do you see either of these parameters have values too large to fit into an int?

229–230

How did changing the return type from void and dropping the result parameter help with the stated purpose of this change, to allow much longer bitstrings?

sys/sys/bitstring.h
79

There is no conversion to int,? The built-in just keeps the input types.

jacob.e.keller_intel.com added inline comments.
sys/sys/bitstring.h
104

When the bitstring length is very large? (I.e. greater than INT_MAX)

229–230

I believe this is the macro trickery being pointed out in the description. This no longer takes a pointer to a size_t, but returns the size_t value, and then the wrapping macros take a result pointer and will gracefully handle either a pointer to an int or a pointer to size_t without breaking.

sys/sys/bitstring.h
104

Fine. True. But all but the last six bits are discarded by _bit_offset(), so changing the parameter types here changes nothing, except the code size.

229–230

Yes. But why? The trickery is not needed. It does not help accomplish bigger bitstrings.

sys/sys/bitstring.h
229–230

The trickery is needed for the case where someone tries to use a type too small. Both versions give warnings, this version is less harmful to get wrong with all warnings disabled as it truncates the value instead of writing outside the bounds of the object passed in.