From 5f707ea8f42c87803ee18c940f12281a82d15c4e Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 11 Apr 2019 16:32:06 +0300 Subject: [PATCH] Allowing to output large values in console.log(). Previously, the size was limited to 2048 bytes. This closes #127 issue on Github. --- njs/njs_shell.c | 9 ++++++--- nxt/nxt_sprintf.c | 41 ++++++++++++++++++++++++----------------- nxt/nxt_sprintf.h | 6 +++++- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/njs/njs_shell.c b/njs/njs_shell.c index be3ee0ff..424e509f 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -645,7 +645,8 @@ njs_output(njs_vm_t *vm, njs_opts_t *opts, njs_ret_t ret) nxt_error("%V\n", &out); } else if (opts->interactive) { - nxt_printf("%V\n", &out); + nxt_print(out.start, out.length); + nxt_printf("\n"); } } @@ -919,7 +920,8 @@ njs_ext_console_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, return NJS_ERROR; } - nxt_printf("%s%V", (n != 1) ? " " : "", &msg); + nxt_printf("%s", (n != 1) ? " " : ""); + nxt_print(msg.start, msg.length); n++; } @@ -950,7 +952,8 @@ njs_ext_console_dump(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, return NJS_ERROR; } - nxt_printf("%s%V", (n != 1) ? " " : "", &msg); + nxt_printf("%s", (n != 1) ? " " : ""); + nxt_print(msg.start, msg.length); n++; } diff --git a/nxt/nxt_sprintf.c b/nxt/nxt_sprintf.c index cf3e9eb7..442e5594 100644 --- a/nxt/nxt_sprintf.c +++ b/nxt/nxt_sprintf.c @@ -64,23 +64,6 @@ nxt_sprintf(u_char *buf, u_char *end, const char *fmt, ...) } -int -nxt_dprintf(int fd, const char *fmt, ...) -{ - size_t size; - u_char text[2048], *p; - va_list args; - - va_start(args, fmt); - p = nxt_vsprintf(text, text + sizeof(text), fmt, args); - va_end(args); - - size = p - text; - - return write(fd, text, size); -} - - /* * nxt_sprintf_t is used: * to pass several parameters of nxt_integer() via single pointer @@ -602,3 +585,27 @@ nxt_number(nxt_sprintf_t *spf, u_char *buf, double n) return buf; } + + +NXT_EXPORT +int nxt_dprint(int fd, u_char *buf, size_t size) +{ + return write(fd, buf, size); +} + + +int +nxt_dprintf(int fd, const char *fmt, ...) +{ + size_t size; + u_char text[2048], *p; + va_list args; + + va_start(args, fmt); + p = nxt_vsprintf(text, text + sizeof(text), fmt, args); + va_end(args); + + size = p - text; + + return write(fd, text, size); +} diff --git a/nxt/nxt_sprintf.h b/nxt/nxt_sprintf.h index ac3747e6..27afbf7b 100644 --- a/nxt/nxt_sprintf.h +++ b/nxt/nxt_sprintf.h @@ -12,9 +12,13 @@ NXT_EXPORT u_char *nxt_sprintf(u_char *buf, u_char *end, const char *fmt, ...); NXT_EXPORT u_char *nxt_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args); +NXT_EXPORT int nxt_dprint(int fd, u_char *buf, size_t size); NXT_EXPORT int nxt_dprintf(int fd, const char *fmt, ...); -#define nxt_printf(fmt, ...) \ +#define nxt_print(buf, size) \ + nxt_dprint(STDOUT_FILENO, (u_char *) buf, size) + +#define nxt_printf(fmt, ...) \ nxt_dprintf(STDOUT_FILENO, fmt, ##__VA_ARGS__) #define nxt_error(fmt, ...) \ -- 2.47.3