Skip to content

Commit

Permalink
Merge pull request #85 from sile/fix-map-iter-order
Browse files Browse the repository at this point in the history
Fix the issue where map encoding tests fail stochastically on OTP-27.
  • Loading branch information
sile authored May 27, 2024
2 parents fd911a2 + d9cfda9 commit 15f03bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
otp: ['24.0', '25.0', '26.0']
otp: ['25.0', '26.0', '27.0']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
rebar3-version: '3.20.0'
rebar3-version: '3.23.0'
- run: rebar3 compile
- run: rebar3 xref
- run: rebar3 efmt -c
Expand All @@ -34,8 +34,8 @@ jobs:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: '25.0'
rebar3-version: '3.20.0'
otp-version: '26.0'
rebar3-version: '3.23.0'
- run: rebar3 eunit
- run: rebar3 cover
- run: rebar3 covertool generate
Expand Down
7 changes: 7 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
{dialyzer, [{warnings, [error_handling, unmatched_returns, unknown, no_improper_lists]}]}.

{profiles, [{native, [{erl_opts, [{d, 'ENABLE_HIPE'}]}]},
{test, [{erl_opts, [warnings_as_errors,
warn_export_all,
warn_untyped_record,
inline,
{platform_define, "^R[01][0-9]", 'NO_MAP_TYPE'},
{platform_define, "^(R|17)", 'NO_DIALYZER_SPEC'},
{d, 'MAP_ITER_ORDERED'}]}]},
{edown, [{edoc_opts, [{doclet, edown_doclet}]}, {deps, [edown]}]}]}.

{project_plugins, [covertool, rebar3_efmt]}.
Expand Down
9 changes: 9 additions & 0 deletions src/jsone_encode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@
-define(ENCODE_MAP(Value, Nexts, Buf, Opt), ?ERROR(value, [Value, Nexts, Buf, Opt])).
-else.
-define(IS_MAP(X), is_map(X)).
-ifdef('MAP_ITER_ORDERED').
-if(?OTP_RELEASE >= 27).
-define(ENCODE_MAP(Value, Nexts, Buf, Opt),
object(maps:to_list(maps:iterator(Value, ordered)), Nexts, Buf, Opt)).
-else.
-define(ENCODE_MAP(Value, Nexts, Buf, Opt), object(maps:to_list(Value), Nexts, Buf, Opt)).
-endif.
-else.
-define(ENCODE_MAP(Value, Nexts, Buf, Opt), object(maps:to_list(Value), Nexts, Buf, Opt)).
-endif.
-endif.

-type encode_result() :: {ok, binary()} | {error, {Reason :: term(), [jsone:stack_item()]}}.
-type next() :: {array_values, [jsone:json_value()]} |
Expand Down

0 comments on commit 15f03bd

Please sign in to comment.