[erlang-patches] Small fix to erl_interface legacy receive function

Göran Larsson A <>
Tue Apr 26 06:59:49 CEST 2011


When I was playing with the 'erl_interface' in an attempt to write a C++ wrapper for it, I used the 'cnode.c' test case from the 'erl_eterm_SUITE' as a base. Yes I know that the interface it uses is legacy, but it was an easy piece of code to start with.

The problem I got into was when trying to process rpc calls from an erlang node. The function 'erl_xreceive_msg' returned garbage in the 'to' and 'to_name' members of the message. The reason for that was found in the 'erl_do_receive_msg' function. When no 'pid' is provided by the sender, like when doing rpc calls as those uses registered name sends, it doesn't initialize the 'to' member and also the 'to_name' member is copied by the function.
 
The solution is a small modification to the 'erl_do_receive_msg' function in 'legacy/erl_connect.c' from line 294 (erl_interface-3.7.3). Unfortunatly I'm not able to use GIT due to firewall issues in China where I am currently. So have to provide the modified code snippet the old fashioned way!

---erl_connect.c--------------------------------------------------------
static int erl_do_receive_msg(int fd, ei_x_buff* x, ErlMessage* emsg)
{
    ...
    if (msg.from.node[0] != '\0')
        emsg->from = erl_mk_pid(msg.from.node, msg.from.num, msg.from.serial, msg.from.creation);
    else
        emsg->from = NULL; /* Uninitialized pointers are no fun */
    if (msg.to.node[0] != '\0')
        emsg->to = erl_mk_pid(msg.to.node, msg.to.num, msg.to.serial, msg.to.creation);
    else
        emsg->to = NULL; /* Uninitialized pointers are no fun */
    memcpy(emsg->to_name, msg.toname, MAXATOMLEN+1); /* We might be referred by registered name rather than by pid */
    return r;
}
------------------------------------------------------------------------

Regards,
Göran Larsson, Ericsson AB 


More information about the erlang-patches mailing list