Skip to content

Commit 82476c3

Browse files
committed
Use on_load module attribute
Before OTP 19.0, if the on_load directive fails, any previously loaded code would become old, essentially leaving the system without any working and reachable instance of the module. This is not true anymore since OTP 19.0, so loading the nifs within the on_load directive is today the cleanest and best code pattern. It seems indeed very convoluted to have an entire application and supervision tree with a worker gen_server just to load the nifs. Also, one of the `handle_info` heads of the gen_server is even a remnant of the times when `fast_tls` was implemented as a port driver instead of as nifs, which is a high sign this needed some modernisation.
1 parent 7688cf9 commit 82476c3

4 files changed

Lines changed: 4 additions & 119 deletions

File tree

‎src/stringprep.app.src‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
{modules, []},
2727
{registered, []},
2828
{applications, [kernel, stdlib, p1_utils]},
29-
{mod, {stringprep_app,[]}},
3029

3130
%% hex.pm packaging:
3231
{files, ["src/", "c_src/stringprep.cpp", "c_src/uni_data.c", "c_src/uni_norm.c", "configure", "rebar.config", "rebar.config.script", "vars.config.in", "README.md", "LICENSE.txt", "LICENCE.ALL", "LICENSE.TCL"]},

‎src/stringprep.erl‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
%%%----------------------------------------------------------------------
2323

2424
-module(stringprep).
25+
-on_load(load_nif/0).
26+
-nifs([tolower/1, tolower_nofilter/1, nameprep/1, nodeprep/1, resourceprep/1]).
2527

2628
-author('alexey@process-one.net').
2729

28-
-compile(no_native).
29-
30-
-export([start/0, load_nif/0, tolower/1, nameprep/1,
31-
nodeprep/1, resourceprep/1, tolower_nofilter/1]).
30+
-export([start/0, tolower/1, nameprep/1,
31+
nodeprep/1, resourceprep/1, tolower_nofilter/1]).
3232

3333
%%%===================================================================
3434
%%% API functions

‎src/stringprep_app.erl‎

Lines changed: 0 additions & 74 deletions
This file was deleted.

‎src/stringprep_sup.erl‎

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)