[gjs] arg.c: Explicitly convert array(guint8) to byteArray



commit c128858e8ffe0c823edc9ba7aa3b4350de206488
Author: Colin Walters <walters verbum org>
Date:   Mon Jun 20 17:45:01 2011 -0400

    arg.c: Explicitly convert array(guint8) to byteArray
    
    This got lost in the array refactoring.  One of the advantages of
    byteArray is that it's easy to convert to a string (though the
    override of toString() for this is dubious).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=653055

 gi/arg.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/gi/arg.c b/gi/arg.c
index 667a177..c224388 100644
--- a/gi/arg.c
+++ b/gi/arg.c
@@ -1708,6 +1708,20 @@ gjs_array_from_carray_internal (JSContext  *context,
     element_type = g_type_info_get_tag(param_info);
     element_type = replace_gtype(element_type);
 
+    /* Special case array(guint8) */
+    if (element_type == GI_TYPE_TAG_UINT8) {
+        GByteArray gbytearray;
+
+        gbytearray.data = array;
+        gbytearray.len = length;
+        
+        obj = gjs_byte_array_from_byte_array (context, &gbytearray);
+        if (obj == NULL)
+            return JS_FALSE;
+        *value_p = OBJECT_TO_JSVAL(obj);
+        return JS_TRUE;
+    } 
+
     obj = JS_NewArrayObject(context, 0, NULL);
     if (obj == NULL)
       return JS_FALSE;
@@ -1932,6 +1946,20 @@ gjs_array_from_zero_terminated_c_array (JSContext  *context,
     element_type = g_type_info_get_tag(param_info);
     element_type = replace_gtype(element_type);
 
+    /* Special case array(guint8) */
+    if (element_type == GI_TYPE_TAG_UINT8) {
+        GByteArray gbytearray;
+
+        gbytearray.data = c_array;
+        gbytearray.len = strlen(c_array);
+
+        obj = gjs_byte_array_from_byte_array (context, &gbytearray);
+        if (obj == NULL)
+            return JS_FALSE;
+        *value_p = OBJECT_TO_JSVAL(obj);
+        return JS_TRUE;
+    } 
+
     obj = JS_NewArrayObject(context, 0, NULL);
     if (obj == NULL)
       return JS_FALSE;



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