diff options
author | Guilherme Andrade <[email protected]> | 2017-04-19 00:43:37 +0100 |
---|---|---|
committer | Guilherme Andrade <[email protected]> | 2017-04-19 01:25:35 +0100 |
commit | 0835f40ae25f97360dc393928796387d3cd6b16e (patch) | |
tree | 22b56cc3a6cb90d79efb394ecd1fab58e1182f8c /erts/emulator/test/nif_SUITE_data | |
parent | 6124bfc9b61227a5e82f1d7273d0895e909aac6e (diff) | |
download | otp-0835f40ae25f97360dc393928796387d3cd6b16e.tar.gz otp-0835f40ae25f97360dc393928796387d3cd6b16e.tar.bz2 otp-0835f40ae25f97360dc393928796387d3cd6b16e.zip |
erts: Add enif_phash2 and enif_phash2_ranged
These allow one to hash VM terms from NIF code.
Diffstat (limited to 'erts/emulator/test/nif_SUITE_data')
-rw-r--r-- | erts/emulator/test/nif_SUITE_data/nif_SUITE.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c index 8fe5ee809a..3bdd4d93c7 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c +++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c @@ -687,6 +687,23 @@ static ERL_NIF_TERM compare(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) return enif_make_int(env, enif_compare(argv[0],argv[1])); } +static ERL_NIF_TERM phash2_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + if (argc != 1) { + return enif_make_badarg(env); + } + return enif_make_ulong(env, enif_phash2(argv[0])); +} + +static ERL_NIF_TERM phash2_ranged_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + unsigned long range; + if (argc != 2 || !enif_get_ulong(env, argv[1], &range)) { + return enif_make_badarg(env); + } + return enif_make_ulong(env, enif_phash2_ranged(argv[0], range)); +} + static ERL_NIF_TERM many_args_100(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { int i, k; @@ -2864,6 +2881,8 @@ static ErlNifFunc nif_funcs[] = {"tuple_2_list", 1, tuple_2_list}, {"is_identical",2,is_identical}, {"compare",2,compare}, + {"phash2_nif",1,phash2_nif}, + {"phash2_ranged_nif",2,phash2_ranged_nif}, {"many_args_100", 100, many_args_100}, {"clone_bin", 1, clone_bin}, {"make_sub_bin", 3, make_sub_bin}, |