Skip to content

Commit ea39703

Browse files
committed
Fix the formatting of ports
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>
1 parent 44191fc commit ea39703

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/libAtomVM/term.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ int term_funprint(PrinterFun *fun, term t, const GlobalContext *global)
205205
} else if (term_is_local_port(t)) {
206206
// Update also PORT_AS_CSTRING_LEN when changing this format string
207207
int32_t process_id = term_to_local_process_id(t);
208-
return fun->print(fun, "#Port<0.%" PRIu32 ".0>", process_id);
208+
return fun->print(fun, "#Port<0.%" PRIu32 ">", process_id);
209209

210210
} else if (term_is_external_port(t)) {
211211
// Update also PORT_AS_CSTRING_LEN when changing this format string

tests/erlang_tests/test_binary_to_term.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,11 +628,11 @@ test_encode_port() ->
628628
ExpectedSize = byte_size(Bin),
629629
case SupportsV4PortEncoding of
630630
true ->
631-
true = is_port(
632-
binary_to_term(
633-
<<131, 120, 119, 13, "nonode@nohost", 1:64, 0:32>>
634-
)
631+
LocalPort1 = binary_to_term(
632+
<<131, 120, 119, 13, "nonode@nohost", 1:64, 0:32>>
635633
),
634+
true = is_port(LocalPort1),
635+
"#Port<0.1>" = port_to_list(LocalPort1),
636636
Port1 = binary_to_term(<<131, 120, 119, 4, "true", 43:64, 0:32>>),
637637
Port2 = binary_to_term(<<131, 120, 119, 4, "true", 43:64, 1:32>>),
638638
false = Port1 =:= Port2,

0 commit comments

Comments
 (0)