#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_random.h>
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) {
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;
}
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) {
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;
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;
}
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;
}
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);
}
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);
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;
}
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;
}
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;
}
/* 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;
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;
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);
}
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);
}
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);
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"%*s, included",
- text.len, text.data);
+ text.length, text.start);
return NGX_CONF_ERROR;
}
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;
}
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_random.h>
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) {
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;
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;
}
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;
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);
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"%*s, included",
- text.len, text.data);
+ text.length, text.start);
return NGX_CONF_ERROR;
}
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;
}
#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>
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);
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_lvlhsh.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>
#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>
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);
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_lvlhsh.h>
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);
}
#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>
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;
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;
}
}
- 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;
#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>
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_lvlhsh.h>
#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>
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++;
switch (token) {
case NJS_TOKEN_SPACE:
- lexer->text.data = lexer->start;
+ lexer->text.start = lexer->start;
continue;
case NJS_TOKEN_LETTER:
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 */
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;
}
lexer->start = p;
- lexer->text.len = p - lexer->text.data;
+ lexer->text.length = p - lexer->text.start;
if (lexer->property) {
return NJS_TOKEN_NAME;
nxt_bool_t escape;
escape = 0;
- lexer->text.data = lexer->start;
+ lexer->text.start = lexer->start;
p = lexer->start;
while (p < lexer->end) {
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;
}
}
- 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;
}
} while (n != 0);
}
- lexer->text.len = lexer->start - lexer->text.data;
+ lexer->text.length = lexer->start - lexer->text.start;
return token;
}
#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>
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;
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_lvlhsh.h>
#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>
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_array.h>
#include <nxt_lvlhsh.h>
#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>
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);
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;
}
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;
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;
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_utf8.h>
#include <nxt_array.h>
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;
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);
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;
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++;
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);
#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>
#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>
}
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;
}
}
}
- 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);
}
}
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;
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);
#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>
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;
}
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) {
#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>
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;
}
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;
}
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;
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);
#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>
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;
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);
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;
start = value.data.u.string->start;
}
- dst->len = size;
- dst->data = start;
+ dst->length = size;
+ dst->start = start;
return NXT_OK;
}
fail:
- dst->len = 0;
- dst->data = NULL;
+ dst->length = 0;
+ dst->start = NULL;
return NXT_ERROR;
}
{
#if (NXT_DEBUG)
u_char *p;
- uint32_t len;
+ uint32_t length;
switch (value->type) {
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:
#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>
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_malloc.h>
#include <nxt_array.h>
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);
}
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);
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;
}
}
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;
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) {
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) {
}
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;
}
}
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;
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;
}
$(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 \
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_djb_hash.h>
#include <nxt_types.h>
#include <nxt_clang.h>
+#include <nxt_string.h>
#include <nxt_stub.h>
#include <nxt_lvlhsh.h>
#include <string.h>
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;
--- /dev/null
+
+/*
+ * 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_ */
((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)
} 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