[gjs/wip/jasper/690006-add-special-case-for-byte-arrays-going-to-c: 281/281] arg: Add special-case for byte arrays going to C



commit 6f676276ae05d34a93ac7d8dfbe50e5d5f8d6237
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Oct 30 13:10:28 2012 -0400

    arg: Add special-case for byte arrays going to C
    
    If we have a byte array that needs to be a uint8/int8, instead
    of iterating over it, simply grab the bytes themselves.
    
    (Patch originally by Jasper St. Pierre, rebased by Philip Chimento)
    
    Closes #67

 gi/arg.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 6b101341..0fd1b992 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1282,9 +1282,14 @@ gjs_array_to_explicit_array_internal(JSContext       *context,
             goto out;
     } else {
         JS::RootedObject array_obj(context, &value.toObject());
-        if (gjs_object_has_property(context, array_obj, GJS_STRING_LENGTH,
-                                    &found_length) &&
-            found_length) {
+        GITypeTag element_type = g_type_info_get_tag(param_info);
+        if (JS_IsUint8Array(array_obj) && (element_type == GI_TYPE_TAG_INT8 ||
+                                           element_type == GI_TYPE_TAG_UINT8)) {
+            GBytes* bytes = gjs_byte_array_get_bytes(array_obj);
+            *contents = g_bytes_unref_to_data(bytes, length_p);
+        } else if (gjs_object_has_property(context, array_obj,
+                                           GJS_STRING_LENGTH, &found_length) &&
+                   found_length) {
             guint32 length;
 
             if (!gjs_object_require_converted_property(context, array_obj, NULL,


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