File 1481-Remove-indirection-on-set-primary-archive.patch of Package erlang
From 9efaf50b842416e7f5890f84355f499126275572 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@dashbit.co>
Date: Wed, 27 Dec 2023 10:51:20 +0100
Subject: [PATCH] Remove indirection on set primary archive
The previous code called code, which then called the
code server, but none of those calls rely directly on
the code server (or its state).
---
erts/preloaded/src/erl_prim_loader.erl | 2 +-
lib/kernel/src/code.erl | 23 -----------------------
lib/kernel/src/code_server.erl | 10 ----------
lib/stdlib/src/escript.erl | 18 +++++++++++++++---
4 files changed, 16 insertions(+), 37 deletions(-)
diff --git a/erts/preloaded/src/erl_prim_loader.erl b/erts/preloaded/src/erl_prim_loader.erl
index 4442d00914..c6cf28b29d 100644
--- a/erts/preloaded/src/erl_prim_loader.erl
+++ b/erts/preloaded/src/erl_prim_loader.erl
@@ -49,7 +49,7 @@
-export([prim_init/0, prim_get_file/2, prim_list_dir/2,
prim_read_file_info/3, prim_get_cwd/2]).
-%% Used by escript and code
+%% Used by escript
-export([set_primary_archive/4]).
%% Used by test suites
diff --git a/lib/kernel/src/code.erl b/lib/kernel/src/code.erl
index 304638e0a6..4ae10a6e8e 100644
--- a/lib/kernel/src/code.erl
+++ b/lib/kernel/src/code.erl
@@ -73,7 +73,6 @@
get_doc/2,
where_is_file/1,
where_is_file/2,
- set_primary_archive/4,
clash/0,
module_status/0,
module_status/1,
@@ -1029,28 +1028,6 @@ get_function_docs_from_ast({function,Anno,Name,Arity,_Code}, AST) ->
get_function_docs_from_ast(_, _) ->
[].
--spec set_primary_archive(ArchiveFile :: file:filename(),
- ArchiveBin :: binary(),
- FileInfo :: file:file_info(),
- ParserFun :: fun())
- -> 'ok' | {'error', atom()}.
-
-set_primary_archive(ArchiveFile0, ArchiveBin, #file_info{} = FileInfo,
- ParserFun)
- when is_list(ArchiveFile0), is_binary(ArchiveBin) ->
- ArchiveFile = filename:absname(ArchiveFile0),
- case call({set_primary_archive, ArchiveFile, ArchiveBin, FileInfo,
- ParserFun}) of
- {ok, []} ->
- ok;
- {ok, _Mode, Ebins} ->
- %% Prepend the code path with the ebins found in the archive
- Ebins2 = [filename:join([ArchiveFile, E]) || E <- Ebins],
- add_pathsa(Ebins2, cache); % Returns ok
- {error, _Reason} = Error ->
- Error
- end.
-
%% Search the entire path system looking for name clashes
-spec clash() -> 'ok'.
diff --git a/lib/kernel/src/code_server.erl b/lib/kernel/src/code_server.erl
index b96589fbf7..3a6999f316 100644
--- a/lib/kernel/src/code_server.erl
+++ b/lib/kernel/src/code_server.erl
@@ -358,16 +358,6 @@ handle_call({get_object_code_for_loading,Mod}, From, St0) when is_atom(Mod) ->
handle_call(stop,_From, S) ->
{stop,normal,stopped,S};
-handle_call({set_primary_archive, File, ArchiveBin, FileInfo, ParserFun},
- _From, S=#state{mode=Mode}) ->
- case erl_prim_loader:set_primary_archive(File, ArchiveBin, FileInfo,
- ParserFun) of
- {ok, Files} ->
- {reply, {ok, Mode, Files}, S};
- {error, _Reason} = Error ->
- {reply, Error, S}
- end;
-
handle_call(get_mode, _From, S=#state{mode=Mode}) ->
{reply, Mode, S};
diff --git a/lib/stdlib/src/escript.erl b/lib/stdlib/src/escript.erl
index 6db6656380..61bfcfbbc7 100644
--- a/lib/stdlib/src/escript.erl
+++ b/lib/stdlib/src/escript.erl
@@ -335,9 +335,7 @@ parse_and_run(File, Args, Options) ->
is_binary(FormsOrBin) ->
case Source of
archive ->
- {ok, FileInfo} = file:read_file_info(File),
- case code:set_primary_archive(File, FormsOrBin, FileInfo,
- fun escript:parse_file/1) of
+ case set_primary_archive(File, FormsOrBin) of
ok when CheckOnly ->
case code:load_file(Module) of
{module, _} ->
@@ -383,6 +381,20 @@ parse_and_run(File, Args, Options) ->
end
end.
+set_primary_archive(File, FormsOrBin) ->
+ {ok, FileInfo} = file:read_file_info(File),
+ ArchiveFile = filename:absname(File),
+
+ case erl_prim_loader:set_primary_archive(ArchiveFile, FormsOrBin, FileInfo,
+ fun escript:parse_file/1) of
+ {ok, Ebins} ->
+ %% Prepend the code path with the ebins found in the archive
+ Ebins2 = [filename:join([ArchiveFile, E]) || E <- Ebins],
+ code:add_pathsa(Ebins2, cache); % Returns ok
+ {error, _Reason} = Error ->
+ Error
+ end.
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parse script
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--
2.35.3