aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test
diff options
context:
space:
mode:
authorGuilherme Andrade <[email protected]>2017-04-22 17:22:32 +0100
committerGuilherme Andrade <[email protected]>2017-04-22 17:25:13 +0100
commit21e1d879faaae2278a68200fe1085d7e73791fa0 (patch)
treec711ec5ac1659532787af3c0f44b764426fc88e5 /erts/emulator/test
parentd8756f8665a42effa2f3515369058cff4441abeb (diff)
downloadotp-21e1d879faaae2278a68200fe1085d7e73791fa0.tar.gz
otp-21e1d879faaae2278a68200fe1085d7e73791fa0.tar.bz2
otp-21e1d879faaae2278a68200fe1085d7e73791fa0.zip
erts: Support custom salt in enif_hash
Diffstat (limited to 'erts/emulator/test')
-rw-r--r--erts/emulator/test/nif_SUITE.erl6
-rw-r--r--erts/emulator/test/nif_SUITE_data/nif_SUITE.c11
2 files changed, 11 insertions, 6 deletions
diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl
index e177fa4963..36af68be60 100644
--- a/erts/emulator/test/nif_SUITE.erl
+++ b/erts/emulator/test/nif_SUITE.erl
@@ -2628,7 +2628,7 @@ nif_internal_hash(Config) ->
OnesPerBit =
lists:foldl(
fun (Term, Acc) ->
- NifHashValue = hash_nif(internal, Term),
+ NifHashValue = hash_nif(internal, Term, 0),
lists:foldl(
fun (BitIndex, AccB) ->
BitValue = (NifHashValue band (1 bsl BitIndex)) bsr BitIndex,
@@ -2661,7 +2661,7 @@ nif_phash2(Config) ->
lists:foreach(
fun (Term) ->
HashValue = erlang:phash2(Term),
- NifHashValue = hash_nif(phash2, Term),
+ NifHashValue = hash_nif(phash2, Term, 0),
(HashValue =:= NifHashValue
orelse ct:fail("Expected: ~p\nActual: ~p",
[HashValue, NifHashValue]))
@@ -2714,7 +2714,7 @@ type_test() -> ?nif_stub.
tuple_2_list(_) -> ?nif_stub.
is_identical(_,_) -> ?nif_stub.
compare(_,_) -> ?nif_stub.
-hash_nif(_, _) -> ?nif_stub.
+hash_nif(_Type, _Term, _Salt) -> ?nif_stub.
many_args_100(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_) -> ?nif_stub.
clone_bin(_) -> ?nif_stub.
make_sub_bin(_,_,_) -> ?nif_stub.
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
index 9d65b9c09b..2a80d48b62 100644
--- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
+++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
@@ -689,7 +689,7 @@ static ERL_NIF_TERM compare(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
static ERL_NIF_TERM hash_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
- if (argc != 2) {
+ if (argc != 3) {
return enif_make_badarg(env);
}
@@ -704,7 +704,12 @@ static ERL_NIF_TERM hash_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]
return enif_make_badarg(env);
}
- return enif_make_ulong(env, enif_hash(type, argv[1]));
+ unsigned long salt;
+ if (! enif_get_ulong(env, argv[2], &salt)) {
+ return enif_make_badarg(env);
+ }
+
+ return enif_make_ulong(env, enif_hash(type, argv[1], salt));
}
static ERL_NIF_TERM many_args_100(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
@@ -2884,7 +2889,7 @@ static ErlNifFunc nif_funcs[] =
{"tuple_2_list", 1, tuple_2_list},
{"is_identical",2,is_identical},
{"compare",2,compare},
- {"hash_nif",2,hash_nif},
+ {"hash_nif",3,hash_nif},
{"many_args_100", 100, many_args_100},
{"clone_bin", 1, clone_bin},
{"make_sub_bin", 3, make_sub_bin},