Skip to content

Commit ad60330

Browse files
committed
opcodesswitch: fix OP_BS_CREATE_BIN that can have an allocator list
Signed-off-by: Paul Guyot <[email protected]>
1 parent 32ead2c commit ad60330

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/libAtomVM/opcodesswitch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6576,7 +6576,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
65766576
uint32_t fail;
65776577
DECODE_LABEL(fail, pc);
65786578
uint32_t alloc;
6579-
DECODE_LITERAL(alloc, pc);
6579+
DECODE_ALLOCATOR_LIST(alloc, pc);
65806580
uint32_t live;
65816581
DECODE_LITERAL(live, pc);
65826582
uint32_t unit;

tests/erlang_tests/test_op_bs_create_bin.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ start() ->
3838
ok = test_bs_create_bin_utf16(),
3939
ok = test_bs_create_bin_utf32(),
4040
ok = test_bs_create_bin_integer(),
41-
ok = test_bs_create_bin_binary();
41+
ok = test_bs_create_bin_binary(),
42+
ok = test_bs_create_bin_alloc_list();
4243
true ->
4344
ok
4445
end,
@@ -266,3 +267,15 @@ test_bs_create_bin_binary() ->
266267
error:badarg -> unexpected
267268
end,
268269
ok.
270+
271+
test_bs_create_bin_alloc_list() ->
272+
%% Test that bs_create_bin with allocator list works correctly
273+
%% Expected result: <<0,0,0,42>> (42 as 32-bit big-endian integer)
274+
Expected = <<0, 0, 0, 42>>,
275+
Result = test_op_bs_create_bin_asm:bs_create_bin_alloc_list(42),
276+
case Result of
277+
Expected ->
278+
ok;
279+
_ ->
280+
error({unexpected_result, Result, expected, Expected})
281+
end.

tests/erlang_tests/test_op_bs_create_bin_asm.S

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
{bs_create_bin_integer_no_fail, 3},
3232
{bs_create_bin_integer_fail, 3},
3333
{bs_create_bin_binary_no_fail, 3},
34-
{bs_create_bin_binary_fail, 3}
34+
{bs_create_bin_binary_fail, 3},
35+
{bs_create_bin_alloc_list, 1}
3536
]}.
3637

3738
{attributes, []}.
3839

39-
{labels, 26}.
40+
{labels, 28}.
4041

4142
{function, bs_create_bin_utf8_no_fail, 3, 2}.
4243
{label, 1}.
@@ -122,3 +123,12 @@ return.
122123
{label, 26}.
123124
{move, {atom, fail}, {x, 0}}.
124125
return.
126+
127+
{function, bs_create_bin_alloc_list, 1, 28}.
128+
{label, 27}.
129+
{func_info, {atom, test_op_bs_create_bin_asm}, {atom, bs_create_bin_alloc_list}, 1}.
130+
{label, 28}.
131+
%% Test bs_create_bin with allocator list instead of simple literal
132+
{bs_create_bin, {f, 0}, {alloc, [{words, 2}, {floats, 1}, {funs, 1}]}, 1, 1, {x, 0},
133+
{list, [{atom, integer}, 1, 1, nil, {x, 0}, {integer, 32}]}}.
134+
return.

0 commit comments

Comments
 (0)