From 82476c323862c9dd3c59b936755c9a488a80490b Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Wed, 12 Feb 2025 09:45:55 +0100 Subject: [PATCH 1/2] 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. --- src/stringprep.app.src | 1 - src/stringprep.erl | 8 ++--- src/stringprep_app.erl | 74 ------------------------------------------ src/stringprep_sup.erl | 40 ----------------------- 4 files changed, 4 insertions(+), 119 deletions(-) delete mode 100644 src/stringprep_app.erl delete mode 100644 src/stringprep_sup.erl diff --git a/src/stringprep.app.src b/src/stringprep.app.src index 49a9de1..d7da1b5 100644 --- a/src/stringprep.app.src +++ b/src/stringprep.app.src @@ -26,7 +26,6 @@ {modules, []}, {registered, []}, {applications, [kernel, stdlib, p1_utils]}, - {mod, {stringprep_app,[]}}, %% hex.pm packaging: {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"]}, diff --git a/src/stringprep.erl b/src/stringprep.erl index c9aa9f0..5268e6f 100644 --- a/src/stringprep.erl +++ b/src/stringprep.erl @@ -22,13 +22,13 @@ %%%---------------------------------------------------------------------- -module(stringprep). +-on_load(load_nif/0). +-nifs([tolower/1, tolower_nofilter/1, nameprep/1, nodeprep/1, resourceprep/1]). -author('alexey@process-one.net'). --compile(no_native). - --export([start/0, load_nif/0, tolower/1, nameprep/1, - nodeprep/1, resourceprep/1, tolower_nofilter/1]). +-export([start/0, tolower/1, nameprep/1, + nodeprep/1, resourceprep/1, tolower_nofilter/1]). %%%=================================================================== %%% API functions diff --git a/src/stringprep_app.erl b/src/stringprep_app.erl deleted file mode 100644 index 0cc335b..0000000 --- a/src/stringprep_app.erl +++ /dev/null @@ -1,74 +0,0 @@ -%%%---------------------------------------------------------------------- -%%% File : stringprep_app.erl -%%% Author : Evgeniy Khramtsov -%%% Purpose : stringprep application -%%% Created : 4 Apr 2013 by Evgeniy Khramtsov -%%% -%%% -%%% Copyright (C) 2002-2021 ProcessOne, SARL. All Rights Reserved. -%%% -%%% Licensed under the Apache License, Version 2.0 (the "License"); -%%% you may not use this file except in compliance with the License. -%%% You may obtain a copy of the License at -%%% -%%% http://www.apache.org/licenses/LICENSE-2.0 -%%% -%%% Unless required by applicable law or agreed to in writing, software -%%% distributed under the License is distributed on an "AS IS" BASIS, -%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%%% See the License for the specific language governing permissions and -%%% limitations under the License. -%%% -%%%---------------------------------------------------------------------- - --module(stringprep_app). - --behaviour(application). - -%% Application callbacks --export([start/2, stop/1]). - -%%%=================================================================== -%%% Application callbacks -%%%=================================================================== - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% This function is called whenever an application is started using -%% application:start/[1,2], and should start the processes of the -%% application. If the application is structured according to the OTP -%% design principles as a supervision tree, this means starting the -%% top supervisor of the tree. -%% -%% @spec start(StartType, StartArgs) -> {ok, Pid} | -%% {ok, Pid, State} | -%% {error, Reason} -%% StartType = normal | {takeover, Node} | {failover, Node} -%% StartArgs = term() -%% @end -%%-------------------------------------------------------------------- -start(_StartType, _StartArgs) -> - case stringprep:load_nif() of - ok -> - stringprep_sup:start_link(); - Err -> - Err - end. - -%%-------------------------------------------------------------------- -%% @private -%% @doc -%% This function is called whenever an application has stopped. It -%% is intended to be the opposite of Module:start/2 and should do -%% any necessary cleaning up. The return value is ignored. -%% -%% @spec stop(State) -> void() -%% @end -%%-------------------------------------------------------------------- -stop(_State) -> - ok. - -%%%=================================================================== -%%% Internal functions -%%%=================================================================== diff --git a/src/stringprep_sup.erl b/src/stringprep_sup.erl deleted file mode 100644 index 6768bd7..0000000 --- a/src/stringprep_sup.erl +++ /dev/null @@ -1,40 +0,0 @@ -%%%------------------------------------------------------------------- -%%% File : stringprep_sup.erl -%%% Author : Mickael Remond -%%% Description : stringprep supervisor -%%% Created : 29 Jun 2007 by Mickael Remond -%%% -%%% -%%% Copyright (C) 2002-2021 ProcessOne, SARL. All Rights Reserved. -%%% -%%% Licensed under the Apache License, Version 2.0 (the "License"); -%%% you may not use this file except in compliance with the License. -%%% You may obtain a copy of the License at -%%% -%%% http://www.apache.org/licenses/LICENSE-2.0 -%%% -%%% Unless required by applicable law or agreed to in writing, software -%%% distributed under the License is distributed on an "AS IS" BASIS, -%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -%%% See the License for the specific language governing permissions and -%%% limitations under the License. -%%% -%%%------------------------------------------------------------------- - --module(stringprep_sup). - --behaviour(supervisor). - -%% API --export([start_link/0]). - -%% Supervisor callbacks --export([init/1]). - --define(SERVER, ?MODULE). - -start_link() -> - supervisor:start_link({local, ?SERVER}, ?MODULE, []). - -init([]) -> - {ok, {{one_for_all, 10, 1}, []}}. From 955861b035abe7ef61f1748202f9aa593201da09 Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Wed, 12 Feb 2025 10:08:44 +0100 Subject: [PATCH 2/2] Update CI --- .github/workflows/ci.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6522706..23dcfb5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,12 +9,12 @@ jobs: strategy: fail-fast: false matrix: - otp: ['19.3', '21.3', 24] - runs-on: ubuntu-20.04 + otp: ['20', '21', '22', '23', '24', '25', '26', '27'] + runs-on: ubuntu-24.04 container: image: erlang:${{ matrix.otp }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: rebar3 compile - run: rebar3 xref - run: rebar3 dialyzer @@ -23,9 +23,13 @@ jobs: cover: name: Cover needs: [tests] - runs-on: ubuntu-20.04 + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: erlef/setup-beam@v1 + with: + otp-version: '27' + rebar3-version: "3.24.0" - run: ./configure --enable-gcov - run: rebar3 compile - name: Run tests to obtain Erlang coverage