[njs] Removing njs_string_set() from builtin functions.
Dmitry Volyntsev
xeioex at nginx.com
Sat May 18 04:55:29 UTC 2024
details: https://hg.nginx.org/njs/rev/8851a78723dc
branches:
changeset: 2330:8851a78723dc
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri May 17 21:54:50 2024 -0700
description:
Removing njs_string_set() from builtin functions.
This is the last function that produced byte strings.
diffstat:
src/njs_builtin.c | 9 ++++-----
src/njs_error.c | 2 +-
src/njs_extern.c | 5 +++--
src/njs_parser.c | 2 +-
src/njs_regexp.c | 4 ++--
src/njs_string.c | 4 ++--
src/njs_string.h | 3 ++-
src/njs_vm.c | 4 ++--
src/test/njs_benchmark.c | 2 +-
9 files changed, 18 insertions(+), 17 deletions(-)
diffs (159 lines):
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_builtin.c
--- a/src/njs_builtin.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_builtin.c Fri May 17 21:54:50 2024 -0700
@@ -1201,8 +1201,8 @@ njs_process_object_argv(njs_vm_t *vm, nj
i = 0;
for (arg = vm->options.argv; i < vm->options.argc; arg++) {
- njs_string_set(vm, &argv->start[i++], (u_char *) *arg,
- njs_strlen(*arg));
+ njs_string_create(vm, &argv->start[i++], (u_char *) *arg,
+ njs_strlen(*arg));
}
prop = njs_object_prop_alloc(vm, &argv_string, &njs_value_undefined, 1);
@@ -1265,7 +1265,7 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlh
continue;
}
- ret = njs_string_create(vm, &prop->name, (char *) entry, val - entry);
+ ret = njs_string_create(vm, &prop->name, entry, val - entry);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
@@ -1285,8 +1285,7 @@ njs_env_hash_init(njs_vm_t *vm, njs_lvlh
val++;
- ret = njs_string_create(vm, njs_prop_value(prop), (char *) val,
- njs_strlen(val));
+ ret = njs_string_create(vm, njs_prop_value(prop), val, njs_strlen(val));
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_error.c
--- a/src/njs_error.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_error.c Fri May 17 21:54:50 2024 -0700
@@ -147,7 +147,7 @@ njs_error_stack_new(njs_vm_t *vm, njs_ob
return ret;
}
- return njs_string_set(vm, retval, string.start, string.length);
+ return njs_string_create(vm, retval, string.start, string.length);
}
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_extern.c
--- a/src/njs_extern.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_extern.c Fri May 17 21:54:50 2024 -0700
@@ -74,8 +74,9 @@ njs_external_add(njs_vm_t *vm, njs_arr_t
lhq.key_hash = external->name.symbol;
} else {
- ret = njs_string_set(vm, &prop->name, external->name.string.start,
- external->name.string.length);
+ ret = njs_string_create(vm, &prop->name,
+ external->name.string.start,
+ external->name.string.length);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_parser.c
--- a/src/njs_parser.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_parser.c Fri May 17 21:54:50 2024 -0700
@@ -9242,7 +9242,7 @@ njs_parser_error(njs_vm_t *vm, njs_objec
njs_value_property_set(vm, &error, njs_value_arg(&line_number), &value);
if (file->length != 0) {
- ret = njs_string_set(vm, &value, file->start, file->length);
+ ret = njs_string_create(vm, &value, file->start, file->length);
if (ret == NJS_OK) {
njs_value_property_set(vm, &error, njs_value_arg(&file_name),
&value);
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_regexp.c
--- a/src/njs_regexp.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_regexp.c Fri May 17 21:54:50 2024 -0700
@@ -1144,8 +1144,8 @@ njs_regexp_exec_result(njs_vm_t *vm, njs
do {
group = &pattern->groups[i];
- ret = njs_string_set(vm, &name, group->name.start,
- group->name.length);
+ ret = njs_string_create(vm, &name, group->name.start,
+ group->name.length);
if (njs_slow_path(ret != NJS_OK)) {
goto fail;
}
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_string.c
--- a/src/njs_string.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_string.c Fri May 17 21:54:50 2024 -0700
@@ -127,7 +127,7 @@ njs_string_set(njs_vm_t *vm, njs_value_t
njs_int_t
-njs_string_create(njs_vm_t *vm, njs_value_t *value, const char *src,
+njs_string_create(njs_vm_t *vm, njs_value_t *value, const u_char *src,
size_t size)
{
u_char *p, *p_end;
@@ -3152,7 +3152,7 @@ njs_string_get_substitution(njs_vm_t *vm
p += 2;
- ret = njs_string_create(vm, &name, (const char *) p, r - p);
+ ret = njs_string_create(vm, &name, p, r - p);
if (njs_slow_path(ret != NJS_OK)) {
goto exception;
}
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_string.h
--- a/src/njs_string.h Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_string.h Fri May 17 21:54:50 2024 -0700
@@ -103,13 +103,14 @@ typedef enum {
} njs_trim_t;
+/* njs_string_set() Is deprecated. */
njs_int_t njs_string_set(njs_vm_t *vm, njs_value_t *value, const u_char *start,
uint32_t size);
u_char *njs_string_alloc(njs_vm_t *vm, njs_value_t *value, uint64_t size,
uint64_t length);
njs_int_t njs_string_new(njs_vm_t *vm, njs_value_t *value, const u_char *start,
uint32_t size, uint32_t length);
-njs_int_t njs_string_create(njs_vm_t *vm, njs_value_t *value, const char *src,
+njs_int_t njs_string_create(njs_vm_t *vm, njs_value_t *value, const u_char *src,
size_t size);
njs_int_t njs_string_create_chb(njs_vm_t *vm, njs_value_t *value,
njs_chb_t *chain);
diff -r 4e0553f7ea68 -r 8851a78723dc src/njs_vm.c
--- a/src/njs_vm.c Fri May 17 21:54:50 2024 -0700
+++ b/src/njs_vm.c Fri May 17 21:54:50 2024 -0700
@@ -843,7 +843,7 @@ njs_vm_value(njs_vm_t *vm, const njs_str
return NJS_ERROR;
}
- ret = njs_string_set(vm, &key, start, size);
+ ret = njs_string_create(vm, &key, start, size);
if (njs_slow_path(ret != NJS_OK)) {
return NJS_ERROR;
}
@@ -977,7 +977,7 @@ njs_int_t
njs_vm_value_string_create(njs_vm_t *vm, njs_value_t *value,
const u_char *start, uint32_t size)
{
- return njs_string_create(vm, value, (const char *) start, size);
+ return njs_string_create(vm, value, start, size);
}
diff -r 4e0553f7ea68 -r 8851a78723dc src/test/njs_benchmark.c
--- a/src/test/njs_benchmark.c Fri May 17 21:54:50 2024 -0700
+++ b/src/test/njs_benchmark.c Fri May 17 21:54:50 2024 -0700
@@ -715,7 +715,7 @@ njs_benchmark_string(njs_vm_t *vm, njs_v
} else if (memcmp(mode.start, "create", 6) == 0) {
for (i = 0; i < n; i++) {
- njs_string_create(vm, &value, (char *) s.start, s.length);
+ njs_string_create(vm, &value, s.start, s.length);
}
} else {
More information about the nginx-devel
mailing list