From 9dfb4e6cf574870ac6e6a5a2a507c989c64e7525 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Tue, 1 Mar 2016 08:31:58 +0100 Subject: Change code_change/4 to {ok,State,Data} --- lib/stdlib/doc/src/gen_statem.xml | 4 ++-- lib/stdlib/src/gen_statem.erl | 4 ++-- lib/stdlib/test/gen_statem_SUITE.erl | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/stdlib/doc/src/gen_statem.xml b/lib/stdlib/doc/src/gen_statem.xml index 04b80d29ac..01be3099c1 100644 --- a/lib/stdlib/doc/src/gen_statem.xml +++ b/lib/stdlib/doc/src/gen_statem.xml @@ -241,7 +241,7 @@ stop() -> terminate(_Reason, _State, _Data) -> void. code_change(_Vsn, State, Data, _Extra) -> - {ok,{State,Data}}. + {ok,State,Data}. init([]) -> %% Set the callback mode and initial state + data. %% Data is used only as a counter. @@ -1359,7 +1359,7 @@ ok   Vsn = term() OldState = NewState = term() Extra = term() - Result = {ok,{NewState,NewData}} | Reason + Result = {ok,NewState,NewData} | Reason OldState = NewState = state() diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl index 17d361efc2..cc09efc140 100644 --- a/lib/stdlib/src/gen_statem.erl +++ b/lib/stdlib/src/gen_statem.erl @@ -200,7 +200,7 @@ OldState :: state(), OldData :: data(), Extra :: term()) -> - {ok, {NewState :: state(), NewData :: data()}}. + {ok, NewState :: state(), NewData :: data()}. %% Format the callback module state in some sensible that is %% often condensed way. For StatusOption =:= 'normal' the perferred @@ -619,7 +619,7 @@ system_code_change( Result -> Result end of - {ok,{NewState,NewData}} -> + {ok,NewState,NewData} -> {ok, S#{ state := NewState, diff --git a/lib/stdlib/test/gen_statem_SUITE.erl b/lib/stdlib/test/gen_statem_SUITE.erl index f605f0c7b9..573a64bbb7 100644 --- a/lib/stdlib/test/gen_statem_SUITE.erl +++ b/lib/stdlib/test/gen_statem_SUITE.erl @@ -55,7 +55,7 @@ groups() -> {abnormal, [], [abnormal1, abnormal2]}, {abnormal_handle_event, [], [abnormal1, abnormal2]}, {sys, [], - [sys1, + [sys1, code_change, call_format_status, error_format_status, terminate_crash_format, get_state, replace_state]}, @@ -633,6 +633,15 @@ sys1(Config) -> sys:resume(Pid), stop_it(Pid). +code_change(Config) -> + {ok,Pid} = gen_statem:start(?MODULE, start_arg(Config, []), []), + {idle,data} = sys:get_state(Pid), + sys:suspend(Pid), + sys:change_code(Pid, ?MODULE, old_vsn, extra), + sys:resume(Pid), + {idle,{old_vsn,data,extra}} = sys:get_state(Pid), + stop_it(Pid). + call_format_status(Config) -> {ok,Pid} = gen_statem:start(?MODULE, start_arg(Config, []), []), Status = sys:get_status(Pid), @@ -1550,8 +1559,8 @@ wrap_result(Result) -> -code_change(_OldVsn, State, Data, _Extra) -> - {ok,State,Data}. +code_change(OldVsn, State, Data, Extra) -> + {ok,State,{OldVsn,Data,Extra}}. format_status(terminate, [_Pdict,State,Data]) -> {formatted,State,Data}; -- cgit v1.2.3