Skip to content

Commit

Permalink
NJS: loader should be registered using njs_vm_set_module_loader()
Browse files Browse the repository at this point in the history
This change makes NJS module incompatible with NJS older than 0.8.3.
Therefore, the configuration version check has been adjusted accordingly.

This change was introduced in NJS 0.8.3 here:
<https://hg.nginx.com/njs/rev/ad1a7ad3c715>
  • Loading branch information
andrey-zelenkov committed Mar 11, 2024
1 parent 2e61525 commit 3aec4bd
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 25 deletions.
6 changes: 3 additions & 3 deletions auto/njs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ nxt_feature_incs="$NXT_NJS_CFLAGS $NXT_NJS_AUX_CFLAGS"
nxt_feature_libs="$NXT_NJS_LIBS $NXT_NJS_AUX_LIBS"
nxt_feature_test="#include <njs.h>

#if NJS_VERSION_NUMBER < 0x000800
# error NJS < 0.8.0 is not supported.
#if NJS_VERSION_NUMBER < 0x000803
# error NJS < 0.8.3 is not supported.
#endif

int main(void) {
Expand All @@ -44,7 +44,7 @@ nxt_feature_test="#include <njs.h>

if [ $nxt_found = no ]; then
$echo
$echo $0: error: no NJS library \>= 0.8.0 found.
$echo $0: error: no NJS library \>= 0.8.3 found.
$echo
exit 1;
fi
Expand Down
6 changes: 6 additions & 0 deletions docs/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ NGINX Unit updated to 1.33.0.
date="" time=""
packager="Nginx Packaging &lt;nginx-packaging@f5.com&gt;">

<change type="change">
<para>
if building with NJS, version 0.8.3 or later is now required.
</para>
</change>

</changes>


Expand Down
2 changes: 1 addition & 1 deletion pkg/contrib/src/njs/SHA512SUMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cc3110a0c6866dfc03d19c58745e5b75aa9792999db45bc55a752f7b04db8ae51322bfe0156b873109c8477c6c1a030c851c770697cf6791c6e89fb2fed0a2c5 njs-0.8.2.tar.gz
1cec9a322c40aa2b4ec6eb5bea78d7442880b0cff3a41ad171a3dc3157a6990baec6c8b9eda99ee02a9e51c0b933f13ef17431079a5ff409aaf84b912c7f4df7 njs-0.8.3.tar.gz
2 changes: 1 addition & 1 deletion pkg/contrib/src/njs/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NJS_VERSION := 0.8.2
NJS_VERSION := 0.8.3
18 changes: 8 additions & 10 deletions src/nxt_js.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ nxt_js_module_loader(njs_vm_t *vm, njs_external_ptr_t external, njs_str_t *name)
}


static njs_vm_ops_t nxt_js_ops = {
NULL,
NULL,
nxt_js_module_loader,
NULL,
};


njs_int_t nxt_js_proto_id;


Expand Down Expand Up @@ -127,6 +119,7 @@ nxt_js_vm_create(nxt_js_conf_t *jcf)
{
u_char *p;
size_t size;
njs_vm_t *vm;
nxt_uint_t i;
njs_vm_opt_t opts;
nxt_js_module_t *module, *mod;
Expand All @@ -146,7 +139,6 @@ nxt_js_vm_create(nxt_js_conf_t *jcf)
goto done;
}

opts.ops = &nxt_js_ops;
opts.external = jcf;

size = 0;
Expand Down Expand Up @@ -203,7 +195,13 @@ nxt_js_vm_create(nxt_js_conf_t *jcf)

done:

return njs_vm_create(&opts);
vm = njs_vm_create(&opts);

if (nxt_fast_path(vm != NULL)) {
njs_vm_set_module_loader(vm, nxt_js_module_loader, jcf);
}

return vm;
}


Expand Down
10 changes: 0 additions & 10 deletions src/nxt_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ static void nxt_script_buf_completion(nxt_task_t *task, void *obj, void *data);
static nxt_lvlhsh_t nxt_script_info;


static njs_vm_ops_t nxt_js_ops = {
NULL,
NULL,
nxt_js_module_loader,
NULL,
};


nxt_script_t *
nxt_script_new(nxt_task_t *task, nxt_str_t *name, u_char *data, size_t size,
u_char *error)
Expand All @@ -63,8 +55,6 @@ nxt_script_new(nxt_task_t *task, nxt_str_t *name, u_char *data, size_t size,
opts.file.start = (u_char *) "default";
opts.file.length = 7;

opts.ops = &nxt_js_ops;

vm = njs_vm_create(&opts);
if (nxt_slow_path(vm == NULL)) {
return NULL;
Expand Down

0 comments on commit 3aec4bd

Please sign in to comment.