]> git.kaiwu.me - njs.git/commitdiff
nxt_str_t changes.
authorIgor Sysoev <igor@sysoev.ru>
Thu, 4 Aug 2016 11:45:27 +0000 (14:45 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Thu, 4 Aug 2016 11:45:27 +0000 (14:45 +0300)
30 files changed:
nginx/ngx_http_js_module.c
nginx/ngx_stream_js_module.c
njs/njs_array.c
njs/njs_boolean.c
njs/njs_builtin.c
njs/njs_date.c
njs/njs_disassembler.c
njs/njs_extern.c
njs/njs_function.c
njs/njs_generator.c
njs/njs_lexer.c
njs/njs_lexer_keyword.c
njs/njs_math.c
njs/njs_nonrecursive_parser.c
njs/njs_number.c
njs/njs_object.c
njs/njs_parser.c
njs/njs_parser_expression.c
njs/njs_regexp.c
njs/njs_string.c
njs/njs_variable.c
njs/njs_vm.c
njs/njscript.c
njs/test/njs_unit_test.c
nxt/Makefile
nxt/nxt_djb_hash.c
nxt/nxt_lvlhsh.c
nxt/nxt_lvlhsh.h
nxt/nxt_string.h [new file with mode: 0644]
nxt/nxt_stub.h

index f8ad1f27619b99d878c022591b5ef5ebe320de7c..429b3c4286ea50b3f6dfae5c3794ef7ff37d9785 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_random.h>
@@ -432,8 +433,8 @@ ngx_http_js_handler(ngx_http_request_t *r)
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
 
-    name.data = jlcf->content.data;
-    name.len = jlcf->content.len;
+    name.start = jlcf->content.data;
+    name.length = jlcf->content.len;
 
     func = njs_vm_function(ctx->vm, &name);
     if (func == NULL) {
@@ -446,7 +447,7 @@ ngx_http_js_handler(ngx_http_request_t *r)
         njs_vm_exception(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                      "js exception: %*s", exception.len, exception.data);
+                      "js exception: %*s", exception.length, exception.start);
 
         return NGX_ERROR;
     }
@@ -482,8 +483,8 @@ ngx_http_js_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
 
     ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
 
-    name.data = fname->data;
-    name.len = fname->len;
+    name.start = fname->data;
+    name.length = fname->len;
 
     func = njs_vm_function(ctx->vm, &name);
     if (func == NULL) {
@@ -497,7 +498,7 @@ ngx_http_js_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
         njs_vm_exception(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
-                      "js exception: %*s", exception.len, exception.data);
+                      "js exception: %*s", exception.length, exception.start);
 
         v->not_found = 1;
         return NGX_OK;
@@ -507,11 +508,11 @@ ngx_http_js_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
         return NGX_ERROR;
     }
 
-    v->len = value.len;
+    v->len = value.length;
     v->valid = 1;
     v->no_cacheable = 0;
     v->not_found = 0;
-    v->data = value.data;
+    v->data = value.start;
 
     return NGX_OK;
 }
@@ -640,14 +641,14 @@ ngx_http_js_ext_set_string(njs_vm_t *vm, void *obj, uintptr_t data,
     r = (ngx_http_request_t *) obj;
 
     field = (ngx_str_t *) (p + data);
-    field->len = value->len;
+    field->len = value->length;
 
-    field->data = ngx_pnalloc(r->pool, value->len);
+    field->data = ngx_pnalloc(r->pool, value->length);
     if (field->data == NULL) {
         return NJS_ERROR;
     }
 
-    ngx_memcpy(field->data, value->data, value->len);
+    ngx_memcpy(field->data, value->start, value->length);
 
     return NJS_OK;
 }
@@ -757,7 +758,8 @@ ngx_http_js_ext_get_header_out(njs_vm_t *vm, njs_value_t *value, void *obj,
     r = (ngx_http_request_t *) obj;
     v = (nxt_str_t *) data;
 
-    h = ngx_http_js_get_header(&r->headers_out.headers.part, v->data, v->len);
+    h = ngx_http_js_get_header(&r->headers_out.headers.part, v->start,
+                               v->length);
     if (h == NULL) {
         return njs_string_create(vm, value, NULL, 0, 0);
     }
@@ -778,7 +780,8 @@ ngx_http_js_ext_set_header_out(njs_vm_t *vm, void *obj, uintptr_t data,
     r = (ngx_http_request_t *) obj;
     v = (nxt_str_t *) data;
 
-    h = ngx_http_js_get_header(&r->headers_out.headers.part, v->data, v->len);
+    h = ngx_http_js_get_header(&r->headers_out.headers.part, v->start,
+                               v->length);
 
     if (h == NULL || h->hash == 0) {
         h = ngx_list_push(&r->headers_out.headers);
@@ -786,28 +789,28 @@ ngx_http_js_ext_set_header_out(njs_vm_t *vm, void *obj, uintptr_t data,
             return NJS_ERROR;
         }
 
-        p = ngx_pnalloc(r->pool, v->len);
+        p = ngx_pnalloc(r->pool, v->length);
         if (p == NULL) {
             return NJS_ERROR;
         }
 
-        ngx_memcpy(p, v->data, v->len);
+        ngx_memcpy(p, v->start, v->length);
 
         h->key.data = p;
-        h->key.len = v->len;
+        h->key.len = v->length;
         h->hash = 1;
     }
 
 
-    p = ngx_pnalloc(r->pool, value->len);
+    p = ngx_pnalloc(r->pool, value->length);
     if (p == NULL) {
         return NJS_ERROR;
     }
 
-    ngx_memcpy(p, value->data, value->len);
+    ngx_memcpy(p, value->start, value->length);
 
     h->value.data = p;
-    h->value.len = value->len;
+    h->value.len = value->length;
 
     return NJS_OK;
 }
@@ -849,7 +852,7 @@ ngx_http_js_ext_set_status(njs_vm_t *vm, void *obj, uintptr_t data,
     ngx_int_t            n;
     ngx_http_request_t  *r;
 
-    n = ngx_atoi(value->data, value->len);
+    n = ngx_atoi(value->start, value->length);
     if (n == NGX_ERROR) {
         return NJS_ERROR;
     }
@@ -890,7 +893,7 @@ ngx_http_js_ext_set_content_length(njs_vm_t *vm, void *obj, uintptr_t data,
     ngx_int_t            n;
     ngx_http_request_t  *r;
 
-    n = ngx_atoi(value->data, value->len);
+    n = ngx_atoi(value->start, value->length);
     if (n == NGX_ERROR) {
         return NJS_ERROR;
     }
@@ -953,16 +956,16 @@ ngx_http_js_ext_send(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
             /* TODO: njs_value_release(vm, value) in buf completion */
 
             ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                           "http js send: \"%*s\"", s.len, s.data);
+                           "http js send: \"%*s\"", s.length, s.start);
 
             b = ngx_calloc_buf(r->pool);
             if (b == NULL) {
                 return NJS_ERROR;
             }
 
-            b->start = s.data;
+            b->start = s.start;
             b->pos = b->start;
-            b->end = s.data + s.len;
+            b->end = s.start + s.length;
             b->last = b->end;
             b->memory = 1;
 
@@ -1024,7 +1027,7 @@ ngx_http_js_ext_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     handler = c->log->handler;
     c->log->handler = NULL;
 
-    ngx_log_error(NGX_LOG_INFO, c->log, 0, "js: %*s", msg.len, msg.data);
+    ngx_log_error(NGX_LOG_INFO, c->log, 0, "js: %*s", msg.length, msg.start);
 
     c->log->handler = handler;
 
@@ -1085,7 +1088,8 @@ ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value, void *obj,
     r = (ngx_http_request_t *) obj;
     v = (nxt_str_t *) data;
 
-    h = ngx_http_js_get_header(&r->headers_in.headers.part, v->data, v->len);
+    h = ngx_http_js_get_header(&r->headers_in.headers.part, v->start,
+                               v->length);
     if (h == NULL) {
         return njs_string_create(vm, value, NULL, 0, 0);
     }
@@ -1112,7 +1116,7 @@ ngx_http_js_ext_get_arg(njs_vm_t *vm, njs_value_t *value, void *obj,
     r = (ngx_http_request_t *) obj;
     v = (nxt_str_t *) data;
 
-    if (ngx_http_arg(r, v->data, v->len, &arg) == NGX_OK) {
+    if (ngx_http_arg(r, v->start, v->length, &arg) == NGX_OK) {
         return njs_string_create(vm, value, arg.data, arg.len, 0);
     }
 
@@ -1196,8 +1200,8 @@ ngx_http_js_ext_get_variable(njs_vm_t *vm, njs_value_t *value, void *obj,
     r = (ngx_http_request_t *) obj;
     v = (nxt_str_t *) data;
 
-    name.data = v->data;
-    name.len = v->len;
+    name.data = v->start;
+    name.len = v->length;
 
     key = ngx_hash_strlow(name.data, name.data, name.len);
 
@@ -1324,7 +1328,7 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "%*s, included",
-                           text.len, text.data);
+                           text.length, text.start);
         return NGX_CONF_ERROR;
     }
 
@@ -1335,21 +1339,22 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         return NGX_CONF_ERROR;
     }
 
-    nxt_str_set(&ext, "$r");
+    ext = nxt_string_value("$r");
 
     if (njs_vm_external(jlcf->vm, NULL, &ext, &jlcf->args[0]) != NJS_OK) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                           "js external \"%*s\" not found", ext.len, ext.data);
+                           "js external \"%*s\" not found",
+                           ext.length, ext.start);
         return NGX_CONF_ERROR;
     }
 
-    nxt_str_set(&ext, "response");
+    ext = nxt_string_value("response");
 
     rc = njs_vm_external(jlcf->vm, &jlcf->args[0], &ext, &jlcf->args[1]);
     if (rc != NXT_OK) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "js external \"$r.%*s\" not found",
-                           ext.len, ext.data);
+                           ext.length, ext.start);
         return NGX_CONF_ERROR;
     }
 
index 53dfed261e1d380b921743a5d8d947afe139c1c7..bf01e38ddccd33dd6b7fb550b7920b8a99c2fb7d 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_random.h>
@@ -216,8 +217,8 @@ ngx_stream_js_variable(ngx_stream_session_t *s, ngx_stream_variable_value_t *v,
 
     ctx = ngx_stream_get_module_ctx(s, ngx_stream_js_module);
 
-    name.data = fname->data;
-    name.len = fname->len;
+    name.start = fname->data;
+    name.length = fname->len;
 
     func = njs_vm_function(ctx->vm, &name);
     if (func == NULL) {
@@ -231,7 +232,7 @@ ngx_stream_js_variable(ngx_stream_session_t *s, ngx_stream_variable_value_t *v,
         njs_vm_exception(ctx->vm, &exception);
 
         ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
-                      "js exception: %*s", exception.len, exception.data);
+                      "js exception: %*s", exception.length, exception.start);
 
         v->not_found = 1;
         return NGX_OK;
@@ -241,11 +242,11 @@ ngx_stream_js_variable(ngx_stream_session_t *s, ngx_stream_variable_value_t *v,
         return NGX_ERROR;
     }
 
-    v->len = value.len;
+    v->len = value.length;
     v->valid = 1;
     v->no_cacheable = 0;
     v->not_found = 0;
-    v->data = value.data;
+    v->data = value.start;
 
     return NGX_OK;
 }
@@ -382,7 +383,7 @@ ngx_stream_js_ext_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     handler = c->log->handler;
     c->log->handler = NULL;
 
-    ngx_log_error(NGX_LOG_INFO, c->log, 0, "js: %*s", msg.len, msg.data);
+    ngx_log_error(NGX_LOG_INFO, c->log, 0, "js: %*s", msg.length, msg.start);
 
     c->log->handler = handler;
 
@@ -403,8 +404,8 @@ ngx_stream_js_ext_get_variable(njs_vm_t *vm, njs_value_t *value, void *obj,
     s = (ngx_stream_session_t *) obj;
     v = (nxt_str_t *) data;
 
-    name.data = v->data;
-    name.len = v->len;
+    name.data = v->start;
+    name.len = v->length;
 
     key = ngx_hash_strlow(name.data, name.data, name.len);
 
@@ -531,7 +532,7 @@ ngx_stream_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "%*s, included",
-                           text.len, text.data);
+                           text.length, text.start);
         return NGX_CONF_ERROR;
     }
 
@@ -542,11 +543,11 @@ ngx_stream_js_include(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         return NGX_CONF_ERROR;
     }
 
-    nxt_str_set(&ext, "$s");
+    ext = nxt_string_value("$s");
 
     if (njs_vm_external(jscf->vm, NULL, &ext, &jscf->arg) != NJS_OK) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                       "js external \"%*s\" not found", ext.len, ext.data);
+                       "js external \"%*s\" not found", ext.length, ext.start);
         return NGX_CONF_ERROR;
     }
 
index 9d61bb4b0fd788ef5dbb4fb44c915340cfdba5f3..d10369c80a2ec65b9f3edd21f082ecc79f795b7c 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_djb_hash.h>
 #include <nxt_array.h>
@@ -517,8 +518,7 @@ njs_array_prototype_to_string(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     if (njs_is_object(&args[0])) {
         lhq.key_hash = NJS_JOIN_HASH;
-        lhq.key.len = sizeof("join") - 1;
-        lhq.key.data = (u_char *) "join";
+        lhq.key = nxt_string_value("join");
 
         prop = njs_object_property(vm, args[0].data.u.object, &lhq);
 
index 8c89708d1805e2d8a3bfb58571daa7e4d2a6a18f..f173364a3c0f7015eab662ae0c2330057834f616 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index a40a7f86deaa5c60c46a89971870c3444309236c..e38379eba5b94015ebdd935b6ca6d75d0b1c1a20 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index ea15a86dac28239cb72c4270bd7ef6e8b79fdbb3..2bac3f4ebe8ae0c6cd6b86b0aee1191b25b9ebdc 100644 (file)
@@ -8,6 +8,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_djb_hash.h>
 #include <nxt_array.h>
@@ -1754,8 +1755,7 @@ njs_date_prototype_to_json(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     if (njs_is_object(&args[0])) {
         lhq.key_hash = NJS_TO_ISO_STRING_HASH;
-        lhq.key.len = sizeof("toISOString") - 1;
-        lhq.key.data = (u_char *) "toISOString";
+        lhq.key = nxt_string_value("toISOString");
 
         prop = njs_object_property(vm, args[0].data.u.object, &lhq);
 
index 93514e06684315c41d37b8c0e1665bd66f0b697c..8e45a8e4964dc4a1116cd284bdc2cbfc597bf29a 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
@@ -352,21 +353,22 @@ njs_disassemble(u_char *start, u_char *end)
                      code3 = (njs_vmcode_3addr_t *) p;
 
                      printf("%*s  %04zX %04zX %04zX\n",
-                            (int) name->len, name->data, (size_t) code3->dst,
-                            (size_t) code3->src1, (size_t) code3->src2);
+                            (int) name->length, name->start,
+                            (size_t) code3->dst, (size_t) code3->src1,
+                            (size_t) code3->src2);
 
                  } else if (code_name->size == sizeof(njs_vmcode_2addr_t)) {
                      code2 = (njs_vmcode_2addr_t *) p;
 
                      printf("%*s  %04zX %04zX\n",
-                            (int) name->len, name->data,
+                            (int) name->length, name->start,
                             (size_t) code2->dst, (size_t) code2->src);
 
                  } else if (code_name->size == sizeof(njs_vmcode_1addr_t)) {
                      code1 = (njs_vmcode_1addr_t *) p;
 
                      printf("%*s  %04zX\n",
-                            (int) name->len, name->data,
+                            (int) name->length, name->start,
                             (size_t) code1->index);
                  }
 
index b13e28b8b4decdb28a4dfd7359a3cde87e133921..261693938b74258c83d49a712d002a6877f3f3f5 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_djb_hash.h>
@@ -65,13 +66,13 @@ njs_vm_external_add(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp,
             return NXT_ERROR;
         }
 
-        ext->name.len = external->name.len;
-        ext->name.data = nxt_mem_cache_alloc(mcp, external->name.len);
-        if (nxt_slow_path(ext->name.data == NULL)) {
+        ext->name.length = external->name.length;
+        ext->name.start = nxt_mem_cache_alloc(mcp, external->name.length);
+        if (nxt_slow_path(ext->name.start == NULL)) {
             return NXT_ERROR;
         }
 
-        memcpy(ext->name.data, external->name.data, external->name.len);
+        memcpy(ext->name.start, external->name.start, external->name.length);
 
         ext->value.type = NJS_EXTERNAL;
         ext->value.data.truth = 1;
@@ -98,7 +99,7 @@ njs_vm_external_add(nxt_lvlhsh_t *hash, nxt_mem_cache_pool_t *mcp,
         ext->object = object;
         ext->data = external->data;
 
-        lhq.key_hash = nxt_djb_hash(external->name.data, external->name.len);
+        lhq.key_hash = nxt_djb_hash(external->name.start, external->name.length);
         lhq.key = ext->name;
         lhq.replace = 0;
         lhq.value = ext;
@@ -155,7 +156,7 @@ njs_vm_external(njs_vm_t *vm, njs_opaque_value_t *obj, nxt_str_t *property,
         }
     }
 
-    lhq.key_hash = key_hash(property->data, property->len);
+    lhq.key_hash = key_hash(property->start, property->length);
     lhq.key = *property;
     lhq.proto = &njs_extern_hash_proto;
 
index 568e53c55c2b6b3baa540006fb6bdd47d53c8c3d..ed97aecf87ee911d714956bdca93bd1b84027b78 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index 9aacb5eff603306d724e4c35a1596d41ccf9ce2e..3e2825a8b611ff6b86c33ac1111be36e7177df57 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index 3976c2629e61fb37d59c4c3eac524c11ae853bb4..3abcba3513eafb4fa85bb54c9a84661d44834de4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_djb_hash.h>
 #include <nxt_array.h>
@@ -300,7 +301,7 @@ njs_lexer_next_token(njs_lexer_t *lexer)
     njs_token_t              token;
     const njs_lexer_multi_t  *multi;
 
-    lexer->text.data = lexer->start;
+    lexer->text.start = lexer->start;
 
     while (lexer->start < lexer->end) {
         c = *lexer->start++;
@@ -310,7 +311,7 @@ njs_lexer_next_token(njs_lexer_t *lexer)
         switch (token) {
 
         case NJS_TOKEN_SPACE:
-            lexer->text.data = lexer->start;
+            lexer->text.start = lexer->start;
             continue;
 
         case NJS_TOKEN_LETTER:
@@ -415,7 +416,7 @@ njs_lexer_next_token(njs_lexer_t *lexer)
         case NJS_TOKEN_COLON:
         case NJS_TOKEN_SEMICOLON:
         case NJS_TOKEN_CONDITIONAL:
-            lexer->text.len = lexer->start - lexer->text.data;
+            lexer->text.length = lexer->start - lexer->text.start;
             return token;
 
         default:  /* NJS_TOKEN_ILLEGAL */
@@ -459,7 +460,7 @@ njs_lexer_word(njs_lexer_t *lexer, u_char c)
 
     lexer->token_line = lexer->line;
     lexer->key_hash = nxt_djb_hash_add(NXT_DJB_HASH_INIT, c);
-    lexer->text.data = lexer->start - 1;
+    lexer->text.start = lexer->start - 1;
 
     for (p = lexer->start; p < lexer->end; p++) {
         c = *p;
@@ -472,7 +473,7 @@ njs_lexer_word(njs_lexer_t *lexer, u_char c)
     }
 
     lexer->start = p;
-    lexer->text.len = p - lexer->text.data;
+    lexer->text.length = p - lexer->text.start;
 
     if (lexer->property) {
         return NJS_TOKEN_NAME;
@@ -489,7 +490,7 @@ njs_lexer_string(njs_lexer_t *lexer, u_char quote)
     nxt_bool_t  escape;
 
     escape = 0;
-    lexer->text.data = lexer->start;
+    lexer->text.start = lexer->start;
     p = lexer->start;
 
     while (p < lexer->end) {
@@ -509,7 +510,7 @@ njs_lexer_string(njs_lexer_t *lexer, u_char quote)
 
         if (c == quote) {
             lexer->start = p;
-            lexer->text.len = (p - 1) - lexer->text.data;
+            lexer->text.length = (p - 1) - lexer->text.start;
 
             if (escape == 0) {
                 return NJS_TOKEN_STRING;
@@ -519,8 +520,8 @@ njs_lexer_string(njs_lexer_t *lexer, u_char quote)
         }
     }
 
-    lexer->text.data--;
-    lexer->text.len = p - lexer->text.data;
+    lexer->text.start--;
+    lexer->text.length = p - lexer->text.start;
 
     return NJS_TOKEN_UNTERMINATED_STRING;
 }
@@ -616,7 +617,7 @@ njs_lexer_multi(njs_lexer_t *lexer, njs_token_t token, nxt_uint_t n,
         } while (n != 0);
     }
 
-    lexer->text.len = lexer->start - lexer->text.data;
+    lexer->text.length = lexer->start - lexer->text.start;
 
     return token;
 }
index c699342dc1cd9f05733732f1c63efd71a991f90e..d6d39fd8e72e87125da3776e95aca7bd1134daea 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_djb_hash.h>
 #include <nxt_array.h>
@@ -170,7 +171,7 @@ njs_lexer_keywords_init(nxt_mem_cache_pool_t *mcp, nxt_lvlhsh_t *hash)
     lhq.pool = mcp;
 
     do {
-        lhq.key_hash = nxt_djb_hash(keyword->name.data, keyword->name.len);
+        lhq.key_hash = nxt_djb_hash(keyword->name.start, keyword->name.length);
         lhq.key = keyword->name;
         lhq.value = (void *) keyword;
 
index 17e25464a9a93aa14368d94d1faef60ef0827a67..36a8bf3a0d3cbc7b7813953deea0be03cc3983a4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index 43442a9cecc9a09a9047f2e35c6706d88100e4e3..5c24bd99285b606a367130222a0917836e23cdd5 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_auto_config.h>
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index 51b0785c15acb40f1e124559d42ab34437bb9eb6..5fd3fe24139e3bb4bb95e8f466cedb67883ef39c 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index 3f3c9de04a8b8258d25d12203f075af1cb5d39f3..e1242e258219ca5dd633f6ae9581de0433fe7bbf 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_djb_hash.h>
 #include <nxt_array.h>
@@ -101,17 +102,17 @@ njs_object_hash_create(njs_vm_t *vm, nxt_lvlhsh_t *hash,
     lhq.pool = vm->mem_cache_pool;
 
     do {
-        lhq.key.len = prop->name.short_string.size;
+        lhq.key.length = prop->name.short_string.size;
 
-        if (lhq.key.len != NJS_STRING_LONG) {
-            lhq.key.data = (u_char *) prop->name.short_string.start;
+        if (lhq.key.length != NJS_STRING_LONG) {
+            lhq.key.start = (u_char *) prop->name.short_string.start;
 
         } else {
-            lhq.key.len = prop->name.data.string_size;
-            lhq.key.data = prop->name.data.u.string->start;
+            lhq.key.length = prop->name.data.string_size;
+            lhq.key.start = prop->name.data.u.string->start;
         }
 
-        lhq.key_hash = nxt_djb_hash(lhq.key.data, lhq.key.len);
+        lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length);
         lhq.value = (void *) prop;
 
         ret = nxt_lvlhsh_insert(hash, &lhq);
@@ -150,21 +151,21 @@ njs_object_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
     size = prop->name.short_string.size;
 
     if (size != NJS_STRING_LONG) {
-        if (lhq->key.len != size) {
+        if (lhq->key.length != size) {
             return NXT_DECLINED;
         }
 
         start = prop->name.short_string.start;
 
     } else {
-        if (lhq->key.len != prop->name.data.string_size) {
+        if (lhq->key.length != prop->name.data.string_size) {
             return NXT_DECLINED;
         }
 
         start = prop->name.data.u.string->start;
     }
 
-    if (memcmp(start, lhq->key.data, lhq->key.len) == 0) {
+    if (memcmp(start, lhq->key.start, lhq->key.length) == 0) {
         return NXT_OK;
     }
 
@@ -403,8 +404,7 @@ njs_property_prototype_create(njs_vm_t *vm, nxt_lvlhsh_t *hash,
 
     lhq.value = prop;
     lhq.key_hash = NJS_PROTOTYPE_HASH;
-    lhq.key.len = sizeof("prototype") - 1;
-    lhq.key.data = (u_char *) "prototype";
+    lhq.key = nxt_string_value("prototype");
     lhq.replace = 0;
     lhq.pool = vm->mem_cache_pool;
     lhq.proto = &njs_object_hash_proto;
@@ -551,8 +551,7 @@ njs_property_constructor_create(njs_vm_t *vm, nxt_lvlhsh_t *hash,
 
     lhq.value = prop;
     lhq.key_hash = NJS_CONSTRUCTOR_HASH;
-    lhq.key.len = sizeof("constructor") - 1;
-    lhq.key.data = (u_char *) "constructor";
+    lhq.key = nxt_string_value("constructor");
     lhq.replace = 0;
     lhq.pool = vm->mem_cache_pool;
     lhq.proto = &njs_object_hash_proto;
index 680cc6eb0a5b8c757996932e4af8a77f0ebcd881..0d2ebbd71f74eaac0e11cf165f449f3669c4d0c4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_array.h>
@@ -493,13 +494,13 @@ njs_parser_function_lambda(njs_vm_t *vm, njs_function_lambda_t *lambda,
 
         name = &parser->lexer->text;
 
-        arg->name_start = nxt_mem_cache_alloc(vm->mem_cache_pool, name->len);
+        arg->name_start = nxt_mem_cache_alloc(vm->mem_cache_pool, name->length);
         if (nxt_slow_path(arg->name_start == NULL)) {
             return NJS_TOKEN_ERROR;
         }
 
-        memcpy(arg->name_start, name->data, name->len);
-        arg->name_len = name->len;
+        memcpy(arg->name_start, name->start, name->length);
+        arg->name_len = name->length;
 
         arg->state = NJS_VARIABLE_DECLARED;
         arg->index = index;
@@ -1108,7 +1109,7 @@ njs_parser_for_in_statement(njs_vm_t *vm, njs_parser_t *parser, nxt_str_t *name,
         size = snprintf((char *) buf, NJS_EXCEPTION_BUF_LENGTH,
                         "ReferenceError: Invalid left-hand side \"%.*s\" "
                         "in for-in statement in %u",
-                        (int) name->len, name->data, parser->lexer->line);
+                        (int) name->length, name->start, parser->lexer->line);
 
         (void) njs_vm_throw_exception(vm, buf, size);
 
@@ -1966,19 +1967,19 @@ njs_parser_string_create(njs_vm_t *vm, njs_value_t *value)
 
     src = &vm->parser->lexer->text;
 
-    length = nxt_utf8_length(src->data, src->len);
+    length = nxt_utf8_length(src->start, src->length);
 
     if (nxt_slow_path(length < 0)) {
         length = 0;
     }
 
-    p = njs_string_alloc(vm, value, src->len, length);
+    p = njs_string_alloc(vm, value, src->length, length);
 
     if (nxt_fast_path(p != NULL)) {
-        memcpy(p, src->data, src->len);
+        memcpy(p, src->start, src->length);
 
-        if (length > NJS_STRING_MAP_OFFSET && (size_t) length != src->len) {
-            njs_string_offset_map_init(p, src->len);
+        if (length > NJS_STRING_MAP_OFFSET && (size_t) length != src->length) {
+            njs_string_offset_map_init(p, src->length);
         }
 
         return NXT_OK;
@@ -2008,8 +2009,8 @@ njs_parser_escape_string_create(njs_vm_t *vm, njs_parser_t *parser,
         size = 0;
         length = 0;
 
-        src = parser->lexer->text.data;
-        end = src + parser->lexer->text.len;
+        src = parser->lexer->text.start;
+        end = src + parser->lexer->text.length;
 
         while (src < end) {
             c = *src++;
@@ -2245,7 +2246,8 @@ njs_parser_error(njs_vm_t *vm, njs_parser_t *parser, njs_parser_error_t err)
     lexer = parser->lexer;
 
     size = snprintf((char *) buf, NJS_EXCEPTION_BUF_LENGTH,
-                    msg, (int) lexer->text.len, lexer->text.data, lexer->line);
+                    msg, (int) lexer->text.length, lexer->text.start,
+                    lexer->line);
 
     (void) njs_vm_throw_exception(vm, buf, size);
 
index 8aba527a33459a4b3c4b05e9cae8f2a23afcdf92..ee81964d8bacf81564a4f9138cde9d94608c8d66 100644 (file)
@@ -8,6 +8,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_array.h>
index 5c9f19d07693b313ae769966edf651953620b6ee..72568921f233fe3ff629ec72d3fc216911064065 100644 (file)
@@ -8,6 +8,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_djb_hash.h>
@@ -152,24 +153,24 @@ njs_regexp_literal(njs_vm_t *vm, njs_parser_t *parser, njs_value_t *value)
         }
 
         if (*p == '/') {
-            lexer->text.data = lexer->start;
-            lexer->text.len = p - lexer->text.data;
+            lexer->text.start = lexer->start;
+            lexer->text.length = p - lexer->text.start;
             p++;
             lexer->start = p;
 
             flags = njs_regexp_flags(&p, lexer->end, 0);
 
             if (nxt_slow_path(flags < 0)) {
-                lexer->text.data = lexer->start;
-                lexer->text.len = p - lexer->text.data;
+                lexer->text.start = lexer->start;
+                lexer->text.length = p - lexer->text.start;
                 return njs_parser_error(vm, parser,
                                         NJS_PARSER_ERROR_REGEXP_FLAGS);
             }
 
             lexer->start = p;
 
-            pattern = njs_regexp_pattern_create(vm, lexer->text.data,
-                                                lexer->text.len, flags);
+            pattern = njs_regexp_pattern_create(vm, lexer->text.start,
+                                                lexer->text.length, flags);
             if (nxt_slow_path(pattern == NULL)) {
                 return NJS_TOKEN_ILLEGAL;
             }
@@ -180,8 +181,8 @@ njs_regexp_literal(njs_vm_t *vm, njs_parser_t *parser, njs_value_t *value)
         }
     }
 
-    lexer->text.data = lexer->start - 1;
-    lexer->text.len = p - lexer->text.data;
+    lexer->text.start = lexer->start - 1;
+    lexer->text.length = p - lexer->text.start;
 
     return njs_parser_error(vm, parser, NJS_PARSER_ERROR_UNTERMINATED_REGEXP);
 }
@@ -676,8 +677,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, u_char *string,
     }
 
     lhq.key_hash = NJS_INDEX_HASH;
-    lhq.key.len = sizeof("index") - 1;
-    lhq.key.data = (u_char *) "index";
+    lhq.key = nxt_string_value("index");
     lhq.replace = 0;
     lhq.value = prop;
     lhq.pool = vm->mem_cache_pool;
@@ -696,8 +696,7 @@ njs_regexp_exec_result(njs_vm_t *vm, njs_regexp_t *regexp, u_char *string,
     njs_string_copy(&prop->value, &regexp->string);
 
     lhq.key_hash = NJS_INPUT_HASH;
-    lhq.key.len = sizeof("input") - 1;
-    lhq.key.data = (u_char *) "input";
+    lhq.key = nxt_string_value("input");
     lhq.value = prop;
 
     ret = nxt_lvlhsh_insert(&array->object.hash, &lhq);
index 098706e69870275428f228c270f67d4481572d19..2c43cbfef0c63b66f1c480fe51ca0ec3d0145db9 100644 (file)
@@ -8,6 +8,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_djb_hash.h>
@@ -2119,15 +2120,15 @@ njs_values_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
 
     value = data;
 
-    if (lhq->key.len == sizeof(njs_value_t)
-        && memcmp(lhq->key.data, value, sizeof(njs_value_t)) == 0)
+    if (lhq->key.length == sizeof(njs_value_t)
+        && memcmp(lhq->key.start, value, sizeof(njs_value_t)) == 0)
     {
         return NXT_OK;
     }
 
     if (value->type == NJS_STRING
-        && value->data.string_size == lhq->key.len
-        && memcmp(value->data.u.string->start, lhq->key.data, lhq->key.len)
+        && value->data.string_size == lhq->key.length
+        && memcmp(value->data.u.string->start, lhq->key.start, lhq->key.length)
            == 0)
     {
         return NXT_OK;
@@ -2174,8 +2175,8 @@ njs_value_index(njs_vm_t *vm, njs_parser_t *parser, const njs_value_t *src)
     }
 
     lhq.key_hash = nxt_djb_hash(start, size);
-    lhq.key.len = size;
-    lhq.key.data = start;
+    lhq.key.length = size;
+    lhq.key.start = start;
     lhq.proto = &njs_values_hash_proto;
 
     if (nxt_lvlhsh_find(&vm->shared->values_hash, &lhq) == NXT_OK) {
index 46c34d88d175390222e22fbb6355c4b7b75559b6..5915b91a918d6a0bbd43ebed968a3d11a3045534 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_djb_hash.h>
@@ -32,8 +33,8 @@ njs_variables_hash_test(nxt_lvlhsh_query_t *lhq, void *data)
 
     var = data;
 
-    if (lhq->key.len == var->name_len
-        && memcmp(var->name_start, lhq->key.data, lhq->key.len) == 0)
+    if (lhq->key.length == var->name_len
+        && memcmp(var->name_start, lhq->key.start, lhq->key.length) == 0)
     {
         return NXT_OK;
     }
@@ -106,8 +107,8 @@ njs_parser_variable(njs_vm_t *vm, njs_parser_t *parser, nxt_uint_t *level)
         n = scope->arguments->items;
 
         while (n != 0) {
-            if (lhq.key.len == var->name_len
-                && memcmp(var->name_start, lhq.key.data, lhq.key.len) == 0)
+            if (lhq.key.length == var->name_len
+                && memcmp(var->name_start, lhq.key.start, lhq.key.length) == 0)
             {
                 return var;
             }
@@ -157,7 +158,7 @@ njs_vm_function(njs_vm_t *vm, nxt_str_t *name)
     njs_variable_t      *var;
     nxt_lvlhsh_query_t  lhq;
 
-    lhq.key_hash = nxt_djb_hash(name->data, name->len);
+    lhq.key_hash = nxt_djb_hash(name->start, name->length);
     lhq.key = *name;
     lhq.proto = &njs_variables_hash_proto;
 
@@ -187,12 +188,12 @@ njs_variable_alloc(njs_vm_t *vm, njs_parser_t *parser, nxt_str_t *name)
     var = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_variable_t));
 
     if (nxt_fast_path(var != NULL)) {
-        var->name_start = nxt_mem_cache_alloc(vm->mem_cache_pool, name->len);
+        var->name_start = nxt_mem_cache_alloc(vm->mem_cache_pool, name->length);
 
         if (nxt_fast_path(var->name_start != NULL)) {
 
-            memcpy(var->name_start, name->data, name->len);
-            var->name_len = name->len;
+            memcpy(var->name_start, name->start, name->length);
+            var->name_len = name->length;
 
             value = nxt_array_add(parser->scope_values, &njs_array_mem_proto,
                                   vm->mem_cache_pool);
index caca69e71895c0495112f77e715c4b21c3701048..13791973d37cb122d86b1179b9284708faa37b8c 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_utf8.h>
 #include <nxt_djb_hash.h>
@@ -998,17 +999,17 @@ njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object,
 
         if (nxt_fast_path(ret == NXT_OK)) {
 
-            pq->lhq.key.len = pq->value.short_string.size;
+            pq->lhq.key.length = pq->value.short_string.size;
 
-            if (pq->lhq.key.len != NJS_STRING_LONG) {
-                pq->lhq.key.data = pq->value.short_string.start;
+            if (pq->lhq.key.length != NJS_STRING_LONG) {
+                pq->lhq.key.start = pq->value.short_string.start;
 
             } else {
-                pq->lhq.key.len = pq->value.data.string_size;
-                pq->lhq.key.data = pq->value.data.u.string->start;
+                pq->lhq.key.length = pq->value.data.string_size;
+                pq->lhq.key.start = pq->value.data.u.string->start;
             }
 
-            pq->lhq.key_hash = hash(pq->lhq.key.data, pq->lhq.key.len);
+            pq->lhq.key_hash = hash(pq->lhq.key.start, pq->lhq.key.length);
 
             if (obj == NULL) {
                 pq->lhq.proto = &njs_extern_hash_proto;
@@ -1281,8 +1282,7 @@ njs_vmcode_instance_of(njs_vm_t *vm, njs_value_t *object,
     if (njs_is_object(object)) {
 
         lhq.key_hash = NJS_PROTOTYPE_HASH;
-        lhq.key.len = sizeof("prototype") - 1;
-        lhq.key.data = (u_char *) "prototype";
+        lhq.key = nxt_string_value("prototype");
 
         prop = njs_object_property(vm, constructor->data.u.object, &lhq);
 
@@ -2202,8 +2202,7 @@ njs_function_new_object(njs_vm_t *vm, njs_value_t *value)
     if (nxt_fast_path(object != NULL)) {
 
         lhq.key_hash = NJS_PROTOTYPE_HASH;
-        lhq.key.len = sizeof("prototype") - 1;
-        lhq.key.data = (u_char *) "prototype";
+        lhq.key = nxt_string_value("prototype");
         lhq.proto = &njs_object_hash_proto;
         function = value->data.u.function;
 
@@ -3179,8 +3178,8 @@ njs_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src)
                 start = value.data.u.string->start;
             }
 
-            dst->len = size;
-            dst->data = start;
+            dst->length = size;
+            dst->start = start;
 
             return NXT_OK;
         }
@@ -3188,8 +3187,8 @@ njs_value_to_ext_string(njs_vm_t *vm, nxt_str_t *dst, const njs_value_t *src)
 
 fail:
 
-    dst->len = 0;
-    dst->data = NULL;
+    dst->length = 0;
+    dst->start = NULL;
 
     return NXT_ERROR;
 }
@@ -3343,7 +3342,7 @@ njs_debug(njs_index_t index, njs_value_t *value)
 {
 #if (NXT_DEBUG)
     u_char    *p;
-    uint32_t  len;
+    uint32_t  length;
 
     switch (value->type) {
 
@@ -3365,16 +3364,16 @@ njs_debug(njs_index_t index, njs_value_t *value)
         return;
 
     case NJS_STRING:
-        len = value->short_string.size;
-        if (len != NJS_STRING_LONG) {
+        length = value->short_string.size;
+        if (length != NJS_STRING_LONG) {
             p = value->short_string.start;
 
         } else {
-            len = value->data.string_size;
+            length = value->data.string_size;
             p = value->data.u.string->start;
         }
 
-        nxt_thread_log_debug("%p [\"%*s\"]", index, len, p);
+        nxt_thread_log_debug("%p [\"%*s\"]", index, length, p);
         return;
 
     case NJS_ARRAY:
index 8e633147726d098df449efe2e792dc88c5e418f8..48d5241d4e792077fbf6f97c0fafff59c6f1c4c9 100644 (file)
@@ -7,6 +7,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_alignment.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_array.h>
 #include <nxt_lvlhsh.h>
index acb34a3e4c49a7c7da01897f4bbd88187ffadcfa..2056a3c061f9d829e61bc00076de06d3c0e8e77f 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_malloc.h>
 #include <nxt_array.h>
@@ -4653,7 +4654,7 @@ njs_unit_test_r_get_uri_external(njs_vm_t *vm, njs_value_t *value, void *obj,
 
     r = (njs_unit_test_req *) obj;
 
-    return njs_string_create(vm, value, r->uri.data, r->uri.len, 0);
+    return njs_string_create(vm, value, r->uri.start, r->uri.length, 0);
 }
 
 
@@ -4690,15 +4691,15 @@ njs_unit_test_header_external(njs_vm_t *vm, njs_value_t *value, void *obj,
     r = (njs_unit_test_req *) obj;
     h = (nxt_str_t *) data;
 
-    size = 7 + h->len;
+    size = 7 + h->length;
 
     s = nxt_mem_cache_alloc(r->mem_cache_pool, size);
     if (nxt_slow_path(s == NULL)) {
         return NXT_ERROR;
     }
 
-    p = memcpy(s, h->data, h->len);
-    p += h->len;
+    p = memcpy(s, h->start, h->length);
+    p += h->length;
     *p++ = '|';
     memcpy(p, "АБВ", 6);
 
@@ -4751,9 +4752,9 @@ njs_unit_test_method_external(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
         ret = njs_value_string_copy(vm, &s, njs_argument(args, 1), &next);
 
-        if (ret == NXT_OK && s.len == 3 && memcmp(s.data, "YES", 3) == 0) {
+        if (ret == NXT_OK && s.length == 3 && memcmp(s.start, "YES", 3) == 0) {
             r = njs_value_data(njs_argument(args, 0));
-            njs_vm_return_string(vm, r->uri.data, r->uri.len);
+            njs_vm_return_string(vm, r->uri.start, r->uri.length);
 
             return NXT_OK;
         }
@@ -4923,8 +4924,8 @@ njs_unit_test(nxt_bool_t disassemble)
     }
 
     r.mem_cache_pool = mcp;
-    r.uri.len = 6;
-    r.uri.data = (u_char *) "АБВ";
+    r.uri.length = 6;
+    r.uri.start = (u_char *) "АБВ";
 
     ext_object = &r;
 
@@ -4935,16 +4936,16 @@ njs_unit_test(nxt_bool_t disassemble)
     for (i = 0; i < nxt_nitems(njs_test); i++) {
 
         printf("\"%.*s\"\n",
-               (int) njs_test[i].script.len, njs_test[i].script.data);
+               (int) njs_test[i].script.length, njs_test[i].script.start);
 
         vm = njs_vm_create(mcp, &shared, &externals);
         if (vm == NULL) {
             return NXT_ERROR;
         }
 
-        start = njs_test[i].script.data;
+        start = njs_test[i].script.start;
 
-        ret = njs_vm_compile(vm, &start, start + njs_test[i].script.len,
+        ret = njs_vm_compile(vm, &start, start + njs_test[i].script.length,
                              &function);
 
         if (ret == NXT_OK) {
@@ -4957,12 +4958,12 @@ njs_unit_test(nxt_bool_t disassemble)
                 return NXT_ERROR;
             }
 
-            r.uri.len = 6;
-            r.uri.data = (u_char *) "АБВ";
+            r.uri.length = 6;
+            r.uri.start = (u_char *) "АБВ";
 
             if (function != NULL) {
-                r_name.len = 2;
-                r_name.data = (u_char *) "$r";
+                r_name.length = 2;
+                r_name.start = (u_char *) "$r";
 
                 ret = njs_vm_external(nvm, NULL, &r_name, &value);
                 if (ret != NXT_OK) {
@@ -5000,9 +5001,9 @@ njs_unit_test(nxt_bool_t disassemble)
         }
 
         printf("njs(\"%.*s\") failed: \"%.*s\" vs \"%.*s\"\n",
-               (int) njs_test[i].script.len, njs_test[i].script.data,
-               (int) njs_test[i].ret.len, njs_test[i].ret.data,
-               (int) s.len, s.data);
+               (int) njs_test[i].script.length, njs_test[i].script.start,
+               (int) njs_test[i].ret.length, njs_test[i].ret.start,
+               (int) s.length, s.start);
 
         return NXT_ERROR;
     }
@@ -5042,8 +5043,8 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
     }
 
     r.mem_cache_pool = mcp;
-    r.uri.len = 6;
-    r.uri.data = (u_char *) "АБВ";
+    r.uri.length = 6;
+    r.uri.start = (u_char *) "АБВ";
 
     ext_object = &r;
 
@@ -5056,9 +5057,9 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg,
         return NXT_ERROR;
     }
 
-    start = script->data;
+    start = script->start;
 
-    ret = njs_vm_compile(vm, &start, start + script->len, NULL);
+    ret = njs_vm_compile(vm, &start, start + script->length, NULL);
     if (ret != NXT_OK) {
         return NXT_ERROR;
     }
index c248f11bdb6dc9a9ba99d9e2ef4594a329a81b99..4e0f4f9a9cc79d750c7b6022b94d116e502dd67b 100644 (file)
@@ -90,6 +90,7 @@ $(NXT_BUILDDIR)/nxt_rbtree.o: \
 $(NXT_BUILDDIR)/nxt_lvlhsh.o: \
        $(NXT_LIB)/nxt_types.h \
        $(NXT_LIB)/nxt_clang.h \
+       $(NXT_LIB)/nxt_string.h \
        $(NXT_LIB)/nxt_lvlhsh.h \
        $(NXT_LIB)/nxt_lvlhsh.c \
 
index 3c6838a0334ce7a224977a752ea7f0087b1901df..25c3f4546feea682d49b514e8289f005c53d7c89 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_djb_hash.h>
 
index 2842b92cc1790b5bf3cef1973eccaa212e691914..dd0514d0347599852fdc4d79b1af1f4d8712cfb4 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <nxt_types.h>
 #include <nxt_clang.h>
+#include <nxt_string.h>
 #include <nxt_stub.h>
 #include <nxt_lvlhsh.h>
 #include <string.h>
index cc3a58a37e161c4a11e66e7bed4858ba6c755130..18cdcfcd731bcd8703717662c613cdafac4597e7 100644 (file)
@@ -99,11 +99,7 @@ typedef struct {
 
 struct nxt_lvlhsh_query_s {
     uint32_t                 key_hash;
-    nxt_str_t                 key;
-#if 0
-    uint32_t                 key_length;
-    void                     *key_start;
-#endif
+    nxt_str_t                key;
 
     uint8_t                  replace;     /* 1 bit */
     void                     *value;
diff --git a/nxt/nxt_string.h b/nxt/nxt_string.h
new file mode 100644 (file)
index 0000000..db1cdd7
--- /dev/null
@@ -0,0 +1,48 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#ifndef _NXT_STRING_H_INCLUDED_
+#define _NXT_STRING_H_INCLUDED_
+
+
+typedef struct {
+    size_t  length;
+    u_char  *start;
+} nxt_str_t;
+
+
+/*
+ * C99 allows to assign struct as compound literal with struct name cast only.
+ * SunC however issues error on the cast in struct static initialization:
+ *   non-constant initializer: op "NAME"
+ * 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_null_string      { 0, NULL }
+#define nxt_string_value(s)  (nxt_str_t) nxt_string(s)
+
+
+nxt_inline u_char
+nxt_lower_case(u_char c)
+{
+    return (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c);
+}
+
+
+nxt_inline u_char
+nxt_upper_case(u_char c)
+{
+    return (u_char) ((c >= 'a' && c <= 'z') ? c & 0xDF : c);
+}
+
+
+#define nxt_strstr_eq(s1, s2)                                                 \
+    (((s1)->length == (s2)->length)                                           \
+     && (memcmp((s1)->start, (s2)->start, (s1)->length) == 0))
+
+
+#endif /* _NXT_STRING_H_INCLUDED_ */
index f1e3340e6d6969439b6a3e3c31dbafd57b1323d5..28ecc48e5b3064e47f64a0246cfe4cd6ba56b41e 100644 (file)
     ((val1 < val2) ? (val1) : (val2))
 
 
-nxt_inline u_char
-nxt_lower_case(u_char c)
-{
-    return (u_char) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c);
-}
-
-
-nxt_inline u_char
-nxt_upper_case(u_char c)
-{
-    return (u_char) ((c >= 'a' && c <= 'z') ? c & 0xDF : c);
-}
-
-
-#define nxt_strstr_eq(s1, s2)                                                 \
-    (((s1)->len == (s2)->len)                                                 \
-      && (memcmp((s1)->data, (s2)->data, (s1)->len) == 0))
-
-
 #define NXT_OK             0
 #define NXT_ERROR          (-1)
 #define NXT_AGAIN          (-2)
@@ -52,36 +33,10 @@ typedef struct {
 } nxt_mem_proto_t;
 
 
-typedef struct {
-    size_t         len;
-    u_char         *data;
-} nxt_str_t;
-
-
-#define nxt_str_set(str, text)                                                \
-    do {                                                                      \
-        (str)->len = sizeof(text) - 1;                                        \
-        (str)->data = (u_char *) text;                                        \
-    } while (0)
-
-
-#define nxt_str_null(str)                                                     \
-    do {                                                                      \
-        (str)->len = 0;                                                       \
-        (str)->data = NULL;                                                   \
-    } while (0)
-
-
-#define nxt_string(str)       { sizeof(str) - 1, (u_char *) str }
-#define nxt_string_zero(str)  { sizeof(str), (u_char *) str }
-#define nxt_null_string       { 0, NULL }
-
-
 #define nxt_thread_log_alert(...)
 #define nxt_thread_log_error(...)
 #define nxt_log_error(...)
 #define nxt_thread_log_debug(...)
-#define nxt_number_parse(a, b)      1
 
 #define NXT_DOUBLE_LEN   1024