58
58
#include "unicode.h"
59
59
#include "utils.h"
60
60
61
- #define MAX_NIF_NAME_LEN 260
62
61
#define FLOAT_BUF_SIZE 64
63
62
64
63
#define RAISE (a , b ) \
@@ -873,30 +872,11 @@ DEFINE_MATH_NIF(tanh)
873
872
#include "nifs_hash.h"
874
873
#pragma GCC diagnostic pop
875
874
876
- const struct Nif * nifs_get (AtomString module , AtomString function , int arity )
875
+ const struct Nif * nifs_get (const char * mfa )
877
876
{
878
- char nifname [MAX_NIF_NAME_LEN ];
879
-
880
- int module_name_len = atom_string_len (module );
881
- memcpy (nifname , atom_string_data (module ), module_name_len );
882
-
883
- nifname [module_name_len ] = ':' ;
884
-
885
- int function_name_len = atom_string_len (function );
886
- if (UNLIKELY ((arity > 9 ) || (module_name_len + function_name_len + 4 > MAX_NIF_NAME_LEN ))) {
887
- // In AtomVM NIFs are limited to 9 parameters
888
- return NULL ;
889
- }
890
- memcpy (nifname + module_name_len + 1 , atom_string_data (function ), function_name_len );
891
-
892
- //TODO: handle NIFs with more than 9 parameters
893
- nifname [module_name_len + function_name_len + 1 ] = '/' ;
894
- nifname [module_name_len + function_name_len + 2 ] = '0' + arity ;
895
- nifname [module_name_len + function_name_len + 3 ] = 0 ;
896
-
897
- const NifNameAndNifPtr * nameAndPtr = nif_in_word_set (nifname , strlen (nifname ));
877
+ const NifNameAndNifPtr * nameAndPtr = nif_in_word_set (mfa , strlen (mfa ));
898
878
if (!nameAndPtr ) {
899
- return platform_nifs_get_nif (nifname );
879
+ return platform_nifs_get_nif (mfa );
900
880
}
901
881
902
882
return nameAndPtr -> nif ;
@@ -3476,16 +3456,20 @@ static term nif_erlang_function_exported(Context *ctx, int argc, term argv[])
3476
3456
VALIDATE_VALUE (function , term_is_atom );
3477
3457
VALIDATE_VALUE (arity_term , term_is_integer );
3478
3458
3479
- AtomString module_name = globalcontext_atomstring_from_term (ctx -> global , module );
3480
- AtomString function_name = globalcontext_atomstring_from_term (ctx -> global , function );
3459
+ AtomIndex module_name = term_to_atom_index (module );
3460
+ AtomIndex function_name = term_to_atom_index (function );
3461
+
3481
3462
avm_int_t arity = term_to_int (arity_term );
3482
3463
3483
- const struct ExportedFunction * bif = bif_registry_get_handler (module_name , function_name , arity );
3464
+ char mfa [MAX_MFA_NAME_LEN ];
3465
+ atom_table_write_mfa (ctx -> global -> atom_table , mfa , sizeof (mfa ), module_name , function_name , arity );
3466
+
3467
+ const struct ExportedFunction * bif = bif_registry_get_handler (mfa );
3484
3468
if (bif ) {
3485
3469
return TRUE_ATOM ;
3486
3470
}
3487
3471
3488
- struct Nif * nif = (struct Nif * ) nifs_get (module_name , function_name , arity );
3472
+ struct Nif * nif = (struct Nif * ) nifs_get (mfa );
3489
3473
if (nif ) {
3490
3474
return TRUE_ATOM ;
3491
3475
}
@@ -3495,7 +3479,7 @@ static term nif_erlang_function_exported(Context *ctx, int argc, term argv[])
3495
3479
return FALSE_ATOM ;
3496
3480
}
3497
3481
3498
- int target_label = module_search_exported_function (target_module , function_name , arity , ctx -> global );
3482
+ int target_label = module_search_exported_function (target_module , function_name , arity );
3499
3483
if (target_label == 0 ) {
3500
3484
return FALSE_ATOM ;
3501
3485
}
@@ -3625,20 +3609,20 @@ static term nif_erlang_fun_info_2(Context *ctx, int argc, term argv[])
3625
3609
switch (key ) {
3626
3610
case MODULE_ATOM : {
3627
3611
term module_name ;
3628
- term_get_function_mfa (fun , & module_name , NULL , NULL , ctx -> global );
3612
+ term_get_function_mfa (fun , & module_name , NULL , NULL );
3629
3613
value = module_name ;
3630
3614
break ;
3631
3615
}
3632
3616
case NAME_ATOM : {
3633
3617
term function_name ;
3634
- term_get_function_mfa (fun , NULL , & function_name , NULL , ctx -> global );
3618
+ term_get_function_mfa (fun , NULL , & function_name , NULL );
3635
3619
value = function_name ;
3636
3620
break ;
3637
3621
}
3638
3622
3639
3623
case ARITY_ATOM : {
3640
3624
term arity ;
3641
- term_get_function_mfa (fun , NULL , NULL , & arity , ctx -> global );
3625
+ term_get_function_mfa (fun , NULL , NULL , & arity );
3642
3626
value = arity ;
3643
3627
break ;
3644
3628
}
@@ -3977,7 +3961,7 @@ static term nif_erlang_get_module_info(Context *ctx, int argc, term argv[])
3977
3961
if (UNLIKELY (memory_ensure_free (ctx , info_size ) != MEMORY_GC_OK )) {
3978
3962
RAISE_ERROR (OUT_OF_MEMORY_ATOM );
3979
3963
}
3980
- term exports = module_get_exported_functions (target_module , & ctx -> heap , ctx -> global );
3964
+ term exports = module_get_exported_functions (target_module , & ctx -> heap );
3981
3965
if (argc == 2 ) {
3982
3966
return exports ;
3983
3967
}
0 commit comments