[njs] Removed vm->count.

Dmitry Volyntsev xeioex at nginx.com
Fri Aug 2 17:12:21 UTC 2019


details:   https://hg.nginx.org/njs/rev/e592647bdb12
branches:  
changeset: 1098:e592647bdb12
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Aug 02 20:12:01 2019 +0300
description:
Removed vm->count.

Previously it was used to catch infinite recursion.
This is redundant, because NJS_MAX_STACK_SIZE is used for
the same purpose.

diffstat:

 src/njs_vm.h             |   4 +---
 src/njs_vmcode.c         |  23 ++++-------------------
 src/test/njs_unit_test.c |   4 ++++
 3 files changed, 9 insertions(+), 22 deletions(-)

diffs (116 lines):

diff -r 219a6024c4c8 -r e592647bdb12 src/njs_vm.h
--- a/src/njs_vm.h	Fri Aug 02 16:05:44 2019 +0300
+++ b/src/njs_vm.h	Fri Aug 02 20:12:01 2019 +0300
@@ -8,7 +8,7 @@
 #define _NJS_VM_H_INCLUDED_
 
 
-#define NJS_MAX_STACK_SIZE       (16 * 1024 * 1024)
+#define NJS_MAX_STACK_SIZE       (256 * 1024)
 
 
 /*
@@ -229,8 +229,6 @@ struct njs_vm_s {
     /* njs_vm_t must be aligned to njs_value_t due to scratch value. */
     njs_value_t              retval;
 
-    njs_uint_t               count;
-
     njs_arr_t                *paths;
 
     u_char                   *start;
diff -r 219a6024c4c8 -r e592647bdb12 src/njs_vmcode.c
--- a/src/njs_vmcode.c	Fri Aug 02 16:05:44 2019 +0300
+++ b/src/njs_vmcode.c	Fri Aug 02 20:12:01 2019 +0300
@@ -105,13 +105,6 @@ njs_vmcode_interpreter(njs_vm_t *vm, u_c
     njs_vmcode_try_return_t      *try_return;
     njs_vmcode_function_frame_t  *function_frame;
 
-    if (njs_slow_path(vm->count > 128)) {
-        njs_range_error(vm, "Maximum call stack size exceeded");
-        return NJS_ERROR;
-    }
-
-    vm->count++;
-
 next:
 
     for ( ;; ) {
@@ -588,8 +581,7 @@ next:
                 value2 = njs_vmcode_operand(vm, value2);
                 vm->retval = *value2;
 
-                ret = NJS_OK;
-                goto done;
+                return NJS_OK;
 
             case NJS_VMCODE_JUMP:
                 ret = (njs_jump_off_t) value2;
@@ -671,8 +663,7 @@ next:
 
                 njs_function_frame_free(vm, &frame->native);
 
-                ret = NJS_OK;
-                goto done;
+                return NJS_OK;
 
             case NJS_VMCODE_FUNCTION_FRAME:
                 function_frame = (njs_vmcode_function_frame_t *) pc;
@@ -800,7 +791,7 @@ next:
 
                 switch (ret) {
                 case NJS_OK:
-                    goto done;
+                    return NJS_OK;
                 case NJS_ERROR:
                     goto error;
                 }
@@ -822,8 +813,6 @@ next:
 
 error:
 
-    ret = NJS_ERROR;
-
     for ( ;; ) {
         frame = (njs_frame_t *) vm->top_frame;
 
@@ -864,11 +853,7 @@ error:
         }
     }
 
-done:
-
-    vm->count--;
-
-    return ret;
+    return NJS_ERROR;
 }
 
 
diff -r 219a6024c4c8 -r e592647bdb12 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Aug 02 16:05:44 2019 +0300
+++ b/src/test/njs_unit_test.c	Fri Aug 02 20:12:01 2019 +0300
@@ -4154,10 +4154,12 @@ static njs_unit_test_t  njs_test[] =
                  "Array.prototype.fill.call(o, 2).a"),
       njs_str("4") },
 
+#if (!NJS_HAVE_MEMORY_SANITIZER) /* MSAN limits stack size */
     { njs_str("var o = Object({length: 3});"
                  "Object.defineProperty(o, '0', {set: function(v){this[0] = 2 * v}});"
                  "Array.prototype.fill.call(o, 2)"),
       njs_str("RangeError: Maximum call stack size exceeded") },
+#endif
 
     { njs_str("var a = [];"
                  "a.filter(function(v, i, a) { return v > 1 })"),
@@ -6410,8 +6412,10 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("{ function f() {} { var f }}"),
       njs_str("SyntaxError: \"f\" has already been declared in 1") },
 
+#if (!NJS_HAVE_MEMORY_SANITIZER) /* MSAN limits stack size */
     { njs_str("function f() { return f() } f()"),
       njs_str("RangeError: Maximum call stack size exceeded") },
+#endif
 
     { njs_str("function () { } f()"),
       njs_str("SyntaxError: Unexpected token \"(\" in 1") },


More information about the nginx-devel mailing list