[seed] finally get the code right to handle array length offset information



commit b136ca762daa8dd3500c735cda39d3d31c4d4c19
Author: Alan Knowles <alan roojs com>
Date:   Sun May 13 11:34:51 2012 +0800

    finally get the code right to handle array length offset information

 libseed/seed-engine.c |   31 +++++++++++++++++++++++++++----
 libseed/seed-types.c  |   26 ++++++++++++--------------
 libseed/seed-types.h  |    2 +-
 3 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 2e782e8..301b050 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -498,7 +498,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 
   for (i = 0; (i < (n_args)); i++)
     {
-
+      out_pos[i] = -1;
       arg_info = g_callable_info_get_arg ((GICallableInfo *) info, i);
       dir = g_arg_info_get_direction (arg_info);
       type_info = g_arg_info_get_type (arg_info);
@@ -649,6 +649,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 	    {
 	      GArgument *out_value = &out_values[n_out_args];
 	      out_args[n_out_args++].v_pointer = out_value;
+              out_pos[ i ] = n_out_args;
 	    }
 
 	}
@@ -657,6 +658,7 @@ 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) 
 	    {
@@ -791,10 +793,31 @@ seed_gobject_method_invoked (JSContextRef ctx,
       // 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;
+	guint64 array_len = 0;
 	if (length_arg_pos > -1) {
-	  
-	  array_len = ( &out_values[  out_pos[length_arg_pos] ] )->v_int;
+            JSValueRef jsarray_len;
+            GIArgInfo *array_arg_info;
+            GITypeInfo *array_type_info;
+            
+            g_assert (out_pos[length_arg_pos] > -1);
+            
+            array_arg_info = g_callable_info_get_arg ((GICallableInfo *) info, length_arg_pos);
+            array_type_info = g_arg_info_get_type (array_arg_info);
+            jsarray_len = seed_value_from_gi_argument (ctx,  &out_values[  out_pos[length_arg_pos] ],
+						 array_type_info, exception);
+            
+            array_len =  seed_value_to_uint64(ctx, jsarray_len, exception);
+            
+            // this may work, but the above should be more accurate..
+            //array_len =  (&out_values[  out_pos[length_arg_pos] ])->v_uint32;
+                                     
+            SEED_NOTE (INVOCATION, "Getting length from OUTPOS=%d,  ORIGPOS=%d :  result = %d",
+                 out_pos[length_arg_pos],  length_arg_pos, array_len);
+            // free stuff.
+            JSValueUnprotect(ctx, jsarray_len);
+            g_base_info_unref ((GIBaseInfo *) array_type_info);
+	    g_base_info_unref ((GIBaseInfo *) array_arg_info);
+            
 	}
 	
 	
diff --git a/libseed/seed-types.c b/libseed/seed-types.c
index bb1e725..69bf70a 100644
--- a/libseed/seed-types.c
+++ b/libseed/seed-types.c
@@ -838,7 +838,7 @@ seed_value_from_gi_argument_full (JSContextRef ctx,
 			     GArgument * arg,
 			     GITypeInfo * type_info,
 			     JSValueRef * exception,
-			     gint array_len,
+			     guint64 array_len,
                              GITypeTag gi_tag
                              )
 {
@@ -912,10 +912,7 @@ seed_value_from_gi_argument_full (JSContextRef ctx,
 
 	array_type_info = g_type_info_get_param_type (type_info, 0);
 	
-	//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)
           {
@@ -951,12 +948,12 @@ seed_value_from_gi_argument_full (JSContextRef ctx,
 	// 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
 	      && GI_TYPE_TAG_UINT8 == g_type_info_get_tag (array_type_info)
-	      && array_len > -1
+	      && array_len > 0
 	    )
 	  {
 	    // got a stringy array..
@@ -2344,22 +2341,23 @@ seed_value_from_binary_string (JSContextRef ctx,
 {
   JSStringRef jsstr;
   JSValueRef valstr;
-  JSChar *jchar;
+  JSChar* jchar;
   gint i;
-  
+    
+    SEED_NOTE (INVOCATION, "Creating binary string of length %d ",
+                n_bytes);
+    
   if (bytes == NULL)
     {
       return JSValueMakeNull (ctx);
     }
   
   jchar =   g_alloca (sizeof (JSChar) * n_bytes);
-  
-  for(i =0; i < n_bytes; i++)
+  for(i =0;i < n_bytes; i++)
     {
-      jchar[i] = bytes[i]; 
+      jchar[i] = bytes[i];
     }
-    // do we leak memory here?
-
+  // this may leak...
   
   jsstr = JSStringCreateWithCharacters((const JSChar*)jchar, n_bytes);
   valstr = JSValueMakeString (ctx, jsstr);
diff --git a/libseed/seed-types.h b/libseed/seed-types.h
index addf40c..45a5bf4 100644
--- a/libseed/seed-types.h
+++ b/libseed/seed-types.h
@@ -51,7 +51,7 @@ JSValueRef seed_value_from_gi_argument_full (JSContextRef ctx,
 				        GArgument * arg,
 				        GITypeInfo * type_info,
 				        JSValueRef * exception,
-                                        gint array_len,
+                                        guint64 array_len,
                                         GITypeTag gi_tag);
 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]