Skip to content

Commit

Permalink
Fix the formatting of ports
Browse files Browse the repository at this point in the history
Corrects the format of ports to match the OTP spec (and size that was already defined correctly).
Add port format check to Erlang test test_binary_to_term.erl.

Signed-off-by: Winford <winford@object.stream>
  • Loading branch information
UncleGrumpy committed Jan 18, 2025
1 parent 44191fc commit 3990a5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/libAtomVM/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ int term_funprint(PrinterFun *fun, term t, const GlobalContext *global)
} else if (term_is_local_port(t)) {
// Update also PORT_AS_CSTRING_LEN when changing this format string
int32_t process_id = term_to_local_process_id(t);
return fun->print(fun, "#Port<0.%" PRIu32 ".0>", process_id);
return fun->print(fun, "#Port<0.%" PRIu32 ">", process_id);

} else if (term_is_external_port(t)) {
// Update also PORT_AS_CSTRING_LEN when changing this format string
Expand Down
8 changes: 4 additions & 4 deletions tests/erlang_tests/test_binary_to_term.erl
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,11 @@ test_encode_port() ->
ExpectedSize = byte_size(Bin),
case SupportsV4PortEncoding of
true ->
true = is_port(
binary_to_term(
<<131, 120, 119, 13, "nonode@nohost", 1:64, 0:32>>
)
LocalPort1 = binary_to_term(
<<131, 120, 119, 13, "nonode@nohost", 1:64, 0:32>>
),
true = is_port(LocalPort1),
"#Port<0.1>" = port_to_list(LocalPort1),
Port1 = binary_to_term(<<131, 120, 119, 4, "true", 43:64, 0:32>>),
Port2 = binary_to_term(<<131, 120, 119, 4, "true", 43:64, 1:32>>),
false = Port1 =:= Port2,
Expand Down
1 change: 1 addition & 0 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ struct Test tests[] = {
TEST_CASE_EXPECTED(test_atom_to_list, 1),
TEST_CASE(test_display),
TEST_CASE(test_integer_to_list),
TEST_CASE(test_port_to_list),
TEST_CASE_EXPECTED(test_list_to_integer, 99),
TEST_CASE_EXPECTED(test_abs, 5),
TEST_CASE_EXPECTED(test_is_process_alive, 121),
Expand Down

0 comments on commit 3990a5a

Please sign in to comment.