From: Igor Sysoev Date: Thu, 4 Aug 2016 11:45:27 +0000 (+0300) Subject: nxt_str_t changes. X-Git-Tag: 0.1.1~19 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=60d6fbf5325cd4ca80ba3bac11651e1f1ad9a11f;p=njs.git nxt_str_t changes. --- diff --git a/nginx/ngx_http_js_module.c b/nginx/ngx_http_js_module.c index f8ad1f27..429b3c42 100644 --- a/nginx/ngx_http_js_module.c +++ b/nginx/ngx_http_js_module.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c index 53dfed26..bf01e38d 100644 --- a/nginx/ngx_stream_js_module.c +++ b/nginx/ngx_stream_js_module.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/njs/njs_array.c b/njs/njs_array.c index 9d61bb4b..d10369c8 100644 --- a/njs/njs_array.c +++ b/njs/njs_array.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/njs/njs_boolean.c b/njs/njs_boolean.c index 8c89708d..f173364a 100644 --- a/njs/njs_boolean.c +++ b/njs/njs_boolean.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c index a40a7f86..e38379eb 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/njs/njs_date.c b/njs/njs_date.c index ea15a86d..2bac3f4e 100644 --- a/njs/njs_date.c +++ b/njs/njs_date.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/njs/njs_disassembler.c b/njs/njs_disassembler.c index 93514e06..8e45a8e4 100644 --- a/njs/njs_disassembler.c +++ b/njs/njs_disassembler.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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); } diff --git a/njs/njs_extern.c b/njs/njs_extern.c index b13e28b8..26169393 100644 --- a/njs/njs_extern.c +++ b/njs/njs_extern.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/njs/njs_function.c b/njs/njs_function.c index 568e53c5..ed97aecf 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/njs/njs_generator.c b/njs/njs_generator.c index 9aacb5ef..3e2825a8 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/njs/njs_lexer.c b/njs/njs_lexer.c index 3976c262..3abcba35 100644 --- a/njs/njs_lexer.c +++ b/njs/njs_lexer.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/njs/njs_lexer_keyword.c b/njs/njs_lexer_keyword.c index c699342d..d6d39fd8 100644 --- a/njs/njs_lexer_keyword.c +++ b/njs/njs_lexer_keyword.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/njs/njs_math.c b/njs/njs_math.c index 17e25464..36a8bf3a 100644 --- a/njs/njs_math.c +++ b/njs/njs_math.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/njs/njs_nonrecursive_parser.c b/njs/njs_nonrecursive_parser.c index 43442a9c..5c24bd99 100644 --- a/njs/njs_nonrecursive_parser.c +++ b/njs/njs_nonrecursive_parser.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/njs/njs_number.c b/njs/njs_number.c index 51b0785c..5fd3fe24 100644 --- a/njs/njs_number.c +++ b/njs/njs_number.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/njs/njs_object.c b/njs/njs_object.c index 3f3c9de0..e1242e25 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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; diff --git a/njs/njs_parser.c b/njs/njs_parser.c index 680cc6eb..0d2ebbd7 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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); diff --git a/njs/njs_parser_expression.c b/njs/njs_parser_expression.c index 8aba527a..ee81964d 100644 --- a/njs/njs_parser_expression.c +++ b/njs/njs_parser_expression.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 5c9f19d0..72568921 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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, ®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 --git a/njs/njs_string.c b/njs/njs_string.c index 098706e6..2c43cbfe 100644 --- a/njs/njs_string.c +++ b/njs/njs_string.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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) { diff --git a/njs/njs_variable.c b/njs/njs_variable.c index 46c34d88..5915b91a 100644 --- a/njs/njs_variable.c +++ b/njs/njs_variable.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/njs/njs_vm.c b/njs/njs_vm.c index caca69e7..13791973 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -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: diff --git a/njs/njscript.c b/njs/njscript.c index 8e633147..48d5241d 100644 --- a/njs/njscript.c +++ b/njs/njscript.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index acb34a3e..2056a3c0 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/nxt/Makefile b/nxt/Makefile index c248f11b..4e0f4f9a 100644 --- a/nxt/Makefile +++ b/nxt/Makefile @@ -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 \ diff --git a/nxt/nxt_djb_hash.c b/nxt/nxt_djb_hash.c index 3c6838a0..25c3f454 100644 --- a/nxt/nxt_djb_hash.c +++ b/nxt/nxt_djb_hash.c @@ -6,6 +6,7 @@ #include #include +#include #include #include diff --git a/nxt/nxt_lvlhsh.c b/nxt/nxt_lvlhsh.c index 2842b92c..dd0514d0 100644 --- a/nxt/nxt_lvlhsh.c +++ b/nxt/nxt_lvlhsh.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/nxt/nxt_lvlhsh.h b/nxt/nxt_lvlhsh.h index cc3a58a3..18cdcfcd 100644 --- a/nxt/nxt_lvlhsh.h +++ b/nxt/nxt_lvlhsh.h @@ -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 index 00000000..db1cdd70 --- /dev/null +++ b/nxt/nxt_string.h @@ -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_ */ diff --git a/nxt/nxt_stub.h b/nxt/nxt_stub.h index f1e3340e..28ecc48e 100644 --- a/nxt/nxt_stub.h +++ b/nxt/nxt_stub.h @@ -15,25 +15,6 @@ ((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