Skip to content

Commit

Permalink
wrap qoflog
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Jul 6, 2019
1 parent bc1bcc7 commit 898a9cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions libgnucash/engine/engine.i
Expand Up @@ -24,6 +24,7 @@
#include <config.h>
#include <glib.h>
#include "qof.h"
#include "qoflog.h"
#include "Query.h"
#include "gnc-budget.h"
#include "gnc-commodity.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ engine-common.i */

%include "engine-common.i"
%include "engine-deprecated.h"
%include "qoflog.h"

%inline %{
static const GncGUID * gncPriceGetGUID(GNCPrice *x)
Expand Down Expand Up @@ -325,6 +327,8 @@ void qof_book_set_string_option(QofBook* book, const char* opt_name, const char*
SET_ENUM("QOF-COMPARE-CONTAINS");
SET_ENUM("QOF-COMPARE-NCONTAINS");

SET_ENUM("QOF-LOG-DEBUG"); /* errors out */

SET_ENUM("QOF-NUMERIC-MATCH-ANY");
SET_ENUM("QOF-NUMERIC-MATCH-CREDIT");
SET_ENUM("QOF-NUMERIC-MATCH-DEBIT");
Expand Down
2 changes: 1 addition & 1 deletion libgnucash/engine/qoflog.h
Expand Up @@ -104,7 +104,7 @@ extern "C"
_(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \
_(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG)

DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST)
DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST);

This comment has been minimized.

Copy link
@jralls

jralls Jul 6, 2019

C processes macros with a program called the preprocessor that runs before the compiler and replaces macros verbatim with their definition. The definition of DEFINE_ENUM already has a terminating ; so another isn't needed.

The reason you got the error from engine.i is that the %include directive doesn't run the preprocessor and so it thought there was a syntax error. I worked around that by replacing the DEFINE_ENUM call with its expansion:

typedef enum
{
    QOF_LOG_FATAL   = G_LOG_LEVEL_ERROR,
    QOF_LOG_ERROR   = G_LOG_LEVEL_CRITICAL,
    QOF_LOG_WARNING = G_LOG_LEVEL_WARNING,
    QOF_LOG_MESSAGE = G_LOG_LEVEL_MESSAGE,
    QOF_LOG_INFO    = G_LOG_LEVEL_INFO,
    QOF_LOG_DEBUG   = G_LOG_LEVEL_DEBUG
}QofLogLevel;

This change adds a dependency on gncmod-engine to utilities.scm, so

--- a/libgnucash/scm/CMakeLists.txt
+++ b/libgnucash/scm/CMakeLists.txt
@@ -1,6 +1,6 @@
 add_subdirectory(test)

-set(GUILE_DEPENDS      scm-core-utils scm-gnc-module)
+set(GUILE_DEPENDS      scm-core-utils scm-gnc-module gncmod-engine)

That leaves one problem:

    70:8  2 (gnc:debug "stdrpt-dir=" "/Users/john/Development/Gnuca?")
In unknown file:
           1 (qof-log-check "gnc" 128)
In ice-9/boot-9.scm:
   752:25  0 (dispatch-exception _ _ _)

ice-9/boot-9.scm:752:25: In procedure dispatch-exception:
In procedure qof-log-check: Wrong type argument in position 1: "gnc"

Because swig is converting

gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level);

into

#define FUNC_NAME "qof-log-check"
  QofLogModule arg1 ;
  QofLogLevel arg2 ;
  QofLogModule *argp1 ;
  SCM gswig_result;
  SWIGUNUSED int gswig_list_p = 0;
  gboolean result;

  {
    argp1 = (QofLogModule *)SWIG_MustGetPtr(s_0, SWIGTYPE_p_QofLogModule, 1, 0);
    arg1 = *argp1;
  }
  {
    arg2 = (QofLogLevel) scm_to_int(s_1);
  }
  result = qof_log_check(arg1,arg2);
  gswig_result = result ? SCM_BOOL_T : SCM_BOOL_F;

  return gswig_result;
#undef FUNC_NAME
}

QofLogModule is type deffed as const gchar*, so Swig expects to be passed a char** instead of a char*. That took a little studying to figure out, but here's the fix:

--- a/libgnucash/engine/engine.i
+++ b/libgnucash/engine/engine.i
@@ -83,6 +83,18 @@ engine-common.i */

 %include "engine-common.i"
 %include "engine-deprecated.h"
+
+#if defined(SWIGGUILE)
+%ignore QofLogModule;
+%typemap(in) QofLogModule {
+     $1 = (const char *)SWIG_scm2str($input);
+ }
+
+%typemap(freearg) QofLogModule {
+    SWIG_free((char*)$1);
+ }
+
+#endif
 %include "qoflog.h"

const char* qof_log_level_to_string(QofLogLevel lvl);
QofLogLevel qof_log_level_from_string(const char *str);
Expand Down

0 comments on commit 898a9cd

Please sign in to comment.