]> git.kaiwu.me - njs.git/commitdiff
Introduced nxt_length() macro.
authorValentin Bartenev <vbart@nginx.com>
Tue, 26 Jun 2018 15:25:22 +0000 (18:25 +0300)
committerValentin Bartenev <vbart@nginx.com>
Tue, 26 Jun 2018 15:25:22 +0000 (18:25 +0300)
nginx/ngx_http_js_module.c
njs/njs.c
njs/njs_extern.c
njs/njs_json.c
njs/njs_parser.c
njs/njs_string.c
njs/njs_vm.h
nxt/nxt_string.h
nxt/test/random_unit_test.c
nxt/test/utf8_unit_test.c

index 7001645eb721e51a178d7c4b1bfd384f2484b3b2..a9b6c35a410155a6f004e299cec9c3430f1192c5 100644 (file)
@@ -1157,9 +1157,9 @@ ngx_http_js_ext_set_header_out(njs_vm_t *vm, void *obj, uintptr_t data,
     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) {
index dc5907eb317cc8345f39ed7b8c78a9a200212ead..a7184b798d315b8d2672df75fe23f8dbd46b8168 100644 (file)
--- a/njs/njs.c
+++ b/njs/njs.c
@@ -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;
             }
index 2a915ba91133109252ce30108d28c9c35e71c3d6..d24b437d86fc9b23aa25d200d1b3cd287c4055ab 100644 (file)
@@ -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);
index 938110ba831e8032b6311af88349729ef40c9c12..3d14948ada1079aeaa1ba439b48fbb3b5111299d 100644 (file)
@@ -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);
index 1c9fba53809405c79c1e5191e1ee0c40f8e81e65..7071cba7cf52e277e918549bcf84abee0f187cc4 100644 (file)
@@ -2589,7 +2589,7 @@ njs_parser_trace_handler(nxt_trace_t *trace, nxt_trace_data_t *td,
     size_t    size;
     njs_vm_t  *vm;
 
-    size = sizeof("InternalError: ") - 1;
+    size = nxt_length("InternalError: ");
     memcpy(start, "InternalError: ", size);
     p = start + size;
 
index b059dd7ff3554bdd0f1ca774625f2d0bcf0999b1..09be1a1e1f08bc799bf7267ee19c9ed79a94e077 100644 (file)
@@ -3165,7 +3165,7 @@ njs_string_to_number(const njs_value_t *value, nxt_bool_t parse_float)
     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;
 
index 3e3bdb97469bd31b3583dcbb22fa6c5a23eec387..e37c665ba13e34c142ef31ad0a302459a5a72ac7 100644 (file)
@@ -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),                                          \
         }                                                                     \
     }                                                                         \
 }
index ec953cf3cc34cc0088b6614fd1a2afff323ea1d1..f1996262c3f691d91ab6c83b31e39d9493c9486c 100644 (file)
@@ -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)
 
index 13836a6b71e39787584d5cc6e169bf6ec98ff937..a4662bfad9aaf881fb520eba408faf0931f775ae 100644 (file)
@@ -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.
index 8797292f40f05160490a58992f5ba85fb1e7efb9..efc34e9fb1f6afda194b823c48c4462dca321f80 100644 (file)
@@ -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");