[seed] More null checks - arguments that are structs/unions need the pointer checking to see if they are nu



commit ad29012e1a4fee2692077ef44fde42acca6194f8
Author: alan <alan alanfast akbkhome com>
Date:   Fri Feb 26 17:20:42 2010 +0800

    More null checks - arguments that are structs/unions need the pointer checking to see if they are null
    
    This may need moving upwards into make_argument, but that would mean the error messages would be less useful.

 libseed/seed-engine.c |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index ac89f98..b941414 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -518,21 +518,36 @@ seed_gobject_method_invoked (JSContextRef ctx,
       else if (dir == GI_DIRECTION_IN || dir == GI_DIRECTION_INOUT)
 	{
 
-	  if (  
-		( !arguments[i] || JSValueIsNull (ctx, arguments[i]) ) &&
-		!g_arg_info_may_be_null (arg_info) 
-             )
+	  if (  !g_arg_info_may_be_null (arg_info) ) 
             {
-              seed_make_exception (ctx, exception,
+  	      gboolean is_null = ( !arguments[i] || JSValueIsNull (ctx, arguments[i]) );
+
+              if (!is_null && (g_type_info_get_tag (type_info) == GI_TYPE_TAG_INTERFACE)) 
+                {
+                  // see if the pointer is null for struct/unions.
+                  GIBaseInfo *interface = g_type_info_get_interface (type_info);
+                  GIInfoType interface_type = g_base_info_get_type (interface);
+
+                  if ((interface_type == GI_INFO_TYPE_STRUCT || interface_type == GI_INFO_TYPE_UNION) &&
+                             seed_pointer_get_pointer (ctx, arguments[i]) == 0) 
+                      is_null = TRUE;
+                  
+                  g_base_info_unref (interface);
+                }
+
+              if (is_null) 
+                {
+                  seed_make_exception (ctx, exception,
 				   "ArgumentError",
 				   " argument %d must not be null for"
 				   " function: %s. \n",
 				   i + 1,
 				   g_base_info_get_name ((GIBaseInfo *)
 							 info));
-	      goto arg_error;
+                  goto arg_error;
+                }
+            }
 
-          }
           if (!seed_gi_make_argument (ctx, arguments[i], type_info,
 				      &in_args[n_in_args++], exception))
 	    {



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