2010-12-17 14:36:40 -06:00
|
|
|
/** @file
|
2010-12-27 09:36:15 -06:00
|
|
|
@brief interface file for SWIG, used by python-bindings and scheme/guile.
|
|
|
|
@addtogroup python_bindings
|
2010-12-17 14:36:40 -06:00
|
|
|
*/
|
2015-09-29 14:08:48 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License*
|
|
|
|
* along with this program; if not, contact: *
|
|
|
|
* *
|
|
|
|
* Free Software Foundation Voice: +1-617-542-5942 *
|
|
|
|
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
|
|
|
* *
|
|
|
|
\********************************************************************/
|
2017-12-23 17:40:01 -06:00
|
|
|
%include "constraints.i"
|
2015-09-29 14:08:48 -05:00
|
|
|
|
2017-06-03 10:06:09 -05:00
|
|
|
typedef void * gpointer; // Not sure why SWIG doesn't figure this out.
|
|
|
|
%typemap(newfree) gchar * "g_free($1);"
|
|
|
|
|
|
|
|
#if defined(SWIGGUILE)
|
2010-12-17 14:36:40 -06:00
|
|
|
|
2006-10-15 22:35:56 -05:00
|
|
|
typedef int gint;
|
2012-12-01 16:44:31 -06:00
|
|
|
typedef gint64 time64;
|
2006-10-15 22:35:56 -05:00
|
|
|
typedef unsigned int guint;
|
2006-11-08 14:50:45 -06:00
|
|
|
typedef double gdouble;
|
2008-07-07 16:11:02 -05:00
|
|
|
typedef float gfloat;
|
|
|
|
typedef char gchar;
|
|
|
|
|
2006-11-13 20:10:14 -06:00
|
|
|
%typemap (out) char * {
|
2012-12-21 03:19:41 -06:00
|
|
|
$result = SCM_UNSPECIFIED;
|
2012-12-15 11:59:14 -06:00
|
|
|
if ($1) {
|
2013-12-13 14:21:41 -06:00
|
|
|
$result = scm_from_utf8_string((const char *)$1);
|
2012-12-15 11:59:14 -06:00
|
|
|
}
|
|
|
|
if (!$1 || !scm_is_true($result)) {
|
2012-12-15 11:58:58 -06:00
|
|
|
$result = scm_c_make_string(0, SCM_UNDEFINED);
|
2006-11-13 20:10:14 -06:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 22:35:56 -05:00
|
|
|
%typemap(in) GNCPrintAmountInfo "$1 = gnc_scm2printinfo($input);"
|
|
|
|
%typemap(out) GNCPrintAmountInfo "$result = gnc_printinfo2scm($1);"
|
|
|
|
|
2009-12-31 08:41:12 -06:00
|
|
|
%typemap(in) gboolean "$1 = scm_is_true($input) ? TRUE : FALSE;"
|
2008-07-07 16:11:02 -05:00
|
|
|
%typemap(out) gboolean "$result = $1 ? SCM_BOOL_T : SCM_BOOL_F;"
|
|
|
|
|
2017-11-21 11:36:36 -06:00
|
|
|
%typemap(in) GDate "$1 = gnc_time64_to_GDate($input);"
|
2010-09-01 11:23:21 -05:00
|
|
|
|
2010-03-27 16:01:21 -05:00
|
|
|
%typemap(in) GncGUID "$1 = gnc_scm2guid($input);"
|
|
|
|
%typemap(out) GncGUID "$result = gnc_guid2scm($1);"
|
|
|
|
%typemap(in) GncGUID * (GncGUID g) " g = gnc_scm2guid($input); $1 = &g; "
|
|
|
|
%typemap(out) GncGUID * " $result = ($1) ? gnc_guid2scm(*($1)): SCM_BOOL_F; "
|
2008-07-07 16:11:02 -05:00
|
|
|
|
|
|
|
%typemap(in) gnc_numeric "$1 = gnc_scm_to_numeric($input);"
|
|
|
|
%typemap(out) gnc_numeric "$result = gnc_numeric_to_scm($1);"
|
|
|
|
|
2012-12-15 13:15:14 -06:00
|
|
|
%typemap(in) gint64 " $1 = scm_to_int64($input); "
|
|
|
|
%typemap(out) gint64 " $result = scm_from_int64($1); "
|
2006-10-15 22:35:56 -05:00
|
|
|
|
2016-12-11 17:23:55 -06:00
|
|
|
%typemap(in) time64 " $1 = scm_to_int64($input); "
|
|
|
|
%typemap(out) time64 " $result = scm_from_int64($1); "
|
|
|
|
%typemap(in) time64 * (time64 t) "t = scm_to_int64($input); $1 = &t;"
|
|
|
|
%typemap(out) time64 * " $result = ($1) ? scm_from_int64(*($1)) : SCM_BOOL_F; "
|
|
|
|
|
2017-04-04 01:23:44 -05:00
|
|
|
%typemap(in) struct tm * (struct tm t) {
|
2016-12-11 17:23:55 -06:00
|
|
|
SCM tm = $input;
|
2017-04-04 01:23:44 -05:00
|
|
|
SCM zone;
|
|
|
|
t.tm_sec = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 0));
|
|
|
|
t.tm_min = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 1));
|
|
|
|
t.tm_hour = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 2));
|
|
|
|
t.tm_mday = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 3));
|
|
|
|
t.tm_mon = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 4));
|
|
|
|
t.tm_year = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 5));
|
|
|
|
t.tm_wday = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 6));
|
|
|
|
t.tm_yday = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 7));
|
|
|
|
t.tm_isdst = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 8));
|
|
|
|
%#ifdef HAVE_STRUCT_TM_GMTOFF
|
|
|
|
t.tm_gmtoff = scm_to_int(SCM_SIMPLE_VECTOR_REF(tm, 9));
|
|
|
|
zone = SCM_SIMPLE_VECTOR_REF(tm, 10);
|
|
|
|
t.tm_zone = SCM_UNBNDP(zone) ? NULL : scm_to_locale_string(zone);
|
|
|
|
%#endif
|
2016-12-11 17:23:55 -06:00
|
|
|
$1 = &t;
|
|
|
|
}
|
|
|
|
|
|
|
|
%typemap(out) struct tm * {
|
|
|
|
SCM tm = scm_c_make_vector(11, SCM_UNDEFINED);
|
|
|
|
struct tm* t = $1;
|
2017-12-23 17:40:01 -06:00
|
|
|
if (t != NULL)
|
|
|
|
{
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 0, scm_from_int(t->tm_sec));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 1, scm_from_int(t->tm_min));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 2, scm_from_int(t->tm_hour));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 3, scm_from_int(t->tm_mday));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 4, scm_from_int(t->tm_mon));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 5, scm_from_int(t->tm_year));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 6, scm_from_int(t->tm_wday));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 7, scm_from_int(t->tm_yday));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 8, scm_from_int(t->tm_isdst));
|
2017-04-04 01:23:44 -05:00
|
|
|
%#ifdef HAVE_STRUCT_TM_GMTOFF
|
2017-12-23 17:40:01 -06:00
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(t->tm_gmtoff));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string(t->tm_zone?t->tm_zone:"Unset"));
|
2017-04-04 01:23:44 -05:00
|
|
|
%#else
|
2017-12-23 17:40:01 -06:00
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(0));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string("GMT"));
|
2017-04-04 01:23:44 -05:00
|
|
|
%#endif
|
2017-12-23 17:40:01 -06:00
|
|
|
}
|
2016-12-11 17:23:55 -06:00
|
|
|
$result = tm;
|
|
|
|
}
|
2017-04-04 01:23:44 -05:00
|
|
|
|
|
|
|
%typemap(newfree) struct tm * "gnc_tm_free($1);"
|
|
|
|
|
|
|
|
%typemap(argout) struct tm * {
|
|
|
|
struct tm* t = $1;
|
|
|
|
SCM tm = $input;
|
2017-12-23 17:40:01 -06:00
|
|
|
if (t == NULL)
|
|
|
|
{
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 0, scm_from_int(t->tm_sec));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 1, scm_from_int(t->tm_min));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 2, scm_from_int(t->tm_hour));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 3, scm_from_int(t->tm_mday));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 4, scm_from_int(t->tm_mon));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 5, scm_from_int(t->tm_year));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 6, scm_from_int(t->tm_wday));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 7, scm_from_int(t->tm_yday));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 8, scm_from_int(t->tm_isdst));
|
2017-04-04 01:23:44 -05:00
|
|
|
%#ifdef HAVE_STRUCT_TM_GMTOFF
|
2017-12-23 17:40:01 -06:00
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(t->tm_gmtoff));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string(t->tm_zone?t->tm_zone:"Unset"));
|
2017-04-04 01:23:44 -05:00
|
|
|
%#else
|
2017-12-23 17:40:01 -06:00
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 9, scm_from_long(0));
|
|
|
|
SCM_SIMPLE_VECTOR_SET(tm, 10, scm_from_locale_string("GMT"));
|
2017-04-04 01:23:44 -05:00
|
|
|
%#endif
|
2017-12-23 17:40:01 -06:00
|
|
|
}
|
2017-04-04 01:23:44 -05:00
|
|
|
}
|
2016-12-11 17:23:55 -06:00
|
|
|
|
2006-10-15 22:35:56 -05:00
|
|
|
%define GLIST_HELPER_INOUT(ListType, ElemSwigType)
|
|
|
|
%typemap(in) ListType * {
|
|
|
|
SCM list = $input;
|
|
|
|
GList *c_list = NULL;
|
|
|
|
|
2009-12-31 08:41:12 -06:00
|
|
|
while (!scm_is_null(list)) {
|
2007-10-06 18:05:16 -05:00
|
|
|
void *p;
|
2006-10-15 22:35:56 -05:00
|
|
|
|
|
|
|
SCM p_scm = SCM_CAR(list);
|
2009-12-31 08:41:12 -06:00
|
|
|
if (scm_is_false(p_scm) || scm_is_null(p_scm))
|
2006-10-15 22:35:56 -05:00
|
|
|
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
|
2008-07-07 16:11:02 -05:00
|
|
|
#elif defined(SWIGPYTHON) /* Typemaps for Python */
|
2017-06-03 10:06:09 -05:00
|
|
|
|
|
|
|
%import "glib.h"
|
2017-06-03 11:51:54 -05:00
|
|
|
%include <stdint.i>
|
|
|
|
|
|
|
|
%apply int { gint };
|
|
|
|
%apply unsigned int { guint };
|
|
|
|
%apply long { glong };
|
2018-09-18 12:21:09 -05:00
|
|
|
%apply int32_t { gint32 };
|
2017-06-03 11:51:54 -05:00
|
|
|
%apply int64_t { gint64 };
|
|
|
|
%apply unsigned long { gulong };
|
|
|
|
%apply uint64_t { guint64 };
|
|
|
|
%apply double { gdouble };
|
|
|
|
%apply char* { gchar* };
|
2008-07-07 16:11:02 -05:00
|
|
|
|
|
|
|
%typemap(in) gboolean {
|
|
|
|
if ($input == Py_True)
|
|
|
|
$1 = TRUE;
|
|
|
|
else if ($input == Py_False)
|
|
|
|
$1 = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(
|
|
|
|
PyExc_ValueError,
|
|
|
|
"Python object passed to a gboolean argument was not True "
|
|
|
|
"or False" );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
%typemap(out) gboolean {
|
|
|
|
if ($1 == TRUE)
|
|
|
|
{
|
|
|
|
$result = Py_True;
|
2011-11-20 23:43:29 -06:00
|
|
|
Py_INCREF($result);
|
2008-07-07 16:11:02 -05:00
|
|
|
}
|
|
|
|
else if ($1 == FALSE)
|
|
|
|
{
|
|
|
|
$result = Py_False;
|
2011-11-20 23:43:29 -06:00
|
|
|
Py_INCREF($result);
|
2008-07-07 16:11:02 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(
|
|
|
|
PyExc_ValueError,
|
|
|
|
"function returning gboolean returned a value that wasn't "
|
|
|
|
"TRUE or FALSE.");
|
2010-12-08 05:52:18 -06:00
|
|
|
return NULL;
|
2008-07-07 16:11:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-07 08:06:22 -05:00
|
|
|
%typemap(in) QofIdType {
|
|
|
|
if (PyUnicode_Check($input)) {
|
|
|
|
$1 = PyUnicode_AsUTF8($input);
|
|
|
|
} else if (PyBytes_Check($input)) {
|
|
|
|
$1 = PyBytes_AsString($input);
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "not a string or bytes object");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
%typemap(in) QofIdTypeConst {
|
|
|
|
if (PyUnicode_Check($input)) {
|
|
|
|
$1 = PyUnicode_AsUTF8($input);
|
|
|
|
} else if (PyBytes_Check($input)) {
|
|
|
|
$1 = PyBytes_AsString($input);
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "not a string or bytes object");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:20:15 -05:00
|
|
|
%typemap(in) GSList *, QofQueryParamList * {
|
|
|
|
$1 = NULL;
|
|
|
|
/* Check if is a list */
|
|
|
|
if (PyList_Check($input)) {
|
|
|
|
int i;
|
|
|
|
int size = PyList_Size($input);
|
|
|
|
for (i = size-1; i >= 0; i--) {
|
|
|
|
PyObject *o = PyList_GetItem($input, i);
|
2018-09-18 12:21:09 -05:00
|
|
|
if (PyUnicode_Check(o)) {
|
2018-09-18 17:07:47 -05:00
|
|
|
/* There's no way to preserve constness in GSList items. */
|
|
|
|
$1 = g_slist_prepend($1, (char*)PyUnicode_AsUTF8(PyList_GetItem($input, i)));
|
2011-08-23 16:20:15 -05:00
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "list must contain strings");
|
|
|
|
g_slist_free($1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
PyErr_SetString(PyExc_TypeError, "not a list");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-04 16:11:11 -05:00
|
|
|
%typemap(out) GList *, CommodityList *, SplitList *, AccountList *, LotList *,
|
2011-01-20 14:14:51 -06:00
|
|
|
MonetaryList *, PriceList *, EntryList * {
|
2008-07-07 16:11:02 -05:00
|
|
|
guint i;
|
|
|
|
gpointer data;
|
|
|
|
PyObject *list = PyList_New(0);
|
|
|
|
for (i = 0; i < g_list_length($1); i++)
|
|
|
|
{
|
2010-12-08 05:52:18 -06:00
|
|
|
data = g_list_nth_data($1, i);
|
2008-07-07 16:11:02 -05:00
|
|
|
if (GNC_IS_ACCOUNT(data))
|
2010-12-08 05:52:18 -06:00
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_Account, 0));
|
2008-07-07 16:11:02 -05:00
|
|
|
else if (GNC_IS_SPLIT(data))
|
2010-12-08 05:52:18 -06:00
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_Split, 0));
|
2008-07-07 16:11:02 -05:00
|
|
|
else if (GNC_IS_TRANSACTION(data))
|
2010-12-08 05:52:18 -06:00
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_Transaction, 0));
|
2008-07-07 16:11:02 -05:00
|
|
|
else if (GNC_IS_COMMODITY(data))
|
2010-12-08 05:52:18 -06:00
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_gnc_commodity, 0));
|
2010-12-15 09:17:59 -06:00
|
|
|
else if (GNC_IS_COMMODITY_NAMESPACE(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_gnc_commodity_namespace, 0));
|
2008-07-07 16:11:02 -05:00
|
|
|
else if (GNC_IS_LOT(data))
|
2010-08-04 16:11:11 -05:00
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_GNCLot, 0));
|
2010-12-08 05:52:18 -06:00
|
|
|
else if (GNC_IS_PRICE(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_GNCPrice, 0));
|
2011-08-23 16:20:15 -05:00
|
|
|
else if (GNC_IS_INVOICE(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncInvoice, 0));
|
2011-01-20 14:14:51 -06:00
|
|
|
else if (GNC_IS_ENTRY(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncEntry, 0));
|
2011-09-28 08:29:19 -05:00
|
|
|
else if (GNC_IS_CUSTOMER(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncCustomer, 0));
|
|
|
|
else if (GNC_IS_VENDOR(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncVendor, 0));
|
2011-09-29 06:00:06 -05:00
|
|
|
else if (GNC_IS_EMPLOYEE(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncEmployee, 0));
|
|
|
|
else if (GNC_IS_JOB(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncJob, 0));
|
2013-02-22 12:15:28 -06:00
|
|
|
else if (GNC_IS_TAXTABLE(data))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p__gncTaxTable, 0));
|
2010-12-08 05:52:18 -06:00
|
|
|
else if ($1_descriptor == $descriptor(MonetaryList *))
|
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, $descriptor(gnc_monetary *), 0));
|
2008-07-07 16:11:02 -05:00
|
|
|
else
|
2010-12-08 05:52:18 -06:00
|
|
|
PyList_Append(list, SWIG_NewPointerObj(data, SWIGTYPE_p_void, 0));
|
2008-07-07 16:11:02 -05:00
|
|
|
}
|
|
|
|
$result = list;
|
|
|
|
}
|
|
|
|
#endif
|