From: Igor Sysoev Date: Fri, 23 Sep 2016 08:59:56 +0000 (+0300) Subject: Style and small miscellaneous fixes. X-Git-Tag: 0.1.3~13 X-Git-Url: http://git.kaiwu.me/sitemap.xml?a=commitdiff_plain;h=8fc0acb50b085a86fe302916e1d6da2250e2c8f1;p=njs.git Style and small miscellaneous fixes. --- diff --git a/njs/njs_builtin.c b/njs/njs_builtin.c index c493ca88..23af28ac 100644 --- a/njs/njs_builtin.c +++ b/njs/njs_builtin.c @@ -43,7 +43,7 @@ njs_builtin_objects_create(njs_vm_t *vm) njs_function_t *functions, *constructors; njs_object_prototype_t *prototypes; - static const njs_object_init_t *prototype_init[] = { + static const njs_object_init_t *prototype_init[] = { &njs_object_prototype_init, &njs_array_prototype_init, &njs_boolean_prototype_init, @@ -56,7 +56,7 @@ njs_builtin_objects_create(njs_vm_t *vm) static const njs_object_prototype_t prototype_values[] = { /* - * GCC 4 complains about unitialized .shared field, + * GCC 4 complains about uninitialized .shared field, * if the .type field is initialized as .object.type. */ { .object = { .type = NJS_OBJECT } }, @@ -95,15 +95,15 @@ njs_builtin_objects_create(njs_vm_t *vm) static const njs_function_init_t native_constructors[] = { /* SunC does not allow empty array initialization. */ - { njs_object_constructor, { 0 } }, - { njs_array_constructor, { 0 } }, - { njs_boolean_constructor, { 0 } }, - { njs_number_constructor, { NJS_SKIP_ARG, NJS_NUMBER_ARG } }, - { njs_string_constructor, { NJS_SKIP_ARG, NJS_STRING_ARG } }, - { njs_function_constructor, { 0 } }, + { njs_object_constructor, { 0 } }, + { njs_array_constructor, { 0 } }, + { njs_boolean_constructor, { 0 } }, + { njs_number_constructor, { NJS_SKIP_ARG, NJS_NUMBER_ARG } }, + { njs_string_constructor, { NJS_SKIP_ARG, NJS_STRING_ARG } }, + { njs_function_constructor, { 0 } }, { njs_regexp_constructor, { NJS_SKIP_ARG, NJS_STRING_ARG, NJS_STRING_ARG } }, - { njs_date_constructor, { 0 } }, + { njs_date_constructor, { 0 } }, }; static const njs_object_init_t *object_init[] = { diff --git a/njs/njs_function.h b/njs/njs_function.h index 0d2bd088..9fdda918 100644 --- a/njs/njs_function.h +++ b/njs/njs_function.h @@ -47,6 +47,14 @@ struct njs_function_lambda_s { #define NJS_FRAME_SPARE_SIZE 512 + +typedef struct { + njs_function_native_t function; + u_char *return_address; + njs_index_t retval; +} njs_continuation_t; + + #define njs_continuation(frame) \ (void *) ((u_char *) frame + NJS_NATIVE_FRAME_SIZE) diff --git a/njs/njs_regexp.c b/njs/njs_regexp.c index 4d51c129..7beb718b 100644 --- a/njs/njs_regexp.c +++ b/njs/njs_regexp.c @@ -292,7 +292,6 @@ njs_regexp_pattern_create(njs_vm_t *vm, u_char *start, size_t length, } pattern->flags = size; - pattern->next = NULL; p = (u_char *) pattern + sizeof(njs_regexp_pattern_t); pattern->source = p; diff --git a/njs/njs_regexp_pattern.h b/njs/njs_regexp_pattern.h index 4e16d89f..e05ae3c1 100644 --- a/njs/njs_regexp_pattern.h +++ b/njs/njs_regexp_pattern.h @@ -19,7 +19,6 @@ typedef enum { struct njs_regexp_pattern_s { nxt_regex_t regex[2]; - njs_regexp_pattern_t *next; /* * A pattern source is used by RegExp.toString() method and * RegExp.source property. So it is is stored in form "/pattern/flags" diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 481da3af..60995ded 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -162,7 +162,7 @@ njs_vmcode_interpreter(njs_vm_t *vm) njs_native_frame_t *previous; njs_vmcode_generic_t *vmcode; - start: +start: for ( ;; ) { diff --git a/njs/njs_vm.h b/njs/njs_vm.h index 9aab8025..cce7be7f 100644 --- a/njs/njs_vm.h +++ b/njs/njs_vm.h @@ -124,15 +124,6 @@ typedef struct njs_native_frame_s njs_native_frame_t; typedef struct njs_property_next_s njs_property_next_t; -typedef struct njs_continuation_s njs_continuation_t; - -struct njs_continuation_s { - njs_function_native_t function; - u_char *return_address; - njs_index_t retval; -}; - - union njs_value_s { /* * The njs_value_t size is 16 bytes and must be aligned to 16 bytes diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 3fcbaa9a..725c3f69 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -5572,11 +5572,11 @@ njs_unit_test_benchmark(nxt_str_t *script, nxt_str_t *result, const char *msg, + usage.ru_stime.tv_sec * 1000000 + usage.ru_stime.tv_usec; if (n == 1) { - us /= 1000; - printf("%s: %d.%03ds\n", msg, (int) (us / 1000), (int) (us % 1000)); + printf("%s: %.3fs\n", msg, (double) us / 1000000); } else { - printf("%s: %d\n", msg, (int) ((uint64_t) n * 1000000 / us)); + printf("%s: %.3fµs, %d times/s\n", + msg, (double) us / n, (int) ((uint64_t) n * 1000000 / us)); } return NXT_OK; diff --git a/nxt/nxt_mem_cache_pool.c b/nxt/nxt_mem_cache_pool.c index 06a47d53..b270b4f5 100644 --- a/nxt/nxt_mem_cache_pool.c +++ b/nxt/nxt_mem_cache_pool.c @@ -52,12 +52,12 @@ struct nxt_mem_cache_page_s { * Used to link pages with free chunks in pool chunk slot list * or to link free pages in clusters. */ - nxt_queue_link_t link; + nxt_queue_link_t link; }; typedef struct { - NXT_RBTREE_NODE (node); + NXT_RBTREE_NODE (node); uint8_t type; uint32_t size; @@ -67,7 +67,7 @@ typedef struct { typedef struct { - nxt_queue_t pages; + nxt_queue_t pages; #if (NXT_64BIT) uint32_t size; uint32_t chunks; @@ -80,9 +80,9 @@ typedef struct { struct nxt_mem_cache_pool_s { /* rbtree of nxt_mem_cache_block_t. */ - nxt_rbtree_t blocks; + nxt_rbtree_t blocks; - nxt_queue_t free_pages; + nxt_queue_t free_pages; uint8_t chunk_size_shift; uint8_t page_size_shift; @@ -90,11 +90,11 @@ struct nxt_mem_cache_pool_s { uint32_t page_alignment; uint32_t cluster_size; - const nxt_mem_proto_t *proto; + const nxt_mem_proto_t *proto; void *mem; void *trace; - nxt_mem_cache_slot_t slots[]; + nxt_mem_cache_slot_t slots[]; }; @@ -515,7 +515,7 @@ nxt_mem_cache_alloc_cluster(nxt_mem_cache_pool_t *pool) n = pool->cluster_size >> pool->page_size_shift; cluster = pool->proto->zalloc(pool->mem, sizeof(nxt_mem_cache_block_t) - + n * sizeof(nxt_mem_cache_page_t)); + + n * sizeof(nxt_mem_cache_page_t)); if (nxt_slow_path(cluster == NULL)) { return NULL; diff --git a/nxt/nxt_types.h b/nxt/nxt_types.h index 0b28cf4e..9fa99733 100644 --- a/nxt/nxt_types.h +++ b/nxt/nxt_types.h @@ -40,13 +40,13 @@ * instructions are longer. */ #define NXT_INT_T_SIZE 4 -typedef int nxt_int_t; -typedef u_int nxt_uint_t; +typedef int nxt_int_t; +typedef u_int nxt_uint_t; #else #define NXT_INT_T_SIZE NXT_PTR_SIZE -typedef intptr_t nxt_int_t; -typedef uintptr_t nxt_uint_t; +typedef intptr_t nxt_int_t; +typedef uintptr_t nxt_uint_t; #endif diff --git a/nxt/test/lvlhsh_unit_test.c b/nxt/test/lvlhsh_unit_test.c index 27d6b692..bf5367c5 100644 --- a/nxt/test/lvlhsh_unit_test.c +++ b/nxt/test/lvlhsh_unit_test.c @@ -88,7 +88,7 @@ lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, const nxt_lvlhsh_proto_t *proto, lhq.key_hash = key; lhq.key.length = sizeof(uintptr_t); - lhq.key.start = (u_char *) &key; + lhq.key.start = (u_char *) &key; lhq.proto = proto; if (nxt_lvlhsh_find(lh, &lhq) == NXT_OK) { @@ -206,8 +206,8 @@ lvlhsh_unit_test(nxt_uint_t n) const size_t cluster_size = 4096; pool = nxt_mem_cache_pool_create(&mem_cache_pool_proto, NULL, NULL, - cluster_size, page_alignment, - page_size, min_chunk_size); + cluster_size, page_alignment, + page_size, min_chunk_size); if (pool == NULL) { return NXT_ERROR; } diff --git a/nxt/test/utf8_unit_test.c b/nxt/test/utf8_unit_test.c index 3f1ed39f..dc04e0d5 100644 --- a/nxt/test/utf8_unit_test.c +++ b/nxt/test/utf8_unit_test.c @@ -82,7 +82,7 @@ utf8_overlong(u_char *overlong, size_t len) static nxt_int_t -utf8_unit_test(void) +utf8_unit_test(nxt_uint_t start) { u_char *p, utf8[4]; size_t len; @@ -142,7 +142,7 @@ utf8_unit_test(void) /* Test all overlong UTF-8. */ - for (i = NXT_UTF8_START_TEST; i < 256; i++) { + for (i = start; i < 256; i++) { utf8[0] = i; if (utf8_overlong(utf8, 1) != NXT_OK) { @@ -190,7 +190,16 @@ utf8_unit_test(void) int -main(void) +main(int argc, char **argv) { - return utf8_unit_test(); + nxt_uint_t start; + + if (argc > 1 && argv[1][0] == 'a') { + start = NXT_UTF8_START_TEST; + + } else { + start = 256; + } + + return utf8_unit_test(start); }