3 //----------------------------------------------------------------------
 
   5 // The standard t_output_helper has been changed to return a list rather than
 
   6 // a tuple, we'll replace it with the old implementation here.  In SWIG 1.3.27
 
   7 // and earlier it is implemented as a $fragment, so it is only inserted into
 
   8 // the modules that need it.  For SWIG 1.3.28+ we just need to add a -D on the
 
   9 // compile command line to turn on the tuple version of the AppendOuput
 
  11 #if SWIG_VERSION < 0x010328
 
  12 %fragment("t_output_helper","header")
 
  14     static PyObject* t_output_helper(PyObject* result, PyObject* obj)
 
  20         } else if (result == Py_None) {
 
  24             if (!PyTuple_Check(result)) {
 
  26                 result = PyTuple_New(1);
 
  27                 PyTuple_SET_ITEM(result, 0, o2);
 
  30             PyTuple_SetItem(o3, 0, obj);      
 
  32             result = PySequence_Concat(o2, o3); 
 
  45 //----------------------------------------------------------------------
 
  46 // These fragments are inserted in modules that need to convert PyObjects to
 
  47 // integer values, my versions allow any numeric type to be used, as long as
 
  48 // it can be converted to a PyInt.  (Specifically, I allow floats where the
 
  49 // default SWIG_AsVal_long would just raise an exception.
 
  52 #if SWIG_VERSION < 0x010328
 
  54 %fragment(SWIG_AsVal_frag(long), "header") {
 
  56 SWIG_AsVal(long)(PyObject* obj, long* val)
 
  58     if (PyNumber_Check(obj)) {
 
  59         if (val) *val = PyInt_AsLong(obj);
 
  63         SWIG_Python_TypeError("number", obj);
 
  70 %fragment(SWIG_AsVal_frag(unsigned long), "header",
 
  71           fragment=SWIG_AsVal_frag(long)) {
 
  73 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
 
  76     if (SWIG_AsVal_long(obj, &v) && v < 0) {
 
  77         SWIG_Python_TypeError("unsigned number", obj);
 
  80         *val = (unsigned long)v;
 
  86 %fragment(SWIG_AsVal_frag(double), "header") {
 
  88 SWIG_AsVal(double)(PyObject *obj, double* val)
 
  90     if (PyNumber_Check(obj)) {
 
  91         if (val) *val = PyFloat_AsDouble(obj);
 
  95         SWIG_Python_TypeError("number", obj);
 
 102 #else  // SWIG_VERSION >= 1.3.28
 
 104 %fragment(SWIG_AsVal_frag(long), "header") {
 
 106 SWIG_AsVal(long)(PyObject* obj, long* val)
 
 108     if (PyNumber_Check(obj)) {
 
 109         if (val) *val = PyInt_AsLong(obj);
 
 112     return SWIG_TypeError;
 
 117 %fragment(SWIG_AsVal_frag(unsigned long), "header",
 
 118           fragment=SWIG_AsVal_frag(long)) {
 
 120 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
 
 123     if (SWIG_AsVal_long(obj, &v) && v < 0) {
 
 124         return SWIG_TypeError;
 
 127         *val = (unsigned long)v;
 
 133 %fragment(SWIG_AsVal_frag(double), "header") {
 
 135 SWIG_AsVal(double)(PyObject *obj, double* val)
 
 137     if (PyNumber_Check(obj)) {
 
 138         if (val) *val = PyFloat_AsDouble(obj);
 
 141     return SWIG_TypeError;
 
 146 #endif // SWIG_VERSION