[njs] Added nxt_memset().

Dmitry Volyntsev xeioex at nginx.com
Tue Oct 2 17:35:12 UTC 2018


details:   http://hg.nginx.org/njs/rev/891285348d58
branches:  
changeset: 616:891285348d58
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Oct 02 20:33:14 2018 +0300
description:
Added nxt_memset().

diffstat:

 njs/njs_json.c              |  2 +-
 njs/njs_string.c            |  4 ++--
 nxt/nxt_dtoa.c              |  4 ++--
 nxt/nxt_mem_cache_pool.c    |  2 +-
 nxt/nxt_string.h            |  3 +++
 nxt/test/rbtree_unit_test.c |  3 ++-
 6 files changed, 11 insertions(+), 7 deletions(-)

diffs (94 lines):

diff -r 21858b20db0c -r 891285348d58 njs/njs_json.c
--- a/njs/njs_json.c	Tue Oct 02 20:28:10 2018 +0300
+++ b/njs/njs_json.c	Tue Oct 02 20:33:14 2018 +0300
@@ -2316,7 +2316,7 @@ njs_vm_value_dump(njs_vm_t *vm, nxt_str_
         goto memory_error;
     }
 
-    memset(stringify->space.start, ' ', indent);
+    nxt_memset(stringify->space.start, ' ', indent);
 
     if (nxt_array_init(&stringify->stack, NULL, 4, sizeof(njs_json_state_t),
                        &njs_array_mem_proto, vm->mem_cache_pool)
diff -r 21858b20db0c -r 891285348d58 njs/njs_string.c
--- a/njs/njs_string.c	Tue Oct 02 20:28:10 2018 +0300
+++ b/njs/njs_string.c	Tue Oct 02 20:33:14 2018 +0300
@@ -2477,10 +2477,10 @@ njs_string_prototype_pad(njs_vm_t *vm, n
     memcpy(start, string.start, string.size);
 
     if (nargs == 2) {
-        memset(p, ' ', padding);
+        nxt_memset(p, ' ', padding);
 
     } else if (pad_string.size == 1) {
-        memset(p, pad_string.start[0], padding);
+        nxt_memset(p, pad_string.start[0], padding);
 
     } else {
         while (n != 0) {
diff -r 21858b20db0c -r 891285348d58 nxt/nxt_dtoa.c
--- a/nxt/nxt_dtoa.c	Tue Oct 02 20:28:10 2018 +0300
+++ b/nxt/nxt_dtoa.c	Tue Oct 02 20:33:14 2018 +0300
@@ -280,7 +280,7 @@ nxt_prettify(char *start, size_t len, in
         /* 1234e7 -> 12340000000 */
 
         if (kk - length > 0) {
-            memset(&start[length], '0', kk - length);
+            nxt_memset(&start[length], '0', kk - length);
         }
 
         return kk;
@@ -305,7 +305,7 @@ nxt_prettify(char *start, size_t len, in
         start[1] = '.';
 
         if (offset - 2 > 0) {
-            memset(&start[2], '0', offset - 2);
+            nxt_memset(&start[2], '0', offset - 2);
         }
 
         return (length + offset);
diff -r 21858b20db0c -r 891285348d58 nxt/nxt_mem_cache_pool.c
--- a/nxt/nxt_mem_cache_pool.c	Tue Oct 02 20:28:10 2018 +0300
+++ b/nxt/nxt_mem_cache_pool.c	Tue Oct 02 20:33:14 2018 +0300
@@ -131,7 +131,7 @@ struct nxt_mem_cache_pool_s {
 
 
 #define nxt_mem_cache_free_junk(p, size)                                      \
-    memset((p), 0x5A, size)
+    nxt_memset((p), 0x5A, size)
 
 
 #define nxt_is_power_of_two(value)                                            \
diff -r 21858b20db0c -r 891285348d58 nxt/nxt_string.h
--- a/nxt/nxt_string.h	Tue Oct 02 20:28:10 2018 +0300
+++ b/nxt/nxt_string.h	Tue Oct 02 20:33:14 2018 +0300
@@ -44,6 +44,9 @@ nxt_upper_case(u_char c)
 #define nxt_cpymem(dst, src, n)   (((u_char *) memcpy(dst, src, n)) + (n))
 
 
+#define nxt_memset(buf, c, length)   (void) (memset(buf, c, length))
+
+
 #define nxt_memzero(buf, length)   (void) (memset(buf, 0, length))
 
 
diff -r 21858b20db0c -r 891285348d58 nxt/test/rbtree_unit_test.c
--- a/nxt/test/rbtree_unit_test.c	Tue Oct 02 20:28:10 2018 +0300
+++ b/nxt/test/rbtree_unit_test.c	Tue Oct 02 20:33:14 2018 +0300
@@ -8,6 +8,7 @@
 #include <nxt_types.h>
 #include <nxt_clang.h>
 #include <nxt_stub.h>
+#include <nxt_string.h>
 #include <nxt_rbtree.h>
 #include <nxt_murmur_hash.h>
 #include <stdio.h>
@@ -102,7 +103,7 @@ rbtree_unit_test(nxt_uint_t n)
 
     for (i = 0; i < n; i++) {
         nxt_rbtree_delete(&tree, &items[i].node);
-        memset(&items[i], 0xA5, sizeof(nxt_rbtree_test_t));
+        nxt_memset(&items[i], 0xA5, sizeof(nxt_rbtree_test_t));
     }
 
     if (!nxt_rbtree_is_empty(&tree)) {


More information about the nginx-devel mailing list