OTP 26 through at least 29 emit bs_get_binary2 for dynamic-size binary
and bitstring segment extraction (fixed sizes go through bs_match): unit
8 for /binary segments and unit 1 for /bitstring segments. The opcode
previously required unit 8, a byte-aligned source offset and a
whole-byte size, so <<X:N/bitstring, _/bits>> raised unsupported and a
dynamic-size extraction at an unaligned offset raised badarg.
Measure the remainder and the requested size in bits on both the
interpreter and the JIT, extract through the bitstring_slice primitives
(sharing storage when byte-aligned, copying otherwise), and let `all'
take the whole remainder provided it is a multiple of the segment unit.
A negative size now raises badarg instead of wrapping.
test_get_with_unaligned_binary asserted the old badarg and now asserts
the OTP-verified result; new test_dynamic_size_extraction covers
dynamic /binary and /bitstring sizes, unaligned offsets, insufficient
capacity and the non-byte-aligned `all' remainder.
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later