File 7931-Use-the-pre-cached-callback_mode-value-for-logger.patch of Package erlang

From 26fb239a8091dc243df391d8da82c0ce76d73591 Mon Sep 17 00:00:00 2001
From: Raimo Niskanen <raimo@erlang.org>
Date: Tue, 9 Jul 2024 10:17:50 +0200
Subject: [PATCH] Use the pre cached callback_mode value for logger

---
 lib/stdlib/src/gen_statem.erl        | 13 +++++++++++--
 lib/stdlib/test/gen_statem_SUITE.erl | 20 ++++++++++++++------
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index 2dab3ec112..6d4b2a83bf 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -1526,7 +1526,7 @@ format_status(Status) ->
 
 
 %% Helper function for #params.callback_mode, that caches callback_mode()
--compile({inline, [params_callback_mode/2]}).
+-compile({inline, [params_callback_mode/2, params_callback_mode/1]}).
 params_callback_mode(CallbackMode, Modules) ->
     case CallbackMode of
         state_functions -> CallbackMode;
@@ -1534,6 +1534,15 @@ params_callback_mode(CallbackMode, Modules) ->
             Module = hd(Modules),
             fun Module:handle_event/4
 end.
+%%
+%% Inverse of the above - return the callback_mode() value before caching
+params_callback_mode(CallbackMode) ->
+    case CallbackMode of
+        state_functions ->
+            CallbackMode;
+        HandleEventFun when is_function(HandleEventFun, 4) ->
+            handle_event_function
+    end.
 
 %% Type validation functions
 %% - return true if the value is of the type, false otherwise
@@ -4355,7 +4364,7 @@ error_info(
                  queue=>maps:get(queue,Status),
                  postponed=>maps:get(postponed,Status),
                  modules=>Modules,
-                 callback_mode=>CallbackMode,
+                 callback_mode=>params_callback_mode(CallbackMode),
                  state_enter=>StateEnter,
                  state=>NewState,
                  timeouts=>{NumTimers,maps:get(timeouts,Status)},
diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl
index a9e6944541..e3b0264510 100644
--- a/lib/stdlib/test/gen_statem_SUITE.erl
+++ b/lib/stdlib/test/gen_statem_SUITE.erl
@@ -1405,16 +1405,21 @@ terminate_crash_format(Config) ->
     error_logger_forwarder:register(),
     OldFl = process_flag(trap_exit, true),
     try
-        terminate_crash_format(Config,?MODULE,{formatted,idle,crash_terminate}),
-        terminate_crash_format(Config,format_status_statem,
-                               {{formatted,idle},{formatted,crash_terminate}})
+        terminate_crash_format(
+          Config, ?MODULE, {formatted,idle,crash_terminate}, state_functions),
+        terminate_crash_format(
+          Config, format_status_statem,
+          {{formatted,idle},{formatted,crash_terminate}}, state_functions),
+        terminate_crash_format(
+          [{callback_mode,handle_event_function} | Config], ?MODULE,
+          {formatted,idle,crash_terminate}, handle_event_function)
     after
         dbg:stop(),
         process_flag(trap_exit, OldFl),
         error_logger_forwarder:unregister()
     end.
 
-terminate_crash_format(Config, Module, Match) ->
+terminate_crash_format(Config, Module, State, CallbackMode) ->
     Data = crash_terminate,
     {ok,Pid} =
 	gen_statem:start(
@@ -1424,10 +1429,13 @@ terminate_crash_format(Config, Module, Match) ->
     receive
 	{error,_GroupLeader,
 	 {Pid,
-	  "** State machine"++_,
+	  "** State machine "++_,
 	  [Pid,
 	   {{call,{Self,_}},stop},
-	   Match,exit,{crash,terminate}|_]}} ->
+	   State,
+           exit, {crash,terminate},
+           [Module],
+           CallbackMode | _]}} ->
 	    ok;
 	Other when is_tuple(Other), element(1, Other) =:= error ->
 	    ct:fail({unexpected,Other})
-- 
2.35.3

openSUSE Build Service is sponsored by