Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion swmm-toolkit/build-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ setuptools
wheel
scikit-build
cmake
swig == 4.0.2
swig
6 changes: 3 additions & 3 deletions swmm-toolkit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = [
"setuptools>=42",
"scikit-build>=0.13",
"cmake>=3.21",
"swig==4.0.2",
"ninja==1.11.1 ; sys_platform == 'darwin'"
"swig",
"ninja==1.11.1 ; sys_platform == 'darwin'",
]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta"
7 changes: 4 additions & 3 deletions swmm-toolkit/src/swmm/toolkit/output.i
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
%include "typemaps.i"
%include "cstring.i"


/* Docstrings for module */
%include "output_docs.i"

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

/* SWIG Override headers*/
%include "swig_headers.i"

/* MARK FUNCTIONS FOR ALLOCATING AND DEALLOCATING HANDLES */
%newobject SMO_init;
Expand Down Expand Up @@ -77,7 +78,7 @@ and return a (possibly) different pointer */
for(int i=0; i<*$2; i++) {
PyList_SetItem(o, i, PyFloat_FromDouble((double)temp[i]));
}
$result = SWIG_Python_AppendOutput($result, o);
$result = SWIG_AppendOutput($result, o);
SMO_freeMemory(*$1);
}
}
Expand All @@ -94,7 +95,7 @@ and return a (possibly) different pointer */
for(int i=0; i<*$2; i++) {
PyList_SetItem(o, i, PyInt_FromLong((long)temp[i]));
}
$result = SWIG_Python_AppendOutput($result, o);
$result = SWIG_AppendOutput($result, o);
SMO_freeMemory(*$1);
}
}
Expand Down
4 changes: 3 additions & 1 deletion swmm-toolkit/src/swmm/toolkit/solver.i
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

%include "stats_typemaps.i";

/* SWIG Override headers*/
%include "swig_headers.i"


/* TYPEMAP FOR IGNORING INT ERROR CODE RETURN VALUE */
Expand Down Expand Up @@ -108,7 +110,7 @@
for(int i=0; i<*$2; i++) {
PyList_SetItem(o, i, PyFloat_FromDouble(temp$argnum[i]));
}
$result = SWIG_Python_AppendOutput($result, o);
$result = SWIG_AppendOutput($result, o);
swmm_freeMemory(*$1);
}
}
Expand Down
38 changes: 38 additions & 0 deletions swmm-toolkit/src/swmm/toolkit/swig_headers.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

/*
in version 4.3, swig had a breaking change. Python functions that return None
no longer implicitly return void. see https://github.com/swig/swig/pull/2907
and https://github.com/swig/swig/issues/2905

This header block reverts the change from that commit, since I cannot find a
more concise way to implicitly make functions that return None just be void.

I think the "correct" way is to define typemap(outs) that match every function
signature we have and drop the error code accordingly.
*/
%header %{
SWIGINTERN PyObject*
Custom_SWIG_Python_AppendOutput(PyObject* result, PyObject* obj, int is_void) {
if (!result) {
result = obj;
} else if (result == Py_None) {
SWIG_Py_DECREF(result);
result = obj;
} else {
if (!PyList_Check(result)) {
PyObject *o2 = result;
result = PyList_New(1);
if (result) {
PyList_SET_ITEM(result, 0, o2);
} else {
SWIG_Py_DECREF(obj);
return o2;
}
}
PyList_Append(result,obj);
SWIG_Py_DECREF(obj);
}
return result;
}
#define SWIG_Python_AppendOutput Custom_SWIG_Python_AppendOutput
%}
Loading