[seed] [libseed] Use glib types everywhere, don't redefine variables in inner scope, etc.



commit cedbd784516b7309afbeada52256f18239810768
Author: Matt ARSENAULT <arsenm2 rpi edu>
Date:   Sat Jul 11 00:19:04 2009 -0400

    [libseed] Use glib types everywhere, don't redefine variables in inner scope, etc.

 libseed/seed-engine.c     |   39 ++++++++++++++--------------
 libseed/seed-exceptions.c |    8 +++--
 libseed/seed-importer.c   |   61 +++++++++++++++++++++++---------------------
 libseed/seed-signals.c    |    9 ++++--
 libseed/seed-structs.c    |   47 +++++++++++++++++-----------------
 5 files changed, 86 insertions(+), 78 deletions(-)
---
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 360d33f..04b8ca4 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -415,8 +415,7 @@ seed_gobject_method_invoked (JSContextRef ctx,
 
   info = JSObjectGetPrivate (function);
   // We just want to check if there IS an object, not actually throw an
-  // exception if we don't
-  // get it.
+  // exception if we don't get it.
   if (!this_object || !
       ((object = seed_value_to_object (ctx, this_object, 0)) ||
        (object = seed_pointer_get_pointer (ctx, this_object))))
@@ -633,14 +632,13 @@ seed_gobject_add_methods_for_interfaces (JSContextRef ctx,
 					 JSObjectRef object)
 {
   GIInterfaceInfo *interface;
-  gint n_interfaces, i;
+  GIFunctionInfo *function;
+  gint n_interfaces, i, n_functions, k;
 
   n_interfaces = g_object_info_get_n_interfaces (oinfo);
 
   for (i = 0; i < n_interfaces; i++)
     {
-      GIFunctionInfo *function;
-      gint n_functions, k;
       interface = g_object_info_get_interface (oinfo, i);
 
       n_functions = g_interface_info_get_n_methods (interface);
@@ -729,8 +727,8 @@ seed_gobject_get_class_for_gtype (JSContextRef ctx, GType type)
       GType *interfaces;
       GIFunctionInfo *function;
       GIBaseInfo *interface;
-      gint n_functions, k, i;
-      guint n;
+      gint n_functions, k;
+      guint i, n;
 
       interfaces = g_type_interfaces (type, &n);
       for (i = 0; i < n; i++)
@@ -804,7 +802,8 @@ seed_gobject_get_property (JSContextRef context,
   char *cproperty_name;
   gint length;
   JSValueRef ret;
-  gint i, len;
+  guint i;
+  gsize len;
 
   b = seed_value_to_object (context, (JSValueRef) object, exception);
   if (!b)
@@ -819,8 +818,8 @@ seed_gobject_get_property (JSContextRef context,
 
   if (!spec)
     {
-      len = strlen (cproperty_name);
-      for (i = 0; i < len - 1; i++)
+      len = strlen (cproperty_name) - 1;
+      for (i = 0; i < len; i++)
 	{
 	  if (cproperty_name[i] == '_')
 	    cproperty_name[i] = '-';
@@ -831,13 +830,13 @@ seed_gobject_get_property (JSContextRef context,
 	goto found;
       else
 	{
-	  GIFieldInfo *field = 0;
+	  GIFieldInfo *field = NULL;
 	  GIBaseInfo *info = (GIBaseInfo *)
 	    g_irepository_find_by_gtype (0, G_OBJECT_TYPE (b));
 	  gint n;
 	  const gchar *name;
 
-	  for (i = 0; i < len - 1; i++)
+	  for (i = 0; i < len; i++)
 	    {
 	      if (cproperty_name[i] == '-')
 		cproperty_name[i] = '_';
@@ -845,7 +844,7 @@ seed_gobject_get_property (JSContextRef context,
 
 	  if (!info)
 	    {
-	      return 0;
+	      return NULL;
 	    }
 
 	  n = g_object_info_get_n_fields ((GIObjectInfo *) info);
@@ -871,7 +870,7 @@ seed_gobject_get_property (JSContextRef context,
 	    }
 	  g_base_info_unref ((GIBaseInfo *) info);
 	}
-      return 0;
+      return NULL;
     }
 found:
 
@@ -894,7 +893,8 @@ seed_gobject_set_property (JSContextRef context,
   GValue gval = { 0 };
   GType type;
   gchar *cproperty_name;
-  gint length;
+  gsize length;
+  gsize i, len;
 
   if (seed_next_gobject_wrapper || JSValueIsNull (context, value))
     return 0;
@@ -911,7 +911,6 @@ seed_gobject_set_property (JSContextRef context,
 
   if (!spec)
     {
-      gint i, len;
       len = strlen (cproperty_name);
       for (i = 0; i < len; i++)
 	{
@@ -922,7 +921,7 @@ seed_gobject_set_property (JSContextRef context,
 					   cproperty_name);
       if (!spec)
 	{
-	  return 0;
+	  return FALSE;
 	}
     }
 
@@ -934,7 +933,7 @@ seed_gobject_set_property (JSContextRef context,
   seed_gvalue_from_seed_value (context, value, type, &gval, exception);
   if (*exception)
     {
-      return 0;
+      return FALSE;
     }
 
   if (glib_message)
@@ -963,11 +962,11 @@ seed_gobject_constructor_convert_to_type (JSContextRef ctx,
 					  JSValueRef *exception)
 {
   GType gtype;
+  gchar *as_string;
 
   if (type == kJSTypeString)
     {
       JSValueRef ret;
-      gchar *as_string;
       gtype = (GType) JSObjectGetPrivate (object);
 
       as_string = g_strdup_printf("[gobject_constructor %s]", g_type_name (gtype));
@@ -1340,7 +1339,6 @@ seed_init (gint * argc, gchar *** argv)
   seed_gtype_init (eng);
 
 
-
   defaults_script =
 	  JSStringCreateWithUTF8CString ("Seed.include(\""SEED_PREFIX_PATH"extensions/Seed.js\");");
 
@@ -1444,3 +1442,4 @@ seed_init_with_context_group (gint * argc,
 
   return eng;
 }
+
diff --git a/libseed/seed-exceptions.c b/libseed/seed-exceptions.c
index ed3cb93..7a0c4ad 100644
--- a/libseed/seed-exceptions.c
+++ b/libseed/seed-exceptions.c
@@ -43,6 +43,7 @@ seed_make_exception (JSContextRef ctx,
   JSStringRef js_message = 0;
   JSValueRef js_name_ref = 0, js_message_ref = 0;
   JSObjectRef exception_obj;
+  gchar *mes;
   va_list args;
 
   if (!exception)
@@ -57,7 +58,7 @@ seed_make_exception (JSContextRef ctx,
     }
   if (message)
     {
-      gchar *mes = g_strdup_vprintf (message, args);
+      mes = g_strdup_vprintf (message, args);
       js_message = JSStringCreateWithUTF8CString (mes);
       js_message_ref = JSValueMakeString (ctx, js_message);
       g_free (mes);
@@ -90,10 +91,11 @@ seed_make_exception_from_gerror (JSContextRef ctx,
 {
   const gchar *domain = g_quark_to_string (error->domain);
   GString *string = g_string_new (domain);
-  int i;
+  guint i;
+  gsize len = string->len;
 
   *(string->str) = g_unichar_toupper (*(string->str));
-  for (i = 0; i < string->len; i++)
+  for (i = 0; i < len; i++)
     {
       if (*(string->str + i) == '-')
 	{
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index c9dddf4..fbb570d 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -103,7 +103,11 @@ seed_gi_importer_handle_enum (JSContextRef ctx,
 			      JSValueRef *exception)
 {
   JSObjectRef enum_class;
-  gint num_vals, j;
+  guint num_vals, i, j;
+  gsize name_len;
+  glong value;
+  gchar *name;
+  GIValueInfo *val;
 
   enum_class = JSObjectMake (ctx, 0, 0);
   num_vals = g_enum_info_get_n_values (info);
@@ -111,15 +115,12 @@ seed_gi_importer_handle_enum (JSContextRef ctx,
 			    g_base_info_get_name ((GIBaseInfo *)info),
 			    enum_class);
 
-  for (j = 0; j < num_vals; j++)
+  for (i = 0; i < num_vals; i++)
     {
-      GIValueInfo *val =
-	g_enum_info_get_value ((GIEnumInfo *) info, j);
-      gint value = g_value_info_get_value (val);
-      gchar *name =
-	g_strdup (g_base_info_get_name ((GIBaseInfo *) val));
-      gint name_len = strlen (name);
-      gint j;
+      val = g_enum_info_get_value ((GIEnumInfo *) info, i);
+      value = g_value_info_get_value (val);
+      name = g_strdup (g_base_info_get_name ((GIBaseInfo *) val));
+      name_len = strlen (name);
       JSValueRef value_ref;
 
       value_ref = JSValueMakeNumber (ctx, value);
@@ -277,7 +278,7 @@ seed_gi_importer_handle_union (JSContextRef ctx,
 {
   JSObjectRef union_ref;
   JSObjectRef proto;
-  gint i, n_methods;
+  guint i, n_methods;
   GIFunctionInfo *finfo;
 
   union_ref =
@@ -385,6 +386,7 @@ seed_gi_importer_do_namespace (JSContextRef ctx,
     {
       seed_make_exception_from_gerror (ctx, exception, e);
       g_error_free (e);
+	  g_free (version);
       return NULL;
     }
   g_free (version);
@@ -500,6 +502,7 @@ seed_importer_get_search_path (JSContextRef ctx,
 			       JSValueRef *exception)
 {
   GSList *path = NULL;
+  gchar *entry;
   JSValueRef search_path_ref, length_ref;
   guint length, i;
 
@@ -516,7 +519,6 @@ seed_importer_get_search_path (JSContextRef ctx,
   for (i = 0; i < length; i++)
     {
       JSValueRef entry_ref;
-      gchar *entry;
 
       entry_ref = JSObjectGetPropertyAtIndex (ctx, (JSObjectRef) search_path_ref, i, exception);
       entry = seed_value_to_string (ctx, entry_ref, exception);
@@ -661,16 +663,21 @@ seed_importer_search (JSContextRef ctx,
 		      gchar *prop,
 		      JSValueRef *exception)
 {
+
+  GDir *dir;
+  GError *e;
+  gchar *mentry;
   GSList *path, *walk;
+  JSObjectRef ret;
   gchar *prop_as_lib = g_strconcat ("libseed_", prop, ".", G_MODULE_SUFFIX, NULL);
+  gsize i, mentrylen;
 
   path = seed_importer_get_search_path (ctx, exception);
 
   walk = path;
   while (walk)
     {
-      GError *e = NULL;
-      GDir *dir;
+      e = NULL;
       const gchar *entry;
 
       dir = g_dir_open ((gchar *)walk->data, 0, &e);
@@ -683,18 +690,16 @@ seed_importer_search (JSContextRef ctx,
 	}
       while ((entry = g_dir_read_name(dir)))
 	{
-	  guint i;
-	  gchar *mentry = g_strdup (entry);
+	  mentry = g_strdup (entry);
 
-	  for (i = 0; i < strlen (mentry); i++)
+	  mentrylen = strlen(mentry);
+	  for (i = 0; i < mentrylen; i++)
 	    {
 	      if (mentry[i] == '.')
 		mentry[i] = '\0';
 	    }
 	  if (!g_strcmp0 (mentry, prop))
 	    {
-	      JSObjectRef ret;
-
 	      ret = seed_importer_handle_file (ctx, walk->data, entry, exception);
 
 	      g_dir_close (dir);
@@ -706,8 +711,6 @@ seed_importer_search (JSContextRef ctx,
 	    }
 	  else if (!g_strcmp0(entry, prop_as_lib))
 	    {
-	      JSObjectRef ret;
-
 	      ret = seed_importer_handle_native_module (ctx, walk->data, entry, exception);
 	      g_dir_close (dir);
 	      g_free (mentry);
@@ -763,10 +766,11 @@ seed_importer_dir_get_property (JSContextRef ctx,
 {
   GError *e = NULL;
   GDir *dir;
-  guint len;
+  guint len, i;
+  gsize mentrylen;
   const gchar *entry;
-  gchar *dir_path, *prop;
-
+  gchar *dir_path, *prop, *mentry;
+  JSObjectRef ret;
 
   dir_path = JSObjectGetPrivate (object);
 
@@ -785,10 +789,10 @@ seed_importer_dir_get_property (JSContextRef ctx,
     }
   while ((entry = g_dir_read_name (dir)))
     {
-      gchar *mentry = g_strdup (entry);
-      guint i;
+      mentry = g_strdup (entry);
+	  mentrylen = strlen(mentry);
 
-      for (i = 0; i < strlen (mentry); i++)
+      for (i = 0; i < mentrylen; i++)
 	{
 	  if (mentry[i] == '.')
 	    mentry[i] = '\0';
@@ -796,7 +800,6 @@ seed_importer_dir_get_property (JSContextRef ctx,
 
       if (!g_strcmp0 (mentry, prop))
 	{
-	  JSObjectRef ret;
 
 	  ret = seed_importer_handle_file (ctx, dir_path, entry, exception);
 	  g_dir_close (dir);
@@ -818,7 +821,6 @@ seed_importer_dir_finalize (JSObjectRef dir)
   g_free (dir_path);
 }
 
-
 void
 seed_importer_add_global(JSObjectRef global,
 			 gchar *name)
@@ -861,7 +863,7 @@ seed_importer_dir_enumerate_properties (JSContextRef ctx,
 JSObjectRef
 seed_importer_construct_dir (JSContextRef ctx,
 			     JSObjectRef constructor,
-			     size_t argumentCount,
+			     gsize argumentCount,
 			     const JSValueRef arguments[],
 			     JSValueRef *exception)
 {
@@ -993,3 +995,4 @@ void seed_initialize_importer(JSContextRef ctx,
 
   seed_object_set_property (ctx, global, "imports", importer);
 }
+
diff --git a/libseed/seed-signals.c b/libseed/seed-signals.c
index 808f788..1fbe5a5 100644
--- a/libseed/seed-signals.c
+++ b/libseed/seed-signals.c
@@ -148,7 +148,8 @@ seed_signal_marshal_func (GClosure * closure,
   SeedClosure *seed_closure = (SeedClosure *) closure;
   JSValueRef *args, exception = 0;
   JSValueRef ret = 0;
-  gint i;
+  guint i;
+  gchar *mes;
 
   JSContextRef ctx = JSGlobalContextCreateInGroup (context_group,
 						   0);
@@ -192,7 +193,7 @@ seed_signal_marshal_func (GClosure * closure,
 
   if (exception)
     {
-      gchar *mes = seed_exception_to_string (ctx, exception);
+      mes = seed_exception_to_string (ctx, exception);
       g_warning ("Exception in signal handler return value. %s \n", mes);
       g_free (mes);
     }
@@ -326,11 +327,13 @@ seed_gobject_signal_connect_on_property (JSContextRef ctx,
     }
 
   if (argumentCount == 1)
+  {
     id = seed_gobject_signal_connect (ctx, privates->signal_name,
 				      privates->object,
 				      (JSObjectRef) arguments[0], this_obj, NULL);
 
-  if (argumentCount == 2)
+  }
+  else if (argumentCount == 2)
     {
       id = seed_gobject_signal_connect (ctx, privates->signal_name,
 					privates->object,
diff --git a/libseed/seed-structs.c b/libseed/seed-structs.c
index a406266..41a074c 100644
--- a/libseed/seed-structs.c
+++ b/libseed/seed-structs.c
@@ -82,7 +82,7 @@ seed_boxed_finalize (JSObjectRef object)
 GIFieldInfo *
 seed_union_find_field (GIUnionInfo * info, gchar * field_name)
 {
-  int n, i;
+  gint n, i;
   GIFieldInfo *field;
 
   n = g_union_info_get_n_fields (info);
@@ -98,19 +98,19 @@ seed_union_find_field (GIUnionInfo * info, gchar * field_name)
 	g_base_info_unref ((GIBaseInfo *) field);
     }
 
-  return 0;
+  return NULL;
 }
 
 GIFieldInfo *
-seed_struct_find_field (GIStructInfo * info, gchar * field_name)
+seed_struct_find_field (GIStructInfo *info, gchar *field_name)
 {
-  int n, i;
+  gint n, i;
+  const gchar *name;
   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);
@@ -120,7 +120,7 @@ seed_struct_find_field (GIStructInfo * info, gchar * field_name)
 	g_base_info_unref ((GIBaseInfo *) field);
     }
 
-  return 0;
+  return NULL;
 }
 
 JSValueRef
@@ -129,8 +129,10 @@ seed_field_get_value (JSContextRef ctx,
 		      GIFieldInfo * field, JSValueRef * exception)
 {
   GITypeInfo *field_type;
+  GIBaseInfo *interface;
   GArgument field_value;
-  JSValueRef ret = JSValueMakeNull (ctx);;
+  JSValueRef ret = JSValueMakeNull (ctx);
+  gint offset;
 
   field_type = g_field_info_get_type (field);
   if (!g_field_info_get_field (field, object, &field_value))
@@ -140,10 +142,8 @@ seed_field_get_value (JSContextRef ctx,
       tag = g_type_info_get_tag (field_type);
       if (tag == GI_TYPE_TAG_INTERFACE)
 	{
-	  GIBaseInfo *interface;
-
 	  interface = g_type_info_get_interface (field_type);
-	  gint offset = g_field_info_get_offset (field);
+	  offset = g_field_info_get_offset (field);
 
 	  g_base_info_unref ((GIBaseInfo *) field_type);
 	  switch (g_base_info_get_type (interface))
@@ -181,7 +181,7 @@ seed_union_get_property (JSContextRef context,
 			 JSStringRef property_name, JSValueRef * exception)
 {
   gchar *cproperty_name;
-  int length;
+  gsize length;
   seed_struct_privates *priv = JSObjectGetPrivate (object);
   GIFieldInfo *field = 0;
   JSValueRef ret;
@@ -213,7 +213,7 @@ seed_union_set_property (JSContextRef context,
 			 JSStringRef property_name,
 			 JSValueRef value, JSValueRef * exception)
 {
-  gint length;
+  gsize length;
   GArgument field_value;
   GIFieldInfo *field;
   gchar *cproperty_name;
@@ -234,7 +234,7 @@ seed_union_set_property (JSContextRef context,
 
   if (!field)
     {
-      return 0;
+      return FALSE;
     }
 
   field_type = g_field_info_get_type (field);
@@ -254,7 +254,7 @@ seed_struct_set_property (JSContextRef context,
 			  JSStringRef property_name,
 			  JSValueRef value, JSValueRef * exception)
 {
-  gint length;
+  gsize length;
   GArgument field_value;
   GIFieldInfo *field;
   gchar *cproperty_name;
@@ -276,7 +276,7 @@ seed_struct_set_property (JSContextRef context,
 
   if (!field)
     {
-      return 0;
+      return FALSE;
     }
 
   field_type = g_field_info_get_type (field);
@@ -296,9 +296,9 @@ seed_struct_get_property (JSContextRef context,
 			  JSStringRef property_name, JSValueRef * exception)
 {
   gchar *cproperty_name;
-  int length;
+  gsize length;
   seed_struct_privates *priv = JSObjectGetPrivate (object);
-  GIFieldInfo *field = 0;
+  GIFieldInfo *field = NULL;
   JSValueRef ret;
 
   length = JSStringGetMaximumUTF8CStringSize (property_name);
@@ -314,7 +314,7 @@ seed_struct_get_property (JSContextRef context,
 
   if (!field)
     {
-      return 0;
+      return NULL;
     }
 
   ret = seed_field_get_value (context, priv->pointer, field, exception);
@@ -458,7 +458,7 @@ seed_pointer_get_pointer (JSContextRef ctx, JSValueRef pointer)
       seed_struct_privates *priv = JSObjectGetPrivate ((JSObjectRef) pointer);
       return priv->pointer;
     }
-  return 0;
+  return NULL;
 }
 
 void
@@ -499,6 +499,7 @@ seed_union_prototype (JSContextRef ctx, GIBaseInfo * info)
   const gchar *namespace, *name;
   gchar *key;
   gint n_methods, i;
+  GIFunctionInfo *finfo;
 
   name = g_base_info_get_name (info);
   namespace = g_base_info_get_namespace (info);
@@ -514,8 +515,6 @@ seed_union_prototype (JSContextRef ctx, GIBaseInfo * info)
       n_methods = g_union_info_get_n_methods ((GIUnionInfo *) info);
       for (i = 0; i < n_methods; i++)
 	{
-	  GIFunctionInfo *finfo;
-
 	  finfo = g_union_info_get_method ((GIUnionInfo *) info, i);
 
 	  seed_gobject_define_property_from_function_info (ctx,
@@ -672,13 +671,15 @@ seed_construct_struct_type_with_parameters (JSContextRef ctx,
   gpointer object;
   GIInfoType type = g_base_info_get_type (info);
   JSObjectRef ret;
-  gint nparams, i = 0, length;
+  gint nparams, i = 0;
+  gsize length;
   GIFieldInfo *field = 0;
   JSPropertyNameArrayRef jsprops;
   JSStringRef jsprop_name;
   JSValueRef jsprop_value;
   GArgument field_value;
   gchar *prop_name;
+  GITypeInfo *field_type;
 
   if (type == GI_INFO_TYPE_STRUCT)
     {
@@ -711,7 +712,6 @@ seed_construct_struct_type_with_parameters (JSContextRef ctx,
 
   while (i < nparams)
     {
-      GITypeInfo *field_type;
       jsprop_name = JSPropertyNameArrayGetNameAtIndex (jsprops, i);
 
       length = JSStringGetMaximumUTF8CStringSize (jsprop_name);
@@ -750,3 +750,4 @@ seed_construct_struct_type_with_parameters (JSContextRef ctx,
 
   return ret;
 }
+



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