Skip to content

Commit

Permalink
Fix python bindings build with Swig-4.3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
jralls committed Dec 26, 2024
1 parent 6531d3e commit 85084e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bindings/python/time64.i
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
$1 = &secs;
}

#ifdef HAVE_SWIG_APPENDOUTPUT
#define SWIG_APPENDOUTPUT(res, func) SWIG_AppendOutput(res, func)
#else
#define SWIG_APPENDOUTPUT(res, func) SWIG_Python_AppendOutput(res, func)
#endif

%typemap(argout) time64 *date (time64 secs) {
PyDateTime_IMPORT;
PyObject *tp;
Expand All @@ -148,9 +154,8 @@
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);
} else $result = SWIG_Python_AppendOutput($result, Py_None);
$result = SWIG_APPENDOUTPUT($result, tp);
} else $result = SWIG_APPENDOUTPUT($result, Py_None);
}

%apply time64 *date { time64 *last_date };
Expand Down
6 changes: 6 additions & 0 deletions common/cmake_modules/GncAddSwigCommand.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ macro (gnc_add_swig_python_command _target _out_var _py_out_var _output _py_outp
)

set (PYTHON_SWIG_FLAGS ${DEFAULT_SWIG_PYTHON_FLAGS})

if (SWIG_VERSION VERSION_GREATER_EQUAL "4.3.0")
list(APPEND PYTHON_SWIG_FLAGS
-DHAVE_SWIG_APPENDOUTPUT=1)
endif()

foreach (dir ${DEFAULT_SWIG_PYTHON_C_INCLUDES} ${_include_dirs})
list (APPEND PYTHON_SWIG_FLAGS "-I${dir}")
endforeach (dir)
Expand Down

0 comments on commit 85084e7

Please sign in to comment.