diff --git a/src/Makefile.am b/src/Makefile.am index 544592e861..92e867d1b2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,6 +47,7 @@ endif MAINTAINERCLEANFILES = swig-runtime.h EXTRA_DIST = \ + base-typemaps.i \ README.modules \ gnc-test-env \ valgrind-gnucash.supp \ diff --git a/src/app-utils/Makefile.am b/src/app-utils/Makefile.am index 7b8ca9788e..90b7e3bd4a 100644 --- a/src/app-utils/Makefile.am +++ b/src/app-utils/Makefile.am @@ -76,9 +76,9 @@ libgncmod_app_utils_la_LIBADD = \ ${GLIB_LIBS} if BUILDING_FROM_SVN -swig-app-utils.c: app-utils.i ${gncinclude_HEADERS} +swig-app-utils.c: app-utils.i $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ - -I${top_srcdir}/src/engine -I${top_srcdir}/lib/libqof/qof -o $@ $< + -I${top_srcdir}/src -o $@ $< endif gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash diff --git a/src/app-utils/app-utils.i b/src/app-utils/app-utils.i index 8f44ec0adc..9db6eb2f07 100644 --- a/src/app-utils/app-utils.i +++ b/src/app-utils/app-utils.i @@ -17,29 +17,7 @@ SCM scm_init_sw_app_utils_module (void); %} -//%import "engine.i" - -%typemap(in) GNCPrintAmountInfo "$1 = gnc_scm2printinfo($input);" -%typemap(out) GNCPrintAmountInfo "$result = gnc_printinfo2scm($1);" - -%typemap(out) GncCommodityList { - SCM list = SCM_EOL; - GList *node; - - for (node = $1; node; node = node->next) - list = scm_cons(gnc_quoteinfo2scm(node->data), list); - - $result = scm_reverse(list); -} - -// Temporary SWIG<->G-wrap converters for engine types -%typemap(in) gboolean "$1 = SCM_NFALSEP($input) ? TRUE : FALSE;" -%typemap(out) gboolean "$result = $1 ? SCM_BOOL_T : SCM_BOOL_F;" - -%typemap(in) gnc_numeric "$1 = gnc_scm_to_numeric($input);" -%typemap(out) gnc_numeric "$result = gnc_numeric_to_scm($1);" - -// End of temporary typemaps. +%import "base-typemaps.i" typedef void (*GNCOptionChangeCallback) (gpointer user_data); typedef int GNCOptionDBHandle; @@ -55,6 +33,16 @@ void gnc_option_db_destroy(GNCOptionDB *odb); void gnc_option_db_set_option_selectable_by_name(SCM guile_option, const char *section, const char *name, gboolean selectable); +%typemap(out) GncCommodityList { + SCM list = SCM_EOL; + GList *node; + + for (node = $1; node; node = node->next) + list = scm_cons(gnc_quoteinfo2scm(node->data), list); + + $result = scm_reverse(list); +} + %inline %{ typedef GList GncCommodityList; @@ -89,8 +77,6 @@ gnc_numeric gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value); - -typedef int time_t; time_t gnc_accounting_period_fiscal_start(void); time_t gnc_accounting_period_fiscal_end(void); diff --git a/src/base-typemaps.i b/src/base-typemaps.i new file mode 100644 index 0000000000..0c09e4d77f --- /dev/null +++ b/src/base-typemaps.i @@ -0,0 +1,64 @@ +%typemap(in) gboolean "$1 = SCM_NFALSEP($input) ? TRUE : FALSE;" +%typemap(out) gboolean "$result = $1 ? SCM_BOOL_T : SCM_BOOL_F;" + +%typemap(in) Timespec "$1 = gnc_timepair2timespec($input);" +%typemap(out) Timespec "$result = gnc_timespec2timepair($1);" + +%typemap(in) GUID "$1 = gnc_scm2guid($input);" +%typemap(out) GUID "$result = gnc_guid2scm($1);" +%typemap(in) GUID * (GUID g) " g = gnc_scm2guid($input); $1 = &g; " +%typemap(out) GUID * " $result = ($1) ? gnc_guid2scm(*($1)): SCM_UNDEFINED; " + +%typemap(in) gnc_numeric "$1 = gnc_scm_to_numeric($input);" +%typemap(out) gnc_numeric "$result = gnc_numeric_to_scm($1);" + +%typemap(in) gint64 " $1 = gnc_scm_to_gint64($input); " +%typemap(out) gint64 " $result = gnc_gint64_to_scm($1); " + +/* Not sure why SWIG doesn't figure this out. */ +typedef void * gpointer; +typedef int gint; +typedef int time_t; +typedef unsigned int guint; +typedef char * URLType; +typedef char gchar; + +%typemap(newfree) gchar * "g_free($1);" + +%typemap(in) GNCPrintAmountInfo "$1 = gnc_scm2printinfo($input);" +%typemap(out) GNCPrintAmountInfo "$result = gnc_printinfo2scm($1);" + + +%define GLIST_HELPER_INOUT(ListType, ElemSwigType) +%typemap(in) ListType * { + SCM list = $input; + GList *c_list = NULL; + + while (!SCM_NULLP(list)) { + Account *p; + + SCM p_scm = SCM_CAR(list); + if (SCM_FALSEP(p_scm) || SCM_NULLP(p_scm)) + p = NULL; + else + p = SWIG_MustGetPtr(p_scm, ElemSwigType, 1, 0); + + c_list = g_list_prepend(c_list, p); + list = SCM_CDR(list); + } + + $1 = g_list_reverse(c_list); +} +%typemap(out) ListType * { + SCM list = SCM_EOL; + GList *node; + + for (node = $1; node; node = node->next) + list = scm_cons(SWIG_NewPointerObj(node->data, + ElemSwigType, 0), list); + + $result = scm_reverse(list); +} +%enddef + + diff --git a/src/business/business-core/Makefile.am b/src/business/business-core/Makefile.am index c34b9430c1..3857963a88 100644 --- a/src/business/business-core/Makefile.am +++ b/src/business/business-core/Makefile.am @@ -68,7 +68,7 @@ libgncmod_business_core_la_LIBADD = \ if BUILDING_FROM_SVN swig-business-core.c: business-core.i ${noinst_HEADERS} $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ - -I${top_srcdir}/src/engine -o $@ $< + -I${top_srcdir}/src -o $@ $< endif gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash diff --git a/src/business/business-core/business-core.i b/src/business/business-core/business-core.i index 8cfc7eaa18..25ae7f589a 100644 --- a/src/business/business-core/business-core.i +++ b/src/business/business-core/business-core.i @@ -20,21 +20,7 @@ SCM scm_init_sw_business_core_module (void); %} -// Temporary SWIG<->G-wrap converters for engine types -%typemap(in) gboolean "$1 = SCM_NFALSEP($input) ? TRUE : FALSE;" -%typemap(out) gboolean "$result = $1 ? SCM_BOOL_T : SCM_BOOL_F;" - -%typemap(in) Timespec "$1 = gnc_timepair2timespec($input);" -%typemap(out) Timespec "$result = gnc_timespec2timepair($1);" - -%typemap(in) GUID "$1 = gnc_scm2guid($input);" -%typemap(out) GUID "$result = gnc_guid2scm($1);" - -%typemap(in) gnc_numeric "$1 = gnc_scm_to_numeric($input);" -%typemap(out) gnc_numeric "$result = gnc_numeric_to_scm($1);" - -// End of temporary typemaps. - +%import "base-typemaps.i" %rename(gncOwnerReturnGUID) gncOwnerRetGUID; @@ -77,33 +63,14 @@ static GncEmployee * gncEmployeeLookupFlip(GUID g, QofBook *b) %} -%typemap(out) EntryList * { - SCM list = SCM_EOL; - GList *node; - - for (node = $1; node; node = node->next) - list = scm_cons(SWIG_NewPointerObj(node->data, - SWIGTYPE_p__gncEntry, 0), list); - - $result = scm_reverse(list); -} - -%typemap(out) AccountValueList * { - SCM list = SCM_EOL; - GList *node; - - for (node = $1; node; node = node->next) - list = scm_cons(SWIG_NewPointerObj(node->data, - SWIGTYPE_p__gncAccountValue, 0), list); - - $result = scm_reverse(list); -} +GLIST_HELPER_INOUT(EntryList, SWIGTYPE_p__gncEntry); +GLIST_HELPER_INOUT(AccountValueList, SWIGTYPE_p__gncAccountValue); %typemap(in) GncAccountValue * "$1 = gnc_scm_to_account_value_ptr($input);" %typemap(out) GncAccountValue * "$result = gnc_account_value_ptr_to_scm($1);" -/* Parse the header file to generate wrappers */ +/* Parse the header files to generate wrappers */ %include %include %include diff --git a/src/business/dialog-tax-table/Makefile.am b/src/business/dialog-tax-table/Makefile.am index 51ab7f7288..a1e3343f94 100644 --- a/src/business/dialog-tax-table/Makefile.am +++ b/src/business/dialog-tax-table/Makefile.am @@ -41,8 +41,9 @@ libgncmod_dialog_tax_table_la_LIBADD = \ ${EFENCE_LIBS} if BUILDING_FROM_SVN -swig-dialog-tax-table.c: dialog-tax-table.i ${noinst_HEADERS} - $(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $< +swig-dialog-tax-table.c: dialog-tax-table.i + $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ + -I${top_srcdir}/src -o $@ $< endif gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash diff --git a/src/business/dialog-tax-table/dialog-tax-table.i b/src/business/dialog-tax-table/dialog-tax-table.i index 94c7df4725..6361f5545d 100644 --- a/src/business/dialog-tax-table/dialog-tax-table.i +++ b/src/business/dialog-tax-table/dialog-tax-table.i @@ -7,4 +7,6 @@ SCM scm_init_sw_dialog_tax_table_module (void); %} +%import "base-typemaps.i" + TaxTableWindow * gnc_ui_tax_table_window_new (GNCBook *book); diff --git a/src/core-utils/Makefile.am b/src/core-utils/Makefile.am index cab79964d2..1ae85edd42 100644 --- a/src/core-utils/Makefile.am +++ b/src/core-utils/Makefile.am @@ -26,7 +26,8 @@ noinst_HEADERS = \ if BUILDING_FROM_SVN swig-core-utils.c: core-utils.i - $(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $< + $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ + -I${top_srcdir}/src -o $@ $< endif AM_CFLAGS = \ diff --git a/src/core-utils/core-utils.i b/src/core-utils/core-utils.i index e0218994a0..c4282c336b 100644 --- a/src/core-utils/core-utils.i +++ b/src/core-utils/core-utils.i @@ -1,6 +1,5 @@ %module sw_core_utils %{ -//#include #include #include #include @@ -8,12 +7,7 @@ SCM scm_init_sw_core_utils_module (void); %} -typedef char gchar; -%typemap(newfree) gchar * "g_free($1);" -%typemap(in) gboolean " $1 = SCM_NFALSEP($input) ? TRUE : FALSE; " -%typemap(out) gboolean " $result = $1 ? SCM_BOOL_T : SCM_BOOL_F; " - - +%import "base-typemaps.i" %newobject g_find_program_in_path; gchar * g_find_program_in_path(const gchar *); diff --git a/src/engine/Makefile.am b/src/engine/Makefile.am index 9e2ddaf52a..0a6d3b6274 100644 --- a/src/engine/Makefile.am +++ b/src/engine/Makefile.am @@ -170,7 +170,7 @@ noinst_DATA = .scm-links if BUILDING_FROM_SVN swig-engine.c: engine.i ${gncinclude_HEADERS} ${noinst_HEADERS} $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ - -I${top_srcdir}/lib/libqof/qof -o $@ $< + -I${top_srcdir}/lib/libqof/qof -I${top_srcdir}/src -o $@ $< endif iso-4217-currencies.c: iso-4217-currencies.scm iso-currencies-to-c diff --git a/src/engine/engine.i b/src/engine/engine.i index 249adab991..46f204e718 100644 --- a/src/engine/engine.i +++ b/src/engine/engine.i @@ -22,65 +22,8 @@ SCM scm_init_sw_engine_module (void); %} -/* Not sure why SWIG doesn't figure this out. */ -typedef unsigned int guint; -typedef char gchar; -typedef void * gpointer; -typedef int gint; -//%import "glib.h" +%import "base-typemaps.i" -//typedef const gchar * QofIdType; -//%import "qofid.h" - -%typemap(in) gint64 " $1 = gnc_scm_to_gint64($input); " -%typemap(out) gint64 " $result = gnc_gint64_to_scm($1); " - -%typemap(in) gboolean " $1 = SCM_NFALSEP($input) ? TRUE : FALSE; " -%typemap(out) gboolean " $result = $1 ? SCM_BOOL_T : SCM_BOOL_F; " - -%typemap(in) Timespec " $1 = gnc_timepair2timespec($input); " -%typemap(out) Timespec " $result = gnc_timespec2timepair($1); " - -%typemap(in) GUID " $1 = gnc_scm2guid($input); " -%typemap(out) GUID " $result = gnc_guid2scm($1); " -%typemap(in) GUID * (GUID g) " g = gnc_scm2guid($input); $1 = &g; " -%typemap(out) GUID * " $result = ($1) ? gnc_guid2scm(*($1)): SCM_UNDEFINED; " - - -%typemap(in) gnc_numeric " $1 = gnc_scm_to_numeric($input); " -%typemap(out) gnc_numeric " $result = gnc_numeric_to_scm($1); " - -%define GLIST_HELPER_INOUT(ListType, ElemSwigType) -%typemap(in) ListType * { - SCM list = $input; - GList *c_list = NULL; - - while (!SCM_NULLP(list)) { - Account *p; - - SCM p_scm = SCM_CAR(list); - if (SCM_FALSEP(p_scm) || SCM_NULLP(p_scm)) - p = NULL; - else - p = SWIG_MustGetPtr(p_scm, ElemSwigType, 1, 0); - - c_list = g_list_prepend(c_list, p); - list = SCM_CDR(list); - } - - $1 = g_list_reverse(c_list); -} -%typemap(out) ListType * { - SCM list = SCM_EOL; - GList *node; - - for (node = $1; node; node = node->next) - list = scm_cons(SWIG_NewPointerObj(node->data, - ElemSwigType, 0), list); - - $result = scm_reverse(list); -} -%enddef GLIST_HELPER_INOUT(SplitList, SWIGTYPE_p_Split); GLIST_HELPER_INOUT(TransList, SWIGTYPE_p_Transaction); @@ -113,8 +56,10 @@ static const GUID * gncBudgetGetGUID(GncBudget *x) %typemap(newfree) gchar * "g_free($1);" -/* NB: Should cover all the functions currently used, but not all that - * are wrapped */ +/* NB: The object ownership annotations should already cover all the +functions currently used in guile, but not all the functions that are +wrapped. So, we should contract the interface to wrap only the used +functions. */ %newobject xaccGroupGetSubAccountsSorted; %newobject xaccGroupGetAccountListSorted; @@ -138,7 +83,6 @@ static const GUID * gncBudgetGetGUID(GncBudget *x) %newobject gnc_build_book_path; /* Parse the header file to generate wrappers */ -//#define QOF_ID_BOOK "Book" %inline { static QofIdType QOF_ID_BOOK_SCM (void) { return QOF_ID_BOOK; } } diff --git a/src/gnc-module/Makefile.am b/src/gnc-module/Makefile.am index d532d4eaee..f03127ae51 100644 --- a/src/gnc-module/Makefile.am +++ b/src/gnc-module/Makefile.am @@ -28,7 +28,8 @@ noinst_DATA = .scm-links if BUILDING_FROM_SVN swig-gnc-module.c: gnc-module.i - $(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $< + $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ + -I${top_srcdir}/src -o $@ $< endif EXTRA_DIST = \ diff --git a/src/gnc-module/gnc-module.i b/src/gnc-module/gnc-module.i index ac055cd608..6c0e9769cc 100644 --- a/src/gnc-module/gnc-module.i +++ b/src/gnc-module/gnc-module.i @@ -5,8 +5,7 @@ SCM scm_init_sw_gnc_module_module (void); %} -typedef char gchar; -typedef int gint; +%import "base-typemaps.i" void gnc_module_system_init(void); void gnc_module_system_refresh(void); diff --git a/src/gnome-utils/Makefile.am b/src/gnome-utils/Makefile.am index 47ea66a250..3564225f2c 100644 --- a/src/gnome-utils/Makefile.am +++ b/src/gnome-utils/Makefile.am @@ -189,9 +189,9 @@ libgncmod_gnome_utils_la_LIBADD = \ ${LIBXML2_LIBS} if BUILDING_FROM_SVN -swig-gnome-utils.c: gnome-utils.i ${noinst_HEADERS} ${gncinclude_HEADERS} +swig-gnome-utils.c: gnome-utils.i gnc-html.h print-session.h $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ - -I${top_srcdir}/src/engine -o $@ $< + -I${top_srcdir}/src -o $@ $< endif gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash diff --git a/src/gnome-utils/gnome-utils.i b/src/gnome-utils/gnome-utils.i index d1e02cd4cc..2372d79316 100644 --- a/src/gnome-utils/gnome-utils.i +++ b/src/gnome-utils/gnome-utils.i @@ -9,7 +9,6 @@ #include #include #include -//#include #include #include #include @@ -24,18 +23,11 @@ SCM scm_init_sw_gnome_utils_module (void); %} -// Temporary SWIG<->G-wrap converters for engine types -%typemap(in) gboolean "$1 = SCM_NFALSEP($input) ? TRUE : FALSE;" -%typemap(out) gboolean "$result = $1 ? SCM_BOOL_T : SCM_BOOL_F;" +%import "base-typemaps.i" -// End of temporary typemaps. -typedef char * URLType; -typedef char gchar; - -//%include "gnc-main-window.h" +/* Parse the header file to generate wrappers */ %include "gnc-html.h" -/* Parse the header file to generate wrappers */ GNCOptionWin * gnc_options_dialog_new(gchar *title); void gnc_options_dialog_destroy(GNCOptionWin * win); @@ -60,11 +52,7 @@ void gnc_info_dialog(GtkWidget *parent, const char *format, ...); - void gnc_add_scm_extension (SCM extension); -//char * gnc_html_encode_string(const char * str); -//char * gnc_build_url (const gchar * type, const gchar * location, -// const gchar * label); void gnc_set_busy_cursor (GtkWidget *w, gboolean update_now); void gnc_unset_busy_cursor (GtkWidget *w); diff --git a/src/gnome/Makefile.am b/src/gnome/Makefile.am index 6697e5dd6e..20cb6ac847 100644 --- a/src/gnome/Makefile.am +++ b/src/gnome/Makefile.am @@ -89,9 +89,9 @@ noinst_HEADERS = \ window-reconcile.h if BUILDING_FROM_SVN -swig-gnome.c: gnome.i ${noinst_HEADERS} +swig-gnome.c: gnome.i dialog-progress.h $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ - -I${top_srcdir}/src/engine -o $@ $< + -I${top_srcdir}/src -o $@ $< endif EXTRA_DIST = \ diff --git a/src/gnome/gnome.i b/src/gnome/gnome.i index 63a0a1a85f..3f4cb0415e 100644 --- a/src/gnome/gnome.i +++ b/src/gnome/gnome.i @@ -8,10 +8,7 @@ SCM scm_init_sw_gnome_module (void); %} -// Temporary SWIG<->G-wrap converters for engine types -%typemap(in) gboolean "$1 = SCM_NFALSEP($input) ? TRUE : FALSE;" -%typemap(out) gboolean "$result = $1 ? SCM_BOOL_T : SCM_BOOL_F;" -// End of temporary typemaps. +%import "base-typemaps.i" /* Parse the header file to generate wrappers */ %include diff --git a/src/report/report-gnome/Makefile.am b/src/report/report-gnome/Makefile.am index 4d764fe38c..a712ad2244 100644 --- a/src/report/report-gnome/Makefile.am +++ b/src/report/report-gnome/Makefile.am @@ -51,9 +51,9 @@ libgncmod_report_gnome_la_LIBADD = \ ${GLIB_LIBS} if BUILDING_FROM_SVN -swig-report-gnome.c: report-gnome.i ${gncinclude_HEADERS} +swig-report-gnome.c: report-gnome.i $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ - -I${top_srcdir}/src/engine -o $@ $< + -I${top_srcdir}/src -o $@ $< endif gncmoddir = ${GNC_SHAREDIR}/guile-modules/gnucash/report diff --git a/src/report/report-gnome/report-gnome.i b/src/report/report-gnome/report-gnome.i index d683f1001f..7a1878180a 100644 --- a/src/report/report-gnome/report-gnome.i +++ b/src/report/report-gnome/report-gnome.i @@ -10,6 +10,8 @@ SCM scm_init_sw_report_gnome_module (void); %} +%import "base-typemaps.i" + void gnc_report_raise_editor(SCM report); void gnc_main_window_open_report(int report_id, GncMainWindow *window); GtkWidget * gnc_report_window_default_params_editor(SCM options, SCM report); diff --git a/src/report/report-system/Makefile.am b/src/report/report-system/Makefile.am index ebb67e24ee..0c4555457f 100644 --- a/src/report/report-system/Makefile.am +++ b/src/report/report-system/Makefile.am @@ -18,8 +18,9 @@ libgncmod_report_system_la_LIBADD = \ ${GLIB_LIBS} if BUILDING_FROM_SVN -swig-report-system.c: report-system.i ${gncinclude_HEADERS} - $(SWIG) -guile $(SWIG_ARGS) -Linkage module -o $@ $< +swig-report-system.c: report-system.i + $(SWIG) -guile $(SWIG_ARGS) -Linkage module \ + -I${top_srcdir}/src -o $@ $< endif AM_CFLAGS = \ diff --git a/src/report/report-system/report-system.i b/src/report/report-system/report-system.i index d916f05c01..4d4c82f910 100644 --- a/src/report/report-system/report-system.i +++ b/src/report/report-system/report-system.i @@ -7,7 +7,7 @@ SCM scm_init_sw_report_system_module (void); %} -typedef int gint; +%import "base-typemaps.i" SCM gnc_report_find(gint id); gint gnc_report_add(SCM report);