[njs] Refactored njs_arr_t API.
Dmitry Volyntsev
xeioex at nginx.com
Fri Aug 2 09:32:09 UTC 2019
details: https://hg.nginx.org/njs/rev/aaec532e9d08
branches:
changeset: 1093:aaec532e9d08
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Aug 02 12:12:30 2019 +0300
description:
Refactored njs_arr_t API.
1) const njs_mem_proto_t *proto is removed from arguments.
2) njs_mp_t *mp is passed during array creation.
diffstat:
src/njs.h | 2 -
src/njs_arr.c | 121 ++++++++++++++++++++++++++-------------------------
src/njs_arr.h | 49 +++++++++-----------
src/njs_builtin.c | 8 +--
src/njs_extern.c | 3 +-
src/njs_generator.c | 12 ++---
src/njs_json.c | 17 +++---
src/njs_main.h | 2 +-
src/njs_module.c | 5 +-
src/njs_parser.c | 3 +-
src/njs_string.c | 26 ++++------
src/njs_stub.h | 11 ----
src/njs_variable.c | 5 +-
src/njs_vm.c | 47 +++----------------
src/njs_vm.h | 2 +-
15 files changed, 127 insertions(+), 186 deletions(-)
diffs (768 lines):
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs.h
--- a/src/njs.h Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs.h Fri Aug 02 12:12:30 2019 +0300
@@ -18,7 +18,6 @@
#include <njs_clang.h>
#include <njs_str.h>
#include <njs_stub.h>
-#include <njs_arr.h>
#include <njs_lvlhsh.h>
@@ -225,7 +224,6 @@ NJS_EXPORT njs_external_ptr_t njs_vm_ext
const njs_value_t *value);
NJS_EXPORT void njs_disassembler(njs_vm_t *vm);
-NJS_EXPORT njs_arr_t *njs_vm_completions(njs_vm_t *vm, njs_str_t *expression);
NJS_EXPORT const njs_value_t *njs_vm_value(njs_vm_t *vm, const njs_str_t *name);
NJS_EXPORT njs_function_t *njs_vm_function(njs_vm_t *vm, const njs_str_t *name);
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_arr.c
--- a/src/njs_arr.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_arr.c Fri Aug 02 12:12:30 2019 +0300
@@ -7,98 +7,99 @@
#include <njs_auto_config.h>
#include <njs_types.h>
#include <njs_clang.h>
-#include <njs_stub.h>
+#include <njs_mp.h>
#include <njs_arr.h>
#include <njs_str.h>
#include <string.h>
njs_arr_t *
-njs_arr_create(uint32_t items, uint32_t item_size,
- const njs_mem_proto_t *proto, void *pool)
+njs_arr_create(njs_mp_t *mp, njs_uint_t n, size_t size)
{
- njs_arr_t *array;
-
- array = proto->alloc(pool, sizeof(njs_arr_t) + items * item_size);
+ njs_arr_t *arr;
- if (njs_fast_path(array != NULL)) {
- array->start = (char *) array + sizeof(njs_arr_t);
- array->items = 0;
- array->item_size = item_size;
- array->avalaible = items;
- array->pointer = 1;
- array->separate = 1;
+ arr = njs_mp_alloc(mp, sizeof(njs_arr_t) + n * size);
+ if (njs_slow_path(arr == NULL)) {
+ return NULL;
}
- return array;
+ arr->start = (char *) arr + sizeof(njs_arr_t);
+ arr->items = 0;
+ arr->item_size = size;
+ arr->avalaible = n;
+ arr->pointer = 1;
+ arr->separate = 1;
+ arr->mem_pool = mp;
+
+ return arr;
}
void *
-njs_arr_init(njs_arr_t *array, void *start, uint32_t items,
- uint32_t item_size, const njs_mem_proto_t *proto, void *pool)
+njs_arr_init(njs_mp_t *mp, njs_arr_t *arr, void *start, njs_uint_t n,
+ size_t size)
{
- array->start = start;
- array->items = items;
- array->item_size = item_size;
- array->avalaible = items;
- array->pointer = 0;
- array->separate = 0;
+ arr->start = start;
+ arr->items = n;
+ arr->item_size = size;
+ arr->avalaible = n;
+ arr->pointer = 0;
+ arr->separate = 0;
+ arr->mem_pool = mp;
- if (array->start == NULL) {
- array->separate = 1;
- array->items = 0;
+ if (arr->start == NULL) {
+ arr->separate = 1;
+ arr->items = 0;
- array->start = proto->alloc(pool, items * item_size);
+ arr->start = njs_mp_alloc(mp, n * size);
}
- return array->start;
+ return arr->start;
}
void
-njs_arr_destroy(njs_arr_t *array, const njs_mem_proto_t *proto, void *pool)
+njs_arr_destroy(njs_arr_t *arr)
{
- if (array->separate) {
- proto->free(pool, array->start);
+ if (arr->separate) {
+ njs_mp_free(arr->mem_pool, arr->start);
#if (NJS_DEBUG)
- array->start = NULL;
- array->items = 0;
- array->avalaible = 0;
+ arr->start = NULL;
+ arr->items = 0;
+ arr->avalaible = 0;
#endif
}
- if (array->pointer) {
- proto->free(pool, array);
+ if (arr->pointer) {
+ njs_mp_free(arr->mem_pool, arr);
}
}
void *
-njs_arr_add(njs_arr_t *array, const njs_mem_proto_t *proto, void *pool)
+njs_arr_add(njs_arr_t *arr)
{
- return njs_arr_add_multiple(array, proto, pool, 1);
+ return njs_arr_add_multiple(arr, 1);
}
void *
-njs_arr_add_multiple(njs_arr_t *array, const njs_mem_proto_t *proto,
- void *pool, uint32_t items)
+njs_arr_add_multiple(njs_arr_t *arr, njs_uint_t items)
{
void *item, *start, *old;
uint32_t n;
- n = array->avalaible;
- items += array->items;
+ n = arr->avalaible;
+ items += arr->items;
if (items >= n) {
if (n < 16) {
- /* Allocate new array twice as much as current. */
+ /* Allocate new arr twice as much as current. */
n *= 2;
} else {
- /* Allocate new array half as much as current. */
+ /* Allocate new arr half as much as current. */
n += n / 2;
}
@@ -106,42 +107,42 @@ njs_arr_add_multiple(njs_arr_t *array, c
n = items;
}
- start = proto->alloc(pool, n * array->item_size);
+ start = njs_mp_alloc(arr->mem_pool, n * arr->item_size);
if (njs_slow_path(start == NULL)) {
return NULL;
}
- array->avalaible = n;
- old = array->start;
- array->start = start;
+ arr->avalaible = n;
+ old = arr->start;
+ arr->start = start;
- memcpy(start, old, (uint32_t) array->items * array->item_size);
+ memcpy(start, old, (uint32_t) arr->items * arr->item_size);
- if (array->separate == 0) {
- array->separate = 1;
+ if (arr->separate == 0) {
+ arr->separate = 1;
} else {
- proto->free(pool, old);
+ njs_mp_free(arr->mem_pool, old);
}
}
- item = (char *) array->start + (uint32_t) array->items * array->item_size;
+ item = (char *) arr->start + (uint32_t) arr->items * arr->item_size;
- array->items = items;
+ arr->items = items;
return item;
}
void *
-njs_arr_zero_add(njs_arr_t *array, const njs_mem_proto_t *proto, void *pool)
+njs_arr_zero_add(njs_arr_t *arr)
{
void *item;
- item = njs_arr_add(array, proto, pool);
+ item = njs_arr_add(arr);
if (njs_fast_path(item != NULL)) {
- njs_memzero(item, array->item_size);
+ njs_memzero(item, arr->item_size);
}
return item;
@@ -149,13 +150,13 @@ njs_arr_zero_add(njs_arr_t *array, const
void
-njs_arr_remove(njs_arr_t *array, void *item)
+njs_arr_remove(njs_arr_t *arr, void *item)
{
u_char *next, *last, *end;
uint32_t item_size;
- item_size = array->item_size;
- end = (u_char *) array->start + item_size * array->items;
+ item_size = arr->item_size;
+ end = (u_char *) arr->start + item_size * arr->items;
last = end - item_size;
if (item != last) {
@@ -164,5 +165,5 @@ njs_arr_remove(njs_arr_t *array, void *i
memmove(item, next, end - next);
}
- array->items--;
+ arr->items--;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_arr.h
--- a/src/njs_arr.h Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_arr.h Fri Aug 02 12:12:30 2019 +0300
@@ -20,47 +20,44 @@ typedef struct {
uint8_t pointer;
uint8_t separate;
+ njs_mp_t *mem_pool;
} njs_arr_t;
-NJS_EXPORT njs_arr_t *njs_arr_create(uint32_t items, uint32_t item_size,
- const njs_mem_proto_t *proto, void *pool);
-NJS_EXPORT void *njs_arr_init(njs_arr_t *array, void *start, uint32_t items,
- uint32_t item_size, const njs_mem_proto_t *proto, void *pool);
-NJS_EXPORT void njs_arr_destroy(njs_arr_t *array,
- const njs_mem_proto_t *proto, void *pool);
-NJS_EXPORT void *njs_arr_add(njs_arr_t *array, const njs_mem_proto_t *proto,
- void *pool);
-NJS_EXPORT void *njs_arr_add_multiple(njs_arr_t *array,
- const njs_mem_proto_t *proto, void *pool, uint32_t items);
-NJS_EXPORT void *njs_arr_zero_add(njs_arr_t *array,
- const njs_mem_proto_t *proto, void *pool);
-NJS_EXPORT void njs_arr_remove(njs_arr_t *array, void *item);
+NJS_EXPORT njs_arr_t *njs_arr_create(njs_mp_t *mp, njs_uint_t n,
+ size_t size);
+NJS_EXPORT void *njs_arr_init(njs_mp_t *mp, njs_arr_t *arr, void *start,
+ njs_uint_t n, size_t size);
+NJS_EXPORT void njs_arr_destroy(njs_arr_t *arr);
+NJS_EXPORT void *njs_arr_add(njs_arr_t *arr);
+NJS_EXPORT void *njs_arr_add_multiple(njs_arr_t *arr, njs_uint_t n);
+NJS_EXPORT void *njs_arr_zero_add(njs_arr_t *arr);
+NJS_EXPORT void njs_arr_remove(njs_arr_t *arr, void *item);
-#define njs_arr_item(array, i) \
- ((void *) ((char *) (array)->start + (array)->item_size * (i)))
+#define njs_arr_item(arr, i) \
+ ((void *) ((char *) (arr)->start + (arr)->item_size * (i)))
-#define njs_arr_last(array) \
- ((void *) \
- ((char *) (array)->start \
- + (array)->item_size * ((array)->items - 1)))
+#define njs_arr_last(arr) \
+ ((void *) \
+ ((char *) (arr)->start \
+ + (arr)->item_size * ((arr)->items - 1)))
-#define njs_arr_reset(array) \
- (array)->items = 0;
+#define njs_arr_reset(arr) \
+ (arr)->items = 0;
-#define njs_arr_is_empty(array) \
- ((array)->items == 0)
+#define njs_arr_is_empty(arr) \
+ ((arr)->items == 0)
njs_inline void *
-njs_arr_remove_last(njs_arr_t *array)
+njs_arr_remove_last(njs_arr_t *arr)
{
- array->items--;
- return (char *) array->start + array->item_size * array->items;
+ arr->items--;
+ return (char *) arr->start + arr->item_size * arr->items;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_builtin.c
--- a/src/njs_builtin.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_builtin.c Fri Aug 02 12:12:30 2019 +0300
@@ -772,9 +772,7 @@ njs_vm_completions(njs_vm_t *vm, njs_str
if (expression == NULL) {
size = njs_builtin_completions_size(vm);
- completions = njs_arr_create(size, sizeof(njs_str_t),
- &njs_array_mem_proto, vm->mem_pool);
-
+ completions = njs_arr_create(vm->mem_pool, size, sizeof(njs_str_t));
if (njs_slow_path(completions == NULL)) {
return NULL;
}
@@ -897,9 +895,7 @@ njs_object_completions(njs_vm_t *vm, njs
} while (o != NULL);
- completions = njs_arr_create(size, sizeof(njs_str_t),
- &njs_array_mem_proto, vm->mem_pool);
-
+ completions = njs_arr_create(vm->mem_pool, size, sizeof(njs_str_t));
if (njs_slow_path(completions == NULL)) {
return NULL;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_extern.c
--- a/src/njs_extern.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_extern.c Fri Aug 02 12:12:30 2019 +0300
@@ -178,8 +178,7 @@ njs_vm_external_create(njs_vm_t *vm, njs
return NJS_ERROR;
}
- obj = njs_arr_add(vm->external_objects, &njs_array_mem_proto,
- vm->mem_pool);
+ obj = njs_arr_add(vm->external_objects);
if (njs_slow_path(obj == NULL)) {
return NJS_ERROR;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_generator.c
--- a/src/njs_generator.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_generator.c Fri Aug 02 12:12:30 2019 +0300
@@ -2432,14 +2432,13 @@ njs_generate_scope(njs_vm_t *vm, njs_gen
}
if (vm->codes == NULL) {
- vm->codes = njs_arr_create(4, sizeof(njs_vm_code_t),
- &njs_array_mem_proto, vm->mem_pool);
+ vm->codes = njs_arr_create(vm->mem_pool, 4, sizeof(njs_vm_code_t));
if (njs_slow_path(vm->codes == NULL)) {
return NJS_ERROR;
}
}
- code = njs_arr_add(vm->codes, &njs_array_mem_proto, vm->mem_pool);
+ code = njs_arr_add(vm->codes);
if (njs_slow_path(code == NULL)) {
return NJS_ERROR;
}
@@ -3265,8 +3264,7 @@ njs_generate_index_release(njs_vm_t *vm,
cache = generator->index_cache;
if (cache == NULL) {
- cache = njs_arr_create(4, sizeof(njs_value_t *),
- &njs_array_mem_proto, vm->mem_pool);
+ cache = njs_arr_create(vm->mem_pool, 4, sizeof(njs_value_t *));
if (njs_slow_path(cache == NULL)) {
return NJS_ERROR;
}
@@ -3274,7 +3272,7 @@ njs_generate_index_release(njs_vm_t *vm,
generator->index_cache = cache;
}
- last = njs_arr_add(cache, &njs_array_mem_proto, vm->mem_pool);
+ last = njs_arr_add(cache);
if (njs_fast_path(last != NULL)) {
*last = index;
return NJS_OK;
@@ -3317,7 +3315,7 @@ njs_generate_function_debug(njs_vm_t *vm
{
njs_function_debug_t *debug;
- debug = njs_arr_add(vm->debug, &njs_array_mem_proto, vm->mem_pool);
+ debug = njs_arr_add(vm->debug);
if (njs_slow_path(debug == NULL)) {
return NJS_ERROR;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_json.c
--- a/src/njs_json.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_json.c Fri Aug 02 12:12:30 2019 +0300
@@ -208,8 +208,8 @@ njs_json_parse(njs_vm_t *vm, njs_value_t
parse->function = njs_function(reviver);
- if (njs_arr_init(&parse->stack, NULL, 4, sizeof(njs_json_state_t),
- &njs_array_mem_proto, vm->mem_pool)
+ if (njs_arr_init(vm->mem_pool, &parse->stack, NULL, 4,
+ sizeof(njs_json_state_t))
== NULL)
{
goto memory_error;
@@ -305,8 +305,8 @@ njs_json_stringify(njs_vm_t *vm, njs_val
}
}
- if (njs_arr_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t),
- &njs_array_mem_proto, vm->mem_pool)
+ if (njs_arr_init(vm->mem_pool, &stringify->stack, NULL, 4,
+ sizeof(njs_json_state_t))
== NULL)
{
goto memory_error;
@@ -1103,7 +1103,7 @@ njs_json_push_parse_state(njs_vm_t *vm,
{
njs_json_state_t *state;
- state = njs_arr_add(&parse->stack, &njs_array_mem_proto, vm->mem_pool);
+ state = njs_arr_add(&parse->stack);
if (state != NULL) {
state = njs_arr_last(&parse->stack);
state->value = *value;
@@ -1693,8 +1693,7 @@ njs_json_push_stringify_state(njs_vm_t *
return NULL;
}
- state = njs_arr_add(&stringify->stack, &njs_array_mem_proto,
- vm->mem_pool);
+ state = njs_arr_add(&stringify->stack);
if (njs_slow_path(state == NULL)) {
njs_memory_error(vm);
return NULL;
@@ -2419,8 +2418,8 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_
njs_memset(stringify->space.start, ' ', indent);
- if (njs_arr_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t),
- &njs_array_mem_proto, vm->mem_pool)
+ if (njs_arr_init(vm->mem_pool, &stringify->stack, NULL, 4,
+ sizeof(njs_json_state_t))
== NULL)
{
goto memory_error;
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_main.h
--- a/src/njs_main.h Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_main.h Fri Aug 02 12:12:30 2019 +0300
@@ -20,7 +20,6 @@
#include <njs_strtod.h>
#include <njs_djb_hash.h>
#include <njs_trace.h>
-#include <njs_arr.h>
#include <njs_queue.h>
#include <njs_lvlhsh.h>
#include <njs_random.h>
@@ -28,6 +27,7 @@
#include <njs_file.h>
#include <njs_malloc.h>
#include <njs_mp.h>
+#include <njs_arr.h>
#include <njs_sprintf.h>
#include <njs.h>
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_module.c
--- a/src/njs_module.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_module.c Fri Aug 02 12:12:30 2019 +0300
@@ -492,14 +492,13 @@ njs_module_insert(njs_vm_t *vm, njs_modu
}
if (vm->modules == NULL) {
- vm->modules = njs_arr_create(4, sizeof(njs_module_t *),
- &njs_array_mem_proto, vm->mem_pool);
+ vm->modules = njs_arr_create(vm->mem_pool, 4, sizeof(njs_module_t *));
if (njs_slow_path(vm->modules == NULL)) {
return NJS_ERROR;
}
}
- value = njs_arr_add(vm->modules, &njs_array_mem_proto, vm->mem_pool);
+ value = njs_arr_add(vm->modules);
if (njs_slow_path(value == NULL)) {
return NJS_ERROR;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_parser.c
--- a/src/njs_parser.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_parser.c Fri Aug 02 12:12:30 2019 +0300
@@ -218,8 +218,7 @@ njs_parser_scope_begin(njs_vm_t *vm, njs
values = NULL;
if (scope->type < NJS_SCOPE_BLOCK) {
- values = njs_arr_create(4, sizeof(njs_value_t), &njs_array_mem_proto,
- vm->mem_pool);
+ values = njs_arr_create(vm->mem_pool, 4, sizeof(njs_value_t));
if (njs_slow_path(values == NULL)) {
return NJS_ERROR;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_string.c
--- a/src/njs_string.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_string.c Fri Aug 02 12:12:30 2019 +0300
@@ -3112,9 +3112,8 @@ njs_string_prototype_replace(njs_vm_t *v
}
/* This cannot fail. */
- r->part = njs_arr_init(&r->parts, &r->array,
- 3, sizeof(njs_string_replace_part_t),
- &njs_array_mem_proto, vm->mem_pool);
+ r->part = njs_arr_init(vm->mem_pool, &r->parts, &r->array,
+ 3, sizeof(njs_string_replace_part_t));
r->substitutions = NULL;
r->function = NULL;
@@ -3222,14 +3221,12 @@ njs_string_replace_regexp(njs_vm_t *vm,
}
if (r->part != r->parts.start) {
- r->part = njs_arr_add(&r->parts, &njs_array_mem_proto,
- vm->mem_pool);
+ r->part = njs_arr_add(&r->parts);
if (njs_slow_path(r->part == NULL)) {
return NJS_ERROR;
}
- r->part = njs_arr_add(&r->parts, &njs_array_mem_proto,
- vm->mem_pool);
+ r->part = njs_arr_add(&r->parts);
if (njs_slow_path(r->part == NULL)) {
return NJS_ERROR;
}
@@ -3297,7 +3294,7 @@ njs_string_replace_regexp(njs_vm_t *vm,
njs_regex_match_data_free(r->match_data, vm->regex_context);
- njs_arr_destroy(&r->parts, &njs_array_mem_proto, vm->mem_pool);
+ njs_arr_destroy(&r->parts);
njs_string_copy(&vm->retval, &args[0]);
@@ -3513,8 +3510,8 @@ njs_string_replace_parse(njs_vm_t *vm, n
uint32_t type;
njs_string_subst_t *s;
- r->substitutions = njs_arr_create(4, sizeof(njs_string_subst_t),
- &njs_array_mem_proto, vm->mem_pool);
+ r->substitutions = njs_arr_create(vm->mem_pool, 4,
+ sizeof(njs_string_subst_t));
if (njs_slow_path(r->substitutions == NULL)) {
return NJS_ERROR;
@@ -3529,7 +3526,7 @@ njs_string_replace_parse(njs_vm_t *vm, n
copy:
if (s == NULL) {
- s = njs_arr_add(r->substitutions, &njs_array_mem_proto, vm->mem_pool);
+ s = njs_arr_add(r->substitutions);
if (njs_slow_path(s == NULL)) {
return NJS_ERROR;
}
@@ -3593,7 +3590,7 @@ skip:
goto copy;
}
- s = njs_arr_add(r->substitutions, &njs_array_mem_proto, vm->mem_pool);
+ s = njs_arr_add(r->substitutions);
if (njs_slow_path(s == NULL)) {
return NJS_ERROR;
}
@@ -3621,8 +3618,7 @@ njs_string_replace_substitute(njs_vm_t *
last = r->substitutions->items;
end = r->part[0].start + r->part[0].size;
- part = njs_arr_add_multiple(&r->parts, &njs_array_mem_proto, vm->mem_pool,
- last + 1);
+ part = njs_arr_add_multiple(&r->parts, last + 1);
if (njs_slow_path(part == NULL)) {
return NJS_ERROR;
}
@@ -3801,7 +3797,7 @@ njs_string_replace_join(njs_vm_t *vm, nj
/* GC: release valid values. */
}
- njs_arr_destroy(&r->parts, &njs_array_mem_proto, vm->mem_pool);
+ njs_arr_destroy(&r->parts);
return NJS_OK;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_stub.h
--- a/src/njs_stub.h Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_stub.h Fri Aug 02 12:12:30 2019 +0300
@@ -22,17 +22,6 @@
#define NJS_DONE (-4)
-typedef struct {
- void *(*alloc)(void *mem, size_t size);
- void *(*zalloc)(void *mem, size_t size);
- void *(*align)(void *mem, size_t alignment, size_t size);
- void *(*zalign)(void *mem, size_t alignment, size_t size);
- void (*free)(void *mem, void *p);
- void (*alert)(void *trace, const char *fmt, ...);
- void njs_cdecl (*trace)(void *trace, const char *fmt, ...);
-} njs_mem_proto_t;
-
-
#define njs_thread_log_alert(...)
#define njs_thread_log_error(...)
#define njs_log_error(...)
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_variable.c
--- a/src/njs_variable.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_variable.c Fri Aug 02 12:12:30 2019 +0300
@@ -564,8 +564,7 @@ njs_scope_next_index(njs_vm_t *vm, njs_p
values = scope->values[scope_index];
if (values == NULL) {
- values = njs_arr_create(4, sizeof(njs_value_t),
- &njs_array_mem_proto, vm->mem_pool);
+ values = njs_arr_create(vm->mem_pool, 4, sizeof(njs_value_t));
if (njs_slow_path(values == NULL)) {
return NJS_INDEX_ERROR;
}
@@ -573,7 +572,7 @@ njs_scope_next_index(njs_vm_t *vm, njs_p
scope->values[scope_index] = values;
}
- value = njs_arr_add(values, &njs_array_mem_proto, vm->mem_pool);
+ value = njs_arr_add(values);
if (njs_slow_path(value == NULL)) {
return NJS_INDEX_ERROR;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_vm.c
--- a/src/njs_vm.c Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_vm.c Fri Aug 02 12:12:30 2019 +0300
@@ -20,31 +20,6 @@ const njs_str_t njs_entry_unknown =
const njs_str_t njs_entry_anonymous = njs_str("anonymous");
-static void *
-njs_array_mem_alloc(void *mem, size_t size)
-{
- return njs_mp_alloc(mem, size);
-}
-
-
-static void
-njs_array_mem_free(void *mem, void *p)
-{
- njs_mp_free(mem, p);
-}
-
-
-const njs_mem_proto_t njs_array_mem_proto = {
- njs_array_mem_alloc,
- NULL,
- NULL,
- NULL,
- njs_array_mem_free,
- NULL,
- NULL,
-};
-
-
njs_vm_t *
njs_vm_create(njs_vm_opt_t *options)
{
@@ -111,9 +86,7 @@ njs_vm_create(njs_vm_opt_t *options)
vm->external = options->external;
- vm->external_objects = njs_arr_create(4, sizeof(void *),
- &njs_array_mem_proto,
- vm->mem_pool);
+ vm->external_objects = njs_arr_create(vm->mem_pool, 4, sizeof(void *));
if (njs_slow_path(vm->external_objects == NULL)) {
return NULL;
}
@@ -127,8 +100,8 @@ njs_vm_create(njs_vm_opt_t *options)
vm->trace.data = vm;
if (options->backtrace) {
- debug = njs_arr_create(4, sizeof(njs_function_debug_t),
- &njs_array_mem_proto, vm->mem_pool);
+ debug = njs_arr_create(vm->mem_pool, 4,
+ sizeof(njs_function_debug_t));
if (njs_slow_path(debug == NULL)) {
return NULL;
}
@@ -302,9 +275,8 @@ njs_vm_clone(njs_vm_t *vm, njs_external_
nvm->external_prototypes_hash = vm->external_prototypes_hash;
items = vm->external_objects->items;
- externals = njs_arr_create(items + 4, sizeof(void *),
- &njs_array_mem_proto, nvm->mem_pool);
+ externals = njs_arr_create(nvm->mem_pool, items + 4, sizeof(void *));
if (njs_slow_path(externals == NULL)) {
return NULL;
}
@@ -393,8 +365,8 @@ njs_vm_init(njs_vm_t *vm)
njs_queue_init(&vm->posted_events);
if (vm->debug != NULL) {
- backtrace = njs_arr_create(4, sizeof(njs_backtrace_entry_t),
- &njs_array_mem_proto, vm->mem_pool);
+ backtrace = njs_arr_create(vm->mem_pool, 4,
+ sizeof(njs_backtrace_entry_t));
if (njs_slow_path(backtrace == NULL)) {
return NJS_ERROR;
}
@@ -634,14 +606,13 @@ njs_vm_add_path(njs_vm_t *vm, const njs_
njs_str_t *item;
if (vm->paths == NULL) {
- vm->paths = njs_arr_create(4, sizeof(njs_str_t),
- &njs_array_mem_proto, vm->mem_pool);
+ vm->paths = njs_arr_create(vm->mem_pool, 4, sizeof(njs_str_t));
if (njs_slow_path(vm->paths == NULL)) {
return NJS_ERROR;
}
}
- item = njs_arr_add(vm->paths, &njs_array_mem_proto, vm->mem_pool);
+ item = njs_arr_add(vm->paths);
if (njs_slow_path(item == NULL)) {
return NJS_ERROR;
}
@@ -1088,7 +1059,7 @@ njs_vm_add_backtrace_entry(njs_vm_t *vm,
native_frame = &frame->native;
function = native_frame->function;
- be = njs_arr_add(vm->backtrace, &njs_array_mem_proto, vm->mem_pool);
+ be = njs_arr_add(vm->backtrace);
if (njs_slow_path(be == NULL)) {
return NJS_ERROR;
}
diff -r 84f4da1e7d96 -r aaec532e9d08 src/njs_vm.h
--- a/src/njs_vm.h Thu Aug 01 21:01:16 2019 +0300
+++ b/src/njs_vm.h Fri Aug 02 12:12:30 2019 +0300
@@ -348,6 +348,7 @@ njs_int_t njs_builtin_match_native_funct
njs_function_t *function, njs_str_t *name);
njs_arr_t *njs_vm_backtrace(njs_vm_t *vm);
+njs_arr_t *njs_vm_completions(njs_vm_t *vm, njs_str_t *expression);
void *njs_lvlhsh_alloc(void *data, size_t size);
void njs_lvlhsh_free(void *data, void *p, size_t size);
@@ -359,7 +360,6 @@ extern const njs_str_t njs_entry_nati
extern const njs_str_t njs_entry_unknown;
extern const njs_str_t njs_entry_anonymous;
-extern const njs_mem_proto_t njs_array_mem_proto;
extern const njs_lvlhsh_proto_t njs_object_hash_proto;
More information about the nginx-devel
mailing list