[njs] Introduced njs_vm_set_module_loader().
Dmitry Volyntsev
xeioex at nginx.com
Fri Dec 15 06:58:09 UTC 2023
details: https://hg.nginx.org/njs/rev/ad1a7ad3c715
branches:
changeset: 2248:ad1a7ad3c715
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed Dec 13 18:38:47 2023 -0800
description:
Introduced njs_vm_set_module_loader().
diffstat:
external/njs_shell.c | 1 -
nginx/ngx_http_js_module.c | 1 -
nginx/ngx_stream_js_module.c | 1 -
src/njs.h | 3 ++-
src/njs_module.c | 6 +++---
src/njs_vm.c | 9 +++++++++
src/njs_vm.h | 3 +++
7 files changed, 17 insertions(+), 7 deletions(-)
diffs (101 lines):
diff -r 34df3f0796cf -r ad1a7ad3c715 external/njs_shell.c
--- a/external/njs_shell.c Mon Dec 11 19:10:38 2023 -0800
+++ b/external/njs_shell.c Wed Dec 13 18:38:47 2023 -0800
@@ -269,7 +269,6 @@ static njs_external_t njs_ext_262[] = {
static njs_vm_ops_t njs_console_ops = {
- NULL,
njs_console_log,
};
diff -r 34df3f0796cf -r ad1a7ad3c715 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Mon Dec 11 19:10:38 2023 -0800
+++ b/nginx/ngx_http_js_module.c Wed Dec 13 18:38:47 2023 -0800
@@ -840,7 +840,6 @@ static njs_external_t ngx_http_js_ext_p
static njs_vm_ops_t ngx_http_js_ops = {
- NULL,
ngx_js_logger,
};
diff -r 34df3f0796cf -r ad1a7ad3c715 nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c Mon Dec 11 19:10:38 2023 -0800
+++ b/nginx/ngx_stream_js_module.c Wed Dec 13 18:38:47 2023 -0800
@@ -609,7 +609,6 @@ static njs_external_t ngx_stream_js_ext
static njs_vm_ops_t ngx_stream_js_ops = {
- NULL,
ngx_js_logger,
};
diff -r 34df3f0796cf -r ad1a7ad3c715 src/njs.h
--- a/src/njs.h Mon Dec 11 19:10:38 2023 -0800
+++ b/src/njs.h Wed Dec 13 18:38:47 2023 -0800
@@ -214,7 +214,6 @@ typedef void (*njs_logger_t)(njs_vm_t *v
typedef struct {
- njs_module_loader_t module_loader;
njs_logger_t logger;
} njs_vm_ops_t;
@@ -310,6 +309,8 @@ NJS_EXPORT njs_vm_t *njs_vm_create(njs_v
NJS_EXPORT void njs_vm_destroy(njs_vm_t *vm);
NJS_EXPORT njs_int_t njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end);
+NJS_EXPORT void njs_vm_set_module_loader(njs_vm_t *vm,
+ njs_module_loader_t module_loader, void *opaque);
NJS_EXPORT njs_mod_t *njs_vm_add_module(njs_vm_t *vm, njs_str_t *name,
njs_value_t *value);
NJS_EXPORT njs_mod_t *njs_vm_compile_module(njs_vm_t *vm, njs_str_t *name,
diff -r 34df3f0796cf -r ad1a7ad3c715 src/njs_module.c
--- a/src/njs_module.c Mon Dec 11 19:10:38 2023 -0800
+++ b/src/njs_module.c Wed Dec 13 18:38:47 2023 -0800
@@ -48,9 +48,9 @@ njs_parser_module(njs_parser_t *parser,
external = parser;
loader = njs_default_module_loader;
- if (vm->options.ops != NULL && vm->options.ops->module_loader != NULL) {
- loader = vm->options.ops->module_loader;
- external = vm->external;
+ if (vm->module_loader != NULL) {
+ loader = vm->module_loader;
+ external = vm->module_loader_opaque;
}
module = loader(vm, external, name);
diff -r 34df3f0796cf -r ad1a7ad3c715 src/njs_vm.c
--- a/src/njs_vm.c Mon Dec 11 19:10:38 2023 -0800
+++ b/src/njs_vm.c Wed Dec 13 18:38:47 2023 -0800
@@ -730,6 +730,15 @@ njs_vm_execute_pending_job(njs_vm_t *vm)
}
+void
+njs_vm_set_module_loader(njs_vm_t *vm, njs_module_loader_t module_loader,
+ void *opaque)
+{
+ vm->module_loader = module_loader;
+ vm->module_loader_opaque = opaque;
+}
+
+
njs_int_t
njs_vm_add_path(njs_vm_t *vm, const njs_str_t *path)
{
diff -r 34df3f0796cf -r ad1a7ad3c715 src/njs_vm.h
--- a/src/njs_vm.h Mon Dec 11 19:10:38 2023 -0800
+++ b/src/njs_vm.h Wed Dec 13 18:38:47 2023 -0800
@@ -182,6 +182,9 @@ struct njs_vm_s {
njs_rbtree_t global_symbols;
uint64_t symbol_generator;
+
+ njs_module_loader_t module_loader;
+ void *module_loader_opaque;
};
More information about the nginx-devel
mailing list