Skip to content

Commit

Permalink
modify list_to_pid and pid_to_list to use pid(1,2,3) instead of <1.2.3>
Browse files Browse the repository at this point in the history
  • Loading branch information
RJ committed Nov 28, 2011
1 parent 061132c commit 6f6425e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
28 changes: 28 additions & 0 deletions README.md
@@ -1,3 +1,31 @@
RJ's FORK NOTES
===============
Sick of pasting debug output into the erlang shell only to have it choke on
pids, since list\_to\_pid gives: `<1.2.3>`, which isn't a valid erlang term.

I've changed list\_to\_pid to return pid(1,2,3) and pid\_to\_list to accept it:

Erlang R15B (erts-5.9) [source] [smp:4:4] [rq:4] [async-threads:0] [hipe]
[kernel-poll:false]

<pre>
Eshell V5.9 (abort with ^G)
1> pid_to_list(self()).
"pid(0,31,0)"
2> list_to_pid(v(1)).
pid(0,31,0)
3> erlang:is_process_alive(v(2)).
true
4> io:format("my pid is: ~w~n",[self()]).
my pid is: pid(0,31,0)
ok
5> list_to_pid("&lt;0.31.0&gt;"). %% Old format still accepted
pid(0,31,0)

</pre>



Erlang/OTP Erlang/OTP
========== ==========


Expand Down
48 changes: 36 additions & 12 deletions erts/emulator/beam/bif.c
Expand Up @@ -3791,23 +3791,47 @@ BIF_RETTYPE list_to_pid_1(BIF_ALIST_1)
buf[i] = '\0'; /* null terminal */ buf[i] = '\0'; /* null terminal */


cp = buf; cp = buf;
if (*cp++ != '<') goto bad; switch (*cp++) {

case 'p': // pid(1,2,3)
if (*cp < '0' || *cp > '9') goto bad; if (*cp++ != 'i') goto bad;
while(*cp >= '0' && *cp <= '9') { a = 10*a + (*cp - '0'); cp++; } if (*cp++ != 'd') goto bad;
if (*cp++ != '(') goto bad;
if (*cp < '0' || *cp > '9') goto bad;
while(*cp >= '0' && *cp <= '9') { a = 10*a + (*cp - '0'); cp++; }

if (*cp++ != ',') goto bad;

if (*cp < '0' || *cp > '9') goto bad;
while(*cp >= '0' && *cp <= '9') { b = 10*b + (*cp - '0'); cp++; }

if (*cp++ != ',') goto bad;


if (*cp++ != '.') goto bad; if (*cp < '0' || *cp > '9') goto bad;
while(*cp >= '0' && *cp <= '9') { c = 10*c + (*cp - '0'); cp++; }


if (*cp < '0' || *cp > '9') goto bad; if (*cp++ != ')') goto bad;
while(*cp >= '0' && *cp <= '9') { b = 10*b + (*cp - '0'); cp++; } if (*cp != '\0') goto bad;
break;
case '<': // <1.2.3>
if (*cp < '0' || *cp > '9') goto bad;
while(*cp >= '0' && *cp <= '9') { a = 10*a + (*cp - '0'); cp++; }


if (*cp++ != '.') goto bad; if (*cp++ != '.') goto bad;


if (*cp < '0' || *cp > '9') goto bad; if (*cp < '0' || *cp > '9') goto bad;
while(*cp >= '0' && *cp <= '9') { c = 10*c + (*cp - '0'); cp++; } while(*cp >= '0' && *cp <= '9') { b = 10*b + (*cp - '0'); cp++; }


if (*cp++ != '>') goto bad; if (*cp++ != '.') goto bad;
if (*cp != '\0') goto bad;
if (*cp < '0' || *cp > '9') goto bad;
while(*cp >= '0' && *cp <= '9') { c = 10*c + (*cp - '0'); cp++; }

if (*cp++ != '>') goto bad;
if (*cp != '\0') goto bad;
break;
default: // that's no pid
goto bad;
}


erts_free(ERTS_ALC_T_TMP, (void *) buf); erts_free(ERTS_ALC_T_TMP, (void *) buf);
buf = NULL; buf = NULL;
Expand Down
8 changes: 4 additions & 4 deletions erts/emulator/beam/erl_printf_term.c
Expand Up @@ -371,16 +371,16 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
break; break;
case PID_DEF: case PID_DEF:
case EXTERNAL_PID_DEF: case EXTERNAL_PID_DEF:
PRINT_CHAR(res, fn, arg, '<'); PRINT_STRING(res, fn, arg, "pid(");
PRINT_ULONG(res, fn, arg, 'u', 0, 1, PRINT_ULONG(res, fn, arg, 'u', 0, 1,
(unsigned long) pid_channel_no(wobj)); (unsigned long) pid_channel_no(wobj));
PRINT_CHAR(res, fn, arg, '.'); PRINT_CHAR(res, fn, arg, ',');
PRINT_ULONG(res, fn, arg, 'u', 0, 1, PRINT_ULONG(res, fn, arg, 'u', 0, 1,
(unsigned long) pid_number(wobj)); (unsigned long) pid_number(wobj));
PRINT_CHAR(res, fn, arg, '.'); PRINT_CHAR(res, fn, arg, ',');
PRINT_ULONG(res, fn, arg, 'u', 0, 1, PRINT_ULONG(res, fn, arg, 'u', 0, 1,
(unsigned long) pid_serial(wobj)); (unsigned long) pid_serial(wobj));
PRINT_CHAR(res, fn, arg, '>'); PRINT_CHAR(res, fn, arg, ')');
break; break;
case PORT_DEF: case PORT_DEF:
case EXTERNAL_PORT_DEF: case EXTERNAL_PORT_DEF:
Expand Down

0 comments on commit 6f6425e

Please sign in to comment.