From ad2d57d8b62b86ec1f3d03441f7defa595f2c59c Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Wed, 2 May 2018 21:47:52 -0400 Subject: [PATCH] Work around OTP-21 deprecation of get_stacktrace() --- rebar.config | 1 + src/ec_plists.erl | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/rebar.config b/rebar.config index 668108d..e705b66 100644 --- a/rebar.config +++ b/rebar.config @@ -15,6 +15,7 @@ {platform_define, "^1[8|9]", rand_module}, {platform_define, "^2", rand_module}, {platform_define, "^2", unicode_str}, + {platform_define, "^(R|1|20)", fun_stacktrace}, debug_info, warnings_as_errors]}. diff --git a/src/ec_plists.erl b/src/ec_plists.erl index e3c2175..50f122e 100644 --- a/src/ec_plists.erl +++ b/src/ec_plists.erl @@ -822,20 +822,7 @@ cluster_runmany(Fun, Fuse, [Task|TaskList], [N|Nodes], Running, Results) -> Parent ! {erlang:self(), fuse, FuseFunc(R1, R2)} end end, - Fun3 = fun () -> - try - Fun2() - catch - exit:siblingdied -> - ok; - exit:Reason -> - Parent ! {erlang:self(), error, Reason}; - error:R -> - Parent ! {erlang:self(), error, {R, erlang:get_stacktrace()}}; - throw:R -> - Parent ! {erlang:self(), error, {{nocatch, R}, erlang:get_stacktrace()}} - end - end, + Fun3 = fun() -> runmany_wrap(Fun2, Parent) end, Pid = proc_lib:spawn(N, Fun3), erlang:monitor(process, Pid), cluster_runmany(Fun, Fuse, TaskList, Nodes, [{Pid, N, Task}|Running], Results); @@ -885,6 +872,36 @@ cluster_runmany(_, _, [_Non|_Empty], []=_Nodes, []=_Running, _) -> %% We have data, but no nodes either available or occupied erlang:exit(allnodescrashed). +-ifdef(fun_stacktrace). +runmany_wrap(Fun, Parent) -> + try + Fun + catch + exit:siblingdied -> + ok; + exit:Reason -> + Parent ! {erlang:self(), error, Reason}; + error:R -> + Parent ! {erlang:self(), error, {R, erlang:get_stacktrace()}}; + throw:R -> + Parent ! {erlang:self(), error, {{nocatch, R}, erlang:get_stacktrace()}} + end. +-else. +runmany_wrap(Fun, Parent) -> + try + Fun + catch + exit:siblingdied -> + ok; + exit:Reason -> + Parent ! {erlang:self(), error, Reason}; + error:R:Stacktrace -> + Parent ! {erlang:self(), error, {R, Stacktrace}}; + throw:R:Stacktrace -> + Parent ! {erlang:self(), error, {{nocatch, R}, Stacktrace}} + end. +-endif. + delete_running(Pid, [{Pid, Node, List}|Running], Acc) -> {Running ++ Acc, Node, List}; delete_running(Pid, [R|Running], Acc) ->