Skip to content

Commit

Permalink
Merge pull request #1416 from pguyot/w52/fix-gen_server-internal-mess…
Browse files Browse the repository at this point in the history
…ages

Fix gen server internal messages

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Dec 26, 2024
2 parents 421a4f2 + b50438f commit a0a0a5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Introduce ports to represent native processes and added support for external ports and encoded ports in external terms
- Added `atomvm:get_creation/0`, equivalent to `erts_internal:get_creation/0`

### Fixed

- Fixed `gen_server` internal messages to match OTP so it works across erlang distribution

## [0.6.6] - Unreleased

### Added
Expand Down
8 changes: 4 additions & 4 deletions libs/estdlib/src/gen_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ call(Name, Request, TimeoutMs) when is_atom(Name) ->
end;
call(Pid, Request, TimeoutMs) when is_pid(Pid) ->
MonitorRef = monitor(process, Pid),
Pid ! {'$call', {self(), MonitorRef}, Request},
Pid ! {'$gen_call', {self(), MonitorRef}, Request},
receive
{'DOWN', MonitorRef, process, Pid, {E, []} = _Reason} ->
erlang:exit({E, {?MODULE, ?FUNCTION_NAME, [Pid, Request]}});
Expand Down Expand Up @@ -475,7 +475,7 @@ cast(Name, Request) when is_atom(Name) ->
cast(Pid, Request)
end;
cast(Pid, Request) when is_pid(Pid) ->
Pid ! {'$cast', Request},
Pid ! {'$gen_cast', Request},
ok.

%%-----------------------------------------------------------------------------
Expand Down Expand Up @@ -510,7 +510,7 @@ loop(#state{mod = Mod, mod_state = ModState} = State, {continue, Continue}) ->
end;
loop(#state{mod = Mod, mod_state = ModState} = State, Timeout) ->
receive
{'$call', {_Pid, _Ref} = From, Request} ->
{'$gen_call', {_Pid, _Ref} = From, Request} ->
case Mod:handle_call(Request, From, ModState) of
{reply, Reply, NewModState} ->
ok = reply(From, Reply),
Expand All @@ -535,7 +535,7 @@ loop(#state{mod = Mod, mod_state = ModState} = State, Timeout) ->
_ ->
do_terminate(State, {error, unexpected_reply}, ModState)
end;
{'$cast', Request} ->
{'$gen_cast', Request} ->
case Mod:handle_cast(Request, ModState) of
{noreply, NewModState} ->
loop(State#state{mod_state = NewModState}, infinity);
Expand Down

0 comments on commit a0a0a5b

Please sign in to comment.