From dab11bf07c66e1f119cc5d6198c8e90c5a02219e Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Sun, 9 May 2010 12:19:16 -0400 Subject: handle {global, term()} names in format_status/2 The gen_fsm, gen_server, and wx_object format_status implementations fail to handle global names of the form {global, term()} where term() is something other than an atom, pid, or list. Change these format_status implementations to treat names that are atoms, pids, or lists as before, but for all other terms, set the header property of the function return value to a tuple whose first element is a string describing the return value and whose second element is the name term. Add unit tests for gen_server and gen_fsm to verify sys:get_status calls work successfully for globally registered instances. --- lib/stdlib/src/gen_fsm.erl | 15 +++++++++------ lib/stdlib/src/gen_server.erl | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/gen_fsm.erl b/lib/stdlib/src/gen_fsm.erl index 8d1b46d6ab..7d9960b912 100644 --- a/lib/stdlib/src/gen_fsm.erl +++ b/lib/stdlib/src/gen_fsm.erl @@ -614,12 +614,15 @@ get_msg(Msg) -> Msg. format_status(Opt, StatusData) -> [PDict, SysState, Parent, Debug, [Name, StateName, StateData, Mod, _Time]] = StatusData, - NameTag = if is_pid(Name) -> - pid_to_list(Name); - is_atom(Name) -> - Name - end, - Header = lists:concat(["Status for state machine ", NameTag]), + StatusHdr = "Status for state machine", + Header = if + is_pid(Name) -> + lists:concat([StatusHdr, " ", pid_to_list(Name)]); + is_atom(Name); is_list(Name) -> + lists:concat([StatusHdr, " ", Name]); + true -> + {StatusHdr, Name} + end, Log = sys:get_debug(log, Debug, []), DefaultStatus = [{data, [{"StateData", StateData}]}], Specfic = diff --git a/lib/stdlib/src/gen_server.erl b/lib/stdlib/src/gen_server.erl index dc8e7ecd16..ac81df9cab 100644 --- a/lib/stdlib/src/gen_server.erl +++ b/lib/stdlib/src/gen_server.erl @@ -840,12 +840,15 @@ name_to_pid(Name) -> %%----------------------------------------------------------------- format_status(Opt, StatusData) -> [PDict, SysState, Parent, Debug, [Name, State, Mod, _Time]] = StatusData, - NameTag = if is_pid(Name) -> - pid_to_list(Name); - is_atom(Name) -> - Name - end, - Header = lists:concat(["Status for generic server ", NameTag]), + StatusHdr = "Status for generic server", + Header = if + is_pid(Name) -> + lists:concat([StatusHdr, " ", pid_to_list(Name)]); + is_atom(Name); is_list(Name) -> + lists:concat([StatusHdr, " ", Name]); + true -> + {StatusHdr, Name} + end, Log = sys:get_debug(log, Debug, []), DefaultStatus = [{data, [{"State", State}]}], Specfic = -- cgit v1.2.3