Do TODOs in `nif_erlang_register_2`
Adds checks that pid is an active process, atom is not already registered to a
process, and the atom name is not the "undefined" atom.
@@ -762,8 +762,12 @@ static term nif_erlang_register_2(Context *ctx, int argc, term argv[])
int atom_index = term_to_atom_index(reg_name_term);
int32_t pid = term_to_local_process_id(pid_or_port_term);
- // TODO: pid must be existing, not already registered.
- // TODO: reg_name_term must not be the atom undefined and not already registered.
+ // pid must be existing, not already registered, and not the atom undefined.
+ if (UNLIKELY(globalcontext_get_process(ctx->global, pid) == NULL) ||
+ globalcontext_get_registered_process(ctx->global, atom_index) != 0 ||
+ reg_name_term == UNDEFINED_ATOM){
+ RAISE_ERROR(BADARG_ATOM);
+ }
globalcontext_register_process(ctx->global, atom_index, pid);
