3 // There standard t_output_helper has been changed to return a list rather
4 // than a tuple, we'll replace it with the old implementation here.
7 %fragment("t_output_helper","header") %{
8 static PyObject* t_output_helper(PyObject* target, PyObject* o) {
14 } else if (target == Py_None) {
18 if (!PyTuple_Check(target)) {
20 target = PyTuple_New(1);
21 PyTuple_SetItem(target, 0, o2);
24 PyTuple_SetItem(o3, 0, o);
27 target = PySequence_Concat(o2, o3);
37 // These fragments are inserted in modules that need to convert PyObjects to
38 // integer values, my versions allow any numeric type to be used, as long as
39 // it can be converted to a PyInt. (Specifically, I allow floats where the
40 // default SWIG_AsVal_long would just raise an exception.
44 %fragment(SWIG_AsVal_frag(long), "header") {
46 SWIG_AsVal(long)(PyObject* obj, long* val)
48 if (PyNumber_Check(obj)) {
49 if (val) *val = PyInt_AsLong(obj);
53 SWIG_type_error("number", obj);
60 %fragment(SWIG_AsVal_frag(unsigned long), "header",
61 fragment=SWIG_AsVal_frag(long)) {
63 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
66 if (SWIG_AsVal_long(obj, &v) && v < 0) {
67 SWIG_type_error("unsigned number", obj);
70 *val = (unsigned long)v;
76 %fragment(SWIG_AsVal_frag(double), "header") {
78 SWIG_AsVal(double)(PyObject *obj, double* val)
80 if (PyNumber_Check(obj)) {
81 if (val) *val = PyFloat_AsDouble(obj);
85 SWIG_type_error("number", obj);