[njs] Improved njs_function_native_call().

Dmitry Volyntsev xeioex at nginx.com
Sat Apr 27 14:32:39 UTC 2019


details:   https://hg.nginx.org/njs/rev/b9becf29a21d
branches:  
changeset: 933:b9becf29a21d
user:      hongzhidao <hongzhidao at gmail.com>
date:      Fri Apr 26 19:57:54 2019 +0800
description:
Improved njs_function_native_call().

diffstat:

 njs/njs_function.c |   4 +++-
 njs/njs_function.h |   2 +-
 njs/njs_vm.c       |  33 ++++++---------------------------
 3 files changed, 10 insertions(+), 29 deletions(-)

diffs (99 lines):

diff -r 60e98e247a53 -r b9becf29a21d njs/njs_function.c
--- a/njs/njs_function.c	Fri Apr 26 19:30:43 2019 +0300
+++ b/njs/njs_function.c	Fri Apr 26 19:57:54 2019 +0800
@@ -566,7 +566,7 @@ njs_function_lambda_call(njs_vm_t *vm, n
 njs_ret_t
 njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
     njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
-    njs_index_t retval)
+    njs_index_t retval, u_char *return_address)
 {
     njs_ret_t           ret;
     njs_value_t         *value;
@@ -617,6 +617,8 @@ njs_function_native_call(njs_vm_t *vm, n
             *value = vm->retval;
         }
 
+        vm->current = return_address;
+
         njs_function_frame_free(vm, frame);
 
         return NXT_OK;
diff -r 60e98e247a53 -r b9becf29a21d njs/njs_function.h
--- a/njs/njs_function.h	Fri Apr 26 19:30:43 2019 +0300
+++ b/njs/njs_function.h	Fri Apr 26 19:57:54 2019 +0800
@@ -173,7 +173,7 @@ njs_ret_t njs_function_lambda_call(njs_v
     u_char *return_address);
 njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
     njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
-    njs_index_t retval);
+    njs_index_t retval, u_char *return_address);
 void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
 
 
diff -r 60e98e247a53 -r b9becf29a21d njs/njs_vm.c
--- a/njs/njs_vm.c	Fri Apr 26 19:30:43 2019 +0300
+++ b/njs/njs_vm.c	Fri Apr 26 19:57:54 2019 +0800
@@ -2047,7 +2047,8 @@ njs_vmcode_function_call(njs_vm_t *vm, n
             ret = njs_function_native_call(vm, function->u.native,
                                            frame->arguments,
                                            function->args_types, frame->nargs,
-                                           (njs_index_t) retval);
+                                           (njs_index_t) retval,
+                                           return_address);
         }
 
     } else {
@@ -2055,16 +2056,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n
                                        return_address);
     }
 
-    switch (ret) {
-    case NXT_OK:
-        return sizeof(njs_vmcode_function_call_t);
-
-    case NJS_APPLIED:
-        return 0;
-
-    default:
-        return ret;
-    }
+    return (ret == NJS_APPLIED) ? 0 : ret;
 }
 
 
@@ -2292,31 +2284,18 @@ const njs_vmcode_generic_t  njs_continua
 static njs_ret_t
 njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2)
 {
-    u_char              *return_address;
     njs_ret_t           ret;
     njs_native_frame_t  *frame;
     njs_continuation_t  *cont;
 
     frame = vm->top_frame;
-
     cont = njs_vm_continuation(vm);
-    return_address = cont->return_address;
 
     ret = njs_function_native_call(vm, cont->function, frame->arguments,
                                    cont->args_types, frame->nargs,
-                                   cont->retval);
-
-    switch (ret) {
-    case NXT_OK:
-        vm->current = return_address;
-        /* Fall through. */
-
-    case NJS_APPLIED:
-        return 0;
-
-    default:
-        return ret;
-    }
+                                   cont->retval, cont->return_address);
+
+    return (ret == NJS_APPLIED) ? 0 : ret;
 }
 
 


More information about the nginx-devel mailing list