Welcome! Log In Create A New Profile

Advanced

[njs] Added generic handler for external objects.

Dmitry Volyntsev
August 20, 2022 01:10AM
details: https://hg.nginx.org/njs/rev/aecd8b5387d2
branches:
changeset: 1930:aecd8b5387d2
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Aug 19 22:03:06 2022 -0700
description:
Added generic handler for external objects.

diffstat:

src/njs.h | 10 ++++++++++
src/njs_extern.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 0 deletions(-)

diffs (70 lines):

diff -r 7d2fb383e424 -r aecd8b5387d2 src/njs.h
--- a/src/njs.h Fri Aug 19 22:02:37 2022 -0700
+++ b/src/njs.h Fri Aug 19 22:03:06 2022 -0700
@@ -139,6 +139,13 @@ typedef enum {
} njs_extern_flag_t;


+typedef enum {
+ NJS_EXTERN_TYPE_INT = 0,
+ NJS_EXTERN_TYPE_UINT = 1,
+ NJS_EXTERN_TYPE_VALUE = 2,
+} njs_extern_type_t;
+
+
struct njs_external_s {
njs_extern_flag_t flags;

@@ -361,6 +368,9 @@ NJS_EXPORT njs_int_t njs_vm_external_cre
njs_int_t proto_id, njs_external_ptr_t external, njs_bool_t shared);
NJS_EXPORT njs_external_ptr_t njs_vm_external(njs_vm_t *vm,
njs_int_t proto_id, const njs_value_t *value);
+NJS_EXPORT njs_int_t njs_external_property(njs_vm_t *vm,
+ njs_object_prop_t *prop, njs_value_t *value, njs_value_t *setval,
+ njs_value_t *retval);
NJS_EXPORT uintptr_t njs_vm_meta(njs_vm_t *vm, njs_uint_t index);

NJS_EXPORT njs_function_t *njs_vm_function_alloc(njs_vm_t *vm,
diff -r 7d2fb383e424 -r aecd8b5387d2 src/njs_extern.c
--- a/src/njs_extern.c Fri Aug 19 22:02:37 2022 -0700
+++ b/src/njs_extern.c Fri Aug 19 22:03:06 2022 -0700
@@ -343,3 +343,39 @@ njs_value_external_tag(const njs_value_t

return -1;
}
+
+
+njs_int_t
+njs_external_property(njs_vm_t *vm, njs_object_prop_t *prop, njs_value_t *value,
+ njs_value_t *setval, njs_value_t *retval)
+{
+ char *p;
+ njs_int_t i;
+ njs_uint_t ui;
+
+ p = njs_vm_external(vm, NJS_PROTO_ID_ANY, value);
+ if (p == NULL) {
+ njs_value_undefined_set(retval);
+ return NJS_DECLINED;
+ }
+
+ switch (njs_vm_prop_magic16(prop)) {
+ case NJS_EXTERN_TYPE_INT:
+ i = *(njs_int_t *) (p + njs_vm_prop_magic32(prop));
+ njs_value_number_set(retval, i);
+ break;
+
+ case NJS_EXTERN_TYPE_UINT:
+ ui = *(njs_uint_t *) (p + njs_vm_prop_magic32(prop));
+ njs_value_number_set(retval, ui);
+ break;
+
+ case NJS_EXTERN_TYPE_VALUE:
+ default:
+ njs_value_assign(retval,
+ (njs_value_t *) (p + njs_vm_prop_magic32(prop)));
+
+ }
+
+ return NJS_OK;
+}
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Added generic handler for external objects.

Dmitry Volyntsev 215 August 20, 2022 01:10AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 67
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready