Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modify list_to_pid and pid_to_list to use pid(1,2,3) instead of <1.2.3>

  • Loading branch information...
commit 6f6425e9af7dd007b0cf27ae6bb9ce96d7c3147d 1 parent 061132c
@RJ authored
View
28 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
==========
View
48 erts/emulator/beam/bif.c
@@ -3791,23 +3791,47 @@ BIF_RETTYPE list_to_pid_1(BIF_ALIST_1)
buf[i] = '\0'; /* null terminal */
cp = buf;
- if (*cp++ != '<') goto bad;
-
- if (*cp < '0' || *cp > '9') goto bad;
- while(*cp >= '0' && *cp <= '9') { a = 10*a + (*cp - '0'); cp++; }
+ switch (*cp++) {
+ case 'p': // pid(1,2,3)
+ if (*cp++ != 'i') goto bad;
+ 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;
- while(*cp >= '0' && *cp <= '9') { b = 10*b + (*cp - '0'); cp++; }
+ if (*cp++ != ')') goto bad;
+ 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;
- while(*cp >= '0' && *cp <= '9') { c = 10*c + (*cp - '0'); cp++; }
+ if (*cp < '0' || *cp > '9') goto bad;
+ while(*cp >= '0' && *cp <= '9') { b = 10*b + (*cp - '0'); cp++; }
- if (*cp++ != '>') goto bad;
- if (*cp != '\0') 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++ != '>') goto bad;
+ if (*cp != '\0') goto bad;
+ break;
+ default: // that's no pid
+ goto bad;
+ }
erts_free(ERTS_ALC_T_TMP, (void *) buf);
buf = NULL;
View
8 erts/emulator/beam/erl_printf_term.c
@@ -371,16 +371,16 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount,
break;
case 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,
(unsigned long) pid_channel_no(wobj));
- PRINT_CHAR(res, fn, arg, '.');
+ PRINT_CHAR(res, fn, arg, ',');
PRINT_ULONG(res, fn, arg, 'u', 0, 1,
(unsigned long) pid_number(wobj));
- PRINT_CHAR(res, fn, arg, '.');
+ PRINT_CHAR(res, fn, arg, ',');
PRINT_ULONG(res, fn, arg, 'u', 0, 1,
(unsigned long) pid_serial(wobj));
- PRINT_CHAR(res, fn, arg, '>');
+ PRINT_CHAR(res, fn, arg, ')');
break;
case PORT_DEF:
case EXTERNAL_PORT_DEF:
Please sign in to comment.
Something went wrong with that request. Please try again.