deal with functions returning values through arguments

pull/484/head
c-holtermann 7 years ago
parent 445ff7e6c9
commit 79decfb754

@ -69,6 +69,12 @@
// stack. (SWIG will name the variables ts1, ts2, ts3...)
//
// Mark Jenkins <mark@parit.ca>
//
// as far as I can see all occurences of pointers to time64 are now covered
// by the named typemaps below (2019-04)
//
// Christoph Holtermann <mail@c-holtermann.net>
%typemap(in) time64 * (time64 secs) {
PyDateTime_IMPORT;
@ -92,8 +98,9 @@
}
}
// A typemap for converting time64 values returned from functions to
// python dates. Note that we can't use Python DateTime's fromtimestamp function because it relies upon libc's localtime. Note also that while we create times with timegm we retrieve it with localtime
/* A typemap for converting time64 values returned from functions to
python dates. Note that we can't use Python DateTime's fromtimestamp function because it relies upon libc's
localtime. Note also that while we create times with timegm we retrieve it with localtime */
%typemap(out) time64 {
if ($1 == INT64_MAX) {
$result = Py_None;
@ -106,3 +113,35 @@
t.tm_sec, 0);
}
}
// functions using a pointer to time64 to return data
// these are named typemaps focussing for
//
// gboolean qof_query_date_predicate_get_date (const QofQueryPredData *pd, time64 *date)
// gboolean xaccAccountGetReconcileLastDate (const Account *acc, time64 *last_date)
// gboolean xaccAccountGetReconcilePostponeDate (const Account *acc, time64 *postpone_date)
//
// python functions return a list where the first item is the boolean return value and
// the second item is a datetime object. This could be reduced to only returning a date or
// null
//
// the modifiable argument is omitted in python function call
%typemap(in, numinputs=0) time64 *date (time64 secs) {
$1 = &secs;
}
%typemap(argout) time64 *date (time64 secs) {
PyDateTime_IMPORT;
PyObject *tp;
struct tm t;
gnc_localtime_r($1, &t);
tp = PyDateTime_FromDateAndTime(t.tm_year + 1900, t.tm_mon + 1,
t.tm_mday, t.tm_hour, t.tm_min,
t.tm_sec, 0);
$result = SWIG_Python_AppendOutput($result, tp);
}
%apply time64 *date { time64 *last_date };
%apply time64 *date { time64 *postpone_date };

Loading…
Cancel
Save