]>
Commit | Line | Data |
---|---|---|
1b8c7ba6 RD |
1 | |
2 | ||
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. | |
80739955 RD |
5 | |
6 | ||
7 | %fragment("t_output_helper","header") %{ | |
8 | static PyObject* t_output_helper(PyObject* target, PyObject* o) { | |
9 | PyObject* o2; | |
10 | PyObject* o3; | |
11 | ||
12 | if (!target) { | |
13 | target = o; | |
14 | } else if (target == Py_None) { | |
15 | Py_DECREF(Py_None); | |
16 | target = o; | |
17 | } else { | |
18 | if (!PyTuple_Check(target)) { | |
19 | o2 = target; | |
20 | target = PyTuple_New(1); | |
21 | PyTuple_SetItem(target, 0, o2); | |
22 | } | |
23 | o3 = PyTuple_New(1); | |
24 | PyTuple_SetItem(o3, 0, o); | |
25 | ||
26 | o2 = target; | |
27 | target = PySequence_Concat(o2, o3); | |
28 | Py_DECREF(o2); | |
29 | Py_DECREF(o3); | |
30 | } | |
31 | return target; | |
2f9be0b1 | 32 | } |
80739955 RD |
33 | %} |
34 | ||
35 | ||
36 | ||
0190c472 RD |
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. | |
41 | // | |
0190c472 RD |
42 | |
43 | ||
44 | %fragment(SWIG_AsVal_frag(long), "header") { | |
1b8c7ba6 | 45 | SWIGINTERN int |
0190c472 RD |
46 | SWIG_AsVal(long)(PyObject* obj, long* val) |
47 | { | |
48 | if (PyNumber_Check(obj)) { | |
49 | if (val) *val = PyInt_AsLong(obj); | |
50 | return 1; | |
51 | } | |
52 | else { | |
1b8c7ba6 | 53 | SWIG_type_error("number", obj); |
0190c472 RD |
54 | } |
55 | return 0; | |
56 | } | |
57 | } | |
58 | ||
59 | ||
60 | %fragment(SWIG_AsVal_frag(unsigned long), "header", | |
61 | fragment=SWIG_AsVal_frag(long)) { | |
1b8c7ba6 | 62 | SWIGINTERN int |
0190c472 RD |
63 | SWIG_AsVal(unsigned long)(PyObject* obj, unsigned long* val) |
64 | { | |
65 | long v = 0; | |
66 | if (SWIG_AsVal_long(obj, &v) && v < 0) { | |
1b8c7ba6 | 67 | SWIG_type_error("unsigned number", obj); |
0190c472 RD |
68 | } |
69 | else if (val) | |
70 | *val = (unsigned long)v; | |
71 | return 1; | |
72 | } | |
73 | } | |
74 | ||
75 | ||
76 | %fragment(SWIG_AsVal_frag(double), "header") { | |
1b8c7ba6 | 77 | SWIGINTERN int |
0190c472 RD |
78 | SWIG_AsVal(double)(PyObject *obj, double* val) |
79 | { | |
80 | if (PyNumber_Check(obj)) { | |
81 | if (val) *val = PyFloat_AsDouble(obj); | |
82 | return 1; | |
83 | } | |
84 | else { | |
1b8c7ba6 | 85 | SWIG_type_error("number", obj); |
0190c472 RD |
86 | } |
87 | return 0; | |
88 | } | |
89 | } |