diff options
author | Björn Gustavsson <[email protected]> | 2019-05-21 09:02:00 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2019-05-29 16:31:06 +0200 |
commit | 5fef9df3faf0504c5c281a5720b992c19c94a6c2 (patch) | |
tree | 6722280600acf117b75148507b710eb28ee213e2 /lib/erl_interface/test/ei_print_SUITE_data | |
parent | 3d7b35dcc7852ec735f39a66566f80f8dad65701 (diff) | |
download | otp-5fef9df3faf0504c5c281a5720b992c19c94a6c2.tar.gz otp-5fef9df3faf0504c5c281a5720b992c19c94a6c2.tar.bz2 otp-5fef9df3faf0504c5c281a5720b992c19c94a6c2.zip |
Teach ei_print_term() to print funs
Diffstat (limited to 'lib/erl_interface/test/ei_print_SUITE_data')
-rw-r--r-- | lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c | 75 |
1 files changed, 66 insertions, 9 deletions
diff --git a/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c b/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c index 685596e34a..0e2b24e45a 100644 --- a/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c +++ b/lib/erl_interface/test/ei_print_SUITE_data/ei_print_test.c @@ -49,15 +49,22 @@ send_printed_buf(ei_x_buff* x) f = fopen(fn, "w+"); ei_decode_version(x->buff, &index, &ver); n = ei_print_term(f, x->buff, &index); - fseek(f, 0, SEEK_SET); - b = malloc(n+1); - fread(b, 1, n, f); - b[n] = '\0'; - fclose(f); - x->index = 0; - ei_x_format(x, "~s", b); - send_bin_term(x); - free(b); + if (n < 0) { + fclose(f); + x->index = 0; + ei_x_format(x, "~s", "ERROR: term decoding failed"); + send_bin_term(x); + } else { + fseek(f, 0, SEEK_SET); + b = malloc(n+1); + fread(b, 1, n, f); + b[n] = '\0'; + fclose(f); + x->index = 0; + ei_x_format(x, "~s", b); + send_bin_term(x); + free(b); + } } @@ -231,3 +238,53 @@ TESTCASE(maps) report(1); } +TESTCASE(funs) +{ + ei_x_buff x; + erlang_pid self; + erlang_fun fun; + + strcpy(self.node, "node@host"); + self.num = 9; + self.serial = 99; + self.creation = 1; + + ei_init(); + + ei_x_new_with_version(&x); + fun.arity = -1; /* Will encode as FUN_EXT */ + strcpy(fun.module, "some_module"); + fun.type = EI_FUN_CLOSURE; + fun.u.closure.pid = self; + fun.u.closure.index = fun.u.closure.old_index = 42; + fun.u.closure.uniq = 0xDEADBEEF; + fun.u.closure.n_free_vars = 0; + fun.u.closure.free_var_len = 0; + ei_x_encode_fun(&x, &fun); + send_printed_buf(&x); + ei_x_free(&x); + + ei_x_new_with_version(&x); + fun.arity = 0; /* Will encode as NEW_FUN_EXT */ + strcpy(fun.module, "some_module"); + fun.type = EI_FUN_CLOSURE; + fun.u.closure.pid = self; + fun.u.closure.index = fun.u.closure.old_index = 37; + fun.u.closure.uniq = 0xBADBEEF; + fun.u.closure.n_free_vars = 0; + fun.u.closure.free_var_len = 0; + ei_x_encode_fun(&x, &fun); + send_printed_buf(&x); + ei_x_free(&x); + + ei_x_new_with_version(&x); + fun.arity = 1; + strcpy(fun.module, "erlang"); + fun.type = EI_FUN_EXPORT; + fun.u.exprt.func = "abs"; + ei_x_encode_fun(&x, &fun); + send_printed_buf(&x); + ei_x_free(&x); + + report(1); +} |