[rep-gtk: 5/12] Handle GError output argument as rep errors:



commit 6bc30272d657696fc34ba881a9506d4c0220bbf7
Author: Juergen Hoetzel <juergen archlinux org>
Date:   Thu Aug 27 23:26:58 2009 +0200

    Handle GError output argument as rep errors:
    
    Error consisting of (glib-error . (gerror->message))

 README.gtk-defs |    3 ++-
 build-gtk.jl    |    9 +++++++++
 rep-gtk.c       |   14 ++++++++++++++
 rep-gtk.h       |    2 ++
 4 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/README.gtk-defs b/README.gtk-defs
index dd24080..d52f86b 100644
--- a/README.gtk-defs
+++ b/README.gtk-defs
@@ -60,7 +60,8 @@ and each OPTION may be one of:
   (protection *result*)			; gc protect for life of RETURN-VALUE
   (undeferred t)			; no scm interrupt protection?
   (rest-arg t)				; last arg is &rest
-
+  (gerror-arg t)				; last arg is GError arg
+  
 and each ARG-OPTION may be one of:
 
   (= "default expression")
diff --git a/build-gtk.jl b/build-gtk.jl
index 6a69b79..768ab7e 100644
--- a/build-gtk.jl
+++ b/build-gtk.jl
@@ -918,6 +918,8 @@
 		  (@ "  %s c_%s;\n" decl (gtk-arg-name arg))
 		(gtk-warning
 		 "Don't know how to declare type: %s" type)))) args)
+    (when (gtk-get-option 'gerror-arg options)
+      (@ "  GError* error = NULL;\n"))
     (unless (eq ret 'none)
       (let*
 	  ((typage (gtk-type-info ret))
@@ -1040,6 +1042,8 @@
 	      (@ "c_%s" (gtk-arg-name (car tem)))))
 	  (@ (if (cdr tem) ", " ""))
 	  (setq tem (cdr tem))))
+      (if (gtk-get-option 'gerror-arg options)
+	  (@ ", &error"))
       (@ "\);\n\n"))
 
     ;; output ret conversion
@@ -1076,6 +1080,11 @@
 	      (@ "  rep_POPGC;\n"
 		 (gtk-arg-name arg) (gtk-arg-name arg)))) args)
 
+    ;; gerror checking
+    (when (gtk-get-option 'gerror-arg options)
+      (@ "  if (error != NULL)\n" )
+      (@ "    sgtk_throw_gerror (\"%s\", error);\n" fname))
+    
     ;; output return statement
     (if (eq ret 'none)
 	(@ "  return Qnil;\n")
diff --git a/rep-gtk.c b/rep-gtk.c
index 8f53d7a..73ed346 100644
--- a/rep-gtk.c
+++ b/rep-gtk.c
@@ -2318,6 +2318,19 @@ sgtk_sigchld_callback (void)
 
 
 
+/* GError handling */
+DEFSYM(g_error, "glib-error");
+DEFSTRING(err_g_error, "Glib error");
+
+void
+sgtk_throw_gerror (const char *func_name, GError *gerr)
+{
+
+  /* FIXME: We should also handle error domain */
+  Fsignal (Qg_error, rep_list_1(rep_string_dup (gerr->message)));
+  g_error_free (gerr);
+}
+
 /* Initialization */
 
 static int standalone_p = 1;
@@ -2444,6 +2457,7 @@ sgtk_init_substrate (void)
   rep_INTERN (gtk_minor_version);
   rep_INTERN (gtk_micro_version);
   rep_INTERN (rep_gtk_version);
+  rep_INTERN(g_error); rep_ERROR(g_error);
   Fset (Qgtk_major_version, rep_MAKE_INT (GTK_MAJOR_VERSION));
   Fset (Qgtk_minor_version, rep_MAKE_INT (GTK_MINOR_VERSION));
   Fset (Qgtk_micro_version, rep_MAKE_INT (GTK_MICRO_VERSION));
diff --git a/rep-gtk.h b/rep-gtk.h
index d2b2c58..7d068ea 100644
--- a/rep-gtk.h
+++ b/rep-gtk.h
@@ -224,6 +224,8 @@ GParameter *sgtk_build_args (GObjectClass *objclass, int *n_argsp,
 repv sgtk_color_conversion (repv color);
 repv sgtk_font_conversion (repv color);
 
+void sgtk_throw_gerror (const char *func_name, GError *gerr);
+
 void sgtk_set_standalone (int flag);
 int sgtk_is_standalone (void);
 repv sgtk_standalone_p (void);



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