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)
Fri, Apr 19, 5:00 PM
Unknown Object (File)
Fri, Apr 5, 10:34 AM
Unknown Object (File)
Mar 15 2024, 8:02 AM
Unknown Object (File)
Feb 17 2024, 7:53 AM
Unknown Object (File)
Dec 21 2023, 4:16 AM
Unknown Object (File)
Dec 20 2023, 8:38 AM
Unknown Object (File)
Nov 25 2023, 10:31 AM
Unknown Object (File)
Nov 25 2023, 10:30 AM

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 Not Applicable
Unit
Tests Not Applicable

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

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

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

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

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

sys/sys/bitstring.h
229

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.