[njs] Adding const qualifiers njs_value_t arguments of public methods.
Dmitry Volyntsev
xeioex at nginx.com
Wed Aug 1 15:37:32 UTC 2018
details: http://hg.nginx.org/njs/rev/72aa4d9aa606
branches:
changeset: 580:72aa4d9aa606
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Wed Aug 01 18:05:01 2018 +0300
description:
Adding const qualifiers njs_value_t arguments of public methods.
This allows to use the result of safe njs_arg() macro in the
methods.
diffstat:
njs/njs.c | 10 +++++-----
njs/njs.h | 41 ++++++++++++++++++++---------------------
njs/njs_extern.c | 2 +-
njs/njs_function.c | 2 +-
njs/njs_function.h | 2 +-
njs/njs_vm.c | 26 +++++++++++++-------------
6 files changed, 41 insertions(+), 42 deletions(-)
diffs (284 lines):
diff -r c85b07c96e27 -r 72aa4d9aa606 njs/njs.c
--- a/njs/njs.c Tue Jul 31 21:11:44 2018 +0300
+++ b/njs/njs.c Wed Aug 01 18:05:01 2018 +0300
@@ -444,7 +444,7 @@ njs_vm_init(njs_vm_t *vm)
nxt_int_t
-njs_vm_call(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
+njs_vm_call(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
nxt_uint_t nargs)
{
u_char *current;
@@ -531,7 +531,7 @@ njs_vm_pending(njs_vm_t *vm)
nxt_int_t
njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event,
- njs_value_t *args, nxt_uint_t nargs)
+ const njs_value_t *args, nxt_uint_t nargs)
{
njs_event_t *event;
@@ -654,9 +654,9 @@ njs_vm_retval(njs_vm_t *vm)
nxt_noinline void
-njs_vm_retval_set(njs_vm_t *vm, njs_value_t *value)
+njs_vm_retval_set(njs_vm_t *vm, const njs_value_t *value)
{
- vm->retval = *(njs_value_t *) value;
+ vm->retval = *value;
}
@@ -680,7 +680,7 @@ njs_ret_t njs_vm_retval_to_ext_string(nj
njs_value_t *
-njs_vm_object_prop(njs_vm_t *vm, njs_value_t *value, const nxt_str_t *key)
+njs_vm_object_prop(njs_vm_t *vm, const njs_value_t *value, const nxt_str_t *key)
{
nxt_int_t ret;
njs_object_prop_t *prop;
diff -r c85b07c96e27 -r 72aa4d9aa606 njs/njs.h
--- a/njs/njs.h Tue Jul 31 21:11:44 2018 +0300
+++ b/njs/njs.h Wed Aug 01 18:05:01 2018 +0300
@@ -48,8 +48,7 @@ typedef struct {
extern const njs_value_t njs_value_void;
#define njs_arg(args, nargs, n) \
- (njs_value_t *) ((n < nargs) ? njs_argument(args, n) \
- : &njs_value_void)
+ ((n < nargs) ? njs_argument(args, n) : &njs_value_void)
#define njs_value_assign(dst, src) \
*((njs_opaque_value_t *) dst) = *((njs_opaque_value_t *) src);
@@ -162,7 +161,7 @@ NXT_EXPORT void njs_vm_destroy(njs_vm_t
NXT_EXPORT nxt_int_t njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end);
NXT_EXPORT njs_vm_t *njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external);
NXT_EXPORT nxt_int_t njs_vm_call(njs_vm_t *vm, njs_function_t *function,
- njs_value_t *args, nxt_uint_t nargs);
+ const njs_value_t *args, nxt_uint_t nargs);
NXT_EXPORT njs_vm_event_t njs_vm_add_event(njs_vm_t *vm,
njs_function_t *function, njs_host_event_t host_ev,
@@ -170,7 +169,7 @@ NXT_EXPORT njs_vm_event_t njs_vm_add_eve
NXT_EXPORT void njs_vm_del_event(njs_vm_t *vm, njs_vm_event_t vm_event);
NXT_EXPORT nxt_int_t njs_vm_pending(njs_vm_t *vm);
NXT_EXPORT nxt_int_t njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event,
- njs_value_t *args, nxt_uint_t nargs);
+ const njs_value_t *args, nxt_uint_t nargs);
NXT_EXPORT nxt_int_t njs_vm_run(njs_vm_t *vm);
@@ -179,7 +178,7 @@ NXT_EXPORT const njs_extern_t *njs_vm_ex
NXT_EXPORT nxt_int_t njs_vm_external_create(njs_vm_t *vm,
njs_value_t *value, const njs_extern_t *proto, njs_external_ptr_t object);
NXT_EXPORT nxt_int_t njs_vm_external_bind(njs_vm_t *vm,
- const nxt_str_t *var_name, njs_value_t *value);
+ const nxt_str_t *var_name, const njs_value_t *value);
NXT_EXPORT njs_external_ptr_t njs_vm_external(njs_vm_t *vm,
const njs_value_t *value);
@@ -188,7 +187,7 @@ NXT_EXPORT nxt_array_t *njs_vm_completio
NXT_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, nxt_str_t *name);
NXT_EXPORT njs_value_t *njs_vm_retval(njs_vm_t *vm);
-NXT_EXPORT void njs_vm_retval_set(njs_vm_t *vm, njs_value_t *value);
+NXT_EXPORT void njs_vm_retval_set(njs_vm_t *vm, const njs_value_t *value);
NXT_EXPORT u_char * njs_string_alloc(njs_vm_t *vm, njs_value_t *value,
uint32_t size, uint32_t length);
@@ -196,7 +195,7 @@ NXT_EXPORT njs_ret_t njs_string_create(n
u_char *start, uint32_t size, uint32_t length);
NXT_EXPORT nxt_int_t njs_value_string_copy(njs_vm_t *vm, nxt_str_t *retval,
- njs_value_t *value, uintptr_t *next);
+ const njs_value_t *value, uintptr_t *next);
NXT_EXPORT njs_ret_t njs_vm_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst,
const njs_value_t *src, nxt_uint_t handle_exception);
@@ -212,24 +211,24 @@ NXT_EXPORT void njs_value_data_set(njs_v
NXT_EXPORT void njs_value_error_set(njs_vm_t *vm, njs_value_t *value,
const char *fmt, ...);
-NXT_EXPORT uint8_t njs_value_bool(njs_value_t *value);
-NXT_EXPORT double njs_value_number(njs_value_t *value);
-NXT_EXPORT void *njs_value_data(njs_value_t *value);
-NXT_EXPORT njs_function_t *njs_value_function(njs_value_t *value);
+NXT_EXPORT uint8_t njs_value_bool(const njs_value_t *value);
+NXT_EXPORT double njs_value_number(const njs_value_t *value);
+NXT_EXPORT void *njs_value_data(const njs_value_t *value);
+NXT_EXPORT njs_function_t *njs_value_function(const njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_null(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_void(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_boolean(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_number(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_valid_number(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_string(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_object(njs_value_t *value);
-NXT_EXPORT nxt_int_t njs_value_is_function(njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_null(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_void(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_boolean(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_number(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_valid_number(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_string(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_object(const njs_value_t *value);
+NXT_EXPORT nxt_int_t njs_value_is_function(const njs_value_t *value);
NXT_EXPORT njs_ret_t njs_vm_value_dump(njs_vm_t *vm, nxt_str_t *retval,
const njs_value_t *value, nxt_uint_t indent);
-NXT_EXPORT njs_value_t *njs_vm_object_prop(njs_vm_t *vm, njs_value_t *value,
- const nxt_str_t *key);
+NXT_EXPORT njs_value_t *njs_vm_object_prop(njs_vm_t *vm,
+ const njs_value_t *value, const nxt_str_t *key);
extern const nxt_mem_proto_t njs_vm_mem_cache_pool_proto;
diff -r c85b07c96e27 -r 72aa4d9aa606 njs/njs_extern.c
--- a/njs/njs_extern.c Tue Jul 31 21:11:44 2018 +0300
+++ b/njs/njs_extern.c Wed Aug 01 18:05:01 2018 +0300
@@ -193,7 +193,7 @@ njs_vm_external_create(njs_vm_t *vm, njs
nxt_int_t
njs_vm_external_bind(njs_vm_t *vm, const nxt_str_t *var_name,
- njs_value_t *value)
+ const njs_value_t *value)
{
nxt_int_t ret;
njs_extern_value_t *ev;
diff -r c85b07c96e27 -r 72aa4d9aa606 njs/njs_function.c
--- a/njs/njs_function.c Tue Jul 31 21:11:44 2018 +0300
+++ b/njs/njs_function.c Wed Aug 01 18:05:01 2018 +0300
@@ -144,7 +144,7 @@ njs_function_native_frame(njs_vm_t *vm,
nxt_noinline njs_ret_t
njs_function_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
+ const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor)
{
size_t size;
diff -r c85b07c96e27 -r 72aa4d9aa606 njs/njs_function.h
--- a/njs/njs_function.h Tue Jul 31 21:11:44 2018 +0300
+++ b/njs/njs_function.h Wed Aug 01 18:05:01 2018 +0300
@@ -158,7 +158,7 @@ njs_ret_t njs_function_native_frame(njs_
const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
size_t reserve, nxt_bool_t ctor);
njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
- const njs_value_t *this, njs_value_t *args, nxt_uint_t nargs,
+ const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor);
njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
diff -r c85b07c96e27 -r 72aa4d9aa606 njs/njs_vm.c
--- a/njs/njs_vm.c Tue Jul 31 21:11:44 2018 +0300
+++ b/njs/njs_vm.c Wed Aug 01 18:05:01 2018 +0300
@@ -3521,63 +3521,63 @@ memory_error:
nxt_noinline uint8_t
-njs_value_bool(njs_value_t *value)
+njs_value_bool(const njs_value_t *value)
{
return value->data.truth;
}
nxt_noinline double
-njs_value_number(njs_value_t *value)
+njs_value_number(const njs_value_t *value)
{
return value->data.u.number;
}
nxt_noinline void *
-njs_value_data(njs_value_t *value)
+njs_value_data(const njs_value_t *value)
{
return value->data.u.data;
}
nxt_noinline njs_function_t *
-njs_value_function(njs_value_t *value)
+njs_value_function(const njs_value_t *value)
{
return value->data.u.function;
}
nxt_noinline nxt_int_t
-njs_value_is_null(njs_value_t *value)
+njs_value_is_null(const njs_value_t *value)
{
return njs_is_null(value);
}
nxt_noinline nxt_int_t
-njs_value_is_void(njs_value_t *value)
+njs_value_is_void(const njs_value_t *value)
{
return njs_is_void(value);
}
nxt_noinline nxt_int_t
-njs_value_is_boolean(njs_value_t *value)
+njs_value_is_boolean(const njs_value_t *value)
{
return njs_is_boolean(value);
}
nxt_noinline nxt_int_t
-njs_value_is_number(njs_value_t *value)
+njs_value_is_number(const njs_value_t *value)
{
return njs_is_number(value);
}
nxt_noinline nxt_int_t
-njs_value_is_valid_number(njs_value_t *value)
+njs_value_is_valid_number(const njs_value_t *value)
{
return njs_is_number(value)
&& !isnan(value->data.u.number)
@@ -3586,28 +3586,28 @@ njs_value_is_valid_number(njs_value_t *v
nxt_noinline nxt_int_t
-njs_value_is_string(njs_value_t *value)
+njs_value_is_string(const njs_value_t *value)
{
return njs_is_string(value);
}
nxt_noinline nxt_int_t
-njs_value_is_object(njs_value_t *value)
+njs_value_is_object(const njs_value_t *value)
{
return njs_is_object(value);
}
nxt_noinline nxt_int_t
-njs_value_is_function(njs_value_t *value)
+njs_value_is_function(const njs_value_t *value)
{
return njs_is_function(value);
}
nxt_int_t
-njs_value_string_copy(njs_vm_t *vm, nxt_str_t *retval, njs_value_t *value,
+njs_value_string_copy(njs_vm_t *vm, nxt_str_t *retval, const njs_value_t *value,
uintptr_t *next)
{
uintptr_t n;
More information about the nginx-devel
mailing list