r14974 - gnucash/branches/swig-redo/src/engine - Begin the conversion of the engine module from gwrap to swig.

Chris Shoemaker chris at cvs.gnucash.org
Mon Oct 9 20:06:26 EDT 2006


Author: chris
Date: 2006-10-09 20:06:26 -0400 (Mon, 09 Oct 2006)
New Revision: 14974
Trac: http://svn.gnucash.org/trac/changeset/14974

Added:
   gnucash/branches/swig-redo/src/engine/engine.i
Modified:
   gnucash/branches/swig-redo/src/engine/Makefile.am
   gnucash/branches/swig-redo/src/engine/engine.scm
   gnucash/branches/swig-redo/src/engine/gncmod-engine.c
Log:
Begin the conversion of the engine module from gwrap to swig.
  - Add the interface definition.
  - Build and load the swig module.
(Unlike other commits, gwrap is not removed yet, so that there are fully
functional intermediate states.)



Modified: gnucash/branches/swig-redo/src/engine/Makefile.am
===================================================================
--- gnucash/branches/swig-redo/src/engine/Makefile.am	2006-10-10 00:05:22 UTC (rev 14973)
+++ gnucash/branches/swig-redo/src/engine/Makefile.am	2006-10-10 00:06:26 UTC (rev 14974)
@@ -41,6 +41,10 @@
   gnc-session.c \
   gnc-session-scm.c \
   gncmod-engine.c \
+  swig-engine.c \
+  kvp-scm.c \
+  engine-helpers.c \
+  glib-helpers.c  \
   policy.c
 
 EXTRA_libgncmod_engine_la_SOURCES = iso-4217-currencies.c
@@ -182,6 +186,10 @@
 endif
 	touch .scm-links
 
+swig-engine.c: engine.i ${gncinclude_HEADERS} ${noinst_HEADERS}
+	swig -guile $(SWIG_ARGS) -Linkage module \
+	-I${top_srcdir}/lib/libqof/qof -o $@ $<
+
 iso-4217-currencies.c: iso-4217-currencies.scm iso-currencies-to-c
 	-chmod u+x ${srcdir}/iso-currencies-to-c
 	GUILE_LOAD_PATH=@GNC_SRFI_LOAD_PATH@:${GUILE_LOAD_PATH} srcdir=${srcdir} ${srcdir}/iso-currencies-to-c
@@ -210,7 +218,7 @@
 
 BUILT_SOURCES = iso-4217-currencies.c \
   gw-engine.scm gw-engine.c gw-engine.h \
-  gw-kvp.scm gw-kvp.c gw-kvp.h gncla-dir.h
+  gw-kvp.scm gw-kvp.c gw-kvp.h gncla-dir.h swig-engine.c
 
 CLEANFILES = $(BUILT_SOURCES) gnucash g-wrapped .scm-links gncla-dir.h \
 	${SCM_FILE_LINKS} gw-engine.html gw-kvp.html

Added: gnucash/branches/swig-redo/src/engine/engine.i
===================================================================
--- gnucash/branches/swig-redo/src/engine/engine.i	2006-10-10 00:05:22 UTC (rev 14973)
+++ gnucash/branches/swig-redo/src/engine/engine.i	2006-10-10 00:06:26 UTC (rev 14974)
@@ -0,0 +1,410 @@
+%module sw_engine
+%{
+/* Includes the header in the wrapper code */
+#include <config.h>
+#include <glib.h>
+#include <qof.h>
+#include <Group.h>
+#include <Query.h>
+#include <gnc-budget.h>
+#include <gnc-commodity.h>
+#include <gnc-engine.h>
+#include <gnc-filepath-utils.h>
+#include <gnc-pricedb.h>
+#include <gnc-lot.h>
+#include <gnc-session-scm.h>
+#include <gnc-hooks-scm.h>
+#include <engine-helpers.h>
+#include <SX-book.h>
+#include <kvp-scm.h>
+#include "glib-helpers.h"
+#include "g-wrap-wct.h" //temp
+%}
+
+/* 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"
+
+//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); "
+
+//JUST TEMPORARY FOR TESTING ACCTTYPE ONLY
+/*
+%typemap(in) Account * " $1 = gw_wcp_get_ptr($input); "
+%typemap(in) Transaction * " $1 = gw_wcp_get_ptr($input); "
+%typemap(in) Split * " $1 = gw_wcp_get_ptr($input); "
+%typemap(in) QofQuery * " $1 = gw_wcp_get_ptr($input); "
+*/
+
+%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
+
+%define GLIST_HELPER_INOUT_GWRAP(ListType, ElemGWrapTypeStr)
+%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 = gw_wcp_get_ptr(p_scm);
+
+        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(gw_wcp_assimilate_ptr(node->data,
+       scm_c_eval_string(ElemGWrapTypeStr)), list);
+
+  $result = scm_reverse(list);
+}
+%enddef
+
+GLIST_HELPER_INOUT(SplitList, SWIGTYPE_p_Split);
+GLIST_HELPER_INOUT(TransList, SWIGTYPE_p_Transaction);
+GLIST_HELPER_INOUT(LotList, SWIGTYPE_p_GNCLot);
+GLIST_HELPER_INOUT(AccountList, SWIGTYPE_p_Account);
+/*
+GLIST_HELPER_INOUT_GWRAP(SplitList, "<gnc:Split*>");
+GLIST_HELPER_INOUT_GWRAP(TransList, "<gnc:Transction*>");
+GLIST_HELPER_INOUT_GWRAP(LotList, "<gnc:Lot*>");
+GLIST_HELPER_INOUT_GWRAP(AccountList, "<gnc:Account*>");
+*/
+GLIST_HELPER_INOUT(PriceList, SWIGTYPE_p_GNCPrice);
+// TODO: free PriceList?
+GLIST_HELPER_INOUT(CommodityList, SWIGTYPE_p_gnc_commodity);
+
+
+%inline %{
+const GUID * gncSplitGetGUID(Split *x)
+{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
+const GUID * gncTransGetGUID(Transaction *x)
+{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
+const GUID * gncAccountGetGUID(Account *x)
+{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
+const GUID * gncPriceGetGUID(GNCPrice *x)
+{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
+const GUID * gncBudgetGetGUID(GncBudget *x)
+{ return qof_instance_get_guid(QOF_INSTANCE(x)); }
+%}
+
+%typemap(newfree) AccountList * "g_list_free($1);"
+%typemap(newfree) SplitList * "g_list_free($1);"
+%typemap(newfree) TransList * "g_list_free($1);"
+%typemap(newfree) PriceList * "g_list_free($1);"
+%typemap(newfree) LotList * "g_list_free($1);"
+%typemap(newfree) CommodityList * "g_list_free($1);"
+
+%typemap(newfree) gchar * "g_free($1);"
+
+/* NB: Should cover all the functions currently used, but not all that
+ *     are wrapped */
+
+%newobject xaccGroupGetSubAccountsSorted;
+%newobject xaccGroupGetAccountListSorted;
+
+%delobject gnc_price_list_destroy;
+%newobject gnc_pricedb_lookup_latest_any_currency;
+
+%newobject gnc_pricedb_lookup_nearest_in_time_any_currency;
+%newobject gnc_pricedb_lookup_latest_before_any_currency;
+%newobject gnc_pricedb_get_prices;
+%newobject gnc_pricedb_lookup_at_time;
+%newobject gnc_pricedb_lookup_day;
+
+%newobject xaccQueryGetSplitsUniqueTrans;
+%newobject xaccQueryGetTransactions;
+%newobject xaccQueryGetLots;
+
+%newobject xaccSplitGetCorrAccountFullName;
+%newobject gnc_numeric_to_string;
+%newobject gnc_build_dotgnucash_path;
+%newobject gnc_build_book_path;
+
+/* Parse the header file to generate wrappers */
+//#define QOF_ID_BOOK           "Book"
+%inline {
+  QofIdType QOF_ID_BOOK_SCM (void) { return QOF_ID_BOOK; }
+}
+
+%include <Split.h>
+%include <engine-helpers.h>
+%include <Account.h>
+%include <Transaction.h>
+%include <gnc-pricedb.h>
+
+QofSession * qof_session_new (void);
+QofBook * qof_session_get_book (QofSession *session);
+
+%include <Group.h>
+%include <gnc-commodity.h>
+
+// TODO: Maybe unroll
+void qof_book_kvp_changed (QofBook *book);
+
+// TODO: Unroll/remove
+const char *qof_session_get_url (QofSession *session);
+
+const char *gnc_print_date (Timespec ts);
+
+%inline {
+QofQuery * qof_query_create_for_splits(void) {
+  qof_query_create_for(GNC_ID_SPLIT);
+}
+}
+%typemap(in) GSList * "$1 = gnc_query_scm2path($input);"
+
+void qof_query_add_guid_match (QofQuery *q, GSList *param_list,
+                           const GUID *guid, QofQueryOp op);
+void qof_query_set_sort_order (QofQuery *q, GSList *params1,
+                           GSList *params2, GSList *params3);
+
+%clear GSList *;
+SplitList * qof_query_run (QofQuery *q);
+
+%include <Query.h>
+%ignore qof_query_add_guid_match;
+%ignore qof_query_set_sort_order;
+%ignore qof_query_run;
+%include <qofquery.h>
+%include <qofquerycore.h>
+
+gnc_numeric gnc_numeric_create(gint64 num, gint64 denom);
+gnc_numeric gnc_numeric_zero(void);
+gint64 gnc_numeric_num(gnc_numeric a);
+gint64 gnc_numeric_denom(gnc_numeric a);
+gboolean gnc_numeric_zero_p(gnc_numeric a);
+int gnc_numeric_compare(gnc_numeric a, gnc_numeric b);
+gboolean gnc_numeric_negative_p(gnc_numeric a);
+gboolean gnc_numeric_positive_p(gnc_numeric a);
+gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b);
+gnc_numeric
+gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how);
+gnc_numeric
+gnc_numeric_sub(gnc_numeric a, gnc_numeric b, gint64 denom, gint how);
+gnc_numeric
+gnc_numeric_mul(gnc_numeric a, gnc_numeric b, gint64 denom, gint how);
+gnc_numeric
+gnc_numeric_div(gnc_numeric a, gnc_numeric b, gint64 denom, gint how);
+gnc_numeric gnc_numeric_neg(gnc_numeric a);
+gnc_numeric gnc_numeric_abs(gnc_numeric a);
+gnc_numeric gnc_numeric_add_fixed(gnc_numeric a, gnc_numeric b);
+gnc_numeric gnc_numeric_sub_fixed(gnc_numeric a, gnc_numeric b);
+gnc_numeric gnc_numeric_convert(gnc_numeric in, gint64 denom, gint how);
+gnc_numeric double_to_gnc_numeric(double in, gint64 denom, gint how);
+double gnc_numeric_to_double(gnc_numeric in);
+gchar * gnc_numeric_to_string(gnc_numeric n);
+
+Timespec timespecCanonicalDayTime(Timespec t);
+
+gchar * gnc_build_dotgnucash_path (const gchar *filename);
+gchar * gnc_build_book_path (const gchar *filename);
+
+%include <gnc-budget.h>
+
+%typemap(in) GList * {
+  SCM path_scm = $input;
+  GList *path = NULL;
+
+  while (!SCM_NULLP (path_scm))
+  {
+    SCM key_scm = SCM_CAR (path_scm);
+    char *key;
+
+    if (!SCM_STRINGP (key_scm))
+      break;
+
+    key = g_strdup (SCM_STRING_CHARS (key_scm));
+
+    path = g_list_prepend (path, key);
+
+    path_scm = SCM_CDR (path_scm);
+  }
+
+  $result = g_list_reverse (path);
+}
+
+void gnc_quote_source_set_fq_installed (GList *sources_list);
+%clear GList *;
+
+%include <gnc-lot.h>
+%include <gnc-session-scm.h>
+void gnc_hook_add_scm_dangler (const gchar *name, SCM proc);
+void gnc_hook_run (const gchar *name, gpointer data);
+%include <gnc-hooks.h>
+
+AccountGroup * gnc_book_get_template_group(QofBook *book);
+
+// KVP stuff
+%typemap(in) KvpValue * " $1 = gnc_scm_to_kvp_value_ptr($input); "
+%typemap(out) KvpValue * " $result = gnc_kvp_value_ptr_to_scm($1); "
+%typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);"
+
+void gnc_kvp_frame_delete_at_path(KvpFrame *frame, GSList *key_path);
+void kvp_frame_set_slot_path_gslist(
+   KvpFrame *frame, const KvpValue *new_value, GSList *key_path);
+KvpValue * kvp_frame_get_slot_path_gslist (KvpFrame *frame, GSList *key_path);
+
+%clear GSList *key_path;
+
+%inline %{
+KvpFrame * gnc_book_get_slots(QofBook *book) {
+   qof_instance_get_slots(QOF_INSTANCE(book));
+}
+%}
+
+
+%init {
+  {
+    char tmp[100];
+
+#define SET_ENUM(e) snprintf(tmp, 100, "(set! %s (%s))", (e), (e));  \
+    scm_c_eval_string(tmp);
+
+    SET_ENUM("TXN-TYPE-NONE");
+    SET_ENUM("TXN-TYPE-INVOICE");
+    SET_ENUM("TXN-TYPE-PAYMENT");
+
+    SET_ENUM("ACCT-TYPE-INVALID");
+    SET_ENUM("ACCT-TYPE-NONE");
+    SET_ENUM("ACCT-TYPE-BANK");
+    SET_ENUM("ACCT-TYPE-CASH");
+    SET_ENUM("ACCT-TYPE-CREDIT");
+    SET_ENUM("ACCT-TYPE-ASSET");
+    SET_ENUM("ACCT-TYPE-LIABILITY");
+    SET_ENUM("ACCT-TYPE-STOCK");
+    SET_ENUM("ACCT-TYPE-MUTUAL");
+    SET_ENUM("ACCT-TYPE-CURRENCY");
+    SET_ENUM("ACCT-TYPE-INCOME");
+    SET_ENUM("ACCT-TYPE-EXPENSE");
+    SET_ENUM("ACCT-TYPE-EQUITY");
+    SET_ENUM("ACCT-TYPE-RECEIVABLE");
+    SET_ENUM("ACCT-TYPE-PAYABLE");
+    SET_ENUM("NUM-ACCOUNT-TYPES");
+    SET_ENUM("ACCT-TYPE-CHECKING");
+    SET_ENUM("ACCT-TYPE-SAVINGS");
+    SET_ENUM("ACCT-TYPE-MONEYMRKT");
+    SET_ENUM("ACCT-TYPE-CREDITLINE");
+
+    SET_ENUM("QOF-QUERY-AND");
+    SET_ENUM("QOF-QUERY-OR");
+
+    SET_ENUM("QUERY-TXN-MATCH-ALL");
+    SET_ENUM("QUERY-TXN-MATCH-ANY");
+
+    SET_ENUM("QOF-GUID-MATCH-ALL");
+    SET_ENUM("QOF-GUID-MATCH-ANY");
+    SET_ENUM("QOF-GUID-MATCH-NULL");
+    SET_ENUM("QOF-GUID-MATCH-NONE");
+    SET_ENUM("QOF-GUID-MATCH-LIST-ANY");
+
+    SET_ENUM("QOF-COMPARE-LT");
+    SET_ENUM("QOF-COMPARE-LTE");
+    SET_ENUM("QOF-COMPARE-EQUAL");
+    SET_ENUM("QOF-COMPARE-GT");
+    SET_ENUM("QOF-COMPARE-GTE");
+    SET_ENUM("QOF-COMPARE-NEQ");
+
+    SET_ENUM("QOF-NUMERIC-MATCH-ANY");
+    SET_ENUM("QOF-NUMERIC-MATCH-CREDIT");
+    SET_ENUM("QOF-NUMERIC-MATCH-DEBIT");
+
+    SET_ENUM("CLEARED-NO");
+    SET_ENUM("CLEARED-CLEARED");
+    SET_ENUM("CLEARED-FROZEN");
+    SET_ENUM("CLEARED-RECONCILED");
+    SET_ENUM("CLEARED-VOIDED");
+
+    SET_ENUM("HOOK-REPORT");
+    SET_ENUM("HOOK-SAVE-OPTIONS");
+
+    //SET_ENUM("GNC-ID-ACCOUNT");
+    SET_ENUM("QOF-ID-BOOK-SCM");
+    //SET_ENUM("GNC-ID-BUDGET");
+    //SET_ENUM("GNC-ID-LOT");
+    //SET_ENUM("GNC-ID-PRICE");
+    //SET_ENUM("GNC-ID-SPLIT");
+    //SET_ENUM("GNC-ID-SCHEDXACTION");
+    //SET_ENUM("QOF-ID-SESSION");
+    //SET_ENUM("GNC-ID-TRANS");
+
+    SET_ENUM("QUERY-DEFAULT-SORT");
+    SET_ENUM("SPLIT-LOT");
+    SET_ENUM("SPLIT-TRANS");
+    SET_ENUM("SPLIT-ACCOUNT");
+    SET_ENUM("SPLIT-VALUE");
+    SET_ENUM("SPLIT-MEMO");
+    SET_ENUM("SPLIT-DATE-RECONCILED");
+
+    SET_ENUM("TRANS-DATE-POSTED");
+    SET_ENUM("TRANS-DESCRIPTION");
+    SET_ENUM("TRANS-NUM");
+
+    SET_ENUM("ACCOUNT-CODE-");  /* sic */
+
+#undefine SET_ENUM
+  }
+
+}
+

Modified: gnucash/branches/swig-redo/src/engine/engine.scm
===================================================================
--- gnucash/branches/swig-redo/src/engine/engine.scm	2006-10-10 00:05:22 UTC (rev 14973)
+++ gnucash/branches/swig-redo/src/engine/engine.scm	2006-10-10 00:06:26 UTC (rev 14974)
@@ -1,6 +1,7 @@
 (define-module (gnucash engine))
 
 (use-modules (g-wrap gw-wct))
+(use-modules (sw_engine))
 
 (use-modules (g-wrapped gw-engine))
 

Modified: gnucash/branches/swig-redo/src/engine/gncmod-engine.c
===================================================================
--- gnucash/branches/swig-redo/src/engine/gncmod-engine.c	2006-10-10 00:05:22 UTC (rev 14973)
+++ gnucash/branches/swig-redo/src/engine/gncmod-engine.c	2006-10-10 00:06:26 UTC (rev 14974)
@@ -12,7 +12,6 @@
 
 #include "gnc-engine.h"
 #include "gnc-module-api.h"
-#include "gw-engine.h"
 
 /* version of the gnc module system interface we require */
 int libgncmod_engine_LTX_gnc_module_system_interface = 0;
@@ -41,6 +40,8 @@
   return g_strdup("The GnuCash accounting engine");
 }
 
+extern SCM scm_init_sw_engine_module(void);
+
 int
 libgncmod_engine_LTX_gnc_module_init(int refcount) 
 {
@@ -50,6 +51,8 @@
     gnc_engine_init(0, NULL);
   }
   
+  scm_init_sw_engine_module();
+  scm_c_eval_string("(use-modules (sw_engine))");
   scm_c_eval_string("(use-modules (gnucash engine))");
 
   scm_c_eval_string("(use-modules (g-wrap gw-glib))");



More information about the gnucash-changes mailing list