aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test/nif_SUITE_data
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2019-03-06 15:28:30 +0100
committerJohn Högberg <[email protected]>2019-03-07 09:31:16 +0100
commitf951b3fcc69c195ce04ae1022fa53272cb74f71b (patch)
tree781e576d1acc8882eca11c789e0eaedb47387f52 /erts/emulator/test/nif_SUITE_data
parent31bff2cdb13a6e2032b7f067d037da0520752fc0 (diff)
downloadotp-f951b3fcc69c195ce04ae1022fa53272cb74f71b.tar.gz
otp-f951b3fcc69c195ce04ae1022fa53272cb74f71b.tar.bz2
otp-f951b3fcc69c195ce04ae1022fa53272cb74f71b.zip
erts: Add enif_term_type
This helps avoid long sequences of enif_is_xxx in code that serializes terms (such as JSON encoders) by letting the user switch on the type.
Diffstat (limited to 'erts/emulator/test/nif_SUITE_data')
-rw-r--r--erts/emulator/test/nif_SUITE_data/nif_SUITE.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
index 0d5d900d31..1906384af4 100644
--- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
+++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c
@@ -3583,6 +3583,36 @@ static ERL_NIF_TERM compare_pids_nif(ErlNifEnv* env, int argc, const ERL_NIF_TER
return enif_make_int(env, enif_compare_pids(&a, &b));
}
+static ERL_NIF_TERM term_type_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
+{
+ switch (enif_term_type(env, argv[0])) {
+ case ERL_NIF_TERM_TYPE_ATOM:
+ return enif_make_atom(env, "atom");
+ case ERL_NIF_TERM_TYPE_BITSTRING:
+ return enif_make_atom(env, "bitstring");
+ case ERL_NIF_TERM_TYPE_FLOAT:
+ return enif_make_atom(env, "float");
+ case ERL_NIF_TERM_TYPE_FUN:
+ return enif_make_atom(env, "fun");
+ case ERL_NIF_TERM_TYPE_INTEGER:
+ return enif_make_atom(env, "integer");
+ case ERL_NIF_TERM_TYPE_LIST:
+ return enif_make_atom(env, "list");
+ case ERL_NIF_TERM_TYPE_MAP:
+ return enif_make_atom(env, "map");
+ case ERL_NIF_TERM_TYPE_PID:
+ return enif_make_atom(env, "pid");
+ case ERL_NIF_TERM_TYPE_PORT:
+ return enif_make_atom(env, "port");
+ case ERL_NIF_TERM_TYPE_REFERENCE:
+ return enif_make_atom(env, "reference");
+ case ERL_NIF_TERM_TYPE_TUPLE:
+ return enif_make_atom(env, "tuple");
+ default:
+ return enif_make_badarg(env);
+ }
+}
+
static ErlNifFunc nif_funcs[] =
{
{"lib_version", 0, lib_version},
@@ -3690,7 +3720,8 @@ static ErlNifFunc nif_funcs[] =
{"make_pid_nif", 1, make_pid_nif},
{"set_pid_undefined_nif", 0, set_pid_undefined_nif},
{"is_pid_undefined_nif", 1, is_pid_undefined_nif},
- {"compare_pids_nif", 2, compare_pids_nif}
+ {"compare_pids_nif", 2, compare_pids_nif},
+ {"term_type_nif", 1, term_type_nif}
};
ERL_NIF_INIT(nif_SUITE,nif_funcs,load,NULL,upgrade,unload)