[njs] Style and small miscellaneous fixes.

Igor Sysoev igor at sysoev.ru
Fri Sep 23 11:00:21 UTC 2016


details:   http://hg.nginx.org/njs/rev/9d09f9a522d6
branches:  
changeset: 178:9d09f9a522d6
user:      Igor Sysoev <igor at sysoev.ru>
date:      Fri Sep 23 11:59:56 2016 +0300
description:
Style and small miscellaneous fixes.

diffstat:

 njs/njs_builtin.c           |  18 +++++++++---------
 njs/njs_function.h          |   8 ++++++++
 njs/njs_regexp.c            |   1 -
 njs/njs_regexp_pattern.h    |   1 -
 njs/njs_vm.c                |   2 +-
 njs/njs_vm.h                |   9 ---------
 njs/test/njs_unit_test.c    |   6 +++---
 nxt/nxt_mem_cache_pool.c    |  16 ++++++++--------
 nxt/nxt_types.h             |   8 ++++----
 nxt/test/lvlhsh_unit_test.c |   6 +++---
 nxt/test/utf8_unit_test.c   |  17 +++++++++++++----
 11 files changed, 49 insertions(+), 43 deletions(-)

diffs (279 lines):

diff -r 04aee54864c3 -r 9d09f9a522d6 njs/njs_builtin.c
--- a/njs/njs_builtin.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/njs_builtin.c	Fri Sep 23 11:59:56 2016 +0300
@@ -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 -r 04aee54864c3 -r 9d09f9a522d6 njs/njs_function.h
--- a/njs/njs_function.h	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/njs_function.h	Fri Sep 23 11:59:56 2016 +0300
@@ -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 -r 04aee54864c3 -r 9d09f9a522d6 njs/njs_regexp.c
--- a/njs/njs_regexp.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/njs_regexp.c	Fri Sep 23 11:59:56 2016 +0300
@@ -292,7 +292,6 @@ njs_regexp_pattern_create(njs_vm_t *vm, 
     }
 
     pattern->flags = size;
-    pattern->next = NULL;
 
     p = (u_char *) pattern + sizeof(njs_regexp_pattern_t);
     pattern->source = p;
diff -r 04aee54864c3 -r 9d09f9a522d6 njs/njs_regexp_pattern.h
--- a/njs/njs_regexp_pattern.h	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/njs_regexp_pattern.h	Fri Sep 23 11:59:56 2016 +0300
@@ -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 -r 04aee54864c3 -r 9d09f9a522d6 njs/njs_vm.c
--- a/njs/njs_vm.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/njs_vm.c	Fri Sep 23 11:59:56 2016 +0300
@@ -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 -r 04aee54864c3 -r 9d09f9a522d6 njs/njs_vm.h
--- a/njs/njs_vm.h	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/njs_vm.h	Fri Sep 23 11:59:56 2016 +0300
@@ -124,15 +124,6 @@ typedef struct njs_native_frame_s     nj
 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 -r 04aee54864c3 -r 9d09f9a522d6 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/njs/test/njs_unit_test.c	Fri Sep 23 11:59:56 2016 +0300
@@ -5572,11 +5572,11 @@ njs_unit_test_benchmark(nxt_str_t *scrip
          + 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 -r 04aee54864c3 -r 9d09f9a522d6 nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/nxt/nxt_mem_cache_pool.c	Fri Sep 23 11:59:56 2016 +0300
@@ -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_cach
     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 -r 04aee54864c3 -r 9d09f9a522d6 nxt/nxt_types.h
--- a/nxt/nxt_types.h	Fri Sep 23 11:59:48 2016 +0300
+++ b/nxt/nxt_types.h	Fri Sep 23 11:59:56 2016 +0300
@@ -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 -r 04aee54864c3 -r 9d09f9a522d6 nxt/test/lvlhsh_unit_test.c
--- a/nxt/test/lvlhsh_unit_test.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/nxt/test/lvlhsh_unit_test.c	Fri Sep 23 11:59:56 2016 +0300
@@ -88,7 +88,7 @@ lvlhsh_unit_test_get(nxt_lvlhsh_t *lh, c
 
     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 -r 04aee54864c3 -r 9d09f9a522d6 nxt/test/utf8_unit_test.c
--- a/nxt/test/utf8_unit_test.c	Fri Sep 23 11:59:48 2016 +0300
+++ b/nxt/test/utf8_unit_test.c	Fri Sep 23 11:59:56 2016 +0300
@@ -82,7 +82,7 @@ utf8_overlong(u_char *overlong, size_t l
 
 
 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);
 }


More information about the nginx-devel mailing list