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

sending message to a registered process via it's name does not work. #98

Closed
elsbiet opened this issue May 16, 2019 · 4 comments · Fixed by #631
Closed

sending message to a registered process via it's name does not work. #98

elsbiet opened this issue May 16, 2019 · 4 comments · Fixed by #631
Labels

Comments

@elsbiet
Copy link
Contributor

elsbiet commented May 16, 2019

running the pgm

-module(pr).
-export([start/0, ping/1, pong/0]).
ping(0) ->
pong ! finished,
erlang:display("ping finished");

ping(N) ->
erlang:display("ping started"),
pong ! {ping, self()},
erlang:display("ping sent"),
receive
pong ->
erlang:display("Ping received pong")
end,
ping(N - 1).

pong() ->
erlang:display("pong started"),
receive
finished ->
erlang:display("Pong finished");
{ping, Ping_PID} ->
erlang:display("Pong received ping"),
Ping_PID ! pong,
pong()
end.

start() ->
register(pong, spawn(pr, pong, [])),
spawn(pr, ping, [3]).

results in:
"pong started"
"ping started"
term is not a pid: a4b
"ping sent"
Hang detected

after replacing

pong ! Msg,

by

P = whereis(pong), P ! Msg,

the expected output
"pong started"
"ping started"
"ping sent"
"Pong received ping"
"pong started"
"Ping received pong"
"ping started"
"ping sent"
"Pong received ping"
"pong started"
"Ping received pong"
"ping started"
"ping sent"
"Pong received ping"
"pong started"
"Ping received pong"
"ping finished"
"Pong finished"
Return value: <0.3.0>

is displayed.

@bettio
Copy link
Collaborator

bettio commented Sep 4, 2019

Update: this bug is still here (tested on 1939abf)

@bettio bettio added the bug label Sep 4, 2019
@elsbiet
Copy link
Contributor Author

elsbiet commented Apr 28, 2021

still unresolved

UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 8, 2023
Changes `erlang:send/2' to accept a pid or registered process name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 8, 2023
Changes `erlang:send/2' to accept a pid or registered process name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 9, 2023
Changes `erlang:send/2' to accept a pid or registered process name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 9, 2023
Changes `erlang:send/2' to accept a pid or registered process name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 9, 2023
Changes `erlang:send/2' to accept a pid or registered process name.
Updates `tests/erlang_tests/test_send_nif_and_echo.erl` to send directly to the
registered name, and `tests/erlang_tests/test_send.erl` to test sending to an
an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 9, 2023
Changes `erlang:send/2' to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 9, 2023
Changes `erlang:send/2' to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 10, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 11, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 12, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 13, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 14, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 21, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 21, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 27, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 27, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Jun 27, 2023
Changes `erlang:send/2` to accept a pid or registered process name. Updates
`tests/erlang_tests/test_send_nif_and_echo.erl` to also test sending directly to the registered
name, and `tests/erlang_tests/test_send.erl` to test sending to an an unregistered `atom` name.

Fixes issue atomvm#98

Signed-off-by: Winford <winford@object.stream>
@bettio bettio closed this as completed in 9f82c26 Jun 28, 2023
@fadushin
Copy link
Collaborator

This issue is still open, if you consider the send operator (!), which the original poster used. #631 addresses the Erlang:send nif, not the OP_SEND opcode.

Here is a simpler example to reproduce the error:

-module(test).

-export([start/0]).

start() ->
    Pid = spawn_opt(fun loop/0, []),
    register(foo, Pid),
    foo ! {ping, self()},
    receive
        pong ->
            ok
    after 1000 ->
        timeout
    end.

loop() ->
    receive
        {ping, Pid} ->
            Pid ! pong,
            loop()
    end.

On OTP:

Eshell V12.3.2.15  (abort with ^G)
1> test:start().
ok

On AtomVM:

> atomvm test.beam
Unsupported line_ref tag: 0
Return value: timeout

I believe the issue may relate to the current implementation of the send opcode:

            case OP_SEND: {
                #ifdef IMPL_CODE_LOADER
                    TRACE("send/0\n");
                #endif

                #ifdef IMPL_EXECUTE_LOOP
                    int local_process_id = term_to_local_process_id(x_regs[0]);
                    TRACE("send/0 target_pid=%i\n", local_process_id);
                    TRACE_SEND(ctx, x_regs[0], x_regs[1]);
                    globalcontext_send_message(ctx->global, local_process_id, x_regs[1]);

                    x_regs[0] = x_regs[1];
                #endif
                break;
            }

As you can see, we are assuming the term in the 0th x-register is a Pid, when in fact it could be an atom.

@UncleGrumpy
Copy link
Collaborator

The oversight of missing OP_SEND opcode is finally addressed in #1047.

UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 18, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 19, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 19, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 19, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 19, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 19, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Feb 19, 2024
Enables sending messages to registered processes using the shorhand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

closes atomvm#1011
closes atomvm#98

Signed-off-by: Winford <winford@object.stream>
bettio added a commit that referenced this issue Feb 22, 2024
Allow sending messages to registered process with `!`

Enables sending messages to registered processes using the shorthand `!`
operator. If a message is sent to an atom name that is not registered using the
`!` operator a `badarg` run-time error occurs, matching OTP behaviour.

Closes #1011
Closes #98

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
@bettio bettio closed this as completed in eab4e32 Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants