diff options
author | Sverker Eriksson <[email protected]> | 2017-04-28 14:54:42 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2017-04-28 14:54:42 +0200 |
commit | 61e55780e2800e340e8ff16b5414f08373f89ef3 (patch) | |
tree | c584727c8695ac4c72c4fae9deff18931a8c54d4 /erts/emulator/beam/erl_nif.c | |
parent | 2e2526b58f74c6c3209b3feca34866772be65335 (diff) | |
parent | e40ec046a2a1037b2f87b657503c5f21c5de4e2a (diff) | |
download | otp-61e55780e2800e340e8ff16b5414f08373f89ef3.tar.gz otp-61e55780e2800e340e8ff16b5414f08373f89ef3.tar.bz2 otp-61e55780e2800e340e8ff16b5414f08373f89ef3.zip |
Merge PR1413 from g-andrade/feature/phash2_nif
Support hashing terms from NIF code
Diffstat (limited to 'erts/emulator/beam/erl_nif.c')
-rw-r--r-- | erts/emulator/beam/erl_nif.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c index 872b58d1ef..e041fd7b83 100644 --- a/erts/emulator/beam/erl_nif.c +++ b/erts/emulator/beam/erl_nif.c @@ -55,6 +55,7 @@ #include "dtrace-wrapper.h" #include "erl_process.h" #include "erl_bif_unique.h" +#include "erl_utils.h" #undef ERTS_WANT_NFUNC_SCHED_INTERNALS__ #define ERTS_WANT_NFUNC_SCHED_INTERNALS__ #include "erl_nfunc_sched.h" @@ -1210,6 +1211,22 @@ int enif_compare(Eterm lhs, Eterm rhs) return result; } +ErlNifUInt64 enif_hash(ErlNifHash type, Eterm term, ErlNifUInt64 salt) +{ + switch (type) { + case ERL_NIF_INTERNAL_HASH: + return make_internal_hash(term, (Uint32) salt); + case ERL_NIF_PHASH2: + /* It appears that make_hash2 doesn't always react to seasoning + * as well as it should. Therefore, let's make it ignore the salt + * value and declare salted uses of phash2 as unsupported. + */ + return make_hash2(term) & ((1 << 27) - 1); + default: + return 0; + } +} + int enif_get_tuple(ErlNifEnv* env, Eterm tpl, int* arity, const Eterm** array) { Eterm* ptr; |