Welcome! Log In Create A New Profile

Advanced

[njs] Shell: improved filenames reporting in exceptions.

Dmitry Volyntsev
February 06, 2019 07:42AM
details: https://hg.nginx.org/njs/rev/2c7a52ca206e
branches:
changeset: 763:2c7a52ca206e
user: hongzhidao <hongzhidao@gmail.com>
date: Wed Feb 06 12:27:41 2019 +0800
description:
Shell: improved filenames reporting in exceptions.

diffstat:

Makefile | 2 ++
njs/njs_core.h | 1 +
njs/njs_shell.c | 7 ++++---
njs/test/njs_expect_test.exp | 4 ++--
nxt/Makefile | 13 +++++++++++++
nxt/nxt_file.c | 33 +++++++++++++++++++++++++++++++++
nxt/nxt_file.h | 14 ++++++++++++++
7 files changed, 69 insertions(+), 5 deletions(-)

diffs (164 lines):

diff -r 3b8ea515add6 -r 2c7a52ca206e Makefile
--- a/Makefile Tue Feb 05 19:27:24 2019 +0300
+++ b/Makefile Wed Feb 06 12:27:41 2019 +0800
@@ -49,6 +49,7 @@ NXT_BUILDDIR = build
$(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 = build
$(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 -r 3b8ea515add6 -r 2c7a52ca206e njs/njs_core.h
--- a/njs/njs_core.h Tue Feb 05 19:27:24 2019 +0300
+++ b/njs/njs_core.h Wed Feb 06 12:27:41 2019 +0800
@@ -25,6 +25,7 @@
#include <nxt_lvlhsh.h>
#include <nxt_random.h>
#include <nxt_time.h>
+#include <nxt_file.h>
#include <nxt_malloc.h>
#include <nxt_mp.h>
#include <nxt_sprintf.h>
diff -r 3b8ea515add6 -r 2c7a52ca206e njs/njs_shell.c
--- a/njs/njs_shell.c Tue Feb 05 19:27:24 2019 +0300
+++ b/njs/njs_shell.c Wed Feb 06 12:27:41 2019 +0800
@@ -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, si
{
nxt_mp_free(pool, p);
}
-
diff -r 3b8ea515add6 -r 2c7a52ca206e njs/test/njs_expect_test.exp
--- a/njs/test/njs_expect_test.exp Tue Feb 05 19:27:24 2019 +0300
+++ b/njs/test/njs_expect_test.exp Wed Feb 06 12:27:41 2019 +0800
@@ -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 -r 3b8ea515add6 -r 2c7a52ca206e nxt/Makefile
--- a/nxt/Makefile Tue Feb 05 19:27:24 2019 +0300
+++ b/nxt/Makefile Wed Feb 06 12:27:41 2019 +0800
@@ -21,6 +21,7 @@ NXT_LIB = nxt
$(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_LIB = nxt
$(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_LIB = nxt
-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 -r 3b8ea515add6 -r 2c7a52ca206e nxt/nxt_file.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nxt/nxt_file.c Wed Feb 06 12:27:41 2019 +0800
@@ -0,0 +1,33 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_auto_config.h>
+#include <nxt_types.h>
+#include <nxt_clang.h>
+#include <nxt_string.h>
+#include <nxt_file.h>
+
+#include <string.h>
+
+
+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 -r 3b8ea515add6 -r 2c7a52ca206e nxt/nxt_file.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nxt/nxt_file.h Wed Feb 06 12:27:41 2019 +0800
@@ -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_ */
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Shell: improved filenames reporting in exceptions.

Dmitry Volyntsev 96 February 06, 2019 07:42AM



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

Online Users

Guests: 74
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