diff options
author | Björn Gustavsson <[email protected]> | 2019-06-03 11:28:59 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2019-06-03 11:28:59 +0200 |
commit | fbee646c4ff63327512f25eb07be0ede66e55599 (patch) | |
tree | 2e077ed99baf611adf6d52c6a6b1d0aab26356ce /lib/erl_interface/src/misc/ei_printterm.c | |
parent | 6e3ce6cac718ff0eae1349eb0b4ab8513abba343 (diff) | |
parent | 5fef9df3faf0504c5c281a5720b992c19c94a6c2 (diff) | |
download | otp-fbee646c4ff63327512f25eb07be0ede66e55599.tar.gz otp-fbee646c4ff63327512f25eb07be0ede66e55599.tar.bz2 otp-fbee646c4ff63327512f25eb07be0ede66e55599.zip |
Merge pull request #2246 from bjorng/bjorn/erl_interface/term-printing/OTP-15814
Support printing of maps and funs in ei_print_term()
Diffstat (limited to 'lib/erl_interface/src/misc/ei_printterm.c')
-rw-r--r-- | lib/erl_interface/src/misc/ei_printterm.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/erl_interface/src/misc/ei_printterm.c b/lib/erl_interface/src/misc/ei_printterm.c index 5c40fb7747..a94d6e2ad8 100644 --- a/lib/erl_interface/src/misc/ei_printterm.c +++ b/lib/erl_interface/src/misc/ei_printterm.c @@ -121,6 +121,7 @@ static int print_term(FILE* fp, ei_x_buff* x, erlang_pid pid; erlang_port port; erlang_ref ref; + erlang_fun fun; double d; long l; @@ -306,12 +307,46 @@ static int print_term(FILE* fp, ei_x_buff* x, } break; - case ERL_FLOAT_EXT: case NEW_FLOAT_EXT: if (ei_decode_double(buf, index, &d) < 0) goto err; ch_written += xprintf(fp, x, "%f", d); break; + case ERL_MAP_EXT: + if (ei_decode_map_header(buf, &tindex, &n) < 0) goto err; + ch_written += xprintf(fp, x, "#{"); + for (i = 0; i < n; ++i) { + r = print_term(fp, x, buf, &tindex); + if (r < 0) goto err; + ch_written += r; + ch_written += xprintf(fp, x, " => "); + r = print_term(fp, x, buf, &tindex); + if (r < 0) goto err; + ch_written += r; + if (i < n-1) { + xputs(", ", fp, x); ch_written += 2; + } + } + *index = tindex; + xputc('}', fp, x); ch_written++; + break; + case ERL_FUN_EXT: + case ERL_NEW_FUN_EXT: + case ERL_EXPORT_EXT: + if (ei_decode_fun(buf, &tindex, &fun) < 0) goto err; + if (fun.type == EI_FUN_EXPORT) { + ch_written += xprintf(fp, x, "fun %s:%s/%ld", + fun.module, + fun.u.exprt.func, + fun.arity); + } else { + ch_written += xprintf(fp, x, "#Fun{%s.%ld.%lu}", + fun.module, + fun.u.closure.index, + fun.u.closure.uniq); + } + *index = tindex; + break; default: goto err; } |