[seed] Make seed_make_exception take a format string, and convert all the calls in libseed to use format st



commit 49f98b91c8ac7f92b5d872268e12249ef72fc67b
Author: Robert Carr <racarr svn gnome org>
Date:   Wed Apr 29 17:28:40 2009 -0400

    Make seed_make_exception take a format string, and convert all the calls in libseed to use format strings rather than formatting them before calling
---
 configure.ac              |    2 +-
 libseed/seed-builtins.c   |   59 +++++++++++++++++---------------------------
 libseed/seed-engine.c     |   40 +++++++++++++----------------
 libseed/seed-exceptions.c |   16 ++++++++++--
 libseed/seed-exceptions.h |    5 ++-
 libseed/seed-gtype.c      |   37 +++++++++++----------------
 libseed/seed-importer.c   |    8 ++----
 libseed/seed-structs.c    |    8 ++----
 libseed/seed.h            |    2 +-
 9 files changed, 80 insertions(+), 97 deletions(-)

diff --git a/configure.ac b/configure.ac
index be27e59..514fb0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
 AC_PREREQ(2.59)
-AC_INIT(seed, 0.5.5)
+AC_INIT(seed, 0.6)
 
 AM_INIT_AUTOMAKE([1.7 -Wno-portability])
 AM_MAINTAINER_MODE
diff --git a/libseed/seed-builtins.c b/libseed/seed-builtins.c
index 4756892..bba8ee4 100644
--- a/libseed/seed-builtins.c
+++ b/libseed/seed-builtins.c
@@ -38,11 +38,9 @@ seed_include (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes =
-	g_strdup_printf ("Seed.include expected 1 argument, "
-			 "got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Seed.include expected 1 argument, "
+			   "got %Zd", argumentCount);
       return JSValueMakeNull (ctx);
     }
 
