[njs] Introduced nxt_length() macro.
Valentin Bartenev
vbart at nginx.com
Tue Jun 26 15:26:59 UTC 2018
details: http://hg.nginx.org/njs/rev/255c79369f59
branches:
changeset: 540:255c79369f59
user: Valentin Bartenev <vbart at nginx.com>
date: Tue Jun 26 18:25:22 2018 +0300
description:
Introduced nxt_length() macro.
diffstat:
nginx/ngx_http_js_module.c | 4 ++--
njs/njs.c | 2 +-
njs/njs_extern.c | 2 +-
njs/njs_json.c | 10 +++++-----
njs/njs_parser.c | 2 +-
njs/njs_string.c | 2 +-
njs/njs_vm.h | 8 ++++----
nxt/nxt_string.h | 3 ++-
nxt/test/random_unit_test.c | 2 +-
nxt/test/utf8_unit_test.c | 4 ++--
10 files changed, 20 insertions(+), 19 deletions(-)
diffs (157 lines):
diff -r 711079f55d46 -r 255c79369f59 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Tue Jun 19 14:07:22 2018 +0300
+++ b/nginx/ngx_http_js_module.c Tue Jun 26 18:25:22 2018 +0300
@@ -1157,9 +1157,9 @@ ngx_http_js_ext_set_header_out(njs_vm_t
h->value.data = p;
h->value.len = value->length;
- if (h->key.len == sizeof("Content-Length") - 1
+ if (h->key.len == nxt_length("Content-Length")
&& ngx_strncasecmp(h->key.data, (u_char *) "Content-Length",
- sizeof("Content-Length") - 1) == 0)
+ nxt_length("Content-Length")) == 0)
{
n = ngx_atoi(value->start, value->length);
if (n == NGX_ERROR) {
diff -r 711079f55d46 -r 255c79369f59 njs/njs.c
--- a/njs/njs.c Tue Jun 19 14:07:22 2018 +0300
+++ b/njs/njs.c Tue Jun 26 18:25:22 2018 +0300
@@ -131,7 +131,7 @@ njs_vm_create(njs_vm_opt_t *options)
nxt_lvlhsh_init(&vm->shared->values_hash);
pattern = njs_regexp_pattern_create(vm, (u_char *) "(?:)",
- sizeof("(?:)") - 1, 0);
+ nxt_length("(?:)"), 0);
if (nxt_slow_path(pattern == NULL)) {
return NULL;
}
diff -r 711079f55d46 -r 255c79369f59 njs/njs_extern.c
--- a/njs/njs_extern.c Tue Jun 19 14:07:22 2018 +0300
+++ b/njs/njs_extern.c Tue Jun 26 18:25:22 2018 +0300
@@ -273,7 +273,7 @@ found:
len = 0;
for (pr = head; pr != NULL; pr = pr->next) {
- len += pr->str.length + sizeof(".") - 1;
+ len += pr->str.length + nxt_length(".");
}
buf = nxt_mem_cache_zalloc(vm->mem_cache_pool, len);
diff -r 711079f55d46 -r 255c79369f59 njs/njs_json.c
--- a/njs/njs_json.c Tue Jun 19 14:07:22 2018 +0300
+++ b/njs/njs_json.c Tue Jun 26 18:25:22 2018 +0300
@@ -1400,19 +1400,19 @@ done:
* The value to stringify is wrapped as '{"": value}'.
* An empty object means empty result.
*/
- if (str.length <= sizeof("{\n\n}") - 1) {
+ if (str.length <= nxt_length("{\n\n}")) {
vm->retval = njs_value_void;
return NXT_OK;
}
/* Stripping the wrapper's data. */
- str.start += sizeof("{\"\":") - 1;
- str.length -= sizeof("{\"\":}") - 1;
+ str.start += nxt_length("{\"\":");
+ str.length -= nxt_length("{\"\":}");
if (stringify->space.length != 0) {
- str.start += sizeof("\n ") - 1;
- str.length -= sizeof("\n \n") - 1;
+ str.start += nxt_length("\n ");
+ str.length -= nxt_length("\n \n");
}
length = nxt_utf8_length(str.start, str.length);
diff -r 711079f55d46 -r 255c79369f59 njs/njs_parser.c
--- a/njs/njs_parser.c Tue Jun 19 14:07:22 2018 +0300
+++ b/njs/njs_parser.c Tue Jun 26 18:25:22 2018 +0300
@@ -2589,7 +2589,7 @@ njs_parser_trace_handler(nxt_trace_t *tr
size_t size;
njs_vm_t *vm;
- size = sizeof("InternalError: ") - 1;
+ size = nxt_length("InternalError: ");
memcpy(start, "InternalError: ", size);
p = start + size;
diff -r 711079f55d46 -r 255c79369f59 njs/njs_string.c
--- a/njs/njs_string.c Tue Jun 19 14:07:22 2018 +0300
+++ b/njs/njs_string.c Tue Jun 26 18:25:22 2018 +0300
@@ -3165,7 +3165,7 @@ njs_string_to_number(const njs_value_t *
nxt_bool_t minus;
const u_char *p, *start, *end;
- const size_t infinity = sizeof("Infinity") - 1;
+ const size_t infinity = nxt_length("Infinity");
size = value->short_string.size;
diff -r 711079f55d46 -r 255c79369f59 njs/njs_vm.h
--- a/njs/njs_vm.h Tue Jun 19 14:07:22 2018 +0300
+++ b/njs/njs_vm.h Tue Jun 26 18:25:22 2018 +0300
@@ -365,8 +365,8 @@ typedef struct {
#define njs_string(s) { \
.short_string = { \
.type = NJS_STRING, \
- .size = sizeof(s) - 1, \
- .length = sizeof(s) - 1, \
+ .size = nxt_length(s), \
+ .length = nxt_length(s), \
.start = s, \
} \
}
@@ -378,10 +378,10 @@ typedef struct {
.long_string = { \
.type = NJS_STRING, \
.truth = (NJS_STRING_LONG << 4) | NJS_STRING_LONG, \
- .size = sizeof(s) - 1, \
+ .size = nxt_length(s), \
.data = & (njs_string_t) { \
.start = (u_char *) s, \
- .length = sizeof(s) - 1, \
+ .length = nxt_length(s), \
} \
} \
}
diff -r 711079f55d46 -r 255c79369f59 nxt/nxt_string.h
--- a/nxt/nxt_string.h Tue Jun 19 14:07:22 2018 +0300
+++ b/nxt/nxt_string.h Tue Jun 26 18:25:22 2018 +0300
@@ -21,7 +21,8 @@ typedef struct {
* So a separate nxt_string_value() macro is intended to use in assignment.
*/
-#define nxt_string(s) { sizeof(s) - 1, (u_char *) s }
+#define nxt_length(s) (sizeof(s) - 1)
+#define nxt_string(s) { nxt_length(s), (u_char *) s }
#define nxt_null_string { 0, NULL }
#define nxt_string_value(s) (nxt_str_t) nxt_string(s)
diff -r 711079f55d46 -r 255c79369f59 nxt/test/random_unit_test.c
--- a/nxt/test/random_unit_test.c Tue Jun 19 14:07:22 2018 +0300
+++ b/nxt/test/random_unit_test.c Tue Jun 26 18:25:22 2018 +0300
@@ -24,7 +24,7 @@ random_unit_test(void)
r.count = 400000;
- nxt_random_add(&r, (u_char *) "arc4random", sizeof("arc4random") - 1);
+ nxt_random_add(&r, (u_char *) "arc4random", nxt_length("arc4random"));
/*
* Test arc4random() numbers.
diff -r 711079f55d46 -r 255c79369f59 nxt/test/utf8_unit_test.c
--- a/nxt/test/utf8_unit_test.c Tue Jun 19 14:07:22 2018 +0300
+++ b/nxt/test/utf8_unit_test.c Tue Jun 26 18:25:22 2018 +0300
@@ -177,8 +177,8 @@ utf8_unit_test(nxt_uint_t start)
n = nxt_utf8_casecmp((u_char *) "ABC АБВ ΑΒΓ",
(u_char *) "abc абв αβγ",
- sizeof("ABC АБВ ΑΒΓ") - 1,
- sizeof("abc абв αβγ") - 1);
+ nxt_length("ABC АБВ ΑΒΓ"),
+ nxt_length("abc абв αβγ"));
if (n != 0) {
printf("nxt_utf8_casecmp() failed\n");
More information about the nginx-devel
mailing list