diff options
Diffstat (limited to 'erts/preloaded/src/erts_internal.erl')
-rw-r--r-- | erts/preloaded/src/erts_internal.erl | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/erts/preloaded/src/erts_internal.erl b/erts/preloaded/src/erts_internal.erl index 2aa8739388..6688bbfe67 100644 --- a/erts/preloaded/src/erts_internal.erl +++ b/erts/preloaded/src/erts_internal.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2012-2022. All Rights Reserved. +%% Copyright Ericsson AB 2012-2023. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ -export([cmp_term/2]). -export([map_to_tuple_keys/1, term_type/1, map_hashmap_children/1, map_next/3]). +-export([mc_iterator/1, mc_refill/1]). -export([open_port/2, port_command/3, port_connect/2, port_close/1, port_control/3, port_call/3, port_info/1, port_info/2]). @@ -430,7 +431,7 @@ map_hashmap_children(_M) -> %% return the next assoc in the iterator and a new iterator -spec map_next(I, M, A) -> {K,V,NI} | list() when - I :: non_neg_integer(), + I :: non_neg_integer() | list(), M :: map(), K :: term(), V :: term(), @@ -440,6 +441,61 @@ map_hashmap_children(_M) -> map_next(_I, _M, _A) -> erlang:nif_error(undefined). +%% Introduced in Erlang/OTP 26. This function is a helper, called from +%% code generated by the compiler. It must be kept compatible as long +%% code calling this helper can still be loaded. +-spec mc_iterator(MapOrIter) -> NI when + MapOrIter :: map() | maps:iterator(), + NI :: term(). + +mc_iterator(Map) when is_map(Map) -> + erts_internal:map_next(0, Map, iterator); +mc_iterator([Path | Map]) -> + %% This is probably an iterator. + try erts_internal:map_next(Path, Map, iterator) of + Iter -> + Iter + catch + error:badarg -> + [] + end; +mc_iterator(MapIter) -> + %% Possible "used" iterator. Must validate it. + case is_map_iter(MapIter) of + true -> MapIter; + false -> [] + end. + +is_map_iter({_, _, Iter}) -> + is_map_iter(Iter); +is_map_iter(Iter) -> + case Iter of + [Path | Map] -> + try erts_internal:map_next(Path, Map, iterator) of + _ -> + true + catch + error:badarg -> + false + end; + none -> true; + _ -> false + end. + +%% Introduced in Erlang/OTP 26. This function is a helper, called from +%% code generated by the compiler. It must be kept compatible as long +%% code calling this helper can still be loaded. +-spec mc_refill(IM) -> {K,V,NI} when + IM :: nonempty_improper_list(I, M), + I :: non_neg_integer(), + M :: map(), + K :: term(), + V :: term(), + NI :: term(). + +mc_refill([Path | Map]) -> + erts_internal:map_next(Path, Map, iterator). + -spec erts_internal:flush_monitor_messages(Ref, Multi, Res) -> term() when Ref :: reference(), Multi :: boolean(), |