From e2ca71b6e7172b320b5b171359d53a161383fb19 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Wed, 6 Feb 2019 19:08:25 +0100 Subject: erts: Fix bug in erts_map_from_ks_and_vs This sleeping bug was introduced in OTP 19.1 but not possible not provoke until OTP 21.0 when enif_make_map_from_arrays was introduced. --- erts/emulator/beam/erl_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erts/emulator/beam/erl_map.c b/erts/emulator/beam/erl_map.c index 979a0040b0..b48017d338 100644 --- a/erts/emulator/beam/erl_map.c +++ b/erts/emulator/beam/erl_map.c @@ -499,7 +499,7 @@ Eterm erts_hashmap_from_array(ErtsHeapFactory* factory, Eterm *leafs, Uint n, Eterm erts_map_from_ks_and_vs(ErtsHeapFactory *factory, Eterm *ks0, Eterm *vs0, Uint n) { - if (n < MAP_SMALL_MAP_LIMIT) { + if (n <= MAP_SMALL_MAP_LIMIT) { Eterm *ks, *vs, *hp; flatmap_t *mp; Eterm keys; -- cgit v1.2.3 From 2e36105479b300a6c51e21b31e03ded39df8c02b Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Wed, 6 Feb 2019 20:00:20 +0100 Subject: erts: Add test for bug in enif_make_maps_from_arrays --- erts/emulator/test/nif_SUITE.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl index a2f3489943..ca5f90621f 100644 --- a/erts/emulator/test/nif_SUITE.erl +++ b/erts/emulator/test/nif_SUITE.erl @@ -1175,6 +1175,15 @@ maps(Config) when is_list(Config) -> M2 = maps_from_list_nif(maps:to_list(M2)), M3 = maps_from_list_nif(maps:to_list(M3)), + %% Test different map sizes (OTP-15567) + repeat_while(fun({35,_}) -> false; + ({K,Map}) -> + Map = maps_from_list_nif(maps:to_list(Map)), + Map = maps:filter(fun(K,V) -> V =:= K*100 end, Map), + {K+1, maps:put(K,K*100,Map)} + end, + {1,#{}}), + has_duplicate_keys = maps_from_list_nif([{1,1},{1,1}]), verify_tmpmem(TmpMem), @@ -2471,6 +2480,13 @@ repeat(0, _, Arg) -> repeat(N, Fun, Arg0) -> repeat(N-1, Fun, Fun(Arg0)). +repeat_while(Fun, Acc0) -> + case Fun(Acc0) of + false -> ok; + Acc1 -> + repeat_while(Fun, Acc1) + end. + check(Exp,Got,Line) -> case Got of Exp -> Exp; -- cgit v1.2.3