[Gnucash-changes] r13223 - gnucash/trunk/src/report/report-system - gc_protect SCM reports while they are in the GHashTable.

Chris Shoemaker chris at cvs.gnucash.org
Sat Feb 11 16:07:33 EST 2006


Author: chris
Date: 2006-02-11 16:07:32 -0500 (Sat, 11 Feb 2006)
New Revision: 13223
Trac: http://svn.gnucash.org/trac/changeset/13223

Modified:
   gnucash/trunk/src/report/report-system/Makefile.am
   gnucash/trunk/src/report/report-system/gnc-report.c
Log:
   gc_protect SCM reports while they are in the GHashTable.
   Also, use gfec to be a bit more defensive about potential errors while 
   running a report.


Modified: gnucash/trunk/src/report/report-system/Makefile.am
===================================================================
--- gnucash/trunk/src/report/report-system/Makefile.am	2006-02-11 20:46:19 UTC (rev 13222)
+++ gnucash/trunk/src/report/report-system/Makefile.am	2006-02-11 21:07:32 UTC (rev 13223)
@@ -12,6 +12,7 @@
 
 libgncmod_report_system_la_LIBADD = \
   ${top_builddir}/src/gnc-module/libgncmodule.la \
+  ${top_builddir}/src/app-utils/libgncmod-app-utils.la \
   ${GUILE_LIBS} \
   ${GLIB_LIBS}
 
@@ -19,6 +20,7 @@
 AM_CFLAGS = \
   -I${top_srcdir}/src \
   -I${top_srcdir}/src/gnc-module \
+  -I${top_srcdir}/src/app-utils \
   ${GLIB_CFLAGS} ${GUILE_INCS} \
   ${G_WRAP_COMPILE_ARGS}
 

Modified: gnucash/trunk/src/report/report-system/gnc-report.c
===================================================================
--- gnucash/trunk/src/report/report-system/gnc-report.c	2006-02-11 20:46:19 UTC (rev 13222)
+++ gnucash/trunk/src/report/report-system/gnc-report.c	2006-02-11 21:07:32 UTC (rev 13223)
@@ -28,6 +28,7 @@
 #include <libguile.h>
 #include <stdio.h>
 #include <string.h>
+#include "gfec.h"
 
 #include "gnc-report.h"
 
@@ -38,10 +39,10 @@
 static void
 gnc_report_init_table(void)
 {
-    /* TODO: Right now the report-page handles the gc-protection, but
-       it probably makes more sense to do it here on insert and remove. */
     if (!reports) {
-        reports = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
+        reports = g_hash_table_new_full(
+            g_int_hash, g_int_equal, 
+            g_free, (GDestroyNotify) scm_gc_unprotect_object);
     }
 }
 
@@ -73,6 +74,7 @@
     key = g_new(gint, 1);
     *key = report_next_serial_id++;
     g_hash_table_insert(reports, key, (gpointer)report);
+    scm_gc_protect_object(report);
     return *key;
 }
 
@@ -96,20 +98,26 @@
     return reports;
 }
 
+static void
+error_handler(const char *str)
+{
+    g_warning("Failure running report: %s", str);
+}
+
 gboolean
 gnc_run_report (int report_id, char ** data)
 {
   const gchar *free_data;
-  SCM run_report;
   SCM scm_text;
+  gchar *str;
 
   g_return_val_if_fail (data != NULL, FALSE);
   *data = NULL;
 
-  run_report = scm_c_eval_string ("gnc:report-run");
+  str = g_strdup_printf("(gnc:report-run %d)", report_id);
+  scm_text = gfec_eval_string(str, error_handler);
 
-  scm_text = scm_call_1 (run_report, scm_int2num (report_id));
-  if (!SCM_STRINGP (scm_text))
+  if (scm_text == SCM_UNDEFINED || !SCM_STRINGP (scm_text))
     return FALSE;
 
   free_data = SCM_STRING_CHARS (scm_text);



More information about the gnucash-changes mailing list