Legacy bs_put_utf8/16/32 raise unsupported at a non-byte-aligned offset

Open Beginner friendly
#2,444 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, erlang
Domain
backend

Research direction

Read OP_BS_PUT_UTF8, OP_BS_PUT_UTF16 and OP_BS_PUT_UTF32 in opcodesswitch.h, along with the bitstring_insert_utf8/16/32 helpers and the change in #2357. Reproduce using code compiled with erlc +no_bs_create_bin +no_bs_match +no_type_opt and run it on the interpreter. Done when the legacy opcodes accept non-byte-aligned offsets and the examples produce the shown bitstrings.

Written by the indexing model from the issue text.

Description

With the legacy construction opcodes (code compiled by OTP 24 or older, or with +no_bs_create_bin), a utf8, utf16 or utf32 segment that does not start on a byte boundary raises unsupported:

C = id($a),
<<1:1, C/utf8>>          %% OTP 27 <<176,1:1>>          AtomVM unsupported
<<1:1, C/utf16>>         %% OTP 27 <<128,48,1:1>>       AtomVM unsupported
<<1:1, C/utf32>>         %% OTP 27 <<128,0,0,48,1:1>>   AtomVM unsupported
<<C/utf8, 1:1, C/utf8>>  %% OTP 27 <<97,176,1:1>>       AtomVM unsupported

Compiled with OTP 27 erlc +no_bs_create_bin +no_bs_match +no_type_opt and run on the interpreter (the JIT compiler does not accept these opcodes).

Cause: OP_BS_PUT_UTF8, OP_BS_PUT_UTF16 and OP_BS_PUT_UTF32 in opcodesswitch.h still reject ctx->bs_offset % 8 != 0 before calling bitstring_insert_utf8/16/32. With #2357 those helpers write at any bit offset (bs_create_bin already uses them that way), so the three checks can be removed once #2357 is merged.

Dominant language
Erlang
Stars
2.3k
Forks
171
Avg merge
4d 11h
Merged PRs (30d)
20

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from atomvm/AtomVM

All issues in atomvm/AtomVM

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.