From 8b5e6e4a138a8c686cc392c47f866dcaab485f87 Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Mon, 23 Jan 2017 19:04:22 +0300 Subject: [PATCH] Compatibility with R17 in mod_block_strangers --- rebar.config | 1 + src/mod_block_strangers.erl | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index cc04c86d0..7e9fe145e 100644 --- a/rebar.config +++ b/rebar.config @@ -88,6 +88,7 @@ {if_var_true, elixir, {d, 'ELIXIR_ENABLED'}}, {if_var_true, erlang_deprecated_types, {d, 'ERL_DEPRECATED_TYPES'}}, {if_version_above, "18", {d, 'STRONG_RAND_BYTES'}}, + {if_version_above, "17", {d, 'GB_SETS_ITERATOR_FROM'}}, {if_var_true, hipe, native}, {src_dirs, [asn1, src, {if_var_true, tools, tools}, diff --git a/src/mod_block_strangers.erl b/src/mod_block_strangers.erl index 383848724..56fddd093 100644 --- a/src/mod_block_strangers.erl +++ b/src/mod_block_strangers.erl @@ -92,11 +92,30 @@ filter_packet(Acc) -> Acc. sets_bare_member({U, S, <<"">>} = LBJID, Set) -> - case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of + case ?SETS:next(sets_iterator_from(LBJID, Set)) of {{U, S, _}, _} -> true; _ -> false end. +-ifdef(GB_SETS_ITERATOR_FROM). +sets_iterator_from(Element, Set) -> + ?SETS:iterator_from(Element, Set). +-else. +%% Copied from gb_sets.erl +%% TODO: Remove after dropping R17 support +sets_iterator_from(S, {_, T}) -> + iterator_from(S, T, []). + +iterator_from(S, {K, _, T}, As) when K < S -> + iterator_from(S, T, As); +iterator_from(_, {_, nil, _} = T, As) -> + [T | As]; +iterator_from(S, {_, L, _} = T, As) -> + iterator_from(S, L, [T | As]); +iterator_from(_, nil, As) -> + As. +-endif. + depends(_Host, _Opts) -> []. -- 2.40.0