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 in to
 
   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 this version of the AppendOuput function.
 
  10 #if SWIG_VERSION < 0x010328
 
  11 %fragment("t_output_helper","header")
 
  13     static PyObject* t_output_helper(PyObject* result, PyObject* obj)
 
  19         } else if (result == Py_None) {
 
  23             if (!PyTuple_Check(result)) {
 
  25                 result = PyTuple_New(1);
 
  26                 PyTuple_SET_ITEM(result, 0, o2);
 
  29             PyTuple_SetItem(o3, 0, obj);      
 
  31             result = PySequence_Concat(o2, o3); 
 
  44 //----------------------------------------------------------------------
 
  45 // These fragments are inserted in modules that need to convert PyObjects to
 
  46 // integer values, my versions allow any numeric type to be used, as long as
 
  47 // it can be converted to a PyInt.  (Specifically, I allow floats where the
 
  48 // default SWIG_AsVal_long would just raise an exception.
 
  51 #if SWIG_VERSION < 0x010328
 
  53 %fragment(SWIG_AsVal_frag(long), "header") {
 
  55 SWIG_AsVal(long)(PyObject* obj, long* val)
 
  57     if (PyNumber_Check(obj)) {
 
  58         if (val) *val = PyInt_AsLong(obj);
 
  62         SWIG_Python_TypeError("number", obj);
 
  69 %fragment(SWIG_AsVal_frag(unsigned long), "header",
 
  70           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         SWIG_Python_TypeError("unsigned number", obj);
 
  79         *val = (unsigned long)v;
 
  85 %fragment(SWIG_AsVal_frag(double), "header") {
 
  87 SWIG_AsVal(double)(PyObject *obj, double* val)
 
  89     if (PyNumber_Check(obj)) {
 
  90         if (val) *val = PyFloat_AsDouble(obj);
 
  94         SWIG_Python_TypeError("number", obj);
 
 101 #else  // SWIG_VERSION >= 1.3.28
 
 103 %fragment(SWIG_AsVal_frag(long), "header") {
 
 105 SWIG_AsVal(long)(PyObject* obj, long* val)
 
 107     if (PyNumber_Check(obj)) {
 
 108         if (val) *val = PyInt_AsLong(obj);
 
 111     return SWIG_TypeError;
 
 116 %fragment(SWIG_AsVal_frag(unsigned long), "header",
 
 117           fragment=SWIG_AsVal_frag(long)) {
 
 119 SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val)
 
 122     if (SWIG_AsVal_long(obj, &v) && v < 0) {
 
 123         return SWIG_TypeError;
 
 126         *val = (unsigned long)v;
 
 132 %fragment(SWIG_AsVal_frag(double), "header") {
 
 134 SWIG_AsVal(double)(PyObject *obj, double* val)
 
 136     if (PyNumber_Check(obj)) {
 
 137         if (val) *val = PyFloat_AsDouble(obj);
 
 140     return SWIG_TypeError;
 
 145 #endif // SWIG_VERSION