seed r299 - in trunk: libseed tests



Author: racarr
Date: Sat Nov 22 02:31:06 2008
New Revision: 299
URL: http://svn.gnome.org/viewvc/seed?rev=299&view=rev

Log:
seed_struct_find_field and seed_union_find_field. Needed to cleanly implement. seed_struct/union get/set property.


Modified:
   trunk/libseed/seed-structs.c
   trunk/tests/struct-offsets.js

Modified: trunk/libseed/seed-structs.c
==============================================================================
--- trunk/libseed/seed-structs.c	(original)
+++ trunk/libseed/seed-structs.c	Sat Nov 22 02:31:06 2008
@@ -55,6 +55,50 @@
     
 }
 
+static GIFieldInfo * seed_union_find_field(GIUnionInfo * info,
+					   gchar * field_name)
+{
+    int n, i;
+    GIFieldInfo * field;
+    
+    n = g_union_info_get_n_fields(info);
+    for (i = 0; i < n; i++)
+    {
+	const gchar * name;
+	
+	field = g_union_info_get_field(info, i);
+	name = g_base_info_get_name((GIBaseInfo *) field);
+	if (!strcmp(name, field_name))
+	    return field;
+	else
+	    g_base_info_unref((GIBaseInfo *)field);
+    }
+    
+    return 0;
+}
+
+static GIFieldInfo * seed_struct_find_field(GIStructInfo * info,
+					   gchar * field_name)
+{
+    int n, i;
+    GIFieldInfo * field;
+    
+    n = g_struct_info_get_n_fields(info);
+    for (i = 0; i < n; i++)
+    {
+	const gchar * name;
+	
+	field = g_struct_info_get_field(info, i);
+	name = g_base_info_get_name((GIBaseInfo *) field);
+	if (!strcmp(name, field_name))
+	    return field;
+	else
+	    g_base_info_unref((GIBaseInfo *)field);
+    }
+    
+    return 0;
+}
+
 static JSValueRef
 seed_union_get_property(JSContextRef context,
 			 JSObjectRef object,
@@ -63,7 +107,7 @@
 {
     gpointer pointer;
     gchar * cproperty_name;
-    int i, n;
+    int i;
     int length;
     seed_struct_privates * priv = JSObjectGetPrivate(object);
     GIFieldInfo * field = 0;
@@ -75,21 +119,8 @@
     cproperty_name = g_malloc(length * sizeof(gchar));
     JSStringGetUTF8CString(property_name, cproperty_name, length);
     
-    n = g_union_info_get_n_fields((GIUnionInfo *)priv->info);
-    for (i = 0; i < n; i++)
-    {
-	const gchar * name;
-	field = g_union_info_get_field((GIUnionInfo *)priv->info, i);
-	
-	name = g_base_info_get_name((GIBaseInfo *) field);
-	if (!strcmp(name, cproperty_name))
-	    break;
-	else
-	{
-	    g_base_info_unref((GIBaseInfo *) field);
-	    field = 0;
-	}
-    }
+    field = seed_union_find_field((GIUnionInfo *)priv->info,
+				  cproperty_name);
     if (!field)
     {
 	g_free(cproperty_name);
@@ -165,22 +196,10 @@
     length = JSStringGetMaximumUTF8CStringSize(property_name);
     cproperty_name = g_malloc(length * sizeof(gchar));
     JSStringGetUTF8CString(property_name, cproperty_name, length);
+
+    field = seed_struct_find_field((GIStructInfo *)priv->info,
+				   cproperty_name);
     
-    n = g_struct_info_get_n_fields((GIStructInfo *)priv->info);
-    for (i = 0; i < n; i++)
-    {
-	const gchar * name;
-	field = g_struct_info_get_field((GIStructInfo *)priv->info, i);
-	
-	name = g_base_info_get_name((GIBaseInfo *) field);
-	if (!strcmp(name, cproperty_name))
-	    break;
-	else
-	{
-	    g_base_info_unref((GIBaseInfo *) field);
-	    field = 0;
-	}
-    }
     if (!field)
     {
 	g_free(cproperty_name);

Modified: trunk/tests/struct-offsets.js
==============================================================================
--- trunk/tests/struct-offsets.js	(original)
+++ trunk/tests/struct-offsets.js	Sat Nov 22 02:31:06 2008
@@ -1,7 +1,7 @@
 #!/usr/local/bin/seed
 // Returns: 0
 // STDIN:
-// STDOUT:255\.000000
+// STDOUT:255\.000000\n0\.000000
 // STDERR:
 // Returns: 0
 // STDIN:
@@ -13,3 +13,4 @@
 Clutter.color_parse("red", c);
 
 Seed.print(c.red);
+Seed.print(c.blue);



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