diff options
Diffstat (limited to 'erts/emulator/test/nif_SUITE_data/nif_SUITE.c')
-rw-r--r-- | erts/emulator/test/nif_SUITE_data/nif_SUITE.c | 115 |
1 files changed, 109 insertions, 6 deletions
diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c index f2ce6dbe67..0d5d900d31 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c +++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c @@ -1882,12 +1882,23 @@ static ERL_NIF_TERM copy_blob(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[ return enif_make_copy(env, mti.p->blob); } +static int get_pidbin(ErlNifEnv* env, ERL_NIF_TERM pidbin, ErlNifPid* pid) +{ + ErlNifBinary bin; + + if (!enif_inspect_binary(env, pidbin, &bin) || bin.size != sizeof(ErlNifPid)) + return 0; + + memcpy(pid, bin.data, bin.size); + return 1; +} + static ERL_NIF_TERM send_term(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { ErlNifEnv* menv; ErlNifPid pid; int ret; - if (!enif_get_local_pid(env, argv[0], &pid)) { + if (!enif_get_local_pid(env, argv[0], &pid) && !get_pidbin(env, argv[0], &pid)) { return enif_make_badarg(env); } menv = enif_alloc_env(); @@ -2486,7 +2497,8 @@ static ERL_NIF_TERM select_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv enum ErlNifSelectFlags mode; void* obj; ErlNifPid nifpid, *pid = NULL; - ERL_NIF_TERM ref; + ERL_NIF_TERM ref_or_msg; + ErlNifEnv* msg_env = NULL; int retval; if (!get_fd(env, argv[0], &fdr) @@ -2501,11 +2513,27 @@ static ERL_NIF_TERM select_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv return enif_make_badarg(env); pid = &nifpid; } - ref = argv[4]; + ref_or_msg = argv[4]; + if (argv[5] != atom_null) { + msg_env = enif_alloc_env(); + ref_or_msg = enif_make_copy(msg_env, ref_or_msg); + } fdr->was_selected = 1; enif_self(env, &fdr->pid); - retval = enif_select(env, fdr->fd, mode, obj, pid, ref); + switch (mode) { + case ERL_NIF_SELECT_CUSTOM_MSG | ERL_NIF_SELECT_READ: + retval = enif_select_read(env, fdr->fd, obj, pid, ref_or_msg, msg_env); + break; + case ERL_NIF_SELECT_CUSTOM_MSG | ERL_NIF_SELECT_WRITE: + retval = enif_select_write(env, fdr->fd, obj, pid, ref_or_msg, msg_env); + break; + default: + retval = enif_select(env, fdr->fd, mode, obj, pid, ref_or_msg); + } + + if (msg_env) + enif_free_env(msg_env); return enif_make_int(env, retval); } @@ -2830,6 +2858,16 @@ static ERL_NIF_TERM compare_monitors_nif(ErlNifEnv* env, int argc, const ERL_NIF return enif_make_int(env, enif_compare_monitors(&m1, &m2)); } +static ERL_NIF_TERM make_monitor_term_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifMonitor m; + if (!get_monitor(env, argv[0], &m)) { + return enif_make_badarg(env); + } + + return enif_make_monitor_term(env, &m); +} + /*********** monitor_frenzy ************/ @@ -3486,6 +3524,65 @@ static ERL_NIF_TERM ioq(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) return enif_make_badarg(env); } +static ERL_NIF_TERM make_bool(ErlNifEnv* env, int bool) +{ + return bool ? atom_true : atom_false; +} + +static ERL_NIF_TERM get_local_pid_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPid pid; + ERL_NIF_TERM pid_bin; + int ret = enif_get_local_pid(env, argv[0], &pid); + + memcpy(enif_make_new_binary(env, sizeof(ErlNifPid), &pid_bin), + &pid, sizeof(ErlNifPid)); + + return enif_make_tuple2(env, make_bool(env, ret), pid_bin); +} + +static ERL_NIF_TERM make_pid_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPid pid; + + if (!get_pidbin(env, argv[0], &pid)) + return enif_make_badarg(env); + + return enif_make_pid(env, &pid); +} + +static ERL_NIF_TERM set_pid_undefined_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPid pid; + ERL_NIF_TERM pid_bin; + + enif_set_pid_undefined(&pid); + memcpy(enif_make_new_binary(env, sizeof(ErlNifPid), &pid_bin), + &pid, sizeof(ErlNifPid)); + + return pid_bin; +} + +static ERL_NIF_TERM is_pid_undefined_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPid pid; + + if (!get_pidbin(env, argv[0], &pid)) + return enif_make_badarg(env); + + return make_bool(env, enif_is_pid_undefined(&pid)); +} + +static ERL_NIF_TERM compare_pids_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPid a, b; + + if (!get_pidbin(env, argv[0], &a) || !get_pidbin(env, argv[1], &b)) + return enif_make_badarg(env); + + return enif_make_int(env, enif_compare_pids(&a, &b)); +} + static ErlNifFunc nif_funcs[] = { {"lib_version", 0, lib_version}, @@ -3565,7 +3662,7 @@ static ErlNifFunc nif_funcs[] = {"binary_to_term_nif", 3, binary_to_term}, {"port_command_nif", 2, port_command}, {"format_term_nif", 2, format_term}, - {"select_nif", 5, select_nif}, + {"select_nif", 6, select_nif}, #ifndef __WIN32__ {"pipe_nif", 0, pipe_nif}, {"write_nif", 2, write_nif}, @@ -3579,6 +3676,7 @@ static ErlNifFunc nif_funcs[] = {"monitor_process_nif", 4, monitor_process_nif}, {"demonitor_process_nif", 2, demonitor_process_nif}, {"compare_monitors_nif", 2, compare_monitors_nif}, + {"make_monitor_term_nif", 1, make_monitor_term_nif}, {"monitor_frenzy_nif", 4, monitor_frenzy_nif}, {"whereis_send", 3, whereis_send}, {"whereis_term", 2, whereis_term}, @@ -3587,7 +3685,12 @@ static ErlNifFunc nif_funcs[] = {"ioq_nif", 1, ioq}, {"ioq_nif", 2, ioq}, {"ioq_nif", 3, ioq}, - {"ioq_nif", 4, ioq} + {"ioq_nif", 4, ioq}, + {"get_local_pid_nif", 1, get_local_pid_nif}, + {"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} }; ERL_NIF_INIT(nif_SUITE,nif_funcs,load,NULL,upgrade,unload) |