[njs] Removed unused njs_vm_export_functions().
details: http://hg.nginx.org/njs/rev/f8f7540383f2 branches: changeset: 382:f8f7540383f2 user: Dmitry Volyntsev date: Wed Jun 28 15:31:36 2017 +0300 description: Removed unused njs_vm_export_functions(). diffstat: nginx/ngx_http_js_module.c | 4 +- nginx/ngx_stream_js_module.c | 4 +- njs/njs_variable.c | 56 njs/njs_variable.h | 2 - njs/njscript.c | 7 + njs/njscript.h | 3 +- njs/test/njs_unit_test.c | 9 +++--- 7 files changed, 10 insertions(+), 75 deletions(-) diffs (197 lines): diff -r 63d7430291f2 -r f8f7540383f2 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.cTue Jun 27 17:03:16 2017 +0300 +++ b/nginx/ngx_http_js_module.cWed Jun 28 15:31:36 2017 +0300 @@ -1230,7 +1230,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ ngx_fd_t fd; ngx_str_t *value, file; nxt_int_t rc; -nxt_str_t text, ext, *export; +nxt_str_t text, ext; nxt_lvlhsh_t externals; ngx_file_info_tfi; njs_vm_shared_t *shared; @@ -1327,7 +1327,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ return NGX_CONF_ERROR; } -rc = njs_vm_compile(jlcf->vm, &start, end, &export); +rc = njs_vm_compile(jlcf->vm, &start, end); if (rc != NJS_OK) { njs_vm_exception(jlcf->vm, &text); diff -r 63d7430291f2 -r f8f7540383f2 nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Tue Jun 27 17:03:16 2017 +0300 +++ b/nginx/ngx_stream_js_module.c Wed Jun 28 15:31:36 2017 +0300 @@ -940,7 +940,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng ngx_fd_t fd; ngx_str_t *value, file; nxt_int_t rc; -nxt_str_t text, ext, *export; +nxt_str_t text, ext; nxt_lvlhsh_t externals; ngx_file_info_tfi; njs_vm_shared_t *shared; @@ -1037,7 +1037,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ng return NGX_CONF_ERROR; } -rc = njs_vm_compile(jscf->vm, &start, end, &export); +rc = njs_vm_compile(jscf->vm, &start, end); if (rc != NJS_OK) { njs_vm_exception(jscf->vm, &text); diff -r 63d7430291f2 -r f8f7540383f2 njs/njs_variable.c --- a/njs/njs_variable.cTue Jun 27 17:03:16 2017 +0300 +++ b/njs/njs_variable.cWed Jun 28 15:31:36 2017 +0300 @@ -489,62 +489,6 @@ njs_name_copy(njs_vm_t *vm, nxt_str_t *d } -nxt_str_t * -njs_vm_export_functions(njs_vm_t *vm) -{ -size_t n; -nxt_str_t *ex, *export; -njs_value_t*value; -njs_variable_t *var; -nxt_lvlhsh_each_t lhe; - -n = 1; - -nxt_lvlhsh_each_init(&lhe, &njs_variables_hash_proto); - -for ( ;; ) { -var = nxt_lvlhsh_each(&vm->variables_hash, &lhe); -if (var == NULL) { -break; -} - -value = njs_global_variable_value(vm, var); - -if (njs_is_function(value) && !value->data.u.function->native) { -n++; -} -} - -export = nxt_mem_cache_alloc(vm->mem_cache_pool, n * sizeof(nxt_str_t)); -if (nxt_slow_path(export == NULL)) { -return NULL; -} - -nxt_lvlhsh_each_init(&lhe, &njs_variables_hash_proto); - -ex = export; - -for ( ;; ) { -var = nxt_lvlhsh_each(&vm->variables_hash, &lhe); -if (var == NULL) { -break; -} - -value = njs_global_variable_value(vm, var); - -if (njs_is_function(value) && !value->data.u.function->native) { -*ex = var->name; -ex++; -} -} - -ex->length = 0; -ex->start = NULL; - -return export; -} - - njs_function_t * njs_vm_function(njs_vm_t *vm, nxt_str_t *name) { diff -r 63d7430291f2 -r f8f7540383f2 njs/njs_variable.h --- a/njs/njs_variable.hTue Jun 27 17:03:16 2017 +0300 +++ b/njs/njs_variable.hWed Jun 28 15:31:36 2017 +0300 @@ -42,8 +42,6 @@ njs_ret_t njs_variables_scope_reference( njs_parser_scope_t *scope); njs_ret_t njs_name_copy(njs_vm_t *vm, nxt_str_t *dst, nxt_str_t *src); -nxt_str_t *njs_vm_export_functions(njs_vm_t *vm); - extern const nxt_lvlhsh_proto_t njs_variables_hash_proto; diff -r 63d7430291f2 -r f8f7540383f2 njs/njscript.c --- a/njs/njscript.cTue Jun 27 17:03:16 2017 +0300 +++ b/njs/njscript.cWed Jun 28 15:31:36 2017 +0300 @@ -184,7 +184,7 @@ njs_vm_destroy(njs_vm_t *vm) nxt_int_t -njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end, nxt_str_t **export) +njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end) { nxt_int_t ret; njs_lexer_t*lexer; @@ -237,11 +237,6 @@ njs_vm_compile(njs_vm_t *vm, u_char **st vm->parser = NULL; -*export = njs_vm_export_functions(vm); -if (nxt_slow_path(*export == NULL)) { -return NJS_ERROR; -} - return N
[njs] Passing all args to njs_vm_create() through njs_vm_opt_t struct.
details: http://hg.nginx.org/njs/rev/57bd01817edb branches: changeset: 383:57bd01817edb user: Dmitry Volyntsev date: Thu Jul 06 19:07:41 2017 +0300 description: Passing all args to njs_vm_create() through njs_vm_opt_t struct. diffstat: nginx/ngx_http_js_module.c | 10 ++ nginx/ngx_stream_js_module.c | 10 ++ njs/njscript.c | 18 +- njs/njscript.h | 9 +++-- njs/test/njs_unit_test.c | 20 5 files changed, 40 insertions(+), 27 deletions(-) diffs (215 lines): diff -r f8f7540383f2 -r 57bd01817edb nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.cWed Jun 28 15:31:36 2017 +0300 +++ b/nginx/ngx_http_js_module.cThu Jul 06 19:07:41 2017 +0300 @@ -1231,9 +1231,9 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ ngx_str_t *value, file; nxt_int_t rc; nxt_str_t text, ext; +njs_vm_opt_t options; nxt_lvlhsh_t externals; ngx_file_info_tfi; -njs_vm_shared_t *shared; ngx_pool_cleanup_t*cln; nxt_mem_cache_pool_t *mcp; @@ -1309,8 +1309,6 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ cln->handler = ngx_http_js_cleanup_mem_cache_pool; cln->data = mcp; -shared = NULL; - nxt_lvlhsh_init(&externals); if (njs_vm_external_add(&externals, mcp, 0, ngx_http_js_externals, @@ -1321,7 +1319,11 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_ return NGX_CONF_ERROR; } -jlcf->vm = njs_vm_create(mcp, &shared, &externals); +options.mcp = mcp; +options.shared = NULL; +options.externals = &externals; + +jlcf->vm = njs_vm_create(&options); if (jlcf->vm == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to create JS VM"); return NGX_CONF_ERROR; diff -r f8f7540383f2 -r 57bd01817edb nginx/ngx_stream_js_module.c --- a/nginx/ngx_stream_js_module.c Wed Jun 28 15:31:36 2017 +0300 +++ b/nginx/ngx_stream_js_module.c Thu Jul 06 19:07:41 2017 +0300 @@ -941,9 +941,9 @@ ngx_stream_js_include(ngx_conf_t *cf, ng ngx_str_t *value, file; nxt_int_t rc; nxt_str_t text, ext; +njs_vm_opt_t options; nxt_lvlhsh_t externals; ngx_file_info_tfi; -njs_vm_shared_t *shared; ngx_pool_cleanup_t*cln; nxt_mem_cache_pool_t *mcp; @@ -1019,8 +1019,6 @@ ngx_stream_js_include(ngx_conf_t *cf, ng cln->handler = ngx_stream_js_cleanup_mem_cache_pool; cln->data = mcp; -shared = NULL; - nxt_lvlhsh_init(&externals); if (njs_vm_external_add(&externals, mcp, 0, ngx_stream_js_externals, @@ -1031,7 +1029,11 @@ ngx_stream_js_include(ngx_conf_t *cf, ng return NGX_CONF_ERROR; } -jscf->vm = njs_vm_create(mcp, &shared, &externals); +options.mcp = mcp; +options.shared = NULL; +options.externals = &externals; + +jscf->vm = njs_vm_create(&options); if (jscf->vm == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "failed to create JS VM"); return NGX_CONF_ERROR; diff -r f8f7540383f2 -r 57bd01817edb njs/njscript.c --- a/njs/njscript.cWed Jun 28 15:31:36 2017 +0300 +++ b/njs/njscript.cThu Jul 06 19:07:41 2017 +0300 @@ -99,13 +99,15 @@ const nxt_mem_proto_t njs_array_mem_pro njs_vm_t * -njs_vm_create(nxt_mem_cache_pool_t *mcp, njs_vm_shared_t **shared, -nxt_lvlhsh_t *externals) +njs_vm_create(njs_vm_opt_t *options) { njs_vm_t *vm; nxt_int_t ret; +nxt_mem_cache_pool_t *mcp; njs_regexp_pattern_t *pattern; +mcp = options->mcp; + if (mcp == NULL) { mcp = nxt_mem_cache_pool_create(&njs_vm_mem_cache_pool_proto, NULL, NULL, 2 * nxt_pagesize(), 128, 512, 16); @@ -124,8 +126,8 @@ njs_vm_create(nxt_mem_cache_pool_t *mcp, return NULL; } -if (shared != NULL && *shared != NULL) { -vm->shared = *shared; +if (options->shared != NULL) { +vm->shared = options->shared; } else { vm->shared = nxt_mem_cache_zalloc(mcp, sizeof(njs_vm_shared_t)); @@ -133,9 +135,7 @@ njs_vm_create(nxt_mem_cache_pool_t *mcp, return NULL; } -if (shared != NULL) { -*shared = vm->shared; -} +options->shared = vm->shared; nxt_lvlhsh_init(&vm->shared->keywords_hash); @@ -162,8 +162,8 @@ njs_vm_create(nxt_mem_cache_pool_t *mcp, nxt_lvlhsh_init(&vm->values_hash); -if (externals != NULL) { -vm->externals_hash = *externals; +if (options->externals != NULL) { +vm->externals_hash = *options->externals; } vm->trace.level = NXT_LEVEL_TRACE; diff -r f8f7540383f2 -r 57bd01817edb njs/njscript.h --- a/njs/njscript.hWed Jun
[njs] Moving VM initialization from njs_vm_clone() to njs_vm_init().
details: http://hg.nginx.org/njs/rev/d09638142829 branches: changeset: 384:d09638142829 user: Dmitry Volyntsev date: Thu Jul 06 19:09:56 2017 +0300 description: Moving VM initialization from njs_vm_clone() to njs_vm_init(). diffstat: njs/njscript.c | 102 +--- 1 files changed, 60 insertions(+), 42 deletions(-) diffs (144 lines): diff -r 57bd01817edb -r d09638142829 njs/njscript.c --- a/njs/njscript.cThu Jul 06 19:07:41 2017 +0300 +++ b/njs/njscript.cThu Jul 06 19:09:56 2017 +0300 @@ -26,6 +26,9 @@ #include +static nxt_int_t njs_vm_init(njs_vm_t *vm); + + static void * njs_alloc(void *mem, size_t size) { @@ -244,11 +247,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **st njs_vm_t * njs_vm_clone(njs_vm_t *vm, nxt_mem_cache_pool_t *mcp, void **external) { -u_char*values; -size_tsize, scope_size; njs_vm_t *nvm; nxt_int_t ret; -njs_frame_t *frame; nxt_mem_cache_pool_t *nmcp; nxt_thread_log_debug("CLONE:"); @@ -274,54 +274,17 @@ njs_vm_clone(njs_vm_t *vm, nxt_mem_cache nvm->values_hash = vm->values_hash; nvm->externals_hash = vm->externals_hash; -nvm->retval = njs_value_void; nvm->current = vm->current; nvm->external = external; nvm->global_scope = vm->global_scope; -scope_size = vm->scope_size; -nvm->scope_size = scope_size; -scope_size += NJS_INDEX_GLOBAL_OFFSET; - -size = NJS_GLOBAL_FRAME_SIZE + scope_size + NJS_FRAME_SPARE_SIZE; -size = nxt_align_size(size, NJS_FRAME_SPARE_SIZE); - -frame = nxt_mem_cache_align(nmcp, sizeof(njs_value_t), size); -if (nxt_slow_path(frame == NULL)) { -goto fail; -} - -memset(frame, 0, NJS_GLOBAL_FRAME_SIZE); +nvm->scope_size = vm->scope_size; -nvm->top_frame = &frame->native; -nvm->active_frame = frame; - -frame->native.size = size; -frame->native.free_size = size - (NJS_GLOBAL_FRAME_SIZE + scope_size); - -values = (u_char *) frame + NJS_GLOBAL_FRAME_SIZE; - -frame->native.free = values + scope_size; - -nvm->scopes[NJS_SCOPE_GLOBAL] = (njs_value_t *) values; -memcpy(values + NJS_INDEX_GLOBAL_OFFSET, vm->global_scope, - vm->scope_size); - -ret = njs_regexp_init(nvm); +ret = njs_vm_init(nvm); if (nxt_slow_path(ret != NXT_OK)) { goto fail; } -ret = njs_builtin_objects_clone(nvm); -if (nxt_slow_path(ret != NXT_OK)) { -goto fail; -} - -nvm->trace.level = NXT_LEVEL_TRACE; -nvm->trace.size = 2048; -nvm->trace.handler = njs_parser_trace_handler; -nvm->trace.data = nvm; - return nvm; } @@ -335,6 +298,61 @@ fail: } +static nxt_int_t +njs_vm_init(njs_vm_t *vm) +{ +size_t size, scope_size; +u_char *values; +nxt_int_tret; +njs_frame_t *frame; + +scope_size = vm->scope_size + NJS_INDEX_GLOBAL_OFFSET; + +size = NJS_GLOBAL_FRAME_SIZE + scope_size + NJS_FRAME_SPARE_SIZE; +size = nxt_align_size(size, NJS_FRAME_SPARE_SIZE); + +frame = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), size); +if (nxt_slow_path(frame == NULL)) { +return NXT_ERROR; +} + +memset(frame, 0, NJS_GLOBAL_FRAME_SIZE); + +vm->top_frame = &frame->native; +vm->active_frame = frame; + +frame->native.size = size; +frame->native.free_size = size - (NJS_GLOBAL_FRAME_SIZE + scope_size); + +values = (u_char *) frame + NJS_GLOBAL_FRAME_SIZE; + +frame->native.free = values + scope_size; + +vm->scopes[NJS_SCOPE_GLOBAL] = (njs_value_t *) values; +memcpy(values + NJS_INDEX_GLOBAL_OFFSET, vm->global_scope, + vm->scope_size); + +ret = njs_regexp_init(vm); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + +ret = njs_builtin_objects_clone(vm); +if (nxt_slow_path(ret != NXT_OK)) { +return NXT_ERROR; +} + +vm->retval = njs_value_void; + +vm->trace.level = NXT_LEVEL_TRACE; +vm->trace.size = 2048; +vm->trace.handler = njs_parser_trace_handler; +vm->trace.data = vm; + +return NXT_OK; +} + + nxt_int_t njs_vm_call(njs_vm_t *vm, njs_function_t *function, njs_opaque_value_t *args, nxt_uint_t nargs) ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel
Module Development Consulting
Hi, I'm willing to pay someone familiar with nginx module development to spend an hour or 2 with me on google hangouts. The easiest method for me is to send payment via paypal. Is there anyone interested in this? -- Thanks, Joe Spencer (member) Kogo Software LLC ___ nginx-devel mailing list nginx-devel@nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel