From 466b964d3cd5cd599d1f9513f3b1a77156ad6578 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 29 Nov 2011 11:58:23 +0100 Subject: Fix dialyzer warning about gen_event callback init/1 in log_mf_h The warning is about log_mf_h having a different spec for gen_event callback init/1 than defined in gen_event.erl. log_mf_h allows return value {error,Reason}, while gen_even only specifies successful return values. This commit add {error,Reason} as a valid return value to the gen_event callback, since this is handled by the code. --- .../results/gen_event_incorrect_return | 2 +- lib/stdlib/doc/src/gen_event.xml | 17 ++++++++++------- lib/stdlib/src/gen_event.erl | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/dialyzer/test/behaviour_SUITE_data/results/gen_event_incorrect_return b/lib/dialyzer/test/behaviour_SUITE_data/results/gen_event_incorrect_return index 2afb5db133..e646eea383 100644 --- a/lib/dialyzer/test/behaviour_SUITE_data/results/gen_event_incorrect_return +++ b/lib/dialyzer/test/behaviour_SUITE_data/results/gen_event_incorrect_return @@ -1,2 +1,2 @@ -gen_event_incorrect_return.erl:16: The inferred return type of init/1 ('error') has nothing in common with {'ok',_} | {'ok',_,'hibernate'}, which is the expected return type for the callback of gen_event behaviour +gen_event_incorrect_return.erl:16: The inferred return type of init/1 ('error') has nothing in common with {'error',_} | {'ok',_} | {'ok',_,'hibernate'}, which is the expected return type for the callback of gen_event behaviour diff --git a/lib/stdlib/doc/src/gen_event.xml b/lib/stdlib/doc/src/gen_event.xml index 24bcb419fe..79a0c8ad89 100644 --- a/lib/stdlib/doc/src/gen_event.xml +++ b/lib/stdlib/doc/src/gen_event.xml @@ -195,12 +195,13 @@ gen_event:stop -----> Module:terminate/2 handlers using the same callback module.

Args is an arbitrary term which is passed as the argument to Module:init/1.

-

If Module:init/1 returns a correct value, the event - manager adds the event handler and this function returns +

If Module:init/1 returns a correct value indicating + successful completion, the event manager adds the event + handler and this function returns ok. If Module:init/1 fails with Reason or - returns an unexpected value Term, the event handler is + returns {error,Reason}, the event handler is ignored and this function returns {'EXIT',Reason} or - Term, respectively.

+ {error,Reason}, respectively.

@@ -448,12 +449,13 @@ gen_event:stop -----> Module:terminate/2 - Module:init(InitArgs) -> {ok,State} | {ok,State,hibernate} + Module:init(InitArgs) -> {ok,State} | {ok,State,hibernate} | {error,Reason} Initialize an event handler. InitArgs = Args | {Args,Term}  Args = Term = term() State = term() + Reason = term()

Whenever a new event handler is added to an event manager, @@ -470,8 +472,9 @@ gen_event:stop -----> Module:terminate/2 the argument provided in the function call/return tuple and Term is the result of terminating the old event handler, see gen_event:swap_handler/3.

-

The function should return {ok,State} or {ok,State, hibernate} - where State is the initial internal state of the event handler.

+

If successful, the function should return {ok,State} + or {ok,State,hibernate} where State is the + initial internal state of the event handler.

If {ok,State,hibernate} is returned, the event manager will go into hibernation (by calling proc_lib:hibernate/3), diff --git a/lib/stdlib/src/gen_event.erl b/lib/stdlib/src/gen_event.erl index 9879b76391..3317b30e5c 100644 --- a/lib/stdlib/src/gen_event.erl +++ b/lib/stdlib/src/gen_event.erl @@ -70,7 +70,8 @@ -callback init(InitArgs :: term()) -> {ok, State :: term()} | - {ok, State :: term(), hibernate}. + {ok, State :: term(), hibernate} | + {error, Reason :: term()}. -callback handle_event(Event :: term(), State :: term()) -> {ok, NewState :: term()} | {ok, NewState :: term(), hibernate} | -- cgit v1.2.3