Welcome! Log In Create A New Profile

Advanced

[njs] Allowing to output large values in console.log().

Dmitry Volyntsev
April 11, 2019 10:30AM
details: https://hg.nginx.org/njs/rev/b9d619068453
branches:
changeset: 878:b9d619068453
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Apr 11 16:32:06 2019 +0300
description:
Allowing to output large values in console.log().

Previously, the size was limited to 2048 bytes.

This closes #127 issue on Github.

diffstat:

njs/njs_shell.c | 9 ++++++---
nxt/nxt_sprintf.c | 41 ++++++++++++++++++++++++-----------------
nxt/nxt_sprintf.h | 6 +++++-
3 files changed, 35 insertions(+), 21 deletions(-)

diffs (106 lines):

diff -r 0c8a6246a4af -r b9d619068453 njs/njs_shell.c
--- a/njs/njs_shell.c Thu Apr 11 15:00:17 2019 +0300
+++ b/njs/njs_shell.c Thu Apr 11 16:32:06 2019 +0300
@@ -645,7 +645,8 @@ njs_output(njs_vm_t *vm, njs_opts_t *opt
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_va
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_v
return NJS_ERROR;
}

- nxt_printf("%s%V", (n != 1) ? " " : "", &msg);
+ nxt_printf("%s", (n != 1) ? " " : "");
+ nxt_print(msg.start, msg.length);

n++;
}
diff -r 0c8a6246a4af -r b9d619068453 nxt/nxt_sprintf.c
--- a/nxt/nxt_sprintf.c Thu Apr 11 15:00:17 2019 +0300
+++ b/nxt/nxt_sprintf.c Thu Apr 11 16:32:06 2019 +0300
@@ -64,23 +64,6 @@ nxt_sprintf(u_char *buf, u_char *end, co
}


-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 *b

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 -r 0c8a6246a4af -r b9d619068453 nxt/nxt_sprintf.h
--- a/nxt/nxt_sprintf.h Thu Apr 11 15:00:17 2019 +0300
+++ b/nxt/nxt_sprintf.h Thu Apr 11 16:32:06 2019 +0300
@@ -12,9 +12,13 @@ NXT_EXPORT u_char *nxt_sprintf(u_char *b
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, ...) \
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Allowing to output large values in console.log().

Dmitry Volyntsev 123 April 11, 2019 10:30AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 64
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready