[njs] Improved njs_string_to_c_string() prototype.

Dmitry Volyntsev xeioex at nginx.com
Mon Aug 12 18:05:16 UTC 2019


details:   https://hg.nginx.org/njs/rev/03008af6253b
branches:  
changeset: 1123:03008af6253b
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Aug 12 21:04:49 2019 +0300
description:
Improved njs_string_to_c_string() prototype.

To avoid excessive casts.

diffstat:

 src/njs_fs.c     |  12 ++++++------
 src/njs_string.c |   6 +++---
 src/njs_string.h |   2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diffs (96 lines):

diff -r e861b6f6bcae -r 03008af6253b src/njs_fs.c
--- a/src/njs_fs.c	Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_fs.c	Mon Aug 12 21:04:49 2019 +0300
@@ -156,7 +156,7 @@ njs_fs_read_file(njs_vm_t *vm, njs_value
         return NJS_ERROR;
     }
 
-    path = (char *) njs_string_to_c_string(vm, &args[1]);
+    path = njs_string_to_c_string(vm, &args[1]);
     if (njs_slow_path(path == NULL)) {
         return NJS_ERROR;
     }
@@ -380,7 +380,7 @@ njs_fs_read_file_sync(njs_vm_t *vm, njs_
         return NJS_ERROR;
     }
 
-    path = (char *) njs_string_to_c_string(vm, &args[1]);
+    path = njs_string_to_c_string(vm, &args[1]);
     if (njs_slow_path(path == NULL)) {
         return NJS_ERROR;
     }
@@ -660,7 +660,7 @@ static njs_int_t njs_fs_write_file_inter
         md = 0666;
     }
 
-    path = (char *) njs_string_to_c_string(vm, &args[1]);
+    path = njs_string_to_c_string(vm, &args[1]);
     if (njs_slow_path(path == NULL)) {
         return NJS_ERROR;
     }
@@ -837,7 +837,7 @@ njs_fs_write_file_sync_internal(njs_vm_t
         md = 0666;
     }
 
-    path = (char *) njs_string_to_c_string(vm, &args[1]);
+    path = njs_string_to_c_string(vm, &args[1]);
     if (njs_slow_path(path == NULL)) {
         return NJS_ERROR;
     }
@@ -923,12 +923,12 @@ njs_fs_rename_sync(njs_vm_t *vm, njs_val
         return NJS_ERROR;
     }
 
-    old_path = (const char *) njs_string_to_c_string(vm, njs_argument(args, 1));
+    old_path = njs_string_to_c_string(vm, njs_argument(args, 1));
     if (njs_slow_path(old_path == NULL)) {
         return NJS_ERROR;
     }
 
-    new_path = (const char *) njs_string_to_c_string(vm, njs_argument(args, 2));
+    new_path = njs_string_to_c_string(vm, njs_argument(args, 2));
     if (njs_slow_path(new_path == NULL)) {
         return NJS_ERROR;
     }
diff -r e861b6f6bcae -r 03008af6253b src/njs_string.c
--- a/src/njs_string.c	Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_string.c	Mon Aug 12 21:04:49 2019 +0300
@@ -3984,7 +3984,7 @@ njs_string_to_index(const njs_value_t *v
  * is returned as is, otherwise the new copy is allocated with
  * the terminating zero byte.
  */
-const u_char *
+const char *
 njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value)
 {
     u_char  *p, *data, *start;
@@ -3996,7 +3996,7 @@ njs_string_to_c_string(njs_vm_t *vm, njs
 
         if (size < NJS_STRING_SHORT) {
             start[size] = '\0';
-            return start;
+            return (const char *) start;
         }
 
     } else {
@@ -4013,7 +4013,7 @@ njs_string_to_c_string(njs_vm_t *vm, njs
     p = njs_cpymem(data, start, size);
     *p++ = '\0';
 
-    return data;
+    return (const char *) data;
 }
 
 
diff -r e861b6f6bcae -r 03008af6253b src/njs_string.h
--- a/src/njs_string.h	Mon Aug 12 21:04:49 2019 +0300
+++ b/src/njs_string.h	Mon Aug 12 21:04:49 2019 +0300
@@ -177,7 +177,7 @@ const u_char *njs_string_offset(const u_
 uint32_t njs_string_index(njs_string_prop_t *string, uint32_t offset);
 void njs_string_offset_map_init(const u_char *start, size_t size);
 double njs_string_to_index(const njs_value_t *value);
-const u_char *njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value);
+const char *njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value);
 njs_int_t njs_string_encode_uri(njs_vm_t *vm, njs_value_t *args,
     njs_uint_t nargs, njs_index_t unused);
 njs_int_t njs_string_encode_uri_component(njs_vm_t *vm, njs_value_t *args,


More information about the nginx-devel mailing list