Quantcast

Implementation of erlang binary module

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Implementation of erlang binary module

Karlo Kuna
I was wandering how is standard module "binary" implemented 
i am looking at source and i see that most functions are nifs (this makes sense), 
but there is no "-on_load" directive and i can't find c implementation. Please can someone explain to me how is this module using nifs without -on_load directive and also can tell me where is c implementation??


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementation of erlang binary module

Dmytro Lytovchenko
Standard library rarely uses dynamic loaded SO/DLL modules (so called NIFs), rather they use BIF functions, code for them is included straight into Erlang/OTP C source and follows different rules than NIF. Have a search through source C files for binary_<function name>_<arity>, with high chance you will find the C source by this name.

2017-01-21 13:27 GMT+01:00 Karlo Kuna <[hidden email]>:
I was wandering how is standard module "binary" implemented 
i am looking at source and i see that most functions are nifs (this makes sense), 
but there is no "-on_load" directive and i can't find c implementation. Please can someone explain to me how is this module using nifs without -on_load directive and also can tell me where is c implementation??


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementation of erlang binary module

Karlo Kuna
would this imply that erlang runtime is choosing to call bif if present instead of erlang implemented function ??? is this general case or these
"alternative" implementations should be registered somehow somewhere??

and thak you for the search tip it worked  

On Sat, Jan 21, 2017 at 2:38 PM, Dmytro Lytovchenko <[hidden email]> wrote:
Standard library rarely uses dynamic loaded SO/DLL modules (so called NIFs), rather they use BIF functions, code for them is included straight into Erlang/OTP C source and follows different rules than NIF. Have a search through source C files for binary_<function name>_<arity>, with high chance you will find the C source by this name.

2017-01-21 13:27 GMT+01:00 Karlo Kuna <[hidden email]>:
I was wandering how is standard module "binary" implemented 
i am looking at source and i see that most functions are nifs (this makes sense), 
but there is no "-on_load" directive and i can't find c implementation. Please can someone explain to me how is this module using nifs without -on_load directive and also can tell me where is c implementation??


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementation of erlang binary module

Dmytro Lytovchenko
Bifs are registered in special text file located in erts/emulator/beam/bif.tab, based on it an internal C array is generated:

1. bif_table which is traversed in beam_emu.c on first start (after init_emulator label) and erts_export_put is called on each table entry to populate exports table.
2. hash table in nbif_table in hipe_bif0.c that is some HiPE magics i am not familiar with.

During the load time in beam_load.c function final_touch, the erts_export_put will be called for every export and will return existing export pointing at BIF instead of adding Erlang function version.

2017-01-21 15:15 GMT+01:00 Karlo Kuna <[hidden email]>:
would this imply that erlang runtime is choosing to call bif if present instead of erlang implemented function ??? is this general case or these
"alternative" implementations should be registered somehow somewhere??

and thak you for the search tip it worked  

On Sat, Jan 21, 2017 at 2:38 PM, Dmytro Lytovchenko <[hidden email]> wrote:
Standard library rarely uses dynamic loaded SO/DLL modules (so called NIFs), rather they use BIF functions, code for them is included straight into Erlang/OTP C source and follows different rules than NIF. Have a search through source C files for binary_<function name>_<arity>, with high chance you will find the C source by this name.

2017-01-21 13:27 GMT+01:00 Karlo Kuna <[hidden email]>:
I was wandering how is standard module "binary" implemented 
i am looking at source and i see that most functions are nifs (this makes sense), 
but there is no "-on_load" directive and i can't find c implementation. Please can someone explain to me how is this module using nifs without -on_load directive and also can tell me where is c implementation??


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions





_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implementation of erlang binary module

Karlo Kuna
thak you for explanation, i will have look at source but now at least i have some orientation

On Sun, Jan 22, 2017 at 1:39 PM, Dmytro Lytovchenko <[hidden email]> wrote:
Bifs are registered in special text file located in erts/emulator/beam/bif.tab, based on it an internal C array is generated:

1. bif_table which is traversed in beam_emu.c on first start (after init_emulator label) and erts_export_put is called on each table entry to populate exports table.
2. hash table in nbif_table in hipe_bif0.c that is some HiPE magics i am not familiar with.

During the load time in beam_load.c function final_touch, the erts_export_put will be called for every export and will return existing export pointing at BIF instead of adding Erlang function version.

2017-01-21 15:15 GMT+01:00 Karlo Kuna <[hidden email]>:
would this imply that erlang runtime is choosing to call bif if present instead of erlang implemented function ??? is this general case or these
"alternative" implementations should be registered somehow somewhere??

and thak you for the search tip it worked  

On Sat, Jan 21, 2017 at 2:38 PM, Dmytro Lytovchenko <[hidden email]> wrote:
Standard library rarely uses dynamic loaded SO/DLL modules (so called NIFs), rather they use BIF functions, code for them is included straight into Erlang/OTP C source and follows different rules than NIF. Have a search through source C files for binary_<function name>_<arity>, with high chance you will find the C source by this name.

2017-01-21 13:27 GMT+01:00 Karlo Kuna <[hidden email]>:
I was wandering how is standard module "binary" implemented 
i am looking at source and i see that most functions are nifs (this makes sense), 
but there is no "-on_load" directive and i can't find c implementation. Please can someone explain to me how is this module using nifs without -on_load directive and also can tell me where is c implementation??


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions






_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...