[gjs/wip/ptomato/mozjs31: 12/17] js: Remove deprecated jschar in favour of char16_t



commit 40e592f13e6240ac757a1366d580c5eac9c85cfa
Author: Philip Chimento <philip endlessm com>
Date:   Thu Oct 27 14:10:35 2016 -0700

    js: Remove deprecated jschar in favour of char16_t
    
    While jschar is not yet removed in mozjs31, it is now a simple typedef
    for char16_t. That means it switched signedness compared to mozjs24. This
    is slightly annoying for interoperability with GLib since gunichar2 is
    unsigned, but we reinterpret_cast where necessary.

 gi/arg.cpp                |    4 ++--
 gjs/byteArray.cpp         |    6 +++---
 gjs/jsapi-util-string.cpp |   34 ++++++++++++++++------------------
 gjs/jsapi-util.cpp        |    4 ++--
 gjs/jsapi-util.h          |    8 ++++----
 5 files changed, 27 insertions(+), 29 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 130916b..5eefcec 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -641,7 +641,7 @@ gjs_string_to_intarray(JSContext   *context,
 {
     GITypeTag element_type;
     char *result;
-    guint16 *result16;
+    char16_t *result16;
 
     element_type = g_type_info_get_tag(param_info);
 
@@ -654,7 +654,7 @@ gjs_string_to_intarray(JSContext   *context,
     }
 
     if (element_type == GI_TYPE_TAG_INT16 || element_type == GI_TYPE_TAG_UINT16) {
-        if (!gjs_string_get_uint16_data(context, string_val,
+        if (!gjs_string_get_char16_data(context, string_val,
                                         &result16, length))
             return false;
         *arr_p = result16;
diff --git a/gjs/byteArray.cpp b/gjs/byteArray.cpp
index b0eea35..a27825b 100644
--- a/gjs/byteArray.cpp
+++ b/gjs/byteArray.cpp
@@ -453,7 +453,7 @@ to_string_func(JSContext *context,
         GError *error;
         JSString *s;
         char *u16_str;
-        jschar *u16_out;
+        char16_t *u16_out;
 
         error = NULL;
         u16_str = g_convert(data,
@@ -475,7 +475,7 @@ to_string_func(JSContext *context,
          */
         g_assert((bytes_written % 2) == 0);
 
-        u16_out = g_new(jschar, bytes_written / 2);
+        u16_out = g_new(char16_t, bytes_written / 2);
         memcpy(u16_out, u16_str, bytes_written);
         s = JS_NewUCStringCopyN(context, u16_out, bytes_written / 2);
         if (s != NULL) {
@@ -610,7 +610,7 @@ from_string_func(JSContext *context,
         char *encoded;
         gsize bytes_written;
         GError *error;
-        const jschar *u16_chars;
+        const char16_t *u16_chars;
         gsize u16_len;
 
         u16_chars = JS_GetStringCharsAndLength(context, argv[0].toString(), &u16_len);
diff --git a/gjs/jsapi-util-string.cpp b/gjs/jsapi-util-string.cpp
index 421f582..1707256 100644
--- a/gjs/jsapi-util-string.cpp
+++ b/gjs/jsapi-util-string.cpp
@@ -69,7 +69,7 @@ gjs_string_from_utf8(JSContext             *context,
                      ssize_t                n_bytes,
                      JS::MutableHandleValue value_p)
 {
-    jschar *u16_string;
+    char16_t *u16_string;
     glong u16_string_length;
     GError *error;
 
@@ -78,11 +78,9 @@ gjs_string_from_utf8(JSContext             *context,
     */
 
     error = NULL;
-    u16_string = g_utf8_to_utf16(utf8_string,
-                                 n_bytes,
-                                 NULL,
-                                 &u16_string_length,
-                                 &error);
+    u16_string =
+        reinterpret_cast<char16_t *>(g_utf8_to_utf16(utf8_string, n_bytes, NULL,
+                                                     &u16_string_length, &error));
     if (!u16_string) {
         gjs_throw(context,
                   "Failed to convert UTF-8 string to "
@@ -164,25 +162,25 @@ gjs_string_from_filename(JSContext             *context,
 }
 
 /**
- * gjs_string_get_uint16_data:
+ * gjs_string_get_char16_data:
  * @context: js context
  * @value: a JS::Value
  * @data_p: address to return allocated data buffer
- * @len_p: address to return length of data (number of 16-bit integers)
+ * @len_p: address to return length of data (number of 16-bit characters)
  *
- * Get the binary data (as a sequence of 16-bit integers) in the JSString
+ * Get the binary data (as a sequence of 16-bit characters) in the JSString
  * contained in @value.
  * Throws a JS exception if value is not a string.
  *
  * Returns: false if exception thrown
  **/
 bool
-gjs_string_get_uint16_data(JSContext       *context,
+gjs_string_get_char16_data(JSContext       *context,
                            JS::Value        value,
-                           guint16        **data_p,
-                           gsize           *len_p)
+                           char16_t       **data_p,
+                           size_t          *len_p)
 {
-    const jschar *js_data;
+    const char16_t *js_data;
     bool retval = false;
 
     JS_BeginRequest(context);
@@ -197,7 +195,7 @@ gjs_string_get_uint16_data(JSContext       *context,
     if (js_data == NULL)
         goto out;
 
-    *data_p = (guint16*) g_memdup(js_data, sizeof(*js_data)*(*len_p));
+    *data_p = (char16_t *) g_memdup(js_data, sizeof(*js_data) * (*len_p));
 
     retval = true;
 out:
@@ -233,7 +231,7 @@ gjs_string_to_ucs4(JSContext      *cx,
     size_t utf16_len;
     GError *error = NULL;
 
-    const jschar *utf16 = JS_GetStringCharsAndLength(cx, str, &utf16_len);
+    const char16_t *utf16 = JS_GetStringCharsAndLength(cx, str, &utf16_len);
     if (utf16 == NULL) {
         gjs_throw(cx, "Failed to get UTF-16 string data");
         return false;
@@ -271,12 +269,12 @@ gjs_string_from_ucs4(JSContext             *cx,
                      ssize_t                n_chars,
                      JS::MutableHandleValue value_p)
 {
-    uint16_t *u16_string;
     long u16_string_length;
     GError *error = NULL;
 
-    u16_string = g_ucs4_to_utf16(ucs4_string, n_chars, NULL,
-                                 &u16_string_length, &error);
+    char16_t *u16_string =
+        reinterpret_cast<char16_t *>(g_ucs4_to_utf16(ucs4_string, n_chars, NULL,
+                                                     &u16_string_length, &error));
     if (!u16_string) {
         gjs_throw(cx, "Failed to convert UCS-4 string to UTF-16: %s",
                   error->message);
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 9516265..1095f86 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -366,12 +366,12 @@ gjs_string_readable (JSContext   *context,
 
     if (!gjs_string_to_utf8(context, JS::StringValue(string), &chars)) {
         size_t i, len;
-        const jschar *uchars;
+        const char16_t *uchars;
 
         uchars = JS_GetStringCharsAndLength(context, string, &len);
 
         for (i = 0; i < len; i++) {
-            jschar c = uchars[i];
+            char16_t c = uchars[i];
             if (c >> 8 == 0 && g_ascii_isprint(c & 0xFF))
                 g_string_append_c(buf, c & 0xFF);
             else
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index f307349..0ed6b3f 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -405,10 +405,10 @@ bool gjs_string_from_filename(JSContext             *context,
                               ssize_t                n_bytes,
                               JS::MutableHandleValue value_p);
 
-bool        gjs_string_get_uint16_data       (JSContext       *context,
-                                              JS::Value        value,
-                                              guint16        **data_p,
-                                              gsize           *len_p);
+bool gjs_string_get_char16_data(JSContext *context,
+                                JS::Value  value,
+                                char16_t **data_p,
+                                size_t    *len_p);
 
 bool gjs_string_to_ucs4(JSContext      *cx,
                         JS::HandleValue value,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]