[njs] nxt_str_t changes.
Igor Sysoev
igor at sysoev.ru
Thu Aug 4 13:06:19 UTC 2016
details: http://hg.nginx.org/njs/rev/016339472304
branches:
changeset: 139:016339472304
user: Igor Sysoev <igor at sysoev.ru>
date: Thu Aug 04 14:45:27 2016 +0300
description:
nxt_str_t changes.
diffstat:
nginx/ngx_http_js_module.c | 73 ++++++++++++++++++++++--------------------
nginx/ngx_stream_js_module.c | 23 +++++++------
njs/njs_array.c | 4 +-
njs/njs_boolean.c | 1 +
njs/njs_builtin.c | 1 +
njs/njs_date.c | 4 +-
njs/njs_disassembler.c | 10 +++--
njs/njs_extern.c | 13 ++++---
njs/njs_function.c | 1 +
njs/njs_generator.c | 1 +
njs/njs_lexer.c | 21 ++++++-----
njs/njs_lexer_keyword.c | 3 +-
njs/njs_math.c | 1 +
njs/njs_nonrecursive_parser.c | 1 +
njs/njs_number.c | 1 +
njs/njs_object.c | 25 +++++++-------
njs/njs_parser.c | 28 ++++++++-------
njs/njs_parser_expression.c | 1 +
njs/njs_regexp.c | 23 ++++++-------
njs/njs_string.c | 13 ++++---
njs/njs_variable.c | 17 +++++----
njs/njs_vm.c | 39 +++++++++++-----------
njs/njscript.c | 1 +
njs/test/njs_unit_test.c | 49 ++++++++++++++--------------
nxt/Makefile | 1 +
nxt/nxt_djb_hash.c | 1 +
nxt/nxt_lvlhsh.c | 1 +
nxt/nxt_lvlhsh.h | 6 +--
nxt/nxt_string.h | 48 ++++++++++++++++++++++++++++
nxt/nxt_stub.h | 45 --------------------------
30 files changed, 240 insertions(+), 216 deletions(-)
diffs (truncated from 1428 to 1000 lines):
diff -r f171ddad457e -r 016339472304 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Thu Aug 04 14:43:20 2016 +0300
+++ b/nginx/ngx_http_js_module.c Thu Aug 04 14:45:27 2016 +0300
@@ -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 *
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 *
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
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
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
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,
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
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
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
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,
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_v
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_v
/* 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_va
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 *
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, nj
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 *v
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_
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_
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;
}
diff -r f171ddad457e -r 016339472304 nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c Thu Aug 04 14:43:20 2016 +0300
+++ b/nginx/ngx_stream_js_module.c Thu Aug 04 14:45:27 2016 +0300
@@ -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_sessio
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_sessio
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_sessio
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_
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
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, ng
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, ng
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;
}
diff -r f171ddad457e -r 016339472304 njs/njs_array.c
--- a/njs/njs_array.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_array.c Thu Aug 04 14:45:27 2016 +0300
@@ -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 *
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);
diff -r f171ddad457e -r 016339472304 njs/njs_boolean.c
--- a/njs/njs_boolean.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_boolean.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_builtin.c
--- a/njs/njs_builtin.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_builtin.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_date.c
--- a/njs/njs_date.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_date.c Thu Aug 04 14:45:27 2016 +0300
@@ -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,
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);
diff -r f171ddad457e -r 016339472304 njs/njs_disassembler.c
--- a/njs/njs_disassembler.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_disassembler.c Thu Aug 04 14:45:27 2016 +0300
@@ -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 *e
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);
}
diff -r f171ddad457e -r 016339472304 njs/njs_extern.c
--- a/njs/njs_extern.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_extern.c Thu Aug 04 14:45:27 2016 +0300
@@ -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,
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,
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
}
}
- 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;
diff -r f171ddad457e -r 016339472304 njs/njs_function.c
--- a/njs/njs_function.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_function.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_generator.c
--- a/njs/njs_generator.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_generator.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_lexer.c
--- a/njs/njs_lexer.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_lexer.c Thu Aug 04 14:45:27 2016 +0300
@@ -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_cha
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_cha
}
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_c
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_c
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_c
}
}
- 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_
} while (n != 0);
}
- lexer->text.len = lexer->start - lexer->text.data;
+ lexer->text.length = lexer->start - lexer->text.start;
return token;
}
diff -r f171ddad457e -r 016339472304 njs/njs_lexer_keyword.c
--- a/njs/njs_lexer_keyword.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_lexer_keyword.c Thu Aug 04 14:45:27 2016 +0300
@@ -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_po
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;
diff -r f171ddad457e -r 016339472304 njs/njs_math.c
--- a/njs/njs_math.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_math.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_nonrecursive_parser.c
--- a/njs/njs_nonrecursive_parser.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_nonrecursive_parser.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_number.c
--- a/njs/njs_number.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_number.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_object.c
--- a/njs/njs_object.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_object.c Thu Aug 04 14:45:27 2016 +0300
@@ -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
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
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 *
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
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;
diff -r f171ddad457e -r 016339472304 njs/njs_parser.c
--- a/njs/njs_parser.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_parser.c Thu Aug 04 14:45:27 2016 +0300
@@ -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,
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
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, n
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);
-
- if (length > NJS_STRING_MAP_OFFSET && (size_t) length != src->len) {
- njs_string_offset_map_init(p, src->len);
+ memcpy(p, src->start, src->length);
+
+ 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
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_parse
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);
diff -r f171ddad457e -r 016339472304 njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_parser_expression.c Thu Aug 04 14:45:27 2016 +0300
@@ -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>
diff -r f171ddad457e -r 016339472304 njs/njs_regexp.c
--- a/njs/njs_regexp.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_regexp.c Thu Aug 04 14:45:27 2016 +0300
@@ -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_par
}
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_par
}
}
- 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
}
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
njs_string_copy(&prop->value, ®exp->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);
diff -r f171ddad457e -r 016339472304 njs/njs_string.c
--- a/njs/njs_string.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_string.c Thu Aug 04 14:45:27 2016 +0300
@@ -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
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
}
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) {
diff -r f171ddad457e -r 016339472304 njs/njs_variable.c
--- a/njs/njs_variable.c Thu Aug 04 14:43:20 2016 +0300
+++ b/njs/njs_variable.c Thu Aug 04 14:45:27 2016 +0300
@@ -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
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_pa
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
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_par
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;
More information about the nginx-devel
mailing list