[njs] Using nxt_printf() everywhere.

Dmitry Volyntsev xeioex at nginx.com
Thu Mar 28 16:59:51 UTC 2019


details:   https://hg.nginx.org/njs/rev/6b8bb252ad06
branches:  
changeset: 856:6b8bb252ad06
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Mar 28 19:45:58 2019 +0300
description:
Using nxt_printf() everywhere.

diffstat:

 auto/make                       |    2 +-
 njs/njs_builtin.c               |    1 -
 njs/njs_crypto.c                |    1 -
 njs/njs_date.c                  |    1 -
 njs/njs_disassembler.c          |  145 +++++++++++++++++++--------------------
 njs/njs_error.c                 |    1 -
 njs/njs_extern.c                |    1 -
 njs/njs_fs.c                    |    1 -
 njs/njs_module.c                |    1 -
 njs/njs_number.c                |    1 -
 njs/njs_number.h                |    1 -
 njs/njs_parser.c                |    1 -
 njs/njs_regexp.c                |    1 -
 njs/njs_shell.c                 |   88 ++++++++++++------------
 njs/njs_time.c                  |    1 -
 njs/njs_vm.c                    |    1 -
 njs/test/njs_benchmark.c        |   22 ++---
 njs/test/njs_interactive_test.c |   17 +--
 njs/test/njs_unit_test.c        |   52 +++++--------
 nxt/nxt_sprintf.h               |    3 +
 nxt/nxt_trace.c                 |    1 -
 nxt/test/lvlhsh_unit_test.c     |   32 ++++----
 nxt/test/random_unit_test.c     |    8 +-
 nxt/test/rbtree_unit_test.c     |   19 ++--
 nxt/test/utf8_unit_test.c       |   19 ++--
 25 files changed, 197 insertions(+), 224 deletions(-)

diffs (truncated from 1417 to 1000 lines):

diff -r 2f4101c9a608 -r 6b8bb252ad06 auto/make
--- a/auto/make	Wed Mar 27 21:00:20 2019 +0300
+++ b/auto/make	Thu Mar 28 19:45:58 2019 +0300
@@ -103,7 +103,7 @@ do
 	\$(NXT_CC) -o $NXT_BUILD_DIR/$nxt_bin \$(NXT_CFLAGS) \\
 		\$(NXT_LIB_INCS) $nxt_dep_flags \\
 		$nxt_src $NXT_BUILD_DIR/libnxt.a \\
-		$nxt_dep_post
+		$nxt_dep_post -lm
 
 -include $NXT_BUILD_DIR/$nxt_dep
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_builtin.c
--- a/njs/njs_builtin.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_builtin.c	Thu Mar 28 19:45:58 2019 +0300
@@ -15,7 +15,6 @@
 #include <njs_fs.h>
 #include <njs_crypto.h>
 #include <string.h>
-#include <stdio.h>
 
 
 typedef struct {
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_crypto.c
--- a/njs/njs_crypto.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_crypto.c	Thu Mar 28 19:45:58 2019 +0300
@@ -9,7 +9,6 @@
 #include <nxt_sha1.h>
 #include <nxt_sha2.h>
 #include <njs_crypto.h>
-#include <stdio.h>
 #include <string.h>
 #include <math.h>
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_date.c
--- a/njs/njs_date.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_date.c	Thu Mar 28 19:45:58 2019 +0300
@@ -6,7 +6,6 @@
 
 #include <njs_core.h>
 #include <njs_date.h>
-#include <stdio.h>
 #include <string.h>
 #include <sys/time.h>
 #include <time.h>
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_disassembler.c
--- a/njs/njs_disassembler.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_disassembler.c	Thu Mar 28 19:45:58 2019 +0300
@@ -5,7 +5,6 @@
  */
 
 #include <njs_core.h>
-#include <stdio.h>
 
 
 static void njs_disassemble(u_char *start, u_char *end);
@@ -139,8 +138,7 @@ njs_disassembler(njs_vm_t *vm)
     n = vm->code->items;
 
     while (n != 0) {
-        printf("%.*s:%.*s\n", (int) code->file.length, code->file.start,
-               (int) code->name.length, code->name.start);
+        nxt_printf("%V:%V\n", &code->file, &code->name);
         njs_disassemble(code->start, code->end);
         code++;
         n--;
@@ -190,9 +188,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_array) {
             array = (njs_vmcode_array_t *) p;
 
-            printf("%05zd ARRAY             %04zX %zd%s\n",
-                   p - start, (size_t) array->retval, (size_t) array->length,
-                   array->code.ctor ? " INIT" : "");
+            nxt_printf("%05uz ARRAY             %04Xz %uz%s\n",
+                       p - start, (size_t) array->retval,
+                       (size_t) array->length, array->code.ctor ? " INIT" : "");
 
             p += sizeof(njs_vmcode_array_t);
 
@@ -203,9 +201,9 @@ njs_disassemble(u_char *start, u_char *e
             cond_jump = (njs_vmcode_cond_jump_t *) p;
             sign = (cond_jump->offset >= 0) ? "+" : "";
 
-            printf("%05zd JUMP IF TRUE      %04zX %s%zd\n",
-                   p - start, (size_t) cond_jump->cond, sign,
-                   (size_t) cond_jump->offset);
+            nxt_printf("%05uz JUMP IF TRUE      %04Xz %s%uz\n",
+                       p - start, (size_t) cond_jump->cond, sign,
+                       (size_t) cond_jump->offset);
 
             p += sizeof(njs_vmcode_cond_jump_t);
 
@@ -216,9 +214,9 @@ njs_disassemble(u_char *start, u_char *e
             cond_jump = (njs_vmcode_cond_jump_t *) p;
             sign = (cond_jump->offset >= 0) ? "+" : "";
 
-            printf("%05zd JUMP IF FALSE     %04zX %s%zd\n",
-                   p - start, (size_t) cond_jump->cond, sign,
-                   (size_t) cond_jump->offset);
+            nxt_printf("%05uz JUMP IF FALSE     %04Xz %s%uz\n",
+                       p - start, (size_t) cond_jump->cond, sign,
+                       (size_t) cond_jump->offset);
 
             p += sizeof(njs_vmcode_cond_jump_t);
 
@@ -229,8 +227,8 @@ njs_disassemble(u_char *start, u_char *e
             jump = (njs_vmcode_jump_t *) p;
             sign = (jump->offset >= 0) ? "+" : "";
 
-            printf("%05zd JUMP              %s%zd\n",
-                   p - start, sign, (size_t) jump->offset);
+            nxt_printf("%05uz JUMP              %s%uz\n",
+                       p - start, sign, (size_t) jump->offset);
 
             p += sizeof(njs_vmcode_jump_t);
 
@@ -240,9 +238,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_if_equal_jump) {
             equal = (njs_vmcode_equal_jump_t *) p;
 
-            printf("%05zd JUMP IF EQUAL     %04zX %04zX +%zd\n",
-                   p - start, (size_t) equal->value1, (size_t) equal->value2,
-                   (size_t) equal->offset);
+            nxt_printf("%05uz JUMP IF EQUAL     %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) equal->value1,
+                       (size_t) equal->value2, (size_t) equal->offset);
 
             p += sizeof(njs_vmcode_equal_jump_t);
 
@@ -252,9 +250,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_test_if_true) {
             test_jump = (njs_vmcode_test_jump_t *) p;
 
-            printf("%05zd TEST IF TRUE      %04zX %04zX +%zd\n",
-                   p - start, (size_t) test_jump->retval,
-                   (size_t) test_jump->value, (size_t) test_jump->offset);
+            nxt_printf("%05uz TEST IF TRUE      %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) test_jump->retval,
+                       (size_t) test_jump->value, (size_t) test_jump->offset);
 
             p += sizeof(njs_vmcode_test_jump_t);
 
@@ -264,9 +262,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_test_if_false) {
             test_jump = (njs_vmcode_test_jump_t *) p;
 
-            printf("%05zd TEST IF FALSE     %04zX %04zX +%zd\n",
-                   p - start, (size_t) test_jump->retval,
-                   (size_t) test_jump->value, (size_t) test_jump->offset);
+            nxt_printf("%05uz TEST IF FALSE     %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) test_jump->retval,
+                       (size_t) test_jump->value, (size_t) test_jump->offset);
 
             p += sizeof(njs_vmcode_test_jump_t);
 
@@ -276,9 +274,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_function_frame) {
             function = (njs_vmcode_function_frame_t *) p;
 
-            printf("%05zd FUNCTION FRAME    %04zX %zd%s\n",
-                   p - start, (size_t) function->name, function->nargs,
-                   function->code.ctor ? " CTOR" : "");
+            nxt_printf("%05uz FUNCTION FRAME    %04Xz %uz%s\n",
+                       p - start, (size_t) function->name, function->nargs,
+                       function->code.ctor ? " CTOR" : "");
 
             p += sizeof(njs_vmcode_function_frame_t);
 
@@ -288,9 +286,10 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_method_frame) {
             method = (njs_vmcode_method_frame_t *) p;
 
-            printf("%05zd METHOD FRAME      %04zX %04zX %zd%s\n",
-                   p - start, (size_t) method->object, (size_t) method->method,
-                   method->nargs, method->code.ctor ? " CTOR" : "");
+            nxt_printf("%05uz METHOD FRAME      %04Xz %04Xz %uz%s\n",
+                       p - start, (size_t) method->object,
+                       (size_t) method->method, method->nargs,
+                       method->code.ctor ? " CTOR" : "");
 
 
             p += sizeof(njs_vmcode_method_frame_t);
@@ -300,10 +299,10 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_property_foreach) {
             prop_foreach = (njs_vmcode_prop_foreach_t *) p;
 
-            printf("%05zd PROPERTY FOREACH  %04zX %04zX +%zd\n",
-                   p - start, (size_t) prop_foreach->next,
-                   (size_t) prop_foreach->object,
-                   (size_t) prop_foreach->offset);
+            nxt_printf("%05uz PROPERTY FOREACH  %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) prop_foreach->next,
+                       (size_t) prop_foreach->object,
+                       (size_t) prop_foreach->offset);
 
 
             p += sizeof(njs_vmcode_prop_foreach_t);
@@ -313,10 +312,10 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_property_next) {
             prop_next = (njs_vmcode_prop_next_t *) p;
 
-            printf("%05zd PROPERTY NEXT     %04zX %04zX %04zX %zd\n",
-                   p - start, (size_t) prop_next->retval,
-                   (size_t) prop_next->object, (size_t) prop_next->next,
-                   (size_t) prop_next->offset);
+            nxt_printf("%05uz PROPERTY NEXT     %04Xz %04Xz %04Xz %uz\n",
+                       p - start, (size_t) prop_next->retval,
+                       (size_t) prop_next->object, (size_t) prop_next->next,
+                       (size_t) prop_next->offset);
 
             p += sizeof(njs_vmcode_prop_next_t);
 
@@ -326,10 +325,10 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_try_start) {
             try_start = (njs_vmcode_try_start_t *) p;
 
-            printf("%05zd TRY START         %04zX %04zX +%zd\n",
-                   p - start, (size_t) try_start->exception_value,
-                   (size_t) try_start->exit_value,
-                   (size_t) try_start->offset);
+            nxt_printf("%05uz TRY START         %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) try_start->exception_value,
+                       (size_t) try_start->exit_value,
+                       (size_t) try_start->offset);
 
             p += sizeof(njs_vmcode_try_start_t);
 
@@ -339,9 +338,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_try_break) {
             try_tramp = (njs_vmcode_try_trampoline_t *) p;
 
-            printf("%05zd TRY BREAK         %04zX %zd\n",
-                   p - start, (size_t) try_tramp->exit_value,
-                   (size_t) try_tramp->offset);
+            nxt_printf("%05uz TRY BREAK         %04Xz %uz\n",
+                       p - start, (size_t) try_tramp->exit_value,
+                       (size_t) try_tramp->offset);
 
             p += sizeof(njs_vmcode_try_trampoline_t);
 
@@ -351,9 +350,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_try_continue) {
             try_tramp = (njs_vmcode_try_trampoline_t *) p;
 
-            printf("%05zd TRY CONTINUE      %04zX %zd\n",
-                   p - start, (size_t) try_tramp->exit_value,
-                   (size_t) try_tramp->offset);
+            nxt_printf("%05uz TRY CONTINUE      %04Xz %uz\n",
+                       p - start, (size_t) try_tramp->exit_value,
+                       (size_t) try_tramp->offset);
 
             p += sizeof(njs_vmcode_try_trampoline_t);
 
@@ -363,10 +362,10 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_try_return) {
             try_return = (njs_vmcode_try_return_t *) p;
 
-            printf("%05zd TRY RETURN        %04zX %04zX +%zd\n",
-                   p - start, (size_t) try_return->save,
-                   (size_t) try_return->retval,
-                   (size_t) try_return->offset);
+            nxt_printf("%05uz TRY RETURN        %04Xz %04Xz +%uz\n",
+                       p - start, (size_t) try_return->save,
+                       (size_t) try_return->retval,
+                       (size_t) try_return->offset);
 
             p += sizeof(njs_vmcode_try_return_t);
 
@@ -376,9 +375,9 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_catch) {
             catch = (njs_vmcode_catch_t *) p;
 
-            printf("%05zd CATCH             %04zX +%zd\n",
-                   p - start, (size_t) catch->exception,
-                   (size_t) catch->offset);
+            nxt_printf("%05uz CATCH             %04Xz +%uz\n",
+                       p - start, (size_t) catch->exception,
+                       (size_t) catch->offset);
 
             p += sizeof(njs_vmcode_catch_t);
 
@@ -388,8 +387,8 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_try_end) {
             try_end = (njs_vmcode_try_end_t *) p;
 
-            printf("%05zd TRY END           +%zd\n",
-                   p - start, (size_t) try_end->offset);
+            nxt_printf("%05uz TRY END           +%uz\n",
+                       p - start, (size_t) try_end->offset);
 
             p += sizeof(njs_vmcode_try_end_t);
 
@@ -399,11 +398,11 @@ njs_disassemble(u_char *start, u_char *e
         if (operation == njs_vmcode_finally) {
             finally = (njs_vmcode_finally_t *) p;
 
-            printf("%05zd TRY FINALLY       %04zX %04zX +%zd +%zd\n",
-                   p - start, (size_t) finally->retval,
-                   (size_t) finally->exit_value,
-                   (size_t) finally->continue_offset,
-                   (size_t) finally->break_offset);
+            nxt_printf("%05uz TRY FINALLY       %04Xz %04Xz +%uz +%uz\n",
+                       p - start, (size_t) finally->retval,
+                       (size_t) finally->exit_value,
+                       (size_t) finally->continue_offset,
+                       (size_t) finally->break_offset);
 
             p += sizeof(njs_vmcode_finally_t);
 
@@ -420,24 +419,24 @@ njs_disassemble(u_char *start, u_char *e
                 if (code_name->size == sizeof(njs_vmcode_3addr_t)) {
                     code3 = (njs_vmcode_3addr_t *) p;
 
-                    printf("%05zd %*s  %04zX %04zX %04zX\n",
-                           p - start, (int) name->length, name->start,
-                           (size_t) code3->dst, (size_t) code3->src1,
-                           (size_t) code3->src2);
+                    nxt_printf("%05uz %*s  %04Xz %04Xz %04Xz\n",
+                               p - start, (int) name->length, name->start,
+                               (size_t) code3->dst, (size_t) code3->src1,
+                               (size_t) code3->src2);
 
                 } else if (code_name->size == sizeof(njs_vmcode_2addr_t)) {
                     code2 = (njs_vmcode_2addr_t *) p;
 
-                    printf("%05zd %*s  %04zX %04zX\n",
-                           p - start, (int) name->length, name->start,
-                           (size_t) code2->dst, (size_t) code2->src);
+                    nxt_printf("%05uz %*s  %04Xz %04Xz\n",
+                               p - start, (int) name->length, name->start,
+                               (size_t) code2->dst, (size_t) code2->src);
 
                 } else if (code_name->size == sizeof(njs_vmcode_1addr_t)) {
                     code1 = (njs_vmcode_1addr_t *) p;
 
-                    printf("%05zd %*s  %04zX\n",
-                           p - start, (int) name->length, name->start,
-                           (size_t) code1->index);
+                    nxt_printf("%05uz %*s  %04Xz\n",
+                               p - start, (int) name->length, name->start,
+                               (size_t) code1->index);
                 }
 
                 p += code_name->size;
@@ -450,8 +449,8 @@ njs_disassemble(u_char *start, u_char *e
 
         } while (n != 0);
 
-        printf("%05zd UNKNOWN           %04zX\n",
-               p - start, (size_t) (uintptr_t) operation);
+        nxt_printf("%05uz UNKNOWN           %04Xz\n",
+                   p - start, (size_t) (uintptr_t) operation);
 
         p += sizeof(njs_vmcode_operation_t);
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_error.c
--- a/njs/njs_error.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_error.c	Thu Mar 28 19:45:58 2019 +0300
@@ -5,7 +5,6 @@
  */
 
 #include <njs_core.h>
-#include <stdio.h>
 #include <string.h>
 #include <math.h>
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_extern.c
--- a/njs/njs_extern.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_extern.c	Thu Mar 28 19:45:58 2019 +0300
@@ -6,7 +6,6 @@
 
 #include <njs_core.h>
 #include <string.h>
-#include <stdio.h>
 
 
 typedef struct njs_extern_part_s  njs_extern_part_t;
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_fs.c
--- a/njs/njs_fs.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_fs.c	Thu Mar 28 19:45:58 2019 +0300
@@ -10,7 +10,6 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <errno.h>
-#include <stdio.h>
 
 
 typedef struct {
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_module.c
--- a/njs/njs_module.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_module.c	Thu Mar 28 19:45:58 2019 +0300
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_module.h>
 #include <string.h>
-#include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_number.c
--- a/njs/njs_number.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_number.c	Thu Mar 28 19:45:58 2019 +0300
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <math.h>
 #include <string.h>
-#include <stdio.h>
 #include <float.h>
 
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_number.h
--- a/njs/njs_number.h	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_number.h	Thu Mar 28 19:45:58 2019 +0300
@@ -9,7 +9,6 @@
 
 
 #include <math.h>
-#include <stdio.h>
 
 
 uint32_t njs_value_to_index(const njs_value_t *value);
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_parser.c
--- a/njs/njs_parser.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_parser.c	Thu Mar 28 19:45:58 2019 +0300
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_regexp.h>
 #include <string.h>
-#include <stdio.h>
 
 
 static njs_ret_t njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser,
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_regexp.c
--- a/njs/njs_regexp.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_regexp.c	Thu Mar 28 19:45:58 2019 +0300
@@ -9,7 +9,6 @@
 #include <njs_regexp_pattern.h>
 
 #include <string.h>
-#include <stdio.h>
 
 
 static void *njs_regexp_malloc(size_t size, void *memory_data);
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_shell.c
--- a/njs/njs_shell.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_shell.c	Thu Mar 28 19:45:58 2019 +0300
@@ -10,13 +10,13 @@
 #include <time.h>
 #include <errno.h>
 #include <string.h>
-#include <stdio.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <locale.h>
 
+#include <stdio.h>
 #include <readline.h>
 
 
@@ -214,7 +214,7 @@ main(int argc, char **argv)
     }
 
     if (opts.version != 0) {
-        printf("%s\n", NJS_VERSION);
+        nxt_printf("%s\n", NJS_VERSION);
         ret = NXT_OK;
         goto done;
     }
@@ -225,7 +225,7 @@ main(int argc, char **argv)
         if (opts.file == NULL) {
             p = getcwd(path, sizeof(path));
             if (p == NULL) {
-                fprintf(stderr, "getcwd() failed:%s\n", strerror(errno));
+                nxt_error("getcwd() failed:%s\n", strerror(errno));
                 ret = NXT_ERROR;
                 goto done;
             }
@@ -316,7 +316,7 @@ njs_get_options(njs_opts_t *opts, int ar
                 opts->n_paths++;
                 paths = realloc(opts->paths, opts->n_paths * sizeof(char *));
                 if (paths == NULL) {
-                    fprintf(stderr, "failed to add path\n");
+                    nxt_error("failed to add path\n");
                     return NXT_ERROR;
                 }
 
@@ -325,7 +325,7 @@ njs_get_options(njs_opts_t *opts, int ar
                 break;
             }
 
-            fprintf(stderr, "option \"-p\" requires directory name\n");
+            nxt_error("option \"-p\" requires directory name\n");
             return NXT_ERROR;
 
         case 'v':
@@ -334,8 +334,9 @@ njs_get_options(njs_opts_t *opts, int ar
             break;
 
         default:
-            fprintf(stderr, "Unknown argument: \"%s\" "
-                    "try \"%s -h\" for available options\n", argv[i], argv[0]);
+            nxt_error("Unknown argument: \"%s\" "
+                      "try \"%s -h\" for available options\n", argv[i],
+                      argv[0]);
             return NXT_ERROR;
         }
     }
@@ -374,7 +375,7 @@ njs_externals_init(njs_vm_t *vm, njs_con
 
     proto = njs_vm_external_prototype(vm, &njs_externals[0]);
     if (proto == NULL) {
-        fprintf(stderr, "failed to add console proto\n");
+        nxt_error("failed to add console proto\n");
         return NXT_ERROR;
     }
 
@@ -409,7 +410,7 @@ njs_interactive_shell(njs_opts_t *opts, 
     nxt_str_t  line;
 
     if (njs_editline_init() != NXT_OK) {
-        fprintf(stderr, "failed to init completions\n");
+        nxt_error("failed to init completions\n");
         return NXT_ERROR;
     }
 
@@ -419,10 +420,10 @@ njs_interactive_shell(njs_opts_t *opts, 
     }
 
     if (!opts->quiet) {
-        printf("interactive njs %s\n\n", NJS_VERSION);
+        nxt_printf("interactive njs %s\n\n", NJS_VERSION);
 
-        printf("v.<Tab> -> the properties and prototype methods of v.\n");
-        printf("type console.help() for more information\n\n");
+        nxt_printf("v.<Tab> -> the properties and prototype methods of v.\n");
+        nxt_printf("type console.help() for more information\n\n");
     }
 
     for ( ;; ) {
@@ -469,15 +470,15 @@ njs_process_file(njs_opts_t *opts, njs_v
     } else {
         fd = open(file, O_RDONLY);
         if (fd == -1) {
-            fprintf(stderr, "failed to open file: '%s' (%s)\n",
-                    file, strerror(errno));
+            nxt_error("failed to open file: '%s' (%s)\n",
+                      file, strerror(errno));
             return NXT_ERROR;
         }
     }
 
     if (fstat(fd, &sb) == -1) {
-        fprintf(stderr, "fstat(%d) failed while reading '%s' (%s)\n",
-                fd, file, strerror(errno));
+        nxt_error("fstat(%d) failed while reading '%s' (%s)\n",
+                  fd, file, strerror(errno));
         ret = NXT_ERROR;
         goto close_fd;
     }
@@ -491,7 +492,7 @@ njs_process_file(njs_opts_t *opts, njs_v
     script.length = 0;
     script.start = realloc(NULL, size);
     if (script.start == NULL) {
-        fprintf(stderr, "alloc failed while reading '%s'\n", file);
+        nxt_error("alloc failed while reading '%s'\n", file);
         ret = NXT_ERROR;
         goto done;
     }
@@ -507,8 +508,8 @@ njs_process_file(njs_opts_t *opts, njs_v
         }
 
         if (n < 0) {
-            fprintf(stderr, "failed to read file: '%s' (%s)\n",
-                    file, strerror(errno));
+            nxt_error("failed to read file: '%s' (%s)\n",
+                      file, strerror(errno));
             ret = NXT_ERROR;
             goto done;
         }
@@ -518,7 +519,7 @@ njs_process_file(njs_opts_t *opts, njs_v
 
             start = realloc(script.start, size);
             if (start == NULL) {
-                fprintf(stderr, "alloc failed while reading '%s'\n", file);
+                nxt_error("alloc failed while reading '%s'\n", file);
                 ret = NXT_ERROR;
                 goto done;
             }
@@ -576,12 +577,12 @@ njs_create_vm(njs_opts_t *opts, njs_vm_o
 
     vm = njs_vm_create(vm_options);
     if (vm == NULL) {
-        fprintf(stderr, "failed to create vm\n");
+        nxt_error("failed to create vm\n");
         return NULL;
     }
 
     if (njs_externals_init(vm, vm_options->external) != NXT_OK) {
-        fprintf(stderr, "failed to add external protos\n");
+        nxt_error("failed to add external protos\n");
         return NULL;
     }
 
@@ -591,7 +592,7 @@ njs_create_vm(njs_opts_t *opts, njs_vm_o
 
         ret = njs_vm_add_path(vm, &path);
         if (ret != NXT_OK) {
-            fprintf(stderr, "failed to add path\n");
+            nxt_error("failed to add path\n");
             return NULL;
         }
     }
@@ -609,7 +610,7 @@ njs_create_vm(njs_opts_t *opts, njs_vm_o
 
         ret = njs_vm_add_path(vm, &path);
         if (ret != NXT_OK) {
-            fprintf(stderr, "failed to add path\n");
+            nxt_error("failed to add path\n");
             return NULL;
         }
 
@@ -635,10 +636,10 @@ njs_output(njs_vm_t *vm, njs_opts_t *opt
     }
 
     if (ret != NJS_OK) {
-        fprintf(stderr, "%.*s\n", (int) out.length, out.start);
+        nxt_error("%V\n", &out);
 
     } else if (opts->interactive) {
-        printf("%.*s\n", (int) out.length, out.start);
+        nxt_printf("%V\n", &out);
     }
 }
 
@@ -688,7 +689,7 @@ njs_process_script(njs_console_t *consol
     if (ret == NXT_OK) {
         if (opts->disassemble) {
             njs_disassembler(vm);
-            printf("\n");
+            nxt_printf("\n");
         }
 
         ret = njs_vm_start(vm);
@@ -703,7 +704,7 @@ njs_process_script(njs_console_t *consol
 
         ret = njs_process_events(console, opts);
         if (nxt_slow_path(ret != NXT_OK)) {
-            fprintf(stderr, "njs_process_events() failed\n");
+            nxt_error("njs_process_events() failed\n");
             ret = NJS_ERROR;
             break;
         }
@@ -711,8 +712,7 @@ njs_process_script(njs_console_t *consol
         if (njs_vm_waiting(vm) && !njs_vm_posted(vm)) {
             /*TODO: async events. */
 
-            fprintf(stderr, "njs_process_script(): "
-                    "async events unsupported\n");
+            nxt_error("njs_process_script(): async events unsupported\n");
             ret = NJS_ERROR;
             break;
         }
@@ -913,13 +913,13 @@ njs_ext_console_log(njs_vm_t *vm, njs_va
             return NJS_ERROR;
         }
 
-        printf("%s%.*s", (n != 1) ? " " : "", (int) msg.length, msg.start);
+        nxt_printf("%s%V", (n != 1) ? " " : "", &msg);
 
         n++;
     }
 
     if (nargs > 1) {
-        printf("\n");
+        nxt_printf("\n");
     }
 
     vm->retval = njs_value_undefined;
@@ -944,13 +944,13 @@ njs_ext_console_dump(njs_vm_t *vm, njs_v
             return NJS_ERROR;
         }
 
-        printf("%s%.*s", (n != 1) ? " " : "", (int) msg.length, msg.start);
+        nxt_printf("%s%V", (n != 1) ? " " : "", &msg);
 
         n++;
     }
 
     if (nargs > 1) {
-        printf("\n");
+        nxt_printf("\n");
     }
 
     vm->retval = njs_value_undefined;
@@ -965,24 +965,24 @@ njs_ext_console_help(njs_vm_t *vm, njs_v
 {
     const njs_object_init_t  *obj, **objpp;
 
-    printf("VM built-in objects:\n");
+    nxt_printf("VM built-in objects:\n");
 
     for (objpp = njs_constructor_init; *objpp != NULL; objpp++) {
         obj = *objpp;
 
-        printf("  %.*s\n", (int) obj->name.length, obj->name.start);
+        nxt_printf("  %V\n", &obj->name);
     }
 
     for (objpp = njs_object_init; *objpp != NULL; objpp++) {
         obj = *objpp;
 
-        printf("  %.*s\n", (int) obj->name.length, obj->name.start);
+        nxt_printf("  %V\n", &obj->name);
     }
 
-    printf("\nEmbedded objects:\n");
-    printf("  console\n");
+    nxt_printf("\nEmbedded objects:\n");
+    nxt_printf("  console\n");
 
-    printf("\n");
+    nxt_printf("\n");
 
     vm->retval = njs_value_undefined;
 
@@ -1040,12 +1040,12 @@ njs_ext_console_time_end(njs_vm_t *vm, n
         ms = ns / 1000000;
         ns = ns % 1000000;
 
-        printf("default: %" PRIu64 ".%06" PRIu64 "ms\n", ms, ns);
+        nxt_printf("default: %uL.%06uLms\n", ms, ns);
 
         console->time = UINT64_MAX;
 
     } else {
-        printf("Timer \"default\" doesn’t exist.\n");
+        nxt_printf("Timer \"default\" doesn’t exist.\n");
     }
 
     vm->retval = njs_value_undefined;
@@ -1065,7 +1065,7 @@ njs_console_set_timer(njs_external_ptr_t
     nxt_lvlhsh_query_t  lhq;
 
     if (delay != 0) {
-        fprintf(stderr, "njs_console_set_timer(): async timers unsupported\n");
+        nxt_error("njs_console_set_timer(): async timers unsupported\n");
         return NULL;
     }
 
@@ -1125,7 +1125,7 @@ njs_console_clear_timer(njs_external_ptr
 
     ret = nxt_lvlhsh_delete(&console->events, &lhq);
     if (ret != NXT_OK) {
-        fprintf(stderr, "nxt_lvlhsh_delete() failed\n");
+        nxt_error("nxt_lvlhsh_delete() failed\n");
     }
 
     nxt_mp_free(vm->mem_pool, ev);
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_time.c
--- a/njs/njs_time.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_time.c	Thu Mar 28 19:45:58 2019 +0300
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_time.h>
 #include <string.h>
-#include <stdio.h>
 
 
 static njs_ret_t
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/njs_vm.c
--- a/njs/njs_vm.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/njs_vm.c	Thu Mar 28 19:45:58 2019 +0300
@@ -7,7 +7,6 @@
 #include <njs_core.h>
 #include <njs_regexp.h>
 #include <string.h>
-#include <stdio.h>
 
 
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/test/njs_benchmark.c
--- a/njs/test/njs_benchmark.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/test/njs_benchmark.c	Thu Mar 28 19:45:58 2019 +0300
@@ -7,7 +7,7 @@
 #include <njs.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdio.h>
+#include <nxt_sprintf.h>
 #include <sys/resource.h>
 #include <time.h>
 
@@ -34,7 +34,7 @@ njs_unit_test_benchmark(nxt_str_t *scrip
 
     vm = njs_vm_create(&options);
     if (vm == NULL) {
-        printf("njs_vm_create() failed\n");
+        nxt_printf("njs_vm_create() failed\n");
         goto done;
     }
 
@@ -42,7 +42,7 @@ njs_unit_test_benchmark(nxt_str_t *scrip
 
     ret = njs_vm_compile(vm, &start, start + script->length);
     if (ret != NXT_OK) {
-        printf("njs_vm_compile() failed\n");
+        nxt_printf("njs_vm_compile() failed\n");
         goto done;
     }
 
@@ -50,23 +50,21 @@ njs_unit_test_benchmark(nxt_str_t *scrip
 
         nvm = njs_vm_clone(vm, NULL);
         if (nvm == NULL) {
-            printf("njs_vm_clone() failed\n");
+            nxt_printf("njs_vm_clone() failed\n");
             goto done;
         }
 
         (void) njs_vm_start(nvm);
 
         if (njs_vm_retval_to_ext_string(nvm, &s) != NXT_OK) {
-            printf("njs_vm_retval_to_ext_string() failed\n");
+            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
             goto done;
         }
 
         success = nxt_strstr_eq(result, &s);
 
         if (!success) {
-            printf("failed: \"%.*s\" vs \"%.*s\"\n",
-                   (int) result->length, result->start, (int) s.length,
-                   s.start);
+            nxt_printf("failed: \"%V\" vs \"%V\"\n", result, &s);
             goto done;
         }
 
@@ -80,11 +78,11 @@ njs_unit_test_benchmark(nxt_str_t *scrip
          + usage.ru_stime.tv_sec * 1000000 + usage.ru_stime.tv_usec;
 
     if (n == 1) {
-        printf("%s: %.3fs\n", msg, (double) us / 1000000);
+        nxt_printf("%s: %.3fs\n", msg, (double) us / 1000000);
 
     } else {
-        printf("%s: %.3fµs, %d times/s\n",
-               msg, (double) us / n, (int) ((uint64_t) n * 1000000 / us));
+        nxt_printf("%s: %.3fµs, %d times/s\n",
+                   msg, (double) us / n, (int) ((uint64_t) n * 1000000 / us));
     }
 
     rc = NXT_OK;
@@ -170,6 +168,6 @@ main(int argc, char **argv)
         }
     }
 
-    printf("unknown agrument\n");
+    nxt_printf("unknown agrument\n");
     return EXIT_FAILURE;
 }
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/test/njs_interactive_test.c
--- a/njs/test/njs_interactive_test.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/test/njs_interactive_test.c	Thu Mar 28 19:45:58 2019 +0300
@@ -6,7 +6,7 @@
 
 #include <njs.h>
 #include <string.h>
-#include <stdio.h>
+#include <nxt_sprintf.h>
 #include <sys/resource.h>
 #include <time.h>
 
@@ -273,8 +273,7 @@ njs_interactive_test(nxt_bool_t verbose)
         test = &njs_test[i];
 
         if (verbose) {
-            printf("\"%.*s\"\n", (int) test->script.length, test->script.start);
-            fflush(stdout);
+            nxt_printf("\"%V\"\n", &test->script);
         }
 
         nxt_memzero(&options, sizeof(njs_vm_opt_t));
@@ -284,7 +283,7 @@ njs_interactive_test(nxt_bool_t verbose)
 
         vm = njs_vm_create(&options);
         if (vm == NULL) {
-            printf("njs_vm_create() failed\n");
+            nxt_printf("njs_vm_create() failed\n");
             goto done;
         }
 
@@ -307,7 +306,7 @@ njs_interactive_test(nxt_bool_t verbose)
         }
 
         if (njs_vm_retval_to_ext_string(vm, &s) != NXT_OK) {
-            printf("njs_vm_retval_to_ext_string() failed\n");
+            nxt_printf("njs_vm_retval_to_ext_string() failed\n");
             goto done;
         }
 
@@ -318,17 +317,15 @@ njs_interactive_test(nxt_bool_t verbose)
             continue;
         }
 
-        printf("njs_interactive(\"%.*s\") failed: \"%.*s\" vs \"%.*s\"\n",
-               (int) test->script.length, test->script.start,
-               (int) test->ret.length, test->ret.start,
-               (int) s.length, s.start);
+        nxt_printf("njs_interactive(\"%V\") failed: \"%V\" vs \"%V\"\n",
+                   &test->script, &test->ret, &s);
 
         goto done;
     }
 
     ret = NXT_OK;
 
-    printf("njs interactive tests passed\n");
+    nxt_printf("njs interactive tests passed\n");
 
 done:
 
diff -r 2f4101c9a608 -r 6b8bb252ad06 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Mar 27 21:00:20 2019 +0300
+++ b/njs/test/njs_unit_test.c	Thu Mar 28 19:45:58 2019 +0300
@@ -9,7 +9,6 @@
 #include <nxt_djb_hash.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdio.h>
 #include <sys/resource.h>
 #include <time.h>
 
@@ -12237,7 +12236,7 @@ njs_externals_init(njs_vm_t *vm)
 
     proto = njs_vm_external_prototype(vm, &nxt_test_external[0]);
     if (proto == NULL) {
-        printf("njs_vm_external_prototype() failed\n");
+        nxt_printf("njs_vm_external_prototype() failed\n");
         return NXT_ERROR;
     }
 
@@ -12257,14 +12256,14 @@ njs_externals_init(njs_vm_t *vm)
         ret = njs_vm_external_create(vm, njs_value_arg(&requests[i].value),
                                      proto, &requests[i]);
         if (ret != NXT_OK) {
-            printf("njs_vm_external_create() failed\n");
+            nxt_printf("njs_vm_external_create() failed\n");
             return NXT_ERROR;
         }
 
         ret = njs_vm_external_bind(vm, &nxt_test_requests[i].name,
                                    njs_value_arg(&requests[i].value));
         if (ret != NXT_OK) {
-            printf("njs_vm_external_bind() failed\n");
+            nxt_printf("njs_vm_external_bind() failed\n");
             return NXT_ERROR;
         }
 
@@ -12274,13 +12273,13 @@ njs_externals_init(njs_vm_t *vm)
                                           &nxt_test_requests[i].props[j].value);
 
             if (prop == NULL) {
-                printf("lvlhsh_unit_test_alloc() failed\n");
+                nxt_printf("lvlhsh_unit_test_alloc() failed\n");
                 return NXT_ERROR;
             }
 
             ret = lvlhsh_unit_test_add(&requests[i], prop);
             if (ret != NXT_OK) {
-                printf("lvlhsh_unit_test_add() failed\n");
+                nxt_printf("lvlhsh_unit_test_add() failed\n");
                 return NXT_ERROR;
             }
         }
@@ -12310,16 +12309,14 @@ njs_unit_test(njs_unit_test_t tests[], s
     for (i = 0; i < num; i++) {
 
         if (verbose) {
-            printf("\"%.*s\"\n",
-                   (int) njs_test[i].script.length, njs_test[i].script.start);
-            fflush(stdout);
+            nxt_printf("\"%V\"\n", &njs_test[i].script);
         }
 
         nxt_memzero(&options, sizeof(njs_vm_opt_t));
 
         vm = njs_vm_create(&options);
         if (vm == NULL) {
-            printf("njs_vm_create() failed\n");
+            nxt_printf("njs_vm_create() failed\n");
             goto done;
         }
 
@@ -12335,25 +12332,24 @@ njs_unit_test(njs_unit_test_t tests[], s
         if (ret == NXT_OK) {
             if (disassemble) {
                 njs_disassembler(vm);
-                fflush(stdout);


More information about the nginx-devel mailing list