1 // There is a bug in the standard t_output_helper, this one will replace it
5 %fragment("t_output_helper","header") %{
6 static PyObject* t_output_helper(PyObject* target, PyObject* o) {
12 } else if (target == Py_None) {
16 if (!PyTuple_Check(target)) {
18 target = PyTuple_New(1);
19 PyTuple_SetItem(target, 0, o2);
22 PyTuple_SetItem(o3, 0, o);
25 target = PySequence_Concat(o2, o3);
35 // These fragments are inserted in modules that need to convert PyObjects to
36 // integer values, my versions allow any numeric type to be used, as long as
37 // it can be converted to a PyInt. (Specifically, I allow floats where the
38 // default SWIG_AsVal_long would just raise an exception.
40 // NOTE: This file has to be %included very early in the SWIGging process as
41 // it no longer allows existing fragments to be replaced with one of the same
42 // name. So to make this work I had to bring a copy of python.swg into this
43 // project and do the %include there before most other of the standard swiglib
44 // files are %included. This may change in 1.3.23, so adjust accordingly then.
48 %fragment(SWIG_AsVal_frag(long), "header") {
51 SWIG_AsVal(long)(PyObject* obj, long* val)
53 if (PyNumber_Check(obj)) {
54 if (val) *val = PyInt_AsLong(obj);
58 PyObject* errmsg = PyString_FromFormat("Expected number, got %s",
59 obj->ob_type->tp_name);
60 PyErr_SetObject(PyExc_TypeError, errmsg);
68 %fragment(SWIG_AsVal_frag(unsigned long), "header",
69 fragment=SWIG_AsVal_frag(long)) {
72 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
75 if (SWIG_AsVal_long(obj, &v) && v < 0) {
76 PyErr_SetString(PyExc_TypeError, "negative value received for unsigned type");
80 *val = (unsigned long)v;
86 %fragment(SWIG_AsVal_frag(double), "header") {
89 SWIG_AsVal(double)(PyObject *obj, double* val)
91 if (PyNumber_Check(obj)) {
92 if (val) *val = PyFloat_AsDouble(obj);
96 PyObject* errmsg = PyString_FromFormat("Expected number, got %s",
97 obj->ob_type->tp_name);
98 PyErr_SetObject(PyExc_TypeError, errmsg);