@@ -996,7 +996,7 @@ static term nif_erlang_register_2(Context *ctx, int argc, term argv[])
996996 term reg_name_term = argv [0 ];
997997 VALIDATE_VALUE (reg_name_term , term_is_atom );
998998 term pid_or_port_term = argv [1 ];
999- VALIDATE_VALUE (pid_or_port_term , term_is_pid );
999+ VALIDATE_VALUE (pid_or_port_term , term_is_local_pid );
10001000
10011001 int atom_index = term_to_atom_index (reg_name_term );
10021002 int32_t pid = term_to_local_process_id (pid_or_port_term );
@@ -1400,7 +1400,7 @@ static term nif_erlang_send_2(Context *ctx, int argc, term argv[])
14001400 term target = argv [0 ];
14011401 GlobalContext * glb = ctx -> global ;
14021402
1403- if (term_is_pid (target )) {
1403+ if (term_is_local_pid (target )) {
14041404 int32_t local_process_id = term_to_local_process_id (target );
14051405
14061406 globalcontext_send_message (glb , local_process_id , argv [1 ]);
@@ -2741,7 +2741,7 @@ static term nif_erlang_process_flag(Context *ctx, int argc, term argv[])
27412741 flag = argv [1 ];
27422742 value = argv [2 ];
27432743
2744- VALIDATE_VALUE (pid , term_is_pid );
2744+ VALIDATE_VALUE (pid , term_is_local_pid );
27452745 int local_process_id = term_to_local_process_id (pid );
27462746 Context * target = globalcontext_get_process_lock (ctx -> global , local_process_id );
27472747 if (IS_NULL_PTR (target )) {
@@ -3191,7 +3191,7 @@ static term nif_binary_split(Context *ctx, int argc, term argv[])
31913191
31923192 if (num_segments == 1 ) {
31933193 // not found
3194- if (UNLIKELY (memory_ensure_free_with_roots (ctx , 2 , 1 , argv , MEMORY_CAN_SHRINK ) != MEMORY_GC_OK )) {
3194+ if (UNLIKELY (memory_ensure_free_with_roots (ctx , LIST_SIZE ( 1 , 0 ) , 1 , argv , MEMORY_CAN_SHRINK ) != MEMORY_GC_OK )) {
31953195 RAISE_ERROR (OUT_OF_MEMORY_ATOM );
31963196 }
31973197
@@ -3443,11 +3443,11 @@ static term nif_erlang_pid_to_list(Context *ctx, int argc, term argv[])
34433443
34443444 term t = argv [0 ];
34453445 VALIDATE_VALUE (t , term_is_pid );
3446+ size_t max_len = term_is_external (t ) ? EXTERNAL_PID_AS_CSTRING_LEN : LOCAL_PID_AS_CSTRING_LEN ;
34463447
3447- char buf [PID_AS_CSTRING_LEN ];
3448- int str_len = term_snprint (buf , PID_AS_CSTRING_LEN , t , ctx -> global );
3448+ char buf [max_len ];
3449+ int str_len = term_snprint (buf , max_len , t , ctx -> global );
34493450 if (UNLIKELY (str_len < 0 )) {
3450- // TODO: change to internal error or something like that
34513451 RAISE_ERROR (OUT_OF_MEMORY_ATOM );
34523452 }
34533453
@@ -3559,7 +3559,7 @@ static term nif_erlang_garbage_collect(Context *ctx, int argc, term argv[])
35593559 } else {
35603560 // argc == 1
35613561 term t = argv [0 ];
3562- VALIDATE_VALUE (t , term_is_pid );
3562+ VALIDATE_VALUE (t , term_is_local_pid );
35633563
35643564 int local_id = term_to_local_process_id (t );
35653565 Context * target = globalcontext_get_process_lock (ctx -> global , local_id );
@@ -3602,7 +3602,7 @@ static term nif_erlang_exit(Context *ctx, int argc, term argv[])
36023602 RAISE (LOWERCASE_EXIT_ATOM , reason );
36033603 } else {
36043604 term target_process = argv [0 ];
3605- VALIDATE_VALUE (target_process , term_is_pid );
3605+ VALIDATE_VALUE (target_process , term_is_local_pid );
36063606 term reason = argv [1 ];
36073607 GlobalContext * glb = ctx -> global ;
36083608 Context * target = globalcontext_get_process_lock (glb , term_to_local_process_id (target_process ));
@@ -3715,7 +3715,7 @@ static term nif_erlang_monitor(Context *ctx, int argc, term argv[])
37153715 RAISE_ERROR (BADARG_ATOM );
37163716 }
37173717
3718- VALIDATE_VALUE (target_pid , term_is_pid );
3718+ VALIDATE_VALUE (target_pid , term_is_local_pid );
37193719
37203720 int local_process_id = term_to_local_process_id (target_pid );
37213721 Context * target = globalcontext_get_process_lock (ctx -> global , local_process_id );
@@ -3783,7 +3783,7 @@ static term nif_erlang_link(Context *ctx, int argc, term argv[])
37833783
37843784 term target_pid = argv [0 ];
37853785
3786- VALIDATE_VALUE (target_pid , term_is_pid );
3786+ VALIDATE_VALUE (target_pid , term_is_local_pid );
37873787
37883788 int local_process_id = term_to_local_process_id (target_pid );
37893789 Context * target = globalcontext_get_process_lock (ctx -> global , local_process_id );
@@ -3814,7 +3814,7 @@ static term nif_erlang_unlink(Context *ctx, int argc, term argv[])
38143814
38153815 term target_pid = argv [0 ];
38163816
3817- VALIDATE_VALUE (target_pid , term_is_pid );
3817+ VALIDATE_VALUE (target_pid , term_is_local_pid );
38183818
38193819 int local_process_id = term_to_local_process_id (target_pid );
38203820 Context * target = globalcontext_get_process_lock (ctx -> global , local_process_id );
@@ -3845,8 +3845,8 @@ static term nif_erlang_group_leader(Context *ctx, int argc, term argv[])
38453845 } else {
38463846 term leader = argv [0 ];
38473847 term pid = argv [1 ];
3848- VALIDATE_VALUE (pid , term_is_pid );
3849- VALIDATE_VALUE (leader , term_is_pid );
3848+ VALIDATE_VALUE (pid , term_is_local_pid );
3849+ VALIDATE_VALUE (leader , term_is_local_pid );
38503850
38513851 int local_process_id = term_to_local_process_id (pid );
38523852 Context * target = globalcontext_get_process_lock (ctx -> global , local_process_id );
0 commit comments