[gjs] ABI CHANGE: Switch String -> uint8 array coercion to be UTF8



commit d15b8e3ebdc406f2bf92350c9e403f2512f25bf6
Author: Colin Walters <walters verbum org>
Date:   Thu Nov 29 14:55:54 2012 -0500

    ABI CHANGE: Switch String -> uint8 array coercion to be UTF8
    
    Previously for historical reasons, we treated JavaScript Strings as
    byte array containers when in the context of a uint8 array conversion.
    This is not what "most" users expect, particularly when taking UTF-8
    data from one GLib function and passing it to a different GLib
    function that accepts a uint8 array.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680730

 gi/arg.c                     |    4 ++--
 test/js/testGIMarshalling.js |    7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)
---
diff --git a/gi/arg.c b/gi/arg.c
index cad0f35..8fd162f 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -522,10 +522,10 @@ gjs_string_to_intarray(JSContext   *context,
     switch (element_type) {
     case GI_TYPE_TAG_INT8:
     case GI_TYPE_TAG_UINT8:
-        if (!gjs_string_get_binary_data(context, string_val,
-                                        &result, length))
+        if (!gjs_string_to_utf8(context, string_val, &result))
             return JS_FALSE;
         *arr_p = result;
+        *length = strlen(result);
         return JS_TRUE;
 
     case GI_TYPE_TAG_INT16:
diff --git a/test/js/testGIMarshalling.js b/test/js/testGIMarshalling.js
index d91b9d2..0155b66 100644
--- a/test/js/testGIMarshalling.js
+++ b/test/js/testGIMarshalling.js
@@ -167,9 +167,6 @@ function testByteArray() {
 
     // Another test, with a normal array, to test conversion
     GIMarshallingTests.bytearray_none_in([0, 49, 0xFF, 51]);
-
-    // Another test, with a string, to test conversion
-    GIMarshallingTests.bytearray_none_in("\x00\x31\xFF\x33");
 }
 
 function testGBytes() {
@@ -193,8 +190,8 @@ function testGBytes() {
     bytes = GLib.Bytes.new([0, 49, 0xFF, 51]);
     GIMarshallingTests.gbytes_none_in(bytes);
 
-    bytes = GLib.Bytes.new("\x00\x31\xFF\x33");
-    GIMarshallingTests.gbytes_none_in(bytes);
+    bytes = GLib.Bytes.new("const \u2665 utf8");
+    GIMarshallingTests.utf8_as_uint8array_in(bytes.toArray());
 
     bytes = GIMarshallingTests.gbytes_full_return();    
     array = bytes.toArray(); // Array should just be holding a ref, not a copy



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