Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ra_machine: Allow the version/0 callback to return 0 #399

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/ra_machine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@

-callback snapshot_module() -> module().

-callback version() -> pos_integer().
-callback version() -> version().

-callback which_module(version()) -> module().

Expand Down Expand Up @@ -291,11 +291,17 @@ overview(Mod, State) ->
%% code
-spec version(machine()) -> version().
version({machine, Mod, _}) ->
?OPT_CALL(assert_integer(Mod:version()), ?DEFAULT_VERSION).
?OPT_CALL(assert_version(Mod:version()), ?DEFAULT_VERSION).

-spec is_versioned(machine()) -> boolean().
is_versioned(Machine) ->
version(Machine) /= ?DEFAULT_VERSION.
is_versioned({machine, Mod, _}) ->
try
_ = Mod:version(),
true
catch
error:undef ->
false
end.

-spec which_module(machine(), version()) -> module().
which_module({machine, Mod, _}, Version) ->
Expand Down Expand Up @@ -349,5 +355,5 @@ snapshot_module({machine, Mod, _}) ->

%% internals

assert_integer(I) when is_integer(I) andalso I > 0 ->
assert_version(I) when is_integer(I) andalso I >= 0 ->
I.
Loading