[Gnucash-changes] r12993 - gnucash/trunk/src/report - Move
generation of report serial ids from guile to C.
Chris Shoemaker
chris at cvs.gnucash.org
Fri Jan 27 18:03:28 EST 2006
Author: chris
Date: 2006-01-27 18:03:23 -0500 (Fri, 27 Jan 2006)
New Revision: 12993
Trac: http://svn.gnucash.org/trac/changeset/12993
Modified:
gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
gnucash/trunk/src/report/report-system/gnc-report.c
gnucash/trunk/src/report/report-system/gnc-report.h
gnucash/trunk/src/report/report-system/gw-report-system-spec.scm
gnucash/trunk/src/report/report-system/report.scm
Log:
Move generation of report serial ids from guile to C.
Try to gracefully handle more errors during report loading.
Modified: gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c 2006-01-27 21:49:03 UTC (rev 12992)
+++ gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c 2006-01-27 23:03:23 UTC (rev 12993)
@@ -706,6 +706,7 @@
gchar *option_string;
gint report_id;
SCM scm_id;
+ SCM report;
g_return_val_if_fail(key_file, NULL);
g_return_val_if_fail(group_name, NULL);
@@ -716,20 +717,26 @@
if (error) {
g_warning("error reading group %s key %s: %s",
group_name, SCHEME_OPTIONS, error->message);
+ g_error_free(error);
LEAVE("bad value");
return NULL;
}
scm_id = scm_c_eval_string(option_string);
+ g_free(option_string);
if (!scm_integer_p(scm_id)) {
- g_free(option_string);
LEAVE("report id not an integer");
return NULL;
}
report_id = scm_num2int(scm_id, SCM_ARG1, __FUNCTION__);
+ report = gnc_report_find(report_id);
+ if (!report) {
+ LEAVE("report doesn't exist");
+ return NULL;
+ }
+
page = gnc_plugin_page_report_new( report_id );
- g_free(option_string);
LEAVE(" ");
return page;
}
Modified: gnucash/trunk/src/report/report-system/gnc-report.c
===================================================================
--- gnucash/trunk/src/report/report-system/gnc-report.c 2006-01-27 21:49:03 UTC (rev 12992)
+++ gnucash/trunk/src/report/report-system/gnc-report.c 2006-01-27 23:03:23 UTC (rev 12993)
@@ -33,6 +33,7 @@
/* Fow now, this is global, like it was in guile. It _should_ be per-book. */
static GHashTable *reports = NULL;
+static int report_next_serial_id = 0;
static void
gnc_report_init_table(void)
@@ -65,13 +66,14 @@
return report;
}
-void gnc_report_add(gint id, SCM report)
+int gnc_report_add(SCM report)
{
gint *key;
gnc_report_init_table();
key = g_new(gint, 1);
- *key = id;
+ *key = report_next_serial_id++;
g_hash_table_insert(reports, key, (gpointer)report);
+ return *key;
}
static gboolean
Modified: gnucash/trunk/src/report/report-system/gnc-report.h
===================================================================
--- gnucash/trunk/src/report/report-system/gnc-report.h 2006-01-27 21:49:03 UTC (rev 12992)
+++ gnucash/trunk/src/report/report-system/gnc-report.h 2006-01-27 23:03:23 UTC (rev 12993)
@@ -40,7 +40,7 @@
SCM gnc_report_find(gint id);
void gnc_report_remove_by_id(gint id);
-void gnc_report_add(gint id, SCM report);
+int gnc_report_add(SCM report);
void gnc_reports_flush_global(void);
GHashTable *gnc_reports_get_global(void);
Modified: gnucash/trunk/src/report/report-system/gw-report-system-spec.scm
===================================================================
--- gnucash/trunk/src/report/report-system/gw-report-system-spec.scm 2006-01-27 21:49:03 UTC (rev 12992)
+++ gnucash/trunk/src/report/report-system/gw-report-system-spec.scm 2006-01-27 23:03:23 UTC (rev 12993)
@@ -37,9 +37,9 @@
(gw:wrap-function
ws
'gnc:report-add
- '<gw:void>
+ '<gw:int>
"gnc_report_add"
- '((<gw:int> id) (<gw:scm> report))
- "Add report with id")
+ '((<gw:scm> report))
+ "Add report, returns id")
)
Modified: gnucash/trunk/src/report/report-system/report.scm
===================================================================
--- gnucash/trunk/src/report/report-system/report.scm 2006-01-27 21:49:03 UTC (rev 12992)
+++ gnucash/trunk/src/report/report-system/report.scm 2006-01-27 23:03:23 UTC (rev 12993)
@@ -31,8 +31,6 @@
;; value is the report definition structure.
(define *gnc:_report-templates_* (make-hash-table 23))
-(define *gnc:_report-next-serial_* 0)
-
;; Define those strings here to make changes easier and avoid typos.
(define gnc:menuname-reports "Reports/StandardReports")
(define gnc:menuname-asset-liability (N_ "_Assets & Liabilities"))
@@ -242,9 +240,7 @@
#f ;; ctext
))
(template (hash-ref *gnc:_report-templates_* template-name))
- (id *gnc:_report-next-serial_*))
- (gnc:report-set-id! r id)
- (set! *gnc:_report-next-serial_* (+ 1 id))
+ )
(let ((options
(if (not (null? rest))
(car rest)
@@ -259,17 +255,16 @@
(cb r))))
options))
- (gnc:report-add (gnc:report-id r) r)
- id))
+ (gnc:report-set-id! r (gnc:report-add r))
+ (gnc:report-id r))
+ )
;; This is the function that is called when saved reports are evaluated.
(define (gnc:restore-report id template-name options)
(let ((r ((record-constructor <report>)
template-name id options #t #t #f #f)))
- (if (>= id *gnc:_report-next-serial_*)
- (set! *gnc:_report-next-serial_* (+ id 1)))
- (gnc:report-add id r)
- #f))
+ (gnc:report-add r))
+ )
(define (gnc:make-report-options template-name)
More information about the gnucash-changes
mailing list