Skip to content

Commit

Permalink
Merge pull request dwango#1 from amutake/otp-21
Browse files Browse the repository at this point in the history
Support OTP-21
  • Loading branch information
sile authored Jun 20, 2018
2 parents e63b152 + 8ae8c56 commit b3f6829
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: erlang
otp_release:
- 21.0
- 20.3
- 19.3
- 18.3
Expand Down
7 changes: 7 additions & 0 deletions include/moyo_internal.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-ifdef('FUN_STACKTRACE').
-define(CAPTURE_STACKTRACE, ).
-define(GET_STACKTRACE, erlang:get_stacktrace()).
-else.
-define(CAPTURE_STACKTRACE, :__StackTrace).
-define(GET_STACKTRACE, __StackTrace).
-endif.
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
%% erlangのコンパイルオプション.
{erl_opts, [
warnings_as_errors,
warn_untyped_record
warn_untyped_record,
{platform_define, "^(R|1|20)", 'FUN_STACKTRACE'}
]}.


Expand Down
3 changes: 2 additions & 1 deletion src/moyo_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-module(moyo_file).

-include_lib("kernel/include/file.hrl").
-include("moyo_internal.hrl").

%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
Expand Down Expand Up @@ -98,7 +99,7 @@ get_disk_usage_async(Path, Pid, Tag) ->
try
get_disk_usage(Path)
catch
Class:Reason -> {error, {Class, Reason, erlang:get_stacktrace()}}
Class:Reason ?CAPTURE_STACKTRACE -> {error, {Class, Reason, ?GET_STACKTRACE}}
end,
Pid ! {Tag, Result}
end),
Expand Down
10 changes: 6 additions & 4 deletions src/moyo_fun.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
%% @doc 関数に関する処理を集めたユーティリティモジュール.
-module(moyo_fun).

-include("moyo_internal.hrl").

%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
%%----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -64,8 +66,8 @@ try_apply(Module, Function, Args) ->
try
apply(Module, Function, Args)
catch
Class:Reason ->
{error, {'EXIT', {Class, Reason, erlang:get_stacktrace()}}}
Class:Reason ?CAPTURE_STACKTRACE ->
{error, {'EXIT', {Class, Reason, ?GET_STACKTRACE}}}
end.

%% @doc 指定された関数を実行する. 実行中に例外が発生した場合は`ErrorResult'を返す
Expand All @@ -87,8 +89,8 @@ try_call(Fun) ->
try
Fun()
catch
Class:Reason ->
{error, {'EXIT', {Class, Reason, erlang:get_stacktrace()}}}
Class:Reason ?CAPTURE_STACKTRACE ->
{error, {'EXIT', {Class, Reason, ?GET_STACKTRACE}}}
end.

%% @doc 引数の関数を実行する. 実行中に例外が発生した場合は`ErrorResult'を返す
Expand Down
5 changes: 4 additions & 1 deletion src/moyo_list.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
%% @doc リストに関する処理を集めたユーティリティモジュール.
-module(moyo_list).

-include("moyo_internal.hrl").

%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
%%----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -413,7 +415,8 @@ pmap_call(Fun ,Arg) ->
SomeResult -> {error, {'EXIT', SomeResult}}
end
catch
ExceptionClass:SomeReason -> {error, {'EXIT', ExceptionClass, SomeReason, erlang:get_stacktrace()}}
ExceptionClass:SomeReason ?CAPTURE_STACKTRACE ->
{error, {'EXIT', ExceptionClass, SomeReason, ?GET_STACKTRACE}}
end.

-spec pmap_receive(Ref, {Count, Results}) -> Results when
Expand Down
6 changes: 4 additions & 2 deletions src/moyo_pipe.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
%% 現在は出力機能にのみ対応済み
-module(moyo_pipe).

-include("moyo_internal.hrl").

%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
%%----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -100,13 +102,13 @@ output_loop(State) ->
try
true = port_command(Port, Data)
catch
error:badarg ->
error:badarg ?CAPTURE_STACKTRACE ->
case erlang:port_info(Port) of
undefined ->
%% ポートが閉じている(コマンドの実行が終了している)ので、出力プロセスも終了
exit(normal);
_ ->
erlang:raise(error, badarg, erlang:get_stacktrace())
erlang:raise(error, badarg, ?GET_STACKTRACE)
end
end,
ok = timer:sleep(Interval),
Expand Down

0 comments on commit b3f6829

Please sign in to comment.