Skip to content

Commit 2dd627c

Browse files
authored
Merge pull request #140 from karosc/dev_update_swig
2 parents 162acf9 + 9030d7f commit 2dd627c

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

swmm-toolkit/build-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ setuptools
55
wheel
66
scikit-build
77
cmake
8-
swig == 4.0.2
8+
swig

swmm-toolkit/pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [
44
"setuptools>=42",
55
"scikit-build>=0.13",
66
"cmake>=3.21",
7-
"swig==4.0.2",
8-
"ninja==1.11.1 ; sys_platform == 'darwin'"
7+
"swig",
8+
"ninja==1.11.1 ; sys_platform == 'darwin'",
99
]
10-
build-backend = "setuptools.build_meta"
10+
build-backend = "setuptools.build_meta"

swmm-toolkit/src/swmm/toolkit/output.i

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
%include "typemaps.i"
1313
%include "cstring.i"
1414

15-
1615
/* Docstrings for module */
1716
%include "output_docs.i"
1817

@@ -28,6 +27,8 @@
2827
//%rename("%(regex:/^\w+_([a-zA-Z]+)/\L\\1/)s") "";
2928
%include "output_rename.i"
3029

30+
/* SWIG Override headers*/
31+
%include "swig_headers.i"
3132

3233
/* MARK FUNCTIONS FOR ALLOCATING AND DEALLOCATING HANDLES */
3334
%newobject SMO_init;
@@ -77,7 +78,7 @@ and return a (possibly) different pointer */
7778
for(int i=0; i<*$2; i++) {
7879
PyList_SetItem(o, i, PyFloat_FromDouble((double)temp[i]));
7980
}
80-
$result = SWIG_Python_AppendOutput($result, o);
81+
$result = SWIG_AppendOutput($result, o);
8182
SMO_freeMemory(*$1);
8283
}
8384
}
@@ -94,7 +95,7 @@ and return a (possibly) different pointer */
9495
for(int i=0; i<*$2; i++) {
9596
PyList_SetItem(o, i, PyInt_FromLong((long)temp[i]));
9697
}
97-
$result = SWIG_Python_AppendOutput($result, o);
98+
$result = SWIG_AppendOutput($result, o);
9899
SMO_freeMemory(*$1);
99100
}
100101
}

swmm-toolkit/src/swmm/toolkit/solver.i

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
%include "stats_typemaps.i";
3333

34+
/* SWIG Override headers*/
35+
%include "swig_headers.i"
3436

3537

3638
/* TYPEMAP FOR IGNORING INT ERROR CODE RETURN VALUE */
@@ -108,7 +110,7 @@
108110
for(int i=0; i<*$2; i++) {
109111
PyList_SetItem(o, i, PyFloat_FromDouble(temp$argnum[i]));
110112
}
111-
$result = SWIG_Python_AppendOutput($result, o);
113+
$result = SWIG_AppendOutput($result, o);
112114
swmm_freeMemory(*$1);
113115
}
114116
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
/*
3+
in version 4.3, swig had a breaking change. Python functions that return None
4+
no longer implicitly return void. see https://github.com/swig/swig/pull/2907
5+
and https://github.com/swig/swig/issues/2905
6+
7+
This header block reverts the change from that commit, since I cannot find a
8+
more concise way to implicitly make functions that return None just be void.
9+
10+
I think the "correct" way is to define typemap(outs) that match every function
11+
signature we have and drop the error code accordingly.
12+
*/
13+
%header %{
14+
SWIGINTERN PyObject*
15+
Custom_SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
16+
if (!result) {
17+
result = obj;
18+
} else if (result == Py_None) {
19+
SWIG_Py_DECREF(result);
20+
result = obj;
21+
} else {
22+
if (!PyList_Check(result)) {
23+
PyObject *o2 = result;
24+
result = PyList_New(1);
25+
if (result) {
26+
PyList_SET_ITEM(result, 0, o2);
27+
} else {
28+
SWIG_Py_DECREF(obj);
29+
return o2;
30+
}
31+
}
32+
PyList_Append(result,obj);
33+
SWIG_Py_DECREF(obj);
34+
}
35+
return result;
36+
}
37+
#define SWIG_Python_AppendOutput Custom_SWIG_Python_AppendOutput
38+
%}

0 commit comments

Comments
 (0)