-// There standard t_output_helper has been changed to return a list rather
-// than a tuple, we'll replace it with the old implementation here.
-
-
-%fragment("t_output_helper","header") %{
- static PyObject* t_output_helper(PyObject* target, PyObject* o) {
- PyObject* o2;
- PyObject* o3;
-
- if (!target) {
- target = o;
- } else if (target == Py_None) {
- Py_DECREF(Py_None);
- target = o;
- } else {
- if (!PyTuple_Check(target)) {
- o2 = target;
- target = PyTuple_New(1);
- PyTuple_SetItem(target, 0, o2);
- }
- o3 = PyTuple_New(1);
- PyTuple_SetItem(o3, 0, o);
-
- o2 = target;
- target = PySequence_Concat(o2, o3);
- Py_DECREF(o2);
- Py_DECREF(o3);
+//----------------------------------------------------------------------
+
+// The standard t_output_helper has been changed to return a list rather than
+// a tuple, we'll replace it with the old implementation here. In SWIG 1.3.27
+// and earlier it is implemented as a $fragment, so it is only inserted into
+// the modules that need it. For SWIG 1.3.28+ we just need to add a -D on the
+// compile command line to turn on the tuple version of the AppendOuput
+// function.
+#if SWIG_VERSION < 0x010328
+%fragment("t_output_helper","header")
+%{
+ static PyObject* t_output_helper(PyObject* result, PyObject* obj)
+ {
+ PyObject* o2;
+ PyObject* o3;
+ if (!result) {
+ result = obj;
+ } else if (result == Py_None) {
+ Py_DECREF(result);
+ result = obj;
+ } else {
+ if (!PyTuple_Check(result)) {
+ o2 = result;
+ result = PyTuple_New(1);
+ PyTuple_SET_ITEM(result, 0, o2);
+ }
+ o3 = PyTuple_New(1);
+ PyTuple_SetItem(o3, 0, obj);
+ o2 = result;
+ result = PySequence_Concat(o2, o3);
+ Py_DECREF(o2);
+ Py_DECREF(o3);
+ }
+ return result;