[seed] Very hacky support for <array length="x" zero-teminated="0" c:type="gchar**"><type name="..."/>, use



commit 47e939b716deb6ec6774c05fc3bd7d00812bc336
Author: Alan Knowles <alan akbkhome com>
Date:   Fri May 11 00:16:16 2012 +0800

    Very hacky support for <array length="x" zero-teminated="0" c:type="gchar**"><type name="..."/>, used by GLib.file_get_contents in latest girs

 libseed/seed-engine.c |   26 +++++++++++++++++++--
 libseed/seed-types.c  |   57 +++++++++++++++++++++++++++++++++++++++++++++++-
 libseed/seed-types.h  |    5 ++++
 3 files changed, 83 insertions(+), 5 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index ce14d62..ff10c60 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -465,6 +465,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
   GArgument *in_args;
   GArgument *out_args;
   GArgument *out_values;
+  gint *out_pos;
   gint first_out = -1;
   guint use_return_as_out = 0;
   guint n_args, n_in_args, n_out_args, i; 
@@ -486,6 +487,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 
   n_args = g_callable_info_get_n_args ((GICallableInfo *) info);
 
+  out_pos = g_new0 (gint, n_args + 1);
   in_args = g_new0 (GArgument, n_args + 1);
   out_args = g_new0 (GArgument, n_args + 1);
   out_values = g_new0 (GArgument, n_args + 1);
@@ -545,6 +547,9 @@ seed_gobject_method_invoked (JSContextRef ctx,
               GArgument *out_value = &out_values[n_out_args];
               out_values[n_out_args].v_pointer = NULL;
               out_args[n_out_args].v_pointer = out_value;
+	      
+	      out_pos[ i ] = n_out_args;
+	      
 #if GOBJECT_INTROSPECTION_VERSION > 0x000613			  
               if (is_caller_allocates) 
                 {
@@ -635,6 +640,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 #endif
 	      g_free (in_args);
 	      g_free (out_args);
+	      g_free (out_pos);
 	      g_free (out_values);
 
 	      return JSValueMakeNull (ctx);
@@ -743,6 +749,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 
       g_free (in_args);
       g_free (out_args);
+      g_free (out_pos);
       g_error_free (error);
       g_free (out_values);
 
@@ -777,10 +784,22 @@ seed_gobject_method_invoked (JSContextRef ctx,
 	}
       
       // we are now only dealing with OUT arguments.
-      jsout_val = seed_value_from_gi_argument (ctx, &out_values[out_args_pos],
-					       type_info, exception);
+      
+      // if the type_info is an array with a length position, we
+      // need to send that as well, so it can be used to build the seed value.
+      {
+	gint length_arg_pos = g_type_info_get_array_length(type_info);
+	gint array_len = 0;
+	if (length_arg_pos > -1) {
+	  
+	  array_len = ( &out_values[  out_pos[length_arg_pos] ] )->v_int;
+	}
+	
+	
+	jsout_val = seed_value_from_gi_argument_with_length (ctx, &out_values[out_args_pos],
+						 type_info, exception, array_len);
   
-
+      }
 #if GOBJECT_INTROSPECTION_VERSION > 0x000613
      /* caller allocates only applies to structures but GI has
       * no way to denote that yet, so we only use caller allocates
@@ -858,6 +877,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 
   g_free (in_args);
   g_free (out_args);
+  g_free (out_pos);
   g_free (out_values);
   return retval_ref;
 }
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index 2d25eb1..f3204b2 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -818,9 +818,25 @@ seed_value_to_gi_argument (JSContextRef ctx,
 
 JSValueRef
 seed_value_from_gi_argument (JSContextRef ctx,
-			     GArgument * arg, GITypeInfo * type_info,
+			     GArgument * arg,
+			     GITypeInfo * type_info,
 			     JSValueRef * exception)
 {
+  
+ return seed_value_from_gi_argument_with_length (ctx,
+			      arg,
+			      type_info,
+			      exception,
+			     0);
+}
+  
+JSValueRef
+seed_value_from_gi_argument_with_length (JSContextRef ctx,
+			     GArgument * arg,
+			     GITypeInfo * type_info,
+			     JSValueRef * exception,
+			     gint array_len)
+{
   GITypeTag gi_tag = g_type_info_get_tag (type_info);
   switch (gi_tag)
     {
@@ -882,6 +898,13 @@ seed_value_from_gi_argument (JSContextRef ctx,
 
         array_type = g_type_info_get_array_type (type_info);
 
+	//SEED_NOTE (INVOCATION,
+        //        "seed_value_from_gi_argument: array_type = %d  C=%d, ARRAY=%d, PTR_ARRAY=%d BYTE_ARRAY=%d",  
+        //        array_type,  GI_ARRAY_TYPE_C, GI_ARRAY_TYPE_ARRAY, GI_ARRAY_TYPE_PTR_ARRAY, GI_ARRAY_TYPE_BYTE_ARRAY); 
+
+
+
+
         if (array_type == GI_ARRAY_TYPE_PTR_ARRAY)
           {
             JSObjectRef ret_ptr_array;
@@ -912,9 +935,37 @@ seed_value_from_gi_argument (JSContextRef ctx,
               }
             return ret_ptr_array;
           }
+	
+	// technically gir has arrays of bytes, eg.
+	// <array length="2" zero-terminated="0" c:type="gchar**"><type name="guint8"/>
+	// example : g_file_get_contents..
+	// we can treat this as a string.. - it's a bit flakey, we should really use
+	// Uint8Array - need to check the webkit API for this..
+	if (!g_type_info_is_zero_terminated (type_info) && array_type == GI_ARRAY_TYPE_C)
+	  {
+	    GITypeInfo *array_type_info = g_type_info_get_param_type (type_info, 0);
+	    if (GI_TYPE_TAG_UINT8 == g_type_info_get_tag (array_type_info)) {
+	      // got a stringy array..
+	        if (arg->v_pointer == 0)
+		{
+		  return JSValueMakeNull (ctx);
+		}
+		// we should check g_type_info_get_array_fixed_size
+		// we are assuming that this is the array_len from the call..
+	        return seed_value_from_binary_string (ctx, arg->v_pointer, array_len, exception);
+ 
+	    }
+	     
+	  }
+        
+	
+	
+	  
 
-	if (!g_type_info_is_zero_terminated (type_info))
+	if (!g_type_info_is_zero_terminated (type_info)) {
+	   
 	  break;
+	}
 
 	param_type = g_type_info_get_param_type (type_info, 0);
 
@@ -2257,6 +2308,8 @@ seed_value_from_string (JSContextRef ctx,
  * Converts a string representation of the given binary string
  * into a #SeedValue.
  *
+ * FIXME - should use BinaryArray really
+ *
  * Return value: A #SeedValue which represents @bytes as a string.
  *
  */
diff --git a/libseed/seed-types.h b/libseed/seed-types.h
index 322a10a..227aad8 100644
--- a/libseed/seed-types.h
+++ b/libseed/seed-types.h
@@ -47,6 +47,11 @@ JSValueRef seed_value_from_gi_argument (JSContextRef ctx,
 				        GITypeInfo * type_info,
 				        JSValueRef * exception);
 
+JSValueRef seed_value_from_gi_argument_with_length (JSContextRef ctx,
+				        GArgument * arg,
+				        GITypeInfo * type_info,
+				        JSValueRef * exception,
+                                        gint array_len);
 gboolean seed_gi_release_arg (GITransfer transfer,
 			      GITypeInfo * type_info, GArgument * arg);
 



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