From: Dmitry Volyntsev Date: Thu, 28 Mar 2019 16:45:58 +0000 (+0300) Subject: Using nxt_printf() everywhere. X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=5a365c140de88e89c440afcedaa810b323b563e7;p=njs.git Using nxt_printf() everywhere. --- diff --git a/auto/make b/auto/make index 27153000..7c43d690 100644 --- a/auto/make +++ b/auto/make @@ -103,7 +103,7 @@ $NXT_BUILD_DIR/$nxt_bin: $nxt_src \\ \$(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 --git a/njs/njs_builtin.c b/njs/njs_builtin.c index 985e5f48..6d715a0e 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -15,7 +15,6 @@ #include #include #include -#include typedef struct { diff --git a/njs/njs_crypto.c b/njs/njs_crypto.c index 6ede1535..e8a48616 100644 --- a/njs/njs_crypto.c +++ b/njs/njs_crypto.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include diff --git a/njs/njs_date.c b/njs/njs_date.c index eabee2ef..04e61ec1 100644 --- a/njs/njs_date.c +++ b/njs/njs_date.c @@ -6,7 +6,6 @@ #include #include -#include #include #include #include diff --git a/njs/njs_disassembler.c b/njs/njs_disassembler.c index 2780f726..2d82ce3c 100644 --- a/njs/njs_disassembler.c +++ b/njs/njs_disassembler.c @@ -5,7 +5,6 @@ */ #include -#include 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) 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 *end) } 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 --git a/njs/njs_error.c b/njs/njs_error.c index 971e71c0..26e2130e 100644 --- a/njs/njs_error.c +++ b/njs/njs_error.c @@ -5,7 +5,6 @@ */ #include -#include #include #include diff --git a/njs/njs_extern.c b/njs/njs_extern.c index 57790d73..c4600314 100644 --- a/njs/njs_extern.c +++ b/njs/njs_extern.c @@ -6,7 +6,6 @@ #include #include -#include typedef struct njs_extern_part_s njs_extern_part_t; diff --git a/njs/njs_fs.c b/njs/njs_fs.c index 7805f56e..516b820c 100644 --- a/njs/njs_fs.c +++ b/njs/njs_fs.c @@ -10,7 +10,6 @@ #include #include #include -#include typedef struct { diff --git a/njs/njs_module.c b/njs/njs_module.c index 2ce78299..35f73725 100644 --- a/njs/njs_module.c +++ b/njs/njs_module.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/njs/njs_number.c b/njs/njs_number.c index 6c3a066e..3f8c1165 100644 --- a/njs/njs_number.c +++ b/njs/njs_number.c @@ -7,7 +7,6 @@ #include #include #include -#include #include diff --git a/njs/njs_number.h b/njs/njs_number.h index 769ef3bd..d3b699d9 100644 --- a/njs/njs_number.h +++ b/njs/njs_number.h @@ -9,7 +9,6 @@ #include -#include uint32_t njs_value_to_index(const njs_value_t *value); diff --git a/njs/njs_parser.c b/njs/njs_parser.c index 9b6b6a7b..a3baf2a5 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -7,7 +7,6 @@ #include #include #include -#include static njs_ret_t njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 5f469b22..dac8b84c 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -9,7 +9,6 @@ #include #include -#include static void *njs_regexp_malloc(size_t size, void *memory_data); diff --git a/njs/njs_shell.c b/njs/njs_shell.c index 4849557c..9f507438 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -10,13 +10,13 @@ #include #include #include -#include #include #include #include #include #include +#include #include @@ -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 argc, char** argv) 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 argc, char** argv) 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 argc, char** argv) 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_console_t *console) 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, njs_vm_opt_t *vm_options) 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, njs_vm_opt_t *vm_options) } if (!opts->quiet) { - printf("interactive njs %s\n\n", NJS_VERSION); + nxt_printf("interactive njs %s\n\n", NJS_VERSION); - printf("v. -> the properties and prototype methods of v.\n"); - printf("type console.help() for more information\n\n"); + nxt_printf("v. -> 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_vm_opt_t *vm_options) } 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_vm_opt_t *vm_options) 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_vm_opt_t *vm_options) } 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_vm_opt_t *vm_options) 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_opt_t *vm_options) 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_opt_t *vm_options) 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_opt_t *vm_options) 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 *opts, njs_ret_t ret) } 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 *console, njs_opts_t *opts, 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 *console, njs_opts_t *opts, 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 *console, njs_opts_t *opts, 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_value_t *args, nxt_uint_t nargs, 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_value_t *args, nxt_uint_t nargs, 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_value_t *args, nxt_uint_t nargs, { 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, njs_value_t *args, nxt_uint_t nargs, 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 external, uint64_t delay, 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_t external, njs_host_event_t event) 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 --git a/njs/njs_time.c b/njs/njs_time.c index 8ab45598..2521a544 100644 --- a/njs/njs_time.c +++ b/njs/njs_time.c @@ -7,7 +7,6 @@ #include #include #include -#include static njs_ret_t diff --git a/njs/njs_vm.c b/njs/njs_vm.c index cc248fe3..0f8b4ed9 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -7,7 +7,6 @@ #include #include #include -#include diff --git a/njs/test/njs_benchmark.c b/njs/test/njs_benchmark.c index dadeb671..f15106a4 100644 --- a/njs/test/njs_benchmark.c +++ b/njs/test/njs_benchmark.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -34,7 +34,7 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg, 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 *script, nxt_str_t *result, const char *msg, 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 *script, nxt_str_t *result, const char *msg, 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 *script, nxt_str_t *result, const char *msg, + 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 --git a/njs/test/njs_interactive_test.c b/njs/test/njs_interactive_test.c index af628f5d..192b81cc 100644 --- a/njs/test/njs_interactive_test.c +++ b/njs/test/njs_interactive_test.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 016d2c17..d6f62cd2 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -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[], size_t num, nxt_bool_t disassemble, 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[], size_t num, nxt_bool_t disassemble, if (ret == NXT_OK) { if (disassemble) { njs_disassembler(vm); - fflush(stdout); } nvm = njs_vm_clone(vm, NULL); if (nvm == NULL) { - printf("njs_vm_clone() failed\n"); + nxt_printf("njs_vm_clone() failed\n"); goto done; } ret = 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; } } else { 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; } } @@ -12372,10 +12368,8 @@ njs_unit_test(njs_unit_test_t tests[], size_t num, nxt_bool_t disassemble, continue; } - printf("njs(\"%.*s\")\nexpected: \"%.*s\"\n got: \"%.*s\"\n", - (int) njs_test[i].script.length, njs_test[i].script.start, - (int) njs_test[i].ret.length, njs_test[i].ret.start, - (int) s.length, s.start); + nxt_printf("njs(\"%V\")\nexpected: \"%V\"\n got: \"%V\"\n", + &njs_test[i].script, &njs_test[i].ret, &s); goto done; } @@ -12591,11 +12585,9 @@ nxt_file_basename_test(njs_vm_t * vm, nxt_bool_t disassemble, success = nxt_strstr_eq(&tests[i].expected, &name); if (!success) { - printf("nxt_file_basename_test(\"%.*s\"):\n" - "expected: \"%.*s\"\n got: \"%.*s\"\n", - (int) tests[i].path.length, tests[i].path.start, - (int) tests[i].expected.length, tests[i].expected.start, - (int) name.length, name.start); + nxt_printf("nxt_file_basename_test(\"%V\"):\n" + "expected: \"%V\"\n got: \"%V\"\n", + &tests[i].path, &tests[i].expected, &name); return NXT_ERROR; } } @@ -12637,11 +12629,9 @@ nxt_file_dirname_test(njs_vm_t * vm, nxt_bool_t disassemble, success = nxt_strstr_eq(&tests[i].expected, &name); if (!success) { - printf("nxt_file_dirname_test(\"%.*s\"):\n" - "expected: \"%.*s\"\n got: \"%.*s\"\n", - (int) tests[i].path.length, tests[i].path.start, - (int) tests[i].expected.length, tests[i].expected.start, - (int) name.length, name.start); + nxt_printf("nxt_file_dirname_test(\"%V\"):\n" + "expected: \"%V\"\n got: \"%V\"\n", + &tests[i].path, &tests[i].expected, &name); return NXT_ERROR; } } @@ -12745,7 +12735,7 @@ main(int argc, char **argv) return ret; } - printf("njs unit tests passed\n"); + nxt_printf("njs unit tests passed\n"); /* * Chatham Islands NZ-CHAT time zone. @@ -12766,10 +12756,10 @@ main(int argc, char **argv) return ret; } - printf("njs timezone tests passed\n"); + nxt_printf("njs timezone tests passed\n"); } else { - printf("njs timezone tests skipped, timezone is unavailable\n"); + nxt_printf("njs timezone tests skipped, timezone is unavailable\n"); } ret = njs_vm_json_test(disassemble, verbose); diff --git a/nxt/nxt_sprintf.h b/nxt/nxt_sprintf.h index f8aa07f1..ac3747e6 100644 --- a/nxt/nxt_sprintf.h +++ b/nxt/nxt_sprintf.h @@ -17,4 +17,7 @@ NXT_EXPORT int nxt_dprintf(int fd, const char *fmt, ...); #define nxt_printf(fmt, ...) \ nxt_dprintf(STDOUT_FILENO, fmt, ##__VA_ARGS__) +#define nxt_error(fmt, ...) \ + nxt_dprintf(STDERR_FILENO, fmt, ##__VA_ARGS__) + #endif /* _NXT_SPRINTF_H_INCLUDED_ */ diff --git a/nxt/nxt_trace.c b/nxt/nxt_trace.c index 440a7f39..36285310 100644 --- a/nxt/nxt_trace.c +++ b/nxt/nxt_trace.c @@ -10,7 +10,6 @@ #include #include #include -#include static u_char * diff --git a/nxt/test/lvlhsh_unit_test.c b/nxt/test/lvlhsh_unit_test.c index 92848895..a44918c2 100644 --- a/nxt/test/lvlhsh_unit_test.c +++ b/nxt/test/lvlhsh_unit_test.c @@ -7,14 +7,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include -#include #include @@ -72,8 +71,8 @@ lvlhsh_unit_test_add(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, return NXT_OK; case NXT_DECLINED: - printf("lvlhsh unit test failed: key %08lX is already in hash\n", - (long) key); + nxt_printf("lvlhsh unit test failed: key %08Xl is already in hash\n", + (long) key); /* Fall through. */ default: @@ -100,8 +99,8 @@ lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, } } - printf("lvlhsh unit test failed: key %08lX not found in hash\n", - (long) key); + nxt_printf("lvlhsh unit test failed: key %08Xl not found in hash\n", + (long) key); return NXT_ERROR; } @@ -123,7 +122,7 @@ lvlhsh_unit_test_delete(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, ret = nxt_lvlhsh_delete(lh, &lhq); if (ret != NXT_OK) { - printf("lvlhsh unit test failed: key %08lX not found in hash\n", + nxt_printf("lvlhsh unit test failed: key %08lX not found in hash\n", (long) key); } @@ -170,15 +169,14 @@ lvlhsh_free(void *mem, void *p) static void lvlhsh_alert(void *mem, const char *fmt, ...) { - int n; + u_char buf[1024], *p; va_list args; - char buf[1024]; va_start(args, fmt); - n = vsnprintf(buf, sizeof(buf), fmt, args); + p = nxt_sprintf(buf, buf + sizeof(buf), fmt, args); va_end(args); - (void) printf("alert: \"%.*s\"\n", n, buf); + (void) nxt_error("alert: \"%*s\"\n", p - buf, buf); } @@ -213,7 +211,7 @@ lvlhsh_unit_test(nxt_uint_t n) return NXT_ERROR; } - printf("lvlhsh unit test started: %ld items\n", (long) n); + nxt_printf("lvlhsh unit test started: %l items\n", (long) n); nxt_memzero(&lh, sizeof(nxt_lvlhsh_t)); @@ -222,7 +220,7 @@ lvlhsh_unit_test(nxt_uint_t n) key = nxt_murmur_hash2(&key, sizeof(uint32_t)); if (lvlhsh_unit_test_add(&lh, &lvlhsh_proto, pool, key) != NXT_OK) { - printf("lvlhsh add unit test failed at %ld\n", (long) i); + nxt_printf("lvlhsh add unit test failed at %l\n", (long) i); return NXT_ERROR; } } @@ -245,8 +243,8 @@ lvlhsh_unit_test(nxt_uint_t n) } if (i != n) { - printf("lvlhsh each unit test failed at %ld of %ld\n", - (long) i, (long) n); + nxt_printf("lvlhsh each unit test failed at %l of %l\n", + (long) i, (long) n); return NXT_ERROR; } @@ -260,13 +258,13 @@ lvlhsh_unit_test(nxt_uint_t n) } if (!nxt_mp_is_empty(pool)) { - printf("mem cache pool is not empty\n"); + nxt_printf("mem cache pool is not empty\n"); return NXT_ERROR; } nxt_mp_destroy(pool); - printf("lvlhsh unit test passed\n"); + nxt_printf("lvlhsh unit test passed\n"); return NXT_OK; } diff --git a/nxt/test/random_unit_test.c b/nxt/test/random_unit_test.c index 4285050a..ed6dc45d 100644 --- a/nxt/test/random_unit_test.c +++ b/nxt/test/random_unit_test.c @@ -7,10 +7,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -39,17 +39,17 @@ random_unit_test(void) } if (nxt_random(&r) == 0x6FCAE186) { - printf("random unit test passed\n"); + nxt_printf("random unit test passed\n"); nxt_random_stir(&r, getpid()); - printf("random unit test: 0x%08X\n", nxt_random(&r)); + nxt_printf("random unit test: 0x%08uXD\n", nxt_random(&r)); return NXT_OK; } } - printf("random unit test failed\n"); + nxt_printf("random unit test failed\n"); return NXT_ERROR; } diff --git a/nxt/test/rbtree_unit_test.c b/nxt/test/rbtree_unit_test.c index 44bce0b1..8fd9efc7 100644 --- a/nxt/test/rbtree_unit_test.c +++ b/nxt/test/rbtree_unit_test.c @@ -8,10 +8,10 @@ #include #include #include +#include #include #include #include -#include #include #include @@ -39,7 +39,7 @@ rbtree_unit_test(nxt_uint_t n) nxt_rbtree_node_t *node; nxt_rbtree_test_t *items, *item; - printf("rbtree unit test started: %ld nodes\n", (long) n); + nxt_printf("rbtree unit test started: %l nodes\n", (long) n); nxt_rbtree_init(&tree, rbtree_unit_test_comparison); @@ -74,7 +74,8 @@ rbtree_unit_test(nxt_uint_t n) node = nxt_rbtree_find(&tree, &items[i].node); if (node != (nxt_rbtree_node_t *) &items[i].node) { - printf("rbtree unit test failed: %08X not found\n", items[i].key); + nxt_printf("rbtree unit test failed: %08uXD not found\n", + items[i].key); goto fail; } } @@ -87,8 +88,8 @@ rbtree_unit_test(nxt_uint_t n) item = (nxt_rbtree_test_t *) node; if (keys[i] != item->key) { - printf("rbtree unit test failed: %ld: %08X %08X\n", - (long) i, keys[i], item->key); + nxt_printf("rbtree unit test failed: %l: %08uXD %08uXD\n", + (long) i, keys[i], item->key); goto fail; } @@ -97,7 +98,7 @@ rbtree_unit_test(nxt_uint_t n) } if (i != n) { - printf("rbtree unit test failed: %ld\n", (long) i); + nxt_printf("rbtree unit test failed: %l\n", (long) i); goto fail; } @@ -107,21 +108,21 @@ rbtree_unit_test(nxt_uint_t n) } if (!nxt_rbtree_is_empty(&tree)) { - printf("rbtree unit test failed: tree is not empty\n"); + nxt_printf("rbtree unit test failed: tree is not empty\n"); goto fail; } /* Check that the sentinel callback was not modified. */ if (mark != tree.sentinel.right) { - printf("rbtree sentinel unit test failed\n"); + nxt_printf("rbtree sentinel unit test failed\n"); goto fail; } free(keys); free(items); - printf("rbtree unit test passed\n"); + nxt_printf("rbtree unit test passed\n"); return NXT_OK; diff --git a/nxt/test/utf8_unit_test.c b/nxt/test/utf8_unit_test.c index ba8c16ae..0e66262e 100644 --- a/nxt/test/utf8_unit_test.c +++ b/nxt/test/utf8_unit_test.c @@ -7,10 +7,10 @@ #include #include #include +#include #include #include #include -#include #include @@ -72,8 +72,8 @@ utf8_overlong(u_char *overlong, size_t len) u = (u << 8) + overlong[i]; } - printf("nxt_utf8_decode(%05Xd, %zd) failed: %05Xd, %zd\n", - u, len, d, size); + nxt_printf("nxt_utf8_decode(%05uXD, %uz) failed: %05uXD, %uz\n", + u, len, d, size); return NXT_ERROR; } @@ -93,7 +93,7 @@ utf8_unit_test(nxt_uint_t start) nxt_uint_t i, k, l, m; const u_char *pp; - printf("utf8 unit test started\n"); + nxt_printf("utf8 unit test started\n"); /* Test valid UTF-8. */ @@ -102,7 +102,7 @@ utf8_unit_test(nxt_uint_t start) p = nxt_utf8_encode(utf8, u); if (p == NULL) { - printf("nxt_utf8_encode(%05Xd) failed\n", u); + nxt_printf("nxt_utf8_encode(%05uXD) failed\n", u); return NXT_ERROR; } @@ -111,7 +111,7 @@ utf8_unit_test(nxt_uint_t start) d = nxt_utf8_decode(&pp, p); if (u != d) { - printf("nxt_utf8_decode(%05Xd) failed: %05uxD\n", u, d); + nxt_printf("nxt_utf8_decode(%05uXD) failed: %05uxD\n", u, d); return NXT_ERROR; } } @@ -137,7 +137,8 @@ utf8_unit_test(nxt_uint_t start) u = (u << 8) + utf8[i]; } - printf("nxt_utf8_decode(%05Xd, %zd) failed: %05Xd\n", u, len, d); + nxt_printf("nxt_utf8_decode(%05uXD, %uz) failed: %05uXD\n", + u, len, d); return NXT_ERROR; } } @@ -182,11 +183,11 @@ utf8_unit_test(nxt_uint_t start) nxt_length("abc абв αβγ")); if (n != 0) { - printf("nxt_utf8_casecmp() failed\n"); + nxt_printf("nxt_utf8_casecmp() failed\n"); return NXT_ERROR; } - printf("utf8 unit test passed\n"); + nxt_printf("utf8 unit test passed\n"); return NXT_OK; }