From: hongzhidao Date: Wed, 6 Feb 2019 04:27:41 +0000 (+0800) Subject: Shell: improved filenames reporting in exceptions. X-Git-Tag: 0.2.8~39 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=a23dfa3894c28dc58f5d3613e974d27ae02d4dcb;p=njs.git Shell: improved filenames reporting in exceptions. --- diff --git a/Makefile b/Makefile index cedb074d..f7a364f5 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,7 @@ $(NXT_BUILDDIR)/libnjs.a: \ $(NXT_BUILDDIR)/nxt_sha2.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_time.o \ + $(NXT_BUILDDIR)/nxt_file.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_sprintf.o \ @@ -96,6 +97,7 @@ $(NXT_BUILDDIR)/libnjs.a: \ $(NXT_BUILDDIR)/nxt_sha2.o \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_time.o \ + $(NXT_BUILDDIR)/nxt_file.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_sprintf.o \ diff --git a/njs/njs_core.h b/njs/njs_core.h index 614c2069..40f43728 100644 --- a/njs/njs_core.h +++ b/njs/njs_core.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/njs/njs_shell.c b/njs/njs_shell.c index 0645812e..26a24ade 100644 --- a/njs/njs_shell.c +++ b/njs/njs_shell.c @@ -215,8 +215,10 @@ main(int argc, char **argv) nxt_memzero(&vm_options, sizeof(njs_vm_opt_t)); if (opts.file != NULL) { - vm_options.file.start = (u_char *) opts.file; - vm_options.file.length = strlen(opts.file); + nxt_file_name(&vm_options.file, opts.file); + + } else { + vm_options.file = nxt_string_value("shell"); } vm_options.init = !opts.interactive; @@ -1071,4 +1073,3 @@ lvlhsh_pool_free(void *pool, void *p, size_t size) { nxt_mp_free(pool, p); } - diff --git a/njs/test/njs_expect_test.exp b/njs/test/njs_expect_test.exp index 8b56a096..4ddd2bdf 100644 --- a/njs/test/njs_expect_test.exp +++ b/njs/test/njs_expect_test.exp @@ -269,7 +269,7 @@ njs_test { {"JSON.parse(Error())\r\n" "JSON.parse(Error())\r\nSyntaxError: Unexpected token at position 0*at JSON.parse (native)"} {"JSON.parse(Error()\r\n" - "JSON.parse(Error()\r\nSyntaxError: Unexpected token \"\" in 1"} + "JSON.parse(Error()\r\nSyntaxError: Unexpected token \"\" in shell:1"} } njs_test { @@ -281,7 +281,7 @@ njs_test { njs_test { {"(function() { throw 'test' })()\r\n" - "test\r\n at anonymous (:1)"} + "test\r\n at anonymous (shell:1)"} } # Non-ASCII characters diff --git a/nxt/Makefile b/nxt/Makefile index 407f9050..f65e7422 100644 --- a/nxt/Makefile +++ b/nxt/Makefile @@ -21,6 +21,7 @@ $(NXT_BUILDDIR)/libnxt.a: \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_trace.o \ $(NXT_BUILDDIR)/nxt_time.o \ + $(NXT_BUILDDIR)/nxt_file.o \ $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_sprintf.o \ @@ -40,6 +41,7 @@ $(NXT_BUILDDIR)/libnxt.a: \ $(NXT_BUILDDIR)/nxt_pcre.o \ $(NXT_BUILDDIR)/nxt_malloc.o \ $(NXT_BUILDDIR)/nxt_time.o \ + $(NXT_BUILDDIR)/nxt_file.o \ $(NXT_BUILDDIR)/nxt_trace.o \ $(NXT_BUILDDIR)/nxt_mp.o \ $(NXT_BUILDDIR)/nxt_sprintf.o \ @@ -221,6 +223,17 @@ $(NXT_BUILDDIR)/nxt_time.o: \ -I$(NXT_LIB) \ $(NXT_LIB)/nxt_time.c +$(NXT_BUILDDIR)/nxt_file.o: \ + $(NXT_LIB)/nxt_auto_config.h \ + $(NXT_LIB)/nxt_types.h \ + $(NXT_LIB)/nxt_clang.h \ + $(NXT_LIB)/nxt_file.h \ + $(NXT_LIB)/nxt_file.c \ + + $(NXT_CC) -c -o $(NXT_BUILDDIR)/nxt_file.o $(NXT_CFLAGS) \ + -I$(NXT_LIB) \ + $(NXT_LIB)/nxt_file.c + $(NXT_BUILDDIR)/nxt_trace.o: \ $(NXT_LIB)/nxt_auto_config.h \ $(NXT_LIB)/nxt_types.h \ diff --git a/nxt/nxt_file.c b/nxt/nxt_file.c new file mode 100644 index 00000000..2bf3aae3 --- /dev/null +++ b/nxt/nxt_file.c @@ -0,0 +1,33 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#include +#include +#include +#include +#include + +#include + + +void +nxt_file_name(nxt_str_t *name, char *path) +{ + char *p; + size_t length; + + length = strlen(path); + + for (p = path + length; p >= path; p--) { + if (*p == '/') { + p++; + break; + } + } + + name->start = (u_char *) p; + name->length = length - (p - path); +} diff --git a/nxt/nxt_file.h b/nxt/nxt_file.h new file mode 100644 index 00000000..545c5a0a --- /dev/null +++ b/nxt/nxt_file.h @@ -0,0 +1,14 @@ + +/* + * Copyright (C) Igor Sysoev + * Copyright (C) NGINX, Inc. + */ + +#ifndef _NXT_FILE_H_INCLUDED_ +#define _NXT_FILE_H_INCLUDED_ + + +void nxt_file_name(nxt_str_t *name, char *path); + + +#endif /* _NXT_FILE_H_INCLUDED_ */