Skip to content

Commit 65deb50

Browse files
authored
Fix extension re-import check for swig v4.4.0 (#2992)
Extension initialization changed there. `%init` code is now executed each time the extension is executed, not only during the initial import. Fixes #2991.
1 parent 67f3ed6 commit 65deb50

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

swig/modelname.template.i

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ using namespace amici;
5757
// store the time a module was imported
5858
%{
5959
#include <chrono>
60-
static std::chrono::time_point<std::chrono::system_clock> _module_import_time;
60+
static std::chrono::time_point<std::chrono::system_clock> _module_import_time = std::chrono::system_clock::now();
6161

6262
static double _get_import_time() {
6363
auto epoch = _module_import_time.time_since_epoch();
@@ -68,7 +68,9 @@ static double _get_import_time() {
6868
static double _get_import_time();
6969

7070
%init %{
71-
_module_import_time = std::chrono::system_clock::now();
71+
// NOTE: from SWIG 4.4.0 onwards, %init code is executed every time the
72+
// module is executed - not only on first import
73+
// This code ends up in `SWIG_mod_exec`.
7274
%}
7375

7476

0 commit comments

Comments
 (0)