@@ -76,12 +74,11 @@ seed_include (JSContextRef ctx,
 
   if (!buffer)
     {
-      gchar *mes = g_strdup_printf ("File not found: %s", import_file);
-      seed_make_exception (ctx, exception, "FileNotFound", mes);
+      seed_make_exception (ctx, exception, "FileNotFound", 
+			   "File not found: %s", import_file);
 
       g_free (import_file);
       g_free (buffer);
-      g_free (mes);
       return JSValueMakeNull (ctx);
     }
 
@@ -128,11 +125,9 @@ seed_scoped_include (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes =
-	g_strdup_printf ("Seed.include expected 1 argument, "
-			 "got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Seed.include expected 1 argument, "
+			   "got %Zd", argumentCount);
       return JSValueMakeNull (ctx);
     }
 
@@ -166,12 +161,11 @@ seed_scoped_include (JSContextRef ctx,
 
   if (!buffer)
     {
-      gchar *mes = g_strdup_printf ("File not found: %s", import_file);
-      seed_make_exception (ctx, exception, "FileNotFound", mes);
-
+      seed_make_exception (ctx, exception, "FileNotFound", 
+			   "File not found: %s", import_file);
+      
       g_free (import_file);
       g_free (buffer);
-      g_free (mes);
       return JSValueMakeNull (ctx);
     }
 
@@ -217,11 +211,9 @@ seed_print (JSContextRef ctx,
 {
   if (argumentCount != 1)
     {
-      gchar *mes =
-	g_strdup_printf ("Seed.print expected 1 argument," " got %Zd",
-			 argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Seed.print expected 1 argument, got %d", 
+			   argumentCount);
       return JSValueMakeNull (ctx);
     }
 
@@ -268,11 +260,9 @@ seed_introspect (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes =
-	g_strdup_printf ("Seed.introspect expected 1 argument, "
-			 "got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Seed.introspect expected 1 argument, "
+			   "got %Zd", argumentCount);
       return JSValueMakeNull (ctx);
     }
 
@@ -335,10 +325,9 @@ seed_check_syntax (JSContextRef ctx,
     }
   else
     {
-      gchar *mes = g_strdup_printf ("Seed.check_syntax expected "
-				    "1 argument, got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError",
+			   "Seed.check_syntax expected "
+			   "1 argument, got %Zd", argumentCount);
     }
   return JSValueMakeNull (ctx);
 }
@@ -412,11 +401,9 @@ seed_quit (JSContextRef ctx,
     }
   else if (argumentCount > 1)
     {
-      gchar *mes =
-	g_strdup_printf ("Seed.quit expected " "1 argument, got %Zd",
-			 argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Seed.quit expected " "1 argument, got %Zd",
+			   argumentCount);
     }
 
   exit (EXIT_SUCCESS);
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 979fb10..4d9af06 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -120,10 +120,9 @@ seed_gobject_constructor_invoked (JSContextRef ctx,
 
   if (argumentCount > 1)
     {
-      gchar *mes = g_strdup_printf ("Constructor expects"
-				    " 1 argument, got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Constructor expects"
+			   " 1 argument, got %Zd", argumentCount);
 
       return (JSObjectRef) JSValueMakeNull (ctx);
     }
@@ -159,12 +158,10 @@ seed_gobject_constructor_invoked (JSContextRef ctx,
       param_spec = g_object_class_find_property (oclass, prop_name);
       if (param_spec == NULL)
 	{
-	  gchar *mes =
-	    g_strdup_printf ("Invalid property for construction: %s",
-			     prop_name);
-	  seed_make_exception (ctx, exception, "PropertyError", mes);
+	  seed_make_exception (ctx, exception, "PropertyError", 
+			       "Invalid property for construction: %s",
+			       prop_name);
 
-	  g_free (mes);
 	  g_free (params);
 
 	  JSPropertyNameArrayRelease (jsprops);
@@ -233,10 +230,9 @@ seed_gobject_equals (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes = g_strdup_printf ("GObject equals comparison expected"
-				    " 1 argument, got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "GObject equals comparison expected"
+			   " 1 argument, got %Zd", argumentCount);
 
       return JSValueMakeNull (ctx);
     }
@@ -329,14 +325,13 @@ seed_gobject_method_invoked (JSContextRef ctx,
 				      type_info,
 				      &in_args[n_in_args++], exception))
 	    {
-	      gchar *mes =
-		g_strdup_printf
-		("Unable to make argument %d for" " function: %s. \n",
-		 i + 1,
-		 g_base_info_get_name ((GIBaseInfo *) info));
-	      seed_make_exception (ctx, exception, "ArgumentError", mes);
-
-	      g_free (mes);
+	      seed_make_exception (ctx, exception, 
+				   "ArgumentError", 
+				   "Unable to make argument %d for" 
+				   " function: %s. \n",
+				   i + 1,
+				   g_base_info_get_name ((GIBaseInfo *) info));
+
 	      g_base_info_unref ((GIBaseInfo *) type_info);
 	      g_base_info_unref ((GIBaseInfo *) arg_info);
 	      g_free (in_args);
@@ -850,7 +845,8 @@ seed_gobject_set_property (JSContextRef context,
   g_object_set_property (obj, cproperty_name, &gval);
   if (glib_message != 0)
     {
-      seed_make_exception (context, exception, "PropertyError", glib_message);
+      seed_make_exception (context, exception, "PropertyError", 
+			   glib_message, NULL);
 
       return FALSE;
     }
diff --git a/libseed/seed-exceptions.c b/libseed/seed-exceptions.c
index a050842..c4084d3 100644
--- a/libseed/seed-exceptions.c
+++ b/libseed/seed-exceptions.c
@@ -17,6 +17,7 @@
 
 #include "seed-private.h"
 #include <string.h>
+#include <stdarg.h>
 
 /**
  * seed_make_exception:
@@ -34,15 +35,20 @@
 void
 seed_make_exception (JSContextRef ctx,
 		     JSValueRef * exception,
-		     const gchar * name, const gchar * message)
+		     const gchar * name, 
+		     const gchar * message,
+		     ...)
 {
   JSStringRef js_name = 0;
   JSStringRef js_message = 0;
   JSValueRef js_name_ref = 0, js_message_ref = 0;
   JSObjectRef exception_obj;
-
+  va_list args;
+  
   if (!exception)
     return;
+  
+  va_start (args, message);
 
   if (name)
     {
@@ -51,8 +57,10 @@ seed_make_exception (JSContextRef ctx,
     }
   if (message)
     {
-      js_message = JSStringCreateWithUTF8CString (message);
+      gchar *mes = g_strdup_vprintf (message, args);
+      js_message = JSStringCreateWithUTF8CString (mes);
       js_message_ref = JSValueMakeString (ctx, js_message);
+      g_free (mes);
     }
 
   exception_obj = JSObjectMake (ctx, 0, NULL);
@@ -63,6 +71,8 @@ seed_make_exception (JSContextRef ctx,
 
   JSStringRelease (js_name);
   JSStringRelease (js_message);
+  
+  va_end (args);
 }
 
 /**
diff --git a/libseed/seed-exceptions.h b/libseed/seed-exceptions.h
index f6618b1..8ce9977 100644
--- a/libseed/seed-exceptions.h
+++ b/libseed/seed-exceptions.h
@@ -31,10 +31,11 @@
 #include "seed-private.h"
 
 void seed_make_exception (JSContextRef ctx, JSValueRef * exception,
-			  const gchar * name, const gchar * message);
+			  const gchar * name, const gchar * message, ...) G_GNUC_PRINTF(4,5);
 
 void seed_make_exception_from_gerror (JSContextRef ctx,
-				      JSValueRef * exception, GError * e);
+				      JSValueRef * exception, 
+				      GError * e);
 
 gchar *seed_exception_get_name (JSContextRef ctx, JSValueRef e);
 gchar *seed_exception_get_message (JSContextRef ctx, JSValueRef e);
diff --git a/libseed/seed-gtype.c b/libseed/seed-gtype.c
index d6b477c..fe9a589 100644
--- a/libseed/seed-gtype.c
+++ b/libseed/seed-gtype.c
@@ -52,11 +52,9 @@ seed_property_method_invoked (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes =
-	g_strdup_printf ("Property installation expected 1 argument"
-			 " got %Zd \n", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Property installation expected 1 argument"
+			   " got %Zd \n", argumentCount);
 
       return JSValueMakeNull (ctx);
     }
@@ -105,10 +103,9 @@ seed_gsignal_method_invoked (JSContextRef ctx,
   /* Sanity check */
   if (argumentCount != 1)
     {
-      gchar *mes = g_strdup_printf ("Signal constructor expected 1 argument"
-				    " got %Zd \n", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "Signal constructor expected 1 argument"
+			   " got %Zd \n", argumentCount);
       return (JSObjectRef) JSValueMakeNull (ctx);
     }
   if (JSValueIsNull (ctx, arguments[0])
@@ -510,11 +507,9 @@ seed_gtype_constructor_invoked (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes =
-	g_strdup_printf ("GType constructor expected 1 "
-			 "argument, got %Zd \n", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "GType constructor expected 1 "
+			   "argument, got %Zd \n", argumentCount);
       return (JSObjectRef) JSValueMakeNull (ctx);
     }
   if (!JSValueIsObject (ctx, arguments[0]))
@@ -608,10 +603,9 @@ seed_param_getter_invoked (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes = g_strdup_printf ("ParamSpec.get expected "
-				    "1 argument, got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "ParamSpec.get expected "
+			   "1 argument, got %Zd", argumentCount);
 
       return JSValueMakeNull (ctx);
     }
@@ -642,10 +636,9 @@ seed_param_setter_invoked (JSContextRef ctx,
 
   if (argumentCount != 1)
     {
-      gchar *mes = g_strdup_printf ("ParamSpec.set expected "
-				    "1 argument, got %Zd", argumentCount);
-      seed_make_exception (ctx, exception, "ArgumentError", mes);
-      g_free (mes);
+      seed_make_exception (ctx, exception, "ArgumentError", 
+			   "ParamSpec.set expected "
+			   "1 argument, got %Zd", argumentCount);
 
       return JSValueMakeNull (ctx);
     }
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index c5221cf..e9c84d8 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -528,14 +528,12 @@ seed_importer_handle_native_module (JSContextRef ctx,
   
   if (!module)
     {
-      gchar *mes = g_strdup_printf ("Error loading native module at %s: %s",
-				    file_path,
-				    g_module_error());
       // Could be a better exception
       seed_make_exception (ctx, exception, "ModuleError",
-			   mes);
+			   "Error loading native module at %s: %s",
+			   file_path,
+			   g_module_error());
       g_free (file_path);
-      g_free (mes);
       
       return NULL;
     }
diff --git a/libseed/seed-structs.c b/libseed/seed-structs.c
index ec12019..5c0c8f5 100644
--- a/libseed/seed-structs.c
+++ b/libseed/seed-structs.c
@@ -726,12 +726,10 @@ seed_construct_struct_type_with_parameters (JSContextRef ctx,
 	field = seed_union_find_field ((GIUnionInfo *) info, prop_name);
       if (!field)
 	{
-	  gchar *mes =
-	    g_strdup_printf ("Invalid property for construction: %s",
-			     prop_name);
-	  seed_make_exception (ctx, exception, "PropertyError", mes);
+	  seed_make_exception (ctx, exception, "PropertyError", 
+			       "Invalid property for construction: %s",
+			       prop_name);
 
-	  g_free (mes);
 	  JSPropertyNameArrayRelease (jsprops);
 	  return (JSObjectRef) JSValueMakeNull (ctx);
 	}
diff --git a/libseed/seed.h b/libseed/seed.h
index 402a31b..74c3dd0 100644
--- a/libseed/seed.h
+++ b/libseed/seed.h
@@ -86,7 +86,7 @@ SeedScript *seed_make_script (SeedContext ctx,
 SeedScript *seed_script_new_from_file (SeedContext ctx, gchar * file);
 SeedException seed_script_exception (SeedScript * s);
 void seed_make_exception (SeedContext ctx, SeedException exception,
-			  const gchar * name, const gchar * message);
+			  const gchar * name, const gchar * message, ...);
 gchar *seed_exception_get_name (SeedContext ctx, SeedException exception);
 gchar *seed_exception_get_message (SeedContext ctx, SeedException exception);
 guint seed_exception_get_line (SeedContext ctx, SeedException exception);



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