File 9301-Remove-catch-in-proc_lib.patch of Package erlang

From 86e96b0b2f6298b29995a4d7c0010ac47b9d43e2 Mon Sep 17 00:00:00 2001
From: Maria Scott <maria-12648430@hnc-agency.org>
Date: Sun, 22 Feb 2026 18:48:06 +0100
Subject: [PATCH] Remove catch in proc_lib

---
 lib/stdlib/src/proc_lib.erl        | 43 +++++++++++++++++-------------
 lib/stdlib/test/proc_lib_SUITE.erl | 28 ++++++++++++-------
 2 files changed, 43 insertions(+), 28 deletions(-)

diff --git a/lib/stdlib/src/proc_lib.erl b/lib/stdlib/src/proc_lib.erl
index cb3fcf148e..40c6677fc8 100644
--- a/lib/stdlib/src/proc_lib.erl
+++ b/lib/stdlib/src/proc_lib.erl
@@ -722,28 +722,33 @@ visit(_, {_N, _Vs} = NVs) ->
 -spec adjacents(pid()) -> [pid()].
 
 adjacents(Pid) ->
-  case catch proc_info(Pid, links) of
-    {links, Links} -> no_trap(Links);
-    _              -> []
-  end.
+    try proc_info(Pid, links)
+    of
+        {links, Links} -> no_trap(Links);
+        _              -> []
+    catch
+        _:_            -> []
+    end.
   
 no_trap([P|Ps]) ->
-  case catch proc_info(P, trap_exit) of
-    {trap_exit, false} -> [P|no_trap(Ps)];
-    _                  -> no_trap(Ps)
-  end;
+    try proc_info(P, trap_exit)
+    of
+        {trap_exit, false} -> [P|no_trap(Ps)];
+        _                  -> no_trap(Ps)
+    catch
+        _:_                -> no_trap(Ps)
+    end;
 no_trap([]) ->
-  [].
+    [].
  
 get_process_info(Pid, Tag) ->
- translate_process_info(Tag, catch proc_info(Pid, Tag)).
-
-translate_process_info(registered_name, []) ->
-  {registered_name, []};
-translate_process_info(_ , {'EXIT', _}) ->
-  undefined;
-translate_process_info(_, Result) ->
-  Result.
+    try proc_info(Pid, Tag)
+    of
+        Result ->
+            Result
+    catch
+        _:_ -> undefined
+    end.
 
 %%% -----------------------------------------------------------
 %%% Misc. functions
diff --git a/lib/stdlib/test/proc_lib_SUITE.erl b/lib/stdlib/test/proc_lib_SUITE.erl
index 2818b5be6b..a013aabeb1 100644
--- a/lib/stdlib/test/proc_lib_SUITE.erl
+++ b/lib/stdlib/test/proc_lib_SUITE.erl
@@ -55,6 +55,16 @@
 -include_lib("common_test/include/ct.hrl").
 -endif.
 
+-define(do_catch(__X), do_catch(fun() -> __X end)).
+
+do_catch(F) ->
+    try {ok, F()}
+    catch
+        throw:R -> {throw, R};
+        exit:R -> {exit, R};
+        error:R:S -> {error, R, S}
+    end.
+
 suite() -> [{ct_hooks,[ts_install_cth]}].
 
 all() -> 
@@ -674,7 +684,7 @@ stop(_Config) ->
     false = erlang:is_process_alive(Pid1),
 
     %% Process does not exit
-    {'EXIT',noproc} = (catch proc_lib:stop(Pid1)),
+    {exit, noproc} = ?do_catch(proc_lib:stop(Pid1)),
 
     %% Badly handled system message
     DieProc =
@@ -685,7 +695,7 @@ stop(_Config) ->
 		end
 	end,
     Pid2 = proc_lib:spawn(DieProc),
-    {'EXIT',{die,_}} = (catch proc_lib:stop(Pid2)),
+    {exit, {die, _}} = ?do_catch(proc_lib:stop(Pid2)), 
 
     %% Hanging process => timeout
     HangProc =
@@ -696,13 +706,13 @@ stop(_Config) ->
 		end
 	end,
     Pid3 = proc_lib:spawn(HangProc),
-    {'EXIT',timeout} = (catch proc_lib:stop(Pid3,normal,1000)),
+    {exit, timeout} = ?do_catch(proc_lib:stop(Pid3,normal,1000)),
 
     %% Ensure that a termination message is always sent to the
     %% target process and that it eventually terminates.
     Pid4 = proc_lib:spawn(HangProc),
     Ref4 = monitor(process, Pid4),
-    {'EXIT', timeout} = (catch proc_lib:stop(Pid4, normal, 0)),
+    {exit, timeout} = ?do_catch(proc_lib:stop(Pid4, normal, 0)),
     ok = receive
 	{'DOWN', Ref4, process, _, _} ->
 	    ok;
@@ -720,7 +730,7 @@ stop(_Config) ->
     ok = proc_lib:stop(PidDieStop,die,2000),
     false = erlang:is_process_alive(PidDieStop),
     PidDieStopCrash = proc_lib:spawn(fun() -> timer:sleep(1000), exit(die) end),
-    {'EXIT', {die, _}} = catch (proc_lib:stop(PidDieStopCrash,normal,2000)),
+    {exit, {die, _}} = ?do_catch(proc_lib:stop(PidDieStopCrash,normal,2000)),
     false = erlang:is_process_alive(PidDieStopCrash),
 
     %% Success case with other reason than 'normal'
@@ -731,7 +741,7 @@ stop(_Config) ->
     %% System message is handled, but process dies with other reason
     %% than the given (in system_terminate/4 below)
     Pid6 = proc_lib:spawn(SysMsgProc),
-    {'EXIT',{{badmatch,2},_Stacktrace}} = (catch proc_lib:stop(Pid6,crash,infinity)),
+    {exit, {{badmatch, 2}, _}} = ?do_catch(proc_lib:stop(Pid6,crash,infinity)),
     false = erlang:is_process_alive(Pid6),
 
     %% Local registered name
@@ -753,13 +763,13 @@ stop(_Config) ->
     false = rpc:call(Node,erlang,is_process_alive,[Pid8]),
 
     %% Local and remote registered name, but non-existing
-    {'EXIT',noproc} = (catch proc_lib:stop(to_stop)),
-    {'EXIT',noproc} = (catch proc_lib:stop({to_stop,Node})),
+    {exit, noproc} = ?do_catch(proc_lib:stop(to_stop)),
+    {exit, noproc} = ?do_catch(proc_lib:stop({to_stop,Node})),
 
     true = test_server:stop_node(Node),
 
     %% Remote registered name, but non-existing node
-    {'EXIT',{{nodedown,Node},_}} = (catch proc_lib:stop({to_stop,Node})),
+    {exit, {{nodedown, Node}, _}} = ?do_catch(proc_lib:stop({to_stop,Node})),
     ok.
 
 system_terminate(crash,_Parent,_Deb,_State) ->
-- 
2.51.0

openSUSE Build Service is sponsored